dust_cuda_configuration: Detect CUDA configuration

View source: R/cuda.R

dust_cuda_configurationR Documentation

Detect CUDA configuration

Description

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.

Usage

dust_cuda_configuration(
  path_cuda_lib = NULL,
  path_cub_include = NULL,
  quiet = TRUE,
  forget = FALSE
)

Arguments

path_cuda_lib

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

path_cub_include

Optional path to the CUB headers, if using CUDA < 11.0.0. See Details

quiet

Logical, indicating if compilation of test programs should be quiet

forget

Logical, indicating if we should forget cached values and recompute the configuration

Details

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:

dust:::cuda_install_cub(NULL)

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.

Value

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.

See Also

dust_cuda_options which controls additional CUDA compilation options (e.g., profiling, debug mode or custom flags)

Examples

# 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)

# 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)

mrc-ide/dust documentation built on Oct. 6, 2023, 8:26 a.m.