Small Tricks
Table of Contents
Switch CUDA Version
Use enviroment-modules to switch CUDA version in different enviroment
Basic Usage
-
Install enviroment-modules.
conda install -c conda-forge environment-modules conda install -c conda-forge environment-modules -
Create modules file, e.g CONDA_PREFIX/modulefiles/cuda/11.7
#Create module file in the current enviroment mkdir -p $CONDA_PREFIX/modulefiles/cuda -
Create and edit the module file 11.8, an example of module file:
#%Module1.0 proc ModulesHelp { } { global version puts stderr "Sets up environment for CUDA $version" } module-whatis "sets up environment for CUDA 11.8" set version 11.8 #Use your own CUDA path set root /usr/local/cuda-11.8 setenv CUDA_HOME $root prepend-path PATH $root/bin prepend-path LD_LIBRARY_PATH $root/lib64 prepend-path MANPATH $root/doc/man conflict cuda
After all this settings, you can load and unload your own CUDA version with following instrctions:
module load cuda/11.7
module unload cuda/11.7
Auto-load Configuration
-
Activation script edition.
cat > $CONDA_PREFIX/etc/conda/activate.d/load_cuda.sh << 'EOF' #!/bin/bash export MODULEPATH=$CONDA_PREFIX/modulefiles:$MODULEPATH module load cuda/11.8 echo "Loaded CUDA 11.8 for this environment" EOF -
Deactivation script edition.
cat > $CONDA_PREFIX/etc/conda/deactivate.d/unload_cuda.sh << 'EOF' #!/bin/bash module unload cuda echo "Unloaded CUDA modules for this environment" EOF -
Make scripts executable.
chmod +x $CONDA_PREFIX/etc/conda/activate.d/load_cuda.sh chmod +x $CONDA_PREFIX/etc/conda/deactivate.d/unload_cuda.sh
After all this, your enviroment can auto load/unload the CUDA module