Tuesday, March 28, 2023

Installing and Using CUDA Tookit and cuDNN in Conda Virtual Environment of Python

This is straightforward.

  1. Create a conda virtual environment, e.g.,
    
    conda create -n cudacudnn python=3.9 pip
          
  2. Activate the virtual environment, i.e,
    
    conda activate cudacudnn
        
  3. Assume we are using Pytorch 2.0, e.g., install it via
    
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118  
        
  4. Install CUDA toolkit and cuDNN, e.g.,
    
    conda install -c conda-forge cudnn=8 cudatoolkit=11.8
        
  5. Add the library path of the conda environment to LD_LIBRARY_PATH. There are several approaches. Two appraoches are as follows, assuming the environment is at $HOME/.conda/envs/cudacudnn and we want to run foo.py,
    
    virtenv_path=$HOME/.conda/envs/cudacudnn
    export LD_LIBRARY_PATH=${virtenv_path}/lib:$LD_LIBRARY_PATH
    python foo.py
        
    or
    
    virtenv_path=$HOME/.conda/envs/cudacudnn
    LD_LIBRARY_PATH=${virtenv_path}/lib:$LD_LIBRARY_PATH python foo.py
        

No comments:

Post a Comment