Home > Software design >  Conda env downgrade nvcc
Conda env downgrade nvcc

Time:08-08

I'm trying to install/downgrade to nvcc 10.2 in my conda environment (anaconda3) as it is needed by the version of PyTorch (1.10.2) that I'm using.

I have a nvcc 11.7 installation outside of conda, which my conda env is automatically using.

I was able to install and supersede cudatoolkit 10.2 successfully, but that doesn't come with nvcc.

So torch.version.cuda gives me 10.2 but nvcc -V gives me 11.7.

Internet mainly suggests installing cudatoolkit-dev from conda-forge as it seems to come with nvcc but there is no cudatoolkit-dev 10.2 to be found with

conda search cudatoolkit-dev --channel conda-forge

I'm using Ubuntu 22.04, a GTX1080 with driver 515.43.04.

CodePudding user response:

It would help if you could understand how CudaToolkit, NVCC, and the PyTorch version you installed are related. Wikipedia says

Nvidia CUDA Compiler is a proprietary compiler by Nvidia intended for use with CUDA. CUDA code runs on both the CPU and GPU. NVCC separates these two parts and sends host code to a C compiler like GCC or Intel C Compiler or Microsoft Visual C Compiler, and sends the device code to the GPU.

you can have multiple CUDA versions installed on your computer at the same time but only one could be used (the one that is on the set path)

Conda creates a new virtual environment to package your code libraries such has python == 3.6 torch == 10.2 etc. It helps you to have different versions of PyTorch and other libraries so that you can switch between those environments when required (for example for different projects you may have different torch versions NumPy versions etc.). But conda can not change CUDA, CudaToolkit paths

Solution: If you have installed CUDA, CUDA Toolkit you need to put that on the path here is an example how

# PATH FOR CUDA 10.0 being used by tensorflow 1.13
#export PATH="/usr/local/cuda-10.0/bin:$PATH"
#export LD_LIBRARY_PATH="/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH"
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64

#write for CUDA libs 11.0
#export PATH=$PATH:/usr/local/cuda-11.0/bin
#export CUDADIR=/usr/local/cuda-11.0
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.0/lib64

# PATH FOR CUDA 10.2
#export PATH="/usr/local/cuda-10.2/bin:$PATH"
#export LD_LIBRARY_PATH="/usr/local/cuda-10.2/lib64:$LD_LIBRARY_PATH"
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.2/lib64
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.2/extras/CUPTI/l$


#cuda 11.4
export PATH="/usr/local/cuda-11.4/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-11.4/lib64:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.4/lib64

enter image description here

I have multiple CUDA versions installed and I uncomment whenever a specific version is required in bashrc file.

in ubuntu, you can open it with

sudo nano ~/.bashrc

on Windows maybe you need to add it in environment variables please check the NVIDIA guide for that and change your paths as required.

CodePudding user response:

nvcc is mapped to what CUDA version exists in your environment path. This means, that when you install cudatoolkit through conda, you won't be able to get nvcc unless you have installed CUDA manually either through apt or NVIDIA's website. You can validate that using this command: which nvcc, and this command should show some path under /usr/local/ not under your conda environment.

When you install cudatoolkit, you are installing CUDA version within your python environment which torch is mapped and has access. That's why torch.version.cuda gives a different version than nvcc --version.

  • Related