Research CommonsResearch Commons
cpptensor/Overview

cpptensor

A CPU-first C++ tensor library with runtime AVX2/AVX-512 dispatch, optional OpenBLAS acceleration, and early CUDA support.

cpptensor is a C++ tensor library focused on CPU performance. It pairs a generic implementation with build-time AVX2/AVX-512 specializations, dispatches between them at runtime based on the host CPU, and can offload linear algebra to OpenBLAS. Early CUDA support is available behind a build flag.

What you get

  • N-dimensional Tensor with views and contiguous materialization.
  • A broad op set — arithmetic, unary math, reductions, comparisons, plus reshape / transpose / concat / stack.
  • Linear algebramatmul, dot, tensordot, svd, and eig.
  • Runtime ISA dispatch — generic, AVX2, and AVX-512 kernels selected after validating CPU feature bits and OS state.
  • Lazy kernel registry — ops initialize the kernel registry on first use, so a fresh process can call A + B without manual setup.
  • Numerically careful reductionssum, mean, and dot use widened, compensated accumulation.
  • CheckpointsTensor::save / Tensor::load with a versioned binary format.
  • Tests & benchmarks — a Catch2 suite and Google Benchmark targets.

Platform support

PlatformStatus
Linux x86_64Supported / primary path.
Linux aarch64Generic CPU path; AVX2/AVX-512 auto-disabled.
macOSCPU builds expected; CUDA forced OFF.
WindowsExperimental (outside the documented conda workflow).

At a glance

#include "cpptensor/tensor/tensor.hpp"
#include "cpptensor/ops/arithmetic/add.hpp"
 
int main() {
    using namespace cpptensor;
 
    Tensor a = Tensor::full({2, 2}, 1.0f);
    Tensor b = Tensor::full({2, 2}, 2.0f);
    Tensor c = a + b;
    c.print();
}
Status

cpptensor is beta — the CPU path (generic + AVX2/AVX-512), OpenBLAS-backed linear algebra, reductions, and checkpoint I/O are validated, while CUDA support is early and off by default. See the roadmap.

Where to next