Research CommonsResearch Commons
cppgrad/Installation

Installation

Add cppgrad to your project via CMake FetchContent or a submodule, then build with ArrayFire.

cppgrad is built with CMake and depends on ArrayFire for accelerated tensor operations. You can either let CMake fetch the library, or clone it as a submodule of your project.

Requirements

  • C++17 or newer
  • CMake ≥ 3.15
  • ArrayFire — prebuilt (from your package manager or the ArrayFire releases) or built from the bundled source in third_party/arrayfire

Optional but recommended:

  • Docker — a Dockerfile is provided for CPU/GPU builds.
  • VSCode DevContainer.devcontainer/ gives you a preconfigured environment.

Add it to your build

Option 1 — FetchContent

include(FetchContent)
FetchContent_Declare(
  cppgrad
  GIT_REPOSITORY https://github.com/Research-Commons/cppgrad.git
  GIT_TAG        main
)
FetchContent_MakeAvailable(cppgrad)
 
target_link_libraries(your_target PRIVATE cppgrad)

Option 2 — Clone and build

git clone --recurse-submodules https://github.com/Research-Commons/cppgrad.git
Submodules

Use --recurse-submodules so the bundled dependencies (including ArrayFire, if you build it from source) are pulled in. If you forgot, run git submodule update --init --recursive.

Build from source

Install the system dependencies (Fedora example):

sudo dnf install \
    git cmake gcc-c++ \
    fftw-devel blas-devel lapack-devel \
    libpng-devel hdf5-devel \
    boost-devel glm-devel

Then configure and build:

cd cppgrad
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

Run an example to confirm the build:

./examples/tensor_example

Docker

docker build -t cppgrad:latest .
docker run --rm -it cppgrad:latest bash

Next

Continue to the Quickstart to train against your first computation graph.