Serialization
AADC provides boost serialization support for saving and loading computational kernels to and from persistent storage, or across network boundaries. This enables workflow optimization through kernel caching, deployment scenarios where kernels are compiled once and used multiple times, and distributed computing architectures.
Overview
The serialization framework in AADC allows you to:
- Save compiled kernels to disk for reuse across program runs
- Load pre-compiled kernels without re-recording computational graphs
- Share kernels between different processes, systems or programming languages
- Cache expensive compilation for improved application startup times
- Deploy production systems with pre-compiled analytical models
Serializable Components
The following AADC components support serialization using Boost.Serialization:
Core Function Objects
AADCFunctions<mmType>- Complete compiled kernel with all execution codeAADCFunctionArgRegistry- Input/output argument mappings and identifiersAADCWorkSpace<mmType>- Execution workspace (values only, not compiled code)
Variable Handles
AADCArgument- Input variable referencesAADCResult- Output variable referencesAADCScalarArgument- Scalar input referencesAADCVectorArgument- Vector input referencesAADCScalarVectorArgument- Scalar vector input references
Computational Blocks
ComputeBlock- Hierarchical computational block structure- Custom
ComputeBlocksubclasses (must implement serialization methods)
Basic Serialization Example
#include <fstream>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <aadc/aadc.h>
using namespace aadc;
void saveKernel() {
typedef __m256d mmType;
AADCFunctions<mmType> kernel;
// Record your computational graph
kernel.startRecording();
idouble x(1.0), y(2.0), result;
auto x_arg = x.markAsInput();
auto y_arg = y.markAsInput();
result = x * y + sin(x);
auto result_out = result.markAsOutput();
kernel.stopRecording();
// Save kernel to file
std::ofstream ofs("kernel.dat");
boost::archive::binary_oarchive oa(ofs);
oa << kernel;
}
void loadKernel() {
typedef __m256d mmType;
AADCFunctions<mmType> kernel;
// Load kernel from file
std::ifstream ifs("kernel.dat");
boost::archive::binary_iarchive ia(ifs);
ia >> kernel;
// Use the loaded kernel immediately
auto workspace = kernel.createWorkSpace();
workspace->setVal(kernel.vArg("", 0), 3.0); // First input
workspace->setVal(kernel.vArg("", 1), 4.0); // Second input
kernel.forward(*workspace);
std::cout << "Result: " << workspace->valp(kernel.vRes("", 0))[0] << std::endl;
}Cross-Platform Considerations
Architecture Compatibility
Serialized kernels contain compiled machine code specific to the target architecture:
- AVX2 kernels (
__m256d) run on Intel Haswell+ and AMD Zen+ processors - AVX512 kernels (
__m512d) require AVX512-capable processors
Version Compatibility
AADC includes version information in serialized data to ensure compatibility. See Advanced Topics on Serialization Testing.
void checkVersionCompatibility(const AADCFunctions<mmType>& kernel) {
std::cout << "Kernel compiled with AADC version: "
<< kernel.getAADCVersion() << std::endl;
std::cout << "Header checksums: "
<< kernel.getAADCHeaderChecksums() << std::endl;
// Version checks are performed automatically during deserialization
}Performance Implications
Serialization Overhead
- File I/O time scales with kernel complexity and storage device speed
- Compression can reduce file size but increases CPU overhead
- Network transfer benefits from compressed serialization for distributed systems
Troubleshooting
Common Serialization Issues
File corruption or incomplete writes:
- Always check file operations for success
- Use atomic write operations for critical kernel files
- Implement file integrity verification
Version mismatches:
- AADC automatically detects version incompatibilities
- Maintain separate kernel caches for different AADC versions
- Document the AADC version used for each kernel
Cross-platform deployment failures:
- Verify target architecture supports the required instruction sets (AVX2/AVX512)
- Test serialization compatibility across all target platforms
- Maintain architecture-specific kernel caches when necessary