Run GPRidge on a GPU ==================== By default the whole search runs on the CPU. This page lists the parts of GPRidge that can use an NVIDIA GPU, the switch for each, how to see which one a build has, and what happens when the GPU stack is missing. A torch oracle such as the PET-MAD or UMA interatomic potential uses ``--device cuda`` to select the GPU. The CPU examples also run without CUDA. Blocks marked ``needs-gpu`` require a GPU allocation and the stated toolkit or runtime libraries. The reproduction repository retains measured comparisons, with source versions, hardware, inputs, numerical checks and timing boundaries. Measured workloads ------------------ The complete Cholesky GP-fit comparison uses identical energy and Cartesian-gradient observations on Eigen and cuSOLVER. For 512 training geometries (6656 joint observation channels), an NVIDIA GeForce RTX 5070 gives median complete-fit speedups of 2.319 with a one-thread host budget and 1.440 with a four-thread budget. Smaller fits favor the CPU. These timings include covariance assembly, L-BFGS fitting and device transfers; the record identifies the source revision, build correction and exact wheel artifacts. The matched A100 GP-backend comparison measures 36 complete searches with Eigen or cuSOLVER at ``v0.7.0-rc.12``, with the oracle on the CPU. All runs pass measured-force and independent first-order Hessian checks. At one host thread, Grignard's median pipeline time is 596.897 seconds with Eigen and 441.898 seconds with cuSOLVER. The corresponding search counts are 573 and 550, so the timing includes each backend's trajectory. Hydrogen cyanide (HCN) favors Eigen; Diels-Alder favors cuSOLVER, with a smaller difference at four host threads. The record lists all repetitions, calls and timings. The A100 training-product comparison measures 54 complete molecular searches, including independent Hessian validation, at ``v0.7.0-rc.9``. It changes the native or Scheme II product provider while holding the GP factorization backend fixed. Forced GPU products beat Scheme II's CPU implementation on Diels-Alder and Grignard, while the native CPU product gives the lowest complete-search times on all three reactions. The providers also change oracle counts on two reactions; the retained table reports each trajectory's calls and timing. Use these records to distinguish fixed-data fit performance from complete search performance. Compare the workload, matrix order, source and thread budget with the intended calculation before selecting a backend. What can use a GPU ------------------ Every row is opt-in. For CUTLASS, the design page records that nothing in ``.github/workflows`` or ``pyproject.toml`` sets ``use_cutlass``, so release wheels and CI builds use the Eigen path (:doc:`CUTLASS backend design <../development/design/cutlass_rff_kernelinverse>`). .. table:: +-------------------------+-------------------------------------------------------------+-----------------------------------------------------------------+ | Component | Switch | What runs on the GPU | +=========================+=============================================================+=================================================================+ | Oracle (torch models) | ``--device cuda``, TOML ``device`` of the potential | Model evaluation of metatomic (``.pt``) and UMA/OMol (``.pt2``) | +-------------------------+-------------------------------------------------------------+-----------------------------------------------------------------+ | cuSOLVER backend | ``-Dlinalg_backend=cusolver`` | Dense Cholesky, inverse and triangular solves of the GP | +-------------------------+-------------------------------------------------------------+-----------------------------------------------------------------+ | CUTLASS GEMM | ``-Duse_cutlass=true`` | The dense products of the random-feature normal equations | +-------------------------+-------------------------------------------------------------+-----------------------------------------------------------------+ | Environment kernel | ``-Duse_stdpar_gpu=enabled``, ``--environment-gpu-library`` | Environment GP fitting and prediction (nvc++ library) | +-------------------------+-------------------------------------------------------------+-----------------------------------------------------------------+ | INT8 Scheme II products | ``-Dscheme2_cuda=true``, ``--training-product-library`` | Training-matrix products on INT8 tensor cores | +-------------------------+-------------------------------------------------------------+-----------------------------------------------------------------+ Other parallel execution options select CPU code or depend on the installed backend: - ``-Duse_highway`` (default ``auto``) selects Google Highway single-instruction, multiple-data (SIMD) kernels for distance and covariance on the CPU. The option text in ``meson_options.txt`` records a 12 % wall-time reduction at one MPI rank in a five-trial median of the PET-MAD d016 maximum-a-posteriori (MAP) benchmark. - ``-Dlinalg_backend=stdpar`` runs independent kernel blocks through parallel C++ standard-library algorithms on the host with Intel oneTBB. - ``-Dlinalg_backend=kokkos`` runs on the execution space that the installed Kokkos was built for. The :doc:`Kokkos build guide ` gives the CPU, CUDA and HIP dependencies and checks. Record that execution space with the build. - ``-Dlinalg_backend=scalapack`` and ``slate`` distribute the factorisation over Message Passing Interface (MPI) ranks (see :doc:`MPI how-to `). Two limits come from the design page :doc:`GP execution and component ownership <../development/design/gp_execution_components>`. The cuSOLVER and CUTLASS paths still use a static solver handle, a fixed device index 0 in ``gpr/linalg/CusolverEigh.cpp``, and device-wide synchronisation. The device execution contract on that page is design intent. Check what a build supports --------------------------- ``gpridge.backend_name()`` returns the linear-algebra backend that the library was compiled with: ``eigen``, ``cholmod``, ``kokkos``, ``cusolver``, ``stdpar``, ``scalapack`` or ``slate`` (``gpr_backend_name`` in ``gpr/capi/gpridge_c.cpp``). A cuSOLVER build reports ``cusolver``. A ``cholmod`` build reports ``cholmod``. The CUTLASS, stdpar-GPU and Scheme II libraries have no Python probe. .. code:: python import shutil import subprocess import gpridge backend = gpridge.backend_name() assert backend in { "eigen", "cholmod", "kokkos", "cusolver", "stdpar", "scalapack", "slate" } has_nvidia_smi = shutil.which("nvidia-smi") is not None shell_lookup = subprocess.run( ["sh", "-c", "command -v nvidia-smi"], stdout=subprocess.DEVNULL, check=False, ) assert has_nvidia_smi == (shell_lookup.returncode == 0) print("linalg backend:", backend) print("nvidia-smi on PATH:", has_nvidia_smi) The backend depends on the build. The second line reports whether the driver tool is on the host's ``PATH``. Use ``nvidia-smi -L`` to list the devices visible to your process. :: linalg backend: nvidia-smi on PATH: Both drivers list the GPU switches in their help text. The block asserts that the flags this page names exist in the binaries on ``PATH``. .. code:: bash gprn --help > gprn_help.txt gprd --help > gprd_help.txt for flag in --device --environment-gpu-library; do grep -q -e "$flag" gprn_help.txt grep -q -e "$flag" gprd_help.txt done grep -q -e "--training-product-library" gprn_help.txt echo "gpu flags present" :: gpu flags present Device selection for Lennard-Jones ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The CLI help describes ``--device`` as the execution device of metatomic and UMA. The ``lj`` potential runs on the CPU for both flag values. These runs use the five-atom Lennard-Jones pentamer of the :doc:`gprn tutorial <../tutorials/gprn_lj_pentamer>` and give the same band with ``--device cpu`` and ``--device cuda``, with no error on a host that has no GPU. A test of the CPU side of a GPU workflow exercises host behavior; record device activity with a GPU-enabled potential or backend. .. code:: bash examples="$GPRIDGE_ROOT/examples/lj-pentamer" cp "$examples/reactant.con" "$examples/product.con" . .. code:: bash run() { mkdir -p "$1" && cd "$1" gprn --reactant ../reactant.con --product ../product.con \ --potential lj --nimages 7 --gp-model-profile gprd_zbl \ --gp-nonperiodic true --gp-observation-archive off \ --device "$1" --output neb.h5 --write-con band.con > gprn.log 2>&1 cd .. } run cpu run cuda grep -E '^(Oracle calls \(to convergence\)|Converged:)' cuda/gprn.log cmp cpu/band.con cuda/band.con echo "lj band identical for --device cpu and cuda" :: Oracle calls (to convergence): 17 (endpoints=2, initial=0, outer=15, dimer=0, certificate=0, transition=0) Converged: yes lj band identical for --device cpu and cuda Run a torch oracle on the GPU ----------------------------- Install the CUDA environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The pixi environment ``gpu-scalapack`` combines the ``scalapack`` and ``gpu-cuda`` features in its own solve group, so a CPU checkout can keep its CPU torch. The ``gpu-cuda`` feature in ``pixi.toml`` does three things: - It takes ``torch`` (2.7.1 or newer, below 3) from the PyTorch ``cu128`` wheel index, and the matching ``metatomic-torch``, ``metatensor-torch``, ``metatensor``, ``vesin-torch`` and ``vesin`` packages. - It pins the conda CUDA packages (``cuda-nvcc``, ``cuda-cudart-dev``, ``cuda-libraries-dev`` and others) to 12.8 up to, but excluding, 13. The comment in ``pixi.toml`` states that a 13.\* toolkit cannot coexist with the cu128 wheels, so the resolver would fall back to CPU torch. The ``cuda-nvcc`` pin of 13 up to 14 belongs to the separate ``cutlass`` feature. - It does not install the NVIDIA driver. ``nvidia-smi`` must already list the GPU. Installing and loading the kernel driver depends on the distribution and is outside GPRidge. On a shared cluster, run the check inside a GPU allocation and use the site's CUDA modules: a login node need not expose a GPU, and a driver or kernel-module failure on a compute node belongs with the site's administrators. .. code:: bash pixi install -e gpu-scalapack pixi run -e gpu-scalapack python -c \ 'import torch; print(torch.__version__, torch.cuda.is_available())' The version string must carry a ``+cu128`` suffix and the second value must be ``True``. ``False`` means the driver or the CUDA runtime libraries are not visible to torch. If the import fails on ``libcusparseLt.so.0``, add the PyPI package ``nvidia-cusparselt-cu12`` to ``[feature.gpu-cuda.pypi-dependencies]`` in ``pixi.toml``; do not ``pip install`` into the locked environment. Build the drivers against CUDA torch ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The task ``build-scalapack-real`` is defined on the ``scalapack`` feature, so it is available in ``gpu-scalapack``. It writes a Meson native file with ``scripts/write_torch_native_file.py --require-metatomic``, then configures ``build-scalapack-real/`` with ``-Dlinalg_backend=scalapack``, ``-Duse_rgpot_metatomic=true`` and ``-Ddeterministic_reductions=true``, and builds ``gprd`` and ``gprn``. The script lists the torch, metatomic, metatensor and vesin paths from the active environment, so running the task inside ``gpu-scalapack`` picks the CUDA wheels. .. code:: bash pixi run -e gpu-scalapack build-scalapack-real The task takes library and pkg-config paths from ``CONDA_PREFIX``, which Pixi sets to the selected environment. With ``-e gpu-scalapack`` those paths belong to the CUDA environment. The torch native-file generator also imports from that environment. To build outside the task, write the native file yourself and pass it to Meson with the same options: .. code:: bash pixi run -e gpu-scalapack python scripts/write_torch_native_file.py \ --require-metatomic .gpu-native.ini ``--require-metatomic`` makes the script fail when the torch, metatomic, metatensor or vesin paths are missing. Prepare a model and endpoints ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The task ``prepare-petmad-model`` exports the PET-MAD TorchScript model to ``bench_data/petmad/pet-mad-s-v1.5.0.pt`` (``scripts/prepare_petmad_assets.py``). The Baker endpoint pairs are in ``bench_data/baker/endpoints//{reactant,product}.con``, for example ``01_hcn``. The same flags select UMA with ``--potential uma`` and a ``.pt2`` package; see :doc:`the UMA band tutorial <../tutorials/uma_band>`. .. code:: bash pixi run -e petmad-assets prepare-petmad-model Run the band on the GPU ~~~~~~~~~~~~~~~~~~~~~~~ ``gprn`` from ``build-scalapack-real`` links ScaLAPACK, so start it under MPI. The command below uses one rank. ``-x PATH -x LD_LIBRARY_PATH`` passes the environment of the pixi shell to the rank. .. code:: bash pixi run -e gpu-scalapack mpirun -np 1 -x PATH -x LD_LIBRARY_PATH \ build-scalapack-real/gprn \ --reactant bench_data/baker/endpoints/01_hcn/reactant.con \ --product bench_data/baker/endpoints/01_hcn/product.con \ --nimages 16 --idpp true \ --potential metatomic \ --model bench_data/petmad/pet-mad-s-v1.5.0.pt \ --device cuda \ --output band.h5 --write-con band.con Run the same command with ``--device cpu`` for the CPU baseline. ``--device`` accepts ``cpu`` or ``cuda`` in the CLI help. The UMA test of the Cap'n Proto config uses ``device = "cuda:1"`` (``tests/gpr/potentials/RgpotFactoryTest.cpp``); the CLI documentation does not describe how ranks map to devices. Confirm that the GPU is used ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ While the band runs, ``nvidia-smi`` must show non-zero memory use and utilisation spikes at each oracle call. .. code:: bash nvidia-smi --query-gpu=memory.used,utilization.gpu --format=csv,noheader The startup lines of the log do not name the device. The line ``[startup] oracle path=engine|direct`` names the route. On the engine route a ``[startup] engine library``... model=... sha256=...= line names the engine file and the model file that ran. UMA takes the engine route by default and metatomic takes the compiled-in route (``direct``) unless you pass ``--oracle-path engine`` (help text of ``--oracle-path``). What fails when the GPU stack is missing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On the engine route, opening the engine with a ``cuda`` device first loads ``libtorch_cuda.so`` from the directory of the engine's ``libtorch_cpu`` (``gpr/potentials/EnginePotential.cpp``). The open fails with one of these messages. This page did not read the source of the direct metatomic route for its failure messages. .. table:: +----------------------------------------------------------------------------------------------------------------------+-----------------------------------------+ | Message | Cause | +======================================================================================================================+=========================================+ | ``a CUDA device was requested but the engine loads no libtorch_cpu`` | The engine library does not link torch. | +----------------------------------------------------------------------------------------------------------------------+-----------------------------------------+ | ``dlopen .../libtorch_cuda.so: ... (a CUDA device needs the CUDA build of torch next to the engine's libtorch_cpu)`` | CPU-only torch next to the engine. | +----------------------------------------------------------------------------------------------------------------------+-----------------------------------------+ A CUDA error ``no kernel image is available for execution on the device`` means the torch wheel was not compiled for the compute capability of the GPU. Compare ``torch.cuda.get_arch_list()`` with ``torch.cuda.get_device_capability()``. Build the optional GPU libraries -------------------------------- Each optional library changes the GP side. Its build and runtime requirements are separate from the oracle's device setting. cuSOLVER backend ~~~~~~~~~~~~~~~~ ``-Dlinalg_backend=cusolver`` has no link-time CUDA dependency. The backend loads ``libcudart``, ``libcusolver`` and ``libcublas`` with ``dlopen`` on first use (``gpr/linalg/CusolverBackend.h``). It calls cuSOLVER ``potrf`` and ``potri`` and cuBLAS ``trsv``, ``trsm`` and ``dot``. A missing library raises ``std::runtime_error`` with the message ``Failed to load libcusolver.so`` (or ``libcublas.so``). This backend compiles C++ without ``nvcc``; the CUDA runtime libraries must be available in the GPU allocation. The :doc:`EasyBuild guide ` shows how to generate a recipe with the CUDA runtime dependency. .. code:: bash meson setup builddir-cusolver -Dlinalg_backend=cusolver meson compile -C builddir-cusolver CUTLASS GEMM for random-feature fits ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``-Duse_cutlass=true`` compiles CUDA GEMM kernels for the rank-local dense products. Configuration fails with the message ``use_cutlass=true requires CUTLASS headers`` when the header ``cutlass/gemm/device/gemm.h`` is not found. Pass ``-Dcutlass_include_dir`` to point at the headers and ``-Dcutlass_cuda_arch`` for the ``nvcc`` architecture (default ``80``; the pixi tasks use ``89``). Only one step uses it: the normal-equation products ``Z^T P Z`` and ``Z^T P y`` of the random-feature model (``gpr/ml/RFFModel.cpp``). The step uses the GPU when the node has enough visible devices for its local MPI ranks. Otherwise it keeps the Eigen/BLAS path without an error. Device selection is ``local_rank % device_count`` (``gpr/linalg/CutlassGemm.cpp``). Random features apply only when ``--rff-features`` is positive and the conditions on :doc:`Choose GP settings ` are met. The ``cutlass`` pixi environment has tasks that configure, build and run the tests: .. code:: bash pixi run -e cutlass test-cutlass-gemm pixi run -e cutlass test-cutlass-rff To see which path ran, raise the GP report level. ``--gp-report-level 1`` makes the driver print one line per random-feature build, and its ``backend`` field is ``cutlass`` or ``eigen`` (``gpr/ml/gp/Optimize.cpp``). The placeholders below stand for numbers of the run: :: RFF layered predict: built D_rff= features on observations (n_design=, backend=cutlass). Environment-kernel library and Scheme II ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``-Duse_stdpar_gpu=enabled`` builds ``libgpr_stdpar_environment.so`` with ``nvc++``. ``-Dstdpar_gpu_arch`` selects the target (default ``cc80``). Pass the library to ``gprd`` or ``gprn`` with ``--environment-gpu-library PATH``. ``-Dscheme2_cuda=true`` builds ``libgpr_scheme2_cuda.so``, the device half of the INT8 Scheme II engine. It needs ``nvcc`` and cuBLAS. ``-Dscheme2_cuda_arch`` defaults to ``80,90,120``. The CLI selects the engine with ``--training-product-library scheme2:int8:provider=cuda``. The source accepts the provider values ``auto``, ``builtin``, ``mkl``, ``onednn`` and ``cuda`` (``gpr/linalg/schemeii/SchemeII.cpp``). The ``--help`` text lists ``mkl``, ``onednn`` and ``builtin`` only. To tune the launch sizes of the CUDA provider see the last section of this page. For allocation-level advice see :doc:`the HPC how-to `. All build options are listed in :doc:`Build options <../reference/build_options>`. Tune the Scheme II matrix products ---------------------------------- The production Scheme II implementation is ``gpr/linalg/schemeii/SchemeII.cpp``; its CUDA provider calls cuBLAS INT8 products and reconstructs binary64 results. The ``scripts/tune_scheme_ii_pipeline.py`` driver uses the `Kernel Tuner C backend `_ to tune column-residue and reconstruction kernel launch sizes. Each candidate must produce finite output with exactly the CPU Scheme II reference bits. The driver tests square, long-inner-dimension and irregular matrix shapes. It records all 16 launch choices per shape, 15 timing samples per choice, input and source hashes, compiler options, provider hashes and device data. Use an allocated GPU node with a C++20 compiler, Eigen, the CUDA toolkit and Kernel Tuner 1.6.0. Prefer the site's native modules. An isolated environment for a missing tuning tool belongs on the allocation's local scratch; retain its dependency versions and wheel hashes. The C backend does not require PyCUDA. Set ``GPR_TUNE_WORK`` to an owned scratch directory and run these commands from the source root. The commands select ``sm_80`` for an NVIDIA A100; match the architecture of the allocated GPU. .. code:: bash test -d "${GPR_TUNE_WORK:?set an owned allocation scratch directory}" mkdir -p "$GPR_TUNE_WORK/build" for column in 64 128 256 512; do for reconstruct in 64 128 256 512; do nvcc -O3 -std=c++17 -fmad=false \ -Xcompiler=-fPIC,-fvisibility=hidden \ -gencode=arch=compute_80,code=sm_80 \ -DGPR_SCHEME2_CUDA_COLUMN_THREADS=$column \ -DGPR_SCHEME2_CUDA_RECON_THREADS=$reconstruct -shared \ gpr/linalg/schemeii/CudaEngine.cu -lcublas \ -o "$GPR_TUNE_WORK/build/libgpr_scheme2_cuda_c${column}_r${reconstruct}.so" done done g++ -O3 -std=c++20 -ffp-contract=off -fPIC -shared -I"$PWD" \ $(pkg-config --cflags eigen3) \ scripts/scheme_ii_pipeline_host.cpp gpr/linalg/schemeii/SchemeII.cpp \ -ldl -pthread -o "$GPR_TUNE_WORK/build/libgpr_schemeii_host.so" export GPR_SCHEME2_CUDA=$GPR_TUNE_WORK/build/libgpr_scheme2_cuda_c256_r128.so python scripts/tune_scheme_ii_pipeline.py \ --host-library "$GPR_TUNE_WORK/build/libgpr_schemeii_host.so" \ --provider-directory "$GPR_TUNE_WORK/build" \ --output "$GPR_TUNE_WORK/tuning.json" A successful run prints ``ALL_PIPELINE_CONFIGURATIONS_MATCH_CPU_BITS``. Copy ``tuning.json``, the runner, dependency records and compiler/device metadata to retained storage before the allocation ends. The host clock includes operand preparation, allocation, transfers and product execution. Context initialization, five warm-up calls and the exact output comparison are outside each timed call. Kernel Tuner ranks the mean of its repeated samples; every sample remains available for independent analysis. The script does not modify GPRidge defaults or install tuning results. The default CUDA launches use 256 column-residue threads and 128 reconstruction threads. Host ``block_rows`` and ``block_cols`` settings do not select these device launch sizes. For a search comparison, add the selected product specification to the usual ``gprn`` or ``gprd`` command. A matched CPU reference uses ``scheme2:fp64:threads=1``. The CUDA counterpart is: .. code:: bash --training-product-library \ "scheme2:int8:provider=cuda:device_min=0:threads=1:library=$GPR_SCHEME2_CUDA" The ``device_min=0`` setting forces eligible products onto the device for the comparison. The training-product interface still retains its small global-matrix floor; see :doc:`Training matrix products <../reference/training_products>`. Set ``GPR_SCHEME2_PROFILE=1`` for a separate diagnostic run: the exit log reports ``[scheme2-cuda]`` product counts, transfers and device phases. Confirm a positive device-product count for a provider timing. Event instrumentation adds synchronization, so retain diagnostic timings separately from repeated uninstrumented search timings. Report oracle calls, measured force, independent saddle index, initialization, memory and complete pipeline time alongside matrix timings. Allocating multiple GPUs does not by itself distribute a single-device product.