Detect CUDA configuration. This function tries to compile a small
program with nvcc
and confirms that this can be loaded into R,
then uses that program to query the presence and capabilities of
your NVIDIA GPUs. If this works, then you can use the GPU-enabled
dust features, and the information returned will help us. It's
quite slow to execute (several seconds) so we cache the value
within a session. Later versions of dust will cache this across
sessions too.
dust_cuda_configuration(
path_cuda_lib = NULL,
path_cub_include = NULL,
quiet = TRUE,
forget = FALSE
)
Optional path to the CUDA libraries, if they
are not on system library paths. This will be added as
-L{path_cuda_lib}
in calls to nvcc
Optional path to the CUB headers, if using CUDA < 11.0.0. See Details
Logical, indicating if compilation of test programs should be quiet
Logical, indicating if we should forget cached values and recompute the configuration
A list of configuration information. This includes:
has_cuda
: logical, indicating if it is possible to compile CUDA on
this machine (not necessarily use it though)
cuda_version
: the version of CUDA found
devices
: a data.frame of device information:
id: the device id (integer, typically in a sequence from 0)
name: the human-friendly name of the device
memory: the memory of the device, in MB
version: the compute version for this device
path_cuda_lib
: path to CUDA libraries, if required
path_cub_include
: path to CUB headers, if required
If compilation of the test program fails, then has_cuda
will be
FALSE
and all other elements will be NULL
.
Not all installations leave the CUDA libraries on the default
paths, and you may need to provide it. Specifically, when we link
the dynamic library, if the linker complains about not being able
to find libcudart
then your CUDA libraries are not in the
default location. You can manually pass in the path_cuda_lib
argument, or set the DUST_PATH_CUDA_LIB
environment variable (in
that order of precedence).
If you are using older CUDA (< 11.0.0) then you need to provide CUB headers, which we use to manage state on the device (these are included in CUDA 11.0.0 and higher). You can provide this as:
a path to this function (path_cub_include
)
the environment variable DUST_PATH_CUB_INCLUDE
CUB headers installed into the default location (R >= 4.0.0, see below).
These are checked in turn with the first found taking
precedence. The default location is stored with
tools::R_user_dir("dust", "data")
, but this functionality is
only available on R >= 4.0.0.
To install CUB you can do:
which will install CUB into the default path (provide a path on older versions of R and set this path as DUST_PATH_CUB_INCLUDE).
For editing your .Renviron file to set these environment
variables, usethis::edit_r_environ()
is very helpful.
dust_cuda_options which controls additional CUDA compilation options (e.g., profiling, debug mode or custom flags)
# If you have your CUDA library in an unusual location, then you
# may need to add a path_cuda_lib argument:
dust::dust_cuda_configuration(
path_cuda_lib = "/usr/local/cuda-11.1/lib64",
forget = TRUE, quiet = FALSE)
#> nvcc detection reported failure:
#> Did not find 'libcudart' within '/usr/local/cuda-11.1/lib64' (via provided argument)
#> $has_cuda
#> [1] FALSE
#>
#> $cuda_version
#> NULL
#>
#> $devices
#> NULL
#>
#> $path_cuda_lib
#> NULL
#>
#> $path_cub_include
#> NULL
#>
# However, if things are installed in the default location or you
# have set the environment variables described above, then this
# may work:
dust::dust_cuda_configuration(forget = TRUE, quiet = FALSE)
#> ℹ Loading dust85a6f458
#> ℹ 1 functions decorated with [[cpp11::register]]
#> ✔ generated file cpp11.R
#> ✔ generated file cpp11.cpp
#> ℹ Re-compiling dust85a6f458 (debug build)
#> ── R CMD INSTALL ───────────────────────────────────────────────────────────────
#> * installing *source* package ‘dust85a6f458’ ...
#> ** using staged installation
#> ** libs
#> using C++ compiler: ‘g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
#> using C++14
#> g++ -std=gnu++14 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -I'/home/runner/work/_temp/Library/cpp11/include' -I/usr/local/include -I/home/runner/work/_temp/Library/dust/include -DHAVE_INLINE -fopenmp -fpic -g -O2 -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c cpp11.cpp -o cpp11.o
#> nvcc -std=c++14 -O0 -I. -I/opt/R/4.4.1/lib/R/include -I/home/runner/work/_temp/Library/dust/include -I'/home/runner/work/_temp/Library/cpp11/include' -Xcompiler -fPIC -Xcompiler -fopenmp -x cu -c dust.cu -o dust.o
#> /bin/bash: line 1: nvcc: command not found
#> make: *** [Makevars:14: dust.o] Error 127
#> ERROR: compilation failed for package ‘dust85a6f458’
#> * removing ‘/tmp/Rtmp5TWbiw/devtools_install_1a824d09a737/dust85a6f458’
#> nvcc detection reported failure:
#> System command 'R' failed
#> $has_cuda
#> [1] FALSE
#>
#> $cuda_version
#> NULL
#>
#> $devices
#> NULL
#>
#> $path_cuda_lib
#> NULL
#>
#> $path_cub_include
#> NULL
#>