Build the Kokkos backend for CPU, CUDA or HIP¶
The Kokkos backend selects the execution space of its installed Kokkos
library. A CPU installation (Serial or OpenMP) runs the Eigen backend’s
Cholesky, triangular solves and inverse in place on the host matrices, so
those results have the Eigen backend’s bits; Kokkos Kernels serves the
Kokkos posterior and the explicit workspace and factor objects. A CUDA
installation uses cuSOLVER and cuBLAS; a HIP installation uses rocSOLVER
and rocBLAS. Select the backend with
-Dlinalg_backend=kokkos when configuring GPRidge. The choice applies to
both GP dimer and GP-NEB calculations in that build.
The dense GP operations accept and return host Eigen matrices. On a CPU installation the host factor already lives in execution memory, so a GP model keeps no second copy. Solves, whitening and the log determinant use that Eigen factor. The log determinant is the sum of the logarithms of the factor diagonal. A failed factorization releases a device posterior together with any resident factor, so a later query does not follow a null factor. On a device installation each GP model retains an immutable physical Cholesky factor on the device across solves and variance queries. Factorization or an incremental factor update creates a new owner; clearing the training factor releases it. Queries do not compare or upload the host factor. A covariance solve uploads its right-hand side once, runs both triangular solves on the device and downloads the final solution. A variance-diagonal query downloads only the column norms. Independent models own separate workspaces.
Covariance assembly, query assembly and the compensated prediction-mean
contraction remain host operations. Query operands and returned results
still cross the device boundary. The general BackendContext operations
accept mutable Eigen factors and check an exact host witness before reuse;
replacing or modifying that supplied factor uploads it again. The stateless
dense functions copy their supplied factor for each call. Small training
sets can therefore run
faster on the CPU. The measurements in
Run GPRidge on a GPU compare complete fits and complete searches for the
separate cuSOLVER backend.
The oracle has its own device selection.
Choose compatible dependencies¶
Use Kokkos and Kokkos Kernels from matching releases, built with the same C++ compiler and execution space. GPRidge requires version 4.7 or newer; the commands below pin both dependencies to 5.2.2. Kokkos 5 requires C++20 and a supported device compiler. Check the Kokkos compiler requirements against the toolkit installed at the site.
Execution space |
C++ compiler |
Dense dependencies |
|---|---|---|
Serial or OpenMP |
supported host compiler |
Kokkos Kernels BLAS component |
CUDA |
Kokkos |
cuSOLVER and Kokkos Kernels with cuBLAS |
HIP |
|
rocSOLVER and Kokkos Kernels with rocBLAS |
The backend rejects a SYCL configuration at configure time because it has no SYCL dense factorization implementation.
Build on an allocated compute node. Load the site’s compiler and toolkit before configuring dependencies, and keep one toolchain throughout the build. The HPC guide covers allocation, storage, threads and runtime library paths. Prefer the site’s native modules or packages; the commands below describe the dependency settings when a suitable installation is not available.
Build the dependency pair¶
Download and verify the tagged Kokkos and Kokkos Kernels sources before
entering a node without network access. Set kokkos_source and
kernels_source to the two extracted source directories, and
kokkos_prefix to an owned installation prefix. Put temporary sources,
build trees and compiler caches on node-local disk; retain the installed
prefix, checksums and logs on project storage.
For a CPU installation, configure the core with the host C++ compiler:
cmake -S "$kokkos_source" -B "$kokkos_source/build" -G Ninja \
-DCMAKE_INSTALL_PREFIX="$kokkos_prefix" \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 \
-DBUILD_SHARED_LIBS=ON -DKokkos_ENABLE_SERIAL=ON
cmake --build "$kokkos_source/build" --parallel "${SLURM_CPUS_PER_TASK:-1}"
cmake --install "$kokkos_source/build"
For CUDA, add -DKokkos_ENABLE_CUDA=ON and an architecture such as
-DKokkos_ARCH_AMPERE80=ON for an A100. Set
-DCMAKE_CXX_COMPILER”$kokkos_source/bin/nvcc_wrapper”= and
NVCC_WRAPPER_DEFAULT_COMPILER to the supported host compiler. For HIP,
use -DCMAKE_CXX_COMPILER=hipcc, -DKokkos_ENABLE_HIP=ON and the
architecture of the allocated GPU. A MI250X uses
-DKokkos_ARCH_AMD_GFX90A=ON in the pinned release. Set the architecture
explicitly when configuring without a visible GPU.
Build Kokkos Kernels against that prefix. The CPU configuration is:
cmake -S "$kernels_source" -B "$kernels_source/build" -G Ninja \
-DCMAKE_PREFIX_PATH="$kokkos_prefix" \
-DCMAKE_INSTALL_PREFIX="$kokkos_prefix" \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 \
-DBUILD_SHARED_LIBS=ON -DKokkosKernels_ENABLE_ALL_COMPONENTS=OFF \
-DKokkosKernels_ENABLE_COMPONENT_BLAS=ON \
-DKokkosKernels_INST_DOUBLE=ON -DKokkosKernels_INST_FLOAT=OFF \
-DKokkosKernels_INST_COMPLEX_FLOAT=OFF \
-DKokkosKernels_INST_COMPLEX_DOUBLE=OFF \
-DKokkosKernels_INST_LAYOUTRIGHT=OFF
cmake --build "$kernels_source/build" --parallel "${SLURM_CPUS_PER_TASK:-1}"
cmake --install "$kernels_source/build"
Use the same device compiler for this step. CUDA also needs
-DKokkosKernels_ENABLE_TPL_CUBLAS=ON; HIP needs
-DKokkosKernels_ENABLE_TPL_ROCBLAS=ON. The factorization bridge links
cuSOLVER or rocSOLVER directly. The Kokkos Kernels BLAS component is
sufficient for this backend.
Configure and check GPRidge¶
From the GPRidge checkout, extend CMAKE_PREFIX_PATH with the dependency
prefix. A CUDA build uses the host C++ compiler for GP code and Meson’s
CUDA compiler for the device implementation. Set CXX to the supported
host compiler and select nvcc in a Meson native file. Both compilers must
use the same host toolchain. Meson takes the device architecture from
Kokkos_CUDA_ARCHITECTURES in the installed Kokkos configuration.
export CXX=$(command -v g++)
cat > kokkos-cuda.ini <<EOF
[binaries]
cuda = ['$(command -v nvcc)', '-ccbin', '$CXX']
EOF
Pass --native-file=kokkos-cuda.ini to meson setup for CUDA.
The compiler entry can also carry toolchain flags such as
-Xcompiler–sysroot=/path/to/sysroot= on compute nodes that use a
separate development sysroot.
CUDA driver stubs supply link symbols when building on a CPU node. The
GPU allocation needs the installed NVIDIA driver at runtime. GPRidge uses
RUNPATH on supported Linux linkers so the allocation’s library path can
select that driver ahead of a toolkit stub directory. Check the
libcuda.so.1 entry of ldd on the built executable inside the GPU
allocation: it must resolve to the installed driver.
The HIP build uses CXX=hipcc. Its implementation uses the same compiled
host interface; the configured Kokkos execution space selects HIP. The
GPRidge library owns the device templates, so its callers include the
ordinary host C++ interface.
Eigen supplies host matrix storage and arithmetic. The build defines
EIGEN_NO_CUDA and EIGEN_NO_HIP for this backend; Kokkos views and the
native solver libraries supply its device operations.
Configure the library and run its numerical and runtime-ownership checks:
export CMAKE_PREFIX_PATH="$kokkos_prefix${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}"
meson setup build -Dlinalg_backend=kokkos -Dwith_tests=true
meson compile -C build test_eigenbackend test_kokkos_backend \
test_kokkos_resident test_kokkos_lifetime test_kokkos_resident_lifetime
meson test -C build --print-errorlogs \
test_eigenbackend test_kokkos_backend test_kokkos_resident \
test_kokkos_lifetime test_kokkos_resident_lifetime
test_eigenbackend exercises the selected backend despite its name.
The checks cover factor reconstruction, triangular solves, inverse,
physical row scaling and rejection of indefinite covariance matrices.
test_kokkos_lifetime prints execution_space=Serial, execution_space=Cuda
or execution_space=HIP
and checks that an externally initialized runtime stays under its
caller’s ownership. The resident tests check immutable snapshots, factor
replacement, transfer counts and queries after external finalization.
Run the GPU tests inside a scheduler allocation with
a GPU assigned to the test process.
Numerical rejection must return control to the GP’s jitter retry.
GPRidge calls the status-returning native factorization routines because
the Kokkos Kernels 5.2.2 potrf wrapper aborts on a non-positive leading
minor. HIP triangular solves also call rocBLAS directly: that release has
no rocBLAS trsm specialization. Device and library errors propagate as
errors, rather than being treated as rejected covariance matrices.
Measure factor reuse and transfers¶
The native bench_dense_backend executable compares host Eigen, stateless
backend calls, a workspace accepting mutable factors, and the immutable
factor used by the GP. Its inputs are covariance order, right-hand-side
column count and repetition count. Each timed operation includes the
copies it performs. Numerical checks run outside the timer.
meson compile -C build bench_dense_backend
OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 \
build/benchmarks/bench_dense_backend 1024 16 7 > dense-backend.csv
The CSV records each repetition’s wall time in seconds, relative numerical
error, factor upload count and bytes copied in each direction. The
kokkos_immutable route reports its initial factor upload separately and
keeps that owner for all queries. Repeated query rows have zero factor
uploads. A variance-diagonal query returns one double per right-hand-side
column. The kokkos_workspace route also measures the host comparison
required for mutable factors; its first query includes a factor upload.
The stateless and host routes do not instrument transfer counters.
Record the compiler, Kokkos configuration, CPU and GPU models, thread counts and raw repetitions with the results. These dense-operation measurements do not include covariance assembly, hyperparameter fitting, oracle evaluations or a complete dimer or NEB search.
A100 measurement¶
The retained A100 data and reduction contain 1065 raw rows from 15 workloads, including all factor-upload and query-transfer counts. The run uses one A100 PCIe 40 GB, CUDA 12.2.0, GCC 12.3.0, Kokkos and Kokkos Kernels 5.2.2. The CPU reference uses one Eigen thread on a Xeon Platinum 8358 with AVX2 available and floating-point contraction disabled. For 64 right-hand-side columns, covariance-solve medians are:
Order |
One-thread Eigen (ms) |
Stateless GPU (ms) |
Immutable GPU (ms) |
|---|---|---|---|
128 |
0.108 |
0.335 |
0.168 |
512 |
1.221 |
1.517 |
0.594 |
1024 |
4.208 |
3.056 |
1.097 |
2048 |
16.214 |
11.139 |
2.746 |
4096 |
71.067 |
41.510 |
4.838 |
These medians use repetitions 1 through 6 of seven recorded queries and
include RHS and result transfers. The immutable factor’s initial upload
is recorded separately and excluded from repeated-query medians. At order
4096 the solve improves by a factor of 8.58 over stateless GPU calls; at
order 128 the CPU is faster. The corresponding immutable variance-diagonal
query at order 4096 takes 2.475 ms. These measurements concern the dense
API at source revision f6764d464; the data record also identifies the GP
objective-owner correction. They do not measure complete fitting or search
performance, or compare against a fully threaded CPU solve.
Prepare a LUMI build¶
LUMI-G has MI250X devices with two graphics compute dies per device. Use
the site’s Spack instructions or
Kokkos module documentation to choose a consistent compiler and ROCm
stack. The spack-gpu environment and a LUMI/ EasyBuild programming
environment are separate stacks. Choose one stack for the build. Use the
ROCm version supplied by the chosen stack rather than building a second
runtime into the home directory.
Pin gfx90a for the device code, keep package stages and caches under an
owned project or scratch root, and check inode quotas before unpacking
sources. Preserve the concretized package specification or module list,
compiler versions, source checksums and numerical test logs. A successful
compile verifies the build route; performance and numerical validation
require a GPU allocation. No LUMI performance measurement accompanies
this recipe.