CUTLASS backend for RFF and KernelInverse

Status: partially implemented. The optional CUTLASS GEMM facade (gpr/linalg/CutlassGemm.{h,cpp,cu}) is implemented and used by RFFModel::build for the Bayesian-linear-regression normal equations. The KernelInverse integration described in the last design section is design intent: no KernelInverse implementation calls CUTLASS. The CUTLASS build needs a CUDA compiler and CUTLASS headers, and the default build does not use it.

Scope

CUTLASS supplies dense double-precision matrix products for rank-local work. It does not replace a solver. Cholesky factorization and triangular solves stay in DenseLLTInverse, CusolverInverse, ScalapackPDPotrfInverse or another implementation of the KernelInverse interface (gpr/linalg/KernelInverse.h).

The matrix products that run through CUTLASS today are the two products in RFFModel::build. The matrix-matrix operations inside KernelInverse do not.

Documentation inputs

NVIDIA’s CUTLASS C++ quickstart documents two integration facts that matter here:

  • Client applications include CUTLASS headers directly, use C++17 or newer, and instantiate device GEMM types in host code.

  • Build size and compile time are controlled by compiling only the SM architectures and kernel filters that are needed, for example CUTLASS_NVCC_ARCHS and CUTLASS_LIBRARY_KERNELS in the CUTLASS CMake flow.

The CUTLASS device GEMM API exposes cutlass::gemm::device::Gemm and can_implement() support checks around a host-side launch object. gpr/linalg/CutlassGemm.cu uses both. The facade keeps the CUTLASS template types out of the RFFModel and KernelInverse headers.

References:

Existing hot paths

RFFModel::build (gpr/ml/RFFModel.cpp) owns the largest GEMM-shaped work. Each rank forms its local slab of training rows, and:

  • ZtP_loc is Z_loc transposed with each column scaled by the row precision;

  • A_loc = ZtP_loc * Z_loc is the normal matrix of the Bayesian linear regression;

  • rhs_loc = ZtP_loc * y_loc is its right-hand side.

RFFModel::calculatePotential and the variance path also do small repeated products per query, u = W_ * phi + b_ and WJ = W_ * J_phi. They stay on Eigen.

KernelInverse exposes kind(), solve, solve_mat, log_det and trace_inv_times. A GEMM utility belongs below that interface, used by specific implementations, not as a new method on the abstract base.

Backend contract

The facade in gpr/linalg/CutlassGemm.h has this surface:

namespace gpr::linalg::cutlass {

[[nodiscard]] bool compiled() noexcept;
[[nodiscard]] bool available() noexcept;
[[nodiscard]] bool availableForLocalRank(int local_rank,
                                         int local_nprocs) noexcept;
[[nodiscard]] EigenMatrix gemm_nn(const EigenMatrix& A, const EigenMatrix& B);
void setPluginPath(std::string path);

}

The header is always includable. Without GPR_HAVE_CUTLASS the same API reports compiled() and available() as false, setPluginPath does nothing and gemm_nn throws std::logic_error. CPU builds therefore compile the same call sites without CUDA headers.

A CUTLASS build keeps CUDA off the core gpridge link line. The core library compiles CutlassGemm.cpp, which probes the CUDA runtime through gpulite. The GEMM kernels are in the plugin libgpr_cutlass_gemm.so, built from CutlassGemm.cu, which the facade opens with dlopen on first use. The facade tries, in order, the path set by setPluginPath, the directory of libgpridge, and the dynamic loader’s default search. The path comes from the cutlass_plugin_path parameter (GaussianProcessRegression::setCutlassPluginPath in C++ and set_cutlass_plugin_path in Python). Searches that never build an RFF model do not load the CUDA runtime.

RFFModel::build passes its node-local MPI rank and local rank count to availableForLocalRank. The call returns true only when at least one CUDA device is visible per local rank. availableForLocalRank also selects device local_rank % device_count for that rank. On GPU-less or oversubscribed node layouts every rank uses the Eigen path, rather than several ranks sharing one device. RFFModel::normalEquationBackendName() reports eigen or cutlass for the build that ran.

The kernel is a double-precision cutlass::gemm::device::Gemm with the SIMT operator class. Tensor-core FP32 or TF32 variants would need explicit tolerance and acceptance benchmarks, because the regression solution feeds forces and curvature estimates.

Build integration

Meson has explicit CUDA and CUTLASS options, separate from the CPU and MPI backend choices (meson_options.txt):

  • use_cutlass: boolean, default false.

  • cutlass_include_dir: absolute path to the CUTLASS headers. Empty means the CUDA compiler’s include path must already provide cutlass/gemm/device/gemm.h.

  • cutlass_cuda_arch: nvcc SM suffix, default 80. The option text lists 80, 89, 90a and 100a.

With use_cutlass=true, meson.build:

  • adds the CUDA language and requires the CUDA dependency;

  • defines GPR_HAVE_CUTLASS for C++ and CUDA sources;

  • requires the CUTLASS header and stops with an error message when it is not found;

  • compiles gpr/linalg/CutlassGemm.cpp into the core library with gpulite;

  • builds CutlassGemm.cu as the shared library gpr_cutlass_gemm;

  • selects the CUTLASS architecture tag from cutlass_cuda_arch.

Nothing in .github/workflows or pyproject.toml sets use_cutlass, so release wheels and CI builds use the Eigen path.

The linalg_backend=cusolver path loads cuSOLVER and cuBLAS at run time. CUTLASS kernel compilation is a separate build-time CUDA requirement, which is why it is opt-in.

RFF integration

The BLR normal-equation builder is the one RFF step that uses CUTLASS:

  1. Assemble Z_loc and ZtP_loc on the host with the existing descriptor, Jacobian and precision-scaling code.

  2. If availableForLocalRank is true, compute A_loc = ZtP_loc * Z_loc and rhs_loc = ZtP_loc * y_loc with gemm_nn. Otherwise compute them with Eigen.

  3. With more than one rank, reduce A_loc and rhs_loc to rank 0 (MPI_Reduce). The build is available only with linalg_backend=scalapack; other backends throw std::runtime_error for a multi-rank RFF build.

  4. Add the unit ridge to the diagonal of A. With more than one rank, scatter A through the BLACS grid and factor it with ScalapackPDPotrfInverse. Otherwise DenseLLTInverse factors it. A failed factorization is retried once with an extra ridge of \(10^{-6}\).

Ranks own contiguous training slabs, rank 0 receives only the compact normal equations, and the factorization is distributed through the BLACS grid, as in the other ScaLAPACK paths.

RFF replaces the exact GP once the design has at least \(2 D_{\mathrm{rff}}\) rows (n_design > 2 * D_rff=, set through --rff-features). Below that cutoff the exact path stays active, so a small test fixture needs a small D_rff to exercise the RFF build.

The PET-MAD benchmark wrapper scripts/bench_cutlass_rff_petmad.sh, run by pixi run -e scalapack-cutlass bench-cutlass-rff-petmad, defaults to --rff-features 512 (variable GPR_CUTLASS_RFF_FEATURES). 512 is a profiling fixture, not an accuracy guarantee. Low feature counts such as 64 serve only as backend smoke tests and are not predictor settings. The count for a production surrogate comes from the held-out rule of the GP settings how-to (--rff-features auto). For multi-rank runs the log is a CUTLASS timing only when the node has at least as many visible CUDA devices as local MPI ranks. Otherwise the RFF build is a CPU timing by construction. Setting GPR_CUTLASS_REQUIRE_ACTIVE_RFF=1 makes the wrapper exit with status 2 when the PET-MAD log does not contain an RFF build line.

KernelInverse integration

Design intent, not implemented. A CUTLASS-aware KernelInverse should be a CUDA solver implementation with a CUTLASS GEMM helper, not a pure CUTLASS solver. CusolverInverse (gpr/linalg/CusolverInverse.h) factors through the compiled backend’s Cholesky and does not call CUTLASS. Only test_kernel_inverse constructs it; RFFModel::build does not, although the class comment in the header says it does. The proposal is:

  • factorise: cuSOLVER potrf or an equivalent CUDA solver path.

  • solve and solve_mat: a cuBLAS or cuSOLVER triangular solve.

  • trace_inv_times: use solve_mat for \(K^{-1} A\) and reduce the diagonal. CUTLASS helps when the implementation materializes intermediate dense products.

  • kind(): RankLocal until a multi-GPU collective implementation exists.

The KernelInverse abstraction stays the ownership boundary. RFFModel::build chooses its concrete inverse as shown above, between ScalapackPDPotrfInverse and DenseLLTInverse; a CUDA-backed implementation would be a third choice.

Verification

The tests that exist:

Test

What it checks

test_cutlass_gemm (tests/gpr/linalg/CutlassGemmTest.cpp)

A default build reports CUTLASS unavailable, the local-rank gate rejects invalid or oversubscribed ranks, and with CUTLASS available gemm_nn matches Eigen.

test_rff_model (tests/gpr/ml/RFFModelTest.cpp)

The RFF build and prediction path, and that the normal-equation backend reports cutlass when it is available.

test_kernel_inverse (tests/gpr/linalg/KernelInverseTest.cpp)

DenseLLTInverse and CusolverInverse against Eigen. It does not cover CUTLASS.

The Pixi tasks in the cutlass environment run the first two on a CUDA machine: pixi run -e cutlass test-cutlass-gemm and pixi run -e cutlass test-cutlass-rff. Both configure bld-cutlass-gemm with -Dcutlass_cuda_arch=89. The GPU tests have not been run for this page.

Still to add if the KernelInverse integration is built: a test comparing solve, solve_mat, log_det and trace_inv_times of the new implementation against DenseLLTInverse, and a gprn --nebmode gp_oie --rff-features 256 smoke run with use_cutlass=true. The non-CUDA build must keep compiling the same public headers and tests without CUDA headers in the include graph.