Integrate cudatoolkit R package for CUDA library loading#1422
Merged
Conversation
5406071 to
bfa18a3
Compare
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.
bfa18a3 to
56a85fe
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
load_cudatoolkit_libs()inR/lantern_load.Rthat detects an installedcuda*R package (e.g.cuda12.8) and preloads its shared libraries viadyn.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.check-cudatoolkitCI job that runs on anvidia/cuda:12.8.1-base-ubuntu22.04container (driver libs only, no CUDA toolkit), installscuda12.8from r-universe, and runs the full test suite withTORCH_TEST_CUDA=1.Test plan
check-cudatoolkitCI job passes: torch loads CUDA from thecuda12.8R packageload_cudatoolkit_libs()is a no-op when no cudatoolkit package is installed)CUDAis unset or"cpu")