Research CommonsResearch Commons
cpptensor/Backends & ISA

Backends & ISA

How cpptensor selects generic, AVX2, or AVX-512 kernels at runtime, and how OpenBLAS and CUDA fit in.

cpptensor builds ISA-specialized kernels at compile time and chooses among them at runtime, with safe fallbacks. Linear algebra can additionally route through OpenBLAS, and there's early, opt-in CUDA support.

Runtime ISA dispatch

The kernel registry holds generic, AVX2, and AVX-512 implementations. On first use, public ops initialize the registry; at runtime the dispatcher:

  • validates CPU feature bits and OS XSAVE state before selecting AVX2 or AVX-512 kernels, and
  • safely falls back to lower ISA levels when a feature isn't available.

You can hint the desired ISA via the CPPGRAD_CPU_ISA environment variable, bounded by host capability:

ValueBehavior
avx512AVX-512 only when fully supported; otherwise AVX2/generic fallback.
avx2AVX2 only when supported; otherwise generic fallback.
otherGeneric.

Build-time ISA flags

BUILD_AVX2 and BUILD_AVX512 control whether the ISA-specialized object code is compiled. They auto-detect sensible defaults; forcing them ON for an unsupported target fails fast at configure time.

OpenBLAS

USE_OPENBLAS (default ON) enables BLAS-backed matmul / dot when OpenBLAS is found. svd and eig require OpenBLAS/LAPACK support.

CUDA (early)

BUILD_CUDA (default OFF) enables early CUDA support and requires a CUDA toolkit discoverable by CMake. On Apple platforms it is automatically forced OFF.

Lazy initialization

Public tensor ops lazily initialize the kernel registry on first use, so a fresh process can call A + B, sum(), or matmul() without calling initialize_kernels() manually — though that remains available as an optional explicit warm-up step.

Next

See Build options for the complete set of toggles, including sanitizers and warning policy.