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_ARCHSandCUTLASS_LIBRARY_KERNELSin 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_locisZ_loctransposed with each column scaled by the row precision;A_loc = ZtP_loc * Z_locis the normal matrix of the Bayesian linear regression;rhs_loc = ZtP_loc * y_locis 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, defaultfalse.cutlass_include_dir: absolute path to the CUTLASS headers. Empty means the CUDA compiler’s include path must already providecutlass/gemm/device/gemm.h.cutlass_cuda_arch: nvcc SM suffix, default80. The option text lists80,89,90aand100a.
With use_cutlass=true, meson.build:
adds the CUDA language and requires the CUDA dependency;
defines
GPR_HAVE_CUTLASSfor C++ and CUDA sources;requires the CUTLASS header and stops with an error message when it is not found;
compiles
gpr/linalg/CutlassGemm.cppinto the core library withgpulite;builds
CutlassGemm.cuas the shared librarygpr_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:
Assemble
Z_locandZtP_locon the host with the existing descriptor, Jacobian and precision-scaling code.If
availableForLocalRankis true, computeA_loc = ZtP_loc * Z_locandrhs_loc = ZtP_loc * y_locwithgemm_nn. Otherwise compute them with Eigen.With more than one rank, reduce
A_locandrhs_locto rank 0 (MPI_Reduce). The build is available only withlinalg_backend=scalapack; other backends throwstd::runtime_errorfor a multi-rank RFF build.Add the unit ridge to the diagonal of
A. With more than one rank, scatterAthrough the BLACS grid and factor it withScalapackPDPotrfInverse. OtherwiseDenseLLTInversefactors 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: cuSOLVERpotrfor an equivalent CUDA solver path.solveandsolve_mat: a cuBLAS or cuSOLVER triangular solve.trace_inv_times: usesolve_matfor \(K^{-1} A\) and reduce the diagonal. CUTLASS helps when the implementation materializes intermediate dense products.kind():RankLocaluntil 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 |
|---|---|
|
A default build reports CUTLASS unavailable, the local-rank gate rejects invalid or oversubscribed ranks, and with CUTLASS available |
|
The RFF build and prediction path, and that the normal-equation backend reports |
|
|
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.