glearn.device.locate_cuda#
- glearn.device.locate_cuda()#
Returns the directory paths and version of CUDA Toolkit installation.
Note
Either of the environment variables
CUDA_HOME
,CUDA_ROOT
, orCUDA_PATH
should be set with the home directory of the CUDA Toolkit installation before calling this function.- Returns:
- cudadict
A dictionary with the following keys:
home
: str, home directory of CUDA.nvcc
: str, the path tonvcc
compiler file.lib
: str, the path to the library directory of CUDA.include
: str, the path to the directory of header files.version
: dict, the version of CUDA Toolkit with the following keys:major
: int, the major number of versionminor
: int, the minor number of versionparth
: int, the patch number of version
If no CUDA Toolkit is found, it returns an empty dictionary
{}
.
- Raises:
- EnvironmentError
Raised if in the home directory of the CUDA Toolkit, the expected sub-directories cannot be found.
Notes
Setting Environment Variables:
In order to find CUDA Toolkit information properly, either of the environment variables
CUDA_HOME
,CUDA_ROOT
, orCUDA_PATH
should be set to the directory where CUDA Toolkit is installed. Usually on UNIX operating systems, this path is/usr/local/cuda
. In this case, setCUDA_HOME
(or any of the other variables mentioned in the above) as follows:export CUDA_HOME=/usr/local/cuda
To permanently set this variable, place the above line in
profile
file, such as in~/.bashrc
, or~/.profile
, and source this file, for instance bysource ~/.bashrc
Note
It is possible that the CUDA Toolkit is installed on the machine, but
cuda_version
key shows not found. This is because the user did not set the environment variables mentioned in the above.Expected Directory Structure:
This function looks for the executable
nvcc
(ornvcc.exe
if windows) in the directory specified byCUDA_HOME
,CUDA_ROOT
orCUDA_PATH
environment variables. Ifnvcc
executable is found, it continues searching for the directory structure as described below.The expected sub-directories under the CUDA home directory should have the following structure:
/bin
with the executable/bin/nvcc
(or/bin/nvcc.exe
in Windows)/include
with the file/include/cuda.h
/lib
orlib64
in UNIX, andlib/x86
orlib/x64
in Windows.
Examples
Suppose the CUDA Toolkit is installed in
/usr/local/cuda
. First, in a Shell environment, export the variableexport CUDA_HOME=/usr/local/cuda
Then in Python script, obtain info about the CUDA paths and version using:
>>> # Import function >>> from glearn.device import locate_cuda >>> cuda = locate_cuda() >>> # Neatly print the dictionary using pprint >>> from pprint import pprint >>> pprint(cuda) { 'home': '/usr/local/cuda/11.7', 'include': '/usr/local/cuda/11.7/include', 'lib': '/usr/local/cuda/11.7/lib64', 'nvcc': '/usr/local/cuda/11.7/bin/nvcc', 'version': { 'major': 11, 'minor': 7, 'patch': 0 } }