A High-Performance, Zero-Copy C++ Math & Tensor Library for Apple Silicon.
AeroTensor is a strictly native, dependency-free C++20 library designed from the ground up to exploit the unified memory architecture of Apple's M-series chips. By directly bridging modern C++ with Apple's Metal Performance Shaders (MPS) and the Accelerate framework, it delivers hardware-accelerated tensor computations without the overhead of heavy third-party ecosystems.
At the heart of AeroTensor is a strict Zero-Copy principle. On traditional architectures, moving data between the CPU and discrete GPUs across the PCIe bus creates a massive bottleneck. AeroTensor exploits Apple Silicon’s unified memory by ensuring both the CPU and GPU operate on the exact same physical memory allocations.
- All data resides natively in
MTLBufferobjects configured withMTLResourceStorageModeShared. - Tensors are instantly accessible by both the overarching C++ application and the Metal compute units, ensuring deterministic, latency-free synchronization.
AeroTensor imposes a strict zero third-party dependency rule for production code.
- Written in pure C++20.
- Built on foundational Apple frameworks: Accelerate for CPU-bound vectorized operations and Metal Performance Shaders (MPSGraph) for GPU-bound math processing logic.
- Exception: Uses Catch2 via CMake
FetchContentstrictly for testing infrastructure, avoiding any raw dependencies checked into the repository.
- BFloat16 First: Floating-point computations natively target
BFloat16, automatically taking advantage of hardware-acceleration vectors in modern M-series chips for superior data throughput, especially pertinent in deep learning mathematics. - Robust Abstraction: The library employs a templated N-dimensional
Tensorclass. It utilizes the PIMPL (Pointer to IMPLementation) idiom to seamlessly bridge C++ and Metal/Objective-C++ without leaking Objective-C headers into pure C++ translation units.
The library isn't just about static container abstractions; it enforces highly optimized mathematical operations:
- No Raw Loops: Our core constitution prohibits raw scalar loops for matrix operations. All linear algebraic and reduction operations are dispatched through highly optimized, hardware-specific kernels or
MPSGraph. - Compute Graph Execution: Implements a dynamic
ComputeGraphmechanism to track tensor operations and map complex equations to natively executable sequences efficiently on the GPU. - Strict Memory Management: Relies on rigorous smart pointer (
std::shared_ptr) lifecycles and custom memory handling strategies to ensure deterministic allocation and deallocation of heavy tensor states.
- Apple Silicon Mac (M1/M2/M3/M4 series)
- macOS 13.0+ (Ventura or newer recommended)
- Xcode Command Line Tools (Clang with full C++20 support)
- CMake 3.24+
# Clone the repository
git clone https://github.com/abhikumar63/AeroTensor.git
cd AeroTensor
# Generate CMake build system and build
mkdir build && cd build
cmake ..
make -j$(sysctl -n hw.ncpu)Our test suite strongly anchors on Catch2 to validate mathematical correctness, matrix multiplication (MatMul) bindings, and rigorous zero-copy assertions.
# Execute native tests
ctest --output-on-failure
# Or run the executable directly for detailed output
./tests/test_matmulWe welcome architectural enhancements, especially concerning the optimization of the MPSGraph execution contexts or extending BFloat16/Float16 standard library mathematical operators.
If contributing, please remember:
- Adhere strictly to the project constitution: Native Apple frameworks only, absolute Zero-Copy via
MTLBuffer, and C++20 standards. - Ensure Zero Objective-C++ leakage into public
include/headers. - Validate all memory barriers between CPU/GPU access steps.
Harnessing the absolute limits of bare-metal Apple hardware.