Research CommonsResearch Commons
cppgrad/Backends

Backends

cppgrad runs tensor math on ArrayFire, with room to swap in custom CUDA or OpenCL backends.

cppgrad's tensor operations are delegated to a backend. By default that backend is ArrayFire, which provides accelerated implementations across CPU, CUDA, and OpenCL devices.

ArrayFire (default)

ArrayFire supplies the underlying array storage and accelerated kernels. You can provide it in two ways:

  • Prebuilt binaries — install via your package manager or grab the ArrayFire releases.
  • Bundled source — the third_party/arrayfire submodule builds automatically as part of the CMake build.

Because ArrayFire abstracts over the device, the same cppgrad code can run on a CPU build or a GPU build depending on how ArrayFire is configured.

Swapping the backend

The backend is designed to be extensible — the goal is to let you swap ArrayFire for a custom backend (for example a hand-written CUDA or OpenCL implementation) without rewriting model code. The tensor and autograd layers sit above the backend, so they remain unchanged.

Work in progress

Custom backends are an explicit design goal of the architecture rather than a finished, documented plug-in API today. If you're experimenting with one, the ArrayFire integration is the reference to follow. Track progress on the roadmap.

Benchmarking

The repo includes a Google Benchmark setup so you can measure operations and compare backend configurations. Build the benchmark targets via CMake and run the produced binaries to profile your workload.