Skip to content

Integrate cudatoolkit R package for CUDA library loading#1422

Merged
dfalbel merged 18 commits intomainfrom
cudatoolkit-integration
Apr 8, 2026
Merged

Integrate cudatoolkit R package for CUDA library loading#1422
dfalbel merged 18 commits intomainfrom
cudatoolkit-integration

Conversation

@dfalbel
Copy link
Copy Markdown
Member

@dfalbel dfalbel commented Apr 1, 2026

Summary

  • Adds load_cudatoolkit_libs() in R/lantern_load.R that detects an installed cuda* R package (e.g. cuda12.8) and preloads its shared libraries via dyn.load(local = FALSE, now = FALSE) before lantern initialization. This makes CUDA symbols globally available so libtorch can resolve them without a system-wide CUDA toolkit installation.
  • Adds a check-cudatoolkit CI job that runs on a nvidia/cuda:12.8.1-base-ubuntu22.04 container (driver libs only, no CUDA toolkit), installs cuda12.8 from r-universe, and runs the full test suite with TORCH_TEST_CUDA=1.

Test plan

  • check-cudatoolkit CI job passes: torch loads CUDA from the cuda12.8 R package
  • Existing CI jobs are unaffected (load_cudatoolkit_libs() is a no-op when no cudatoolkit package is installed)
  • CPU-only installations continue to work (function short-circuits when CUDA is unset or "cpu")

@dfalbel dfalbel force-pushed the cudatoolkit-integration branch from 5406071 to bfa18a3 Compare April 7, 2026 12:05
dfalbel added 6 commits April 7, 2026 10:11
Preload CUDA shared libraries from the cudatoolkit R package (e.g.
cuda12.8) before loading lantern, so torch can run on systems without
a system-wide CUDA installation. Adds a CI job that tests this on a
bare ubuntu:22.04 container with GPU access.
R CMD check --as-cran can't find the cuda12.6 package since it's not a
declared dependency. Switch to installing locally with pak and running
tests directly via testthat::test_package().
Use cuda12.8 package and container image, and set TORCH_URL to the
CUDA 12.8 libtorch build for compatibility with the older CI GPU.
@dfalbel dfalbel force-pushed the cudatoolkit-integration branch from bfa18a3 to 56a85fe Compare April 7, 2026 13:11
dfalbel added 12 commits April 7, 2026 20:18
Add auto-detection of cuda* R packages (e.g. cuda128) as the first
method for determining CUDA version. Also add TORCH_CUDATOOLKIT env var
to force a specific version or disable cudatoolkit detection/loading.
Only look for installed cudatoolkit R packages when loading CUDA libs
at startup, instead of calling cuda_version() which probes the system
via nvcc/CUDA_HOME and fails on unsupported CUDA versions.
Error if both CUDA and TORCH_CUDATOOLKIT are set. When CUDA is set,
try to use that specific cudatoolkit package version before falling
through to system CUDA detection.
Detection priority:
1. TORCH_CUDATOOLKIT (explicit cudatoolkit R package, must match CUDA)
2. CUDA env var (try matching cudatoolkit R package first)
3. Auto-detect installed cudatoolkit R packages (newest first)
4. System CUDA (CUDA_HOME/CUDA_PATH, nvcc) — only if no cudatoolkit found

Centralizes steps 1-3 in cuda_version_from_cudatoolkit(), shared by
both cuda_version() (install-time) and load_cudatoolkit_libs() (startup).
System probing functions renamed to cuda_version_from_system_*().

Also documents cudatoolkit R packages and env vars in the installation
vignette.
Move the CUDA=cpu early return after cuda_version_from_cudatoolkit()
so the conflict check catches CUDA=cpu + TORCH_CUDATOOLKIT=12.8
at install time instead of only at startup.
@dfalbel dfalbel merged commit a5f63b5 into main Apr 8, 2026
3 of 8 checks passed
@dfalbel dfalbel deleted the cudatoolkit-integration branch April 8, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant