環境設定
CUDA/cuDNN
Note: Unless you need to recompile the code, there is generally no need to install CUDA or cuDNN separately, as the framework includes pre-compiled CUDA. The framework version corresponds to the CUDA version, so you only need to pay attention to the framework version; there is no need to manage the CUDA version separately.
Check the default CUDA/cuDNN version
Note: The CUDA version displayed by the
nvidia-smicommand is only the highest CUDA version supported by the driver; it does not indicate that this specific version of CUDA is installed on the instance.
Run the following command in the terminal to check the CUDA version included with the default image (installation directory is /usr/local/):
# 查询平台内置镜像中的cuda版本
ldconfig -p | grep cuda
libnvrtc.so.11.0 (libc6,x86-64) => /usr/local/cuda-11.0/targets/x86_64-linux/lib/libnvrtc.so.11.0
libnvrtc.so (libc6,x86-64) => /usr/local/cuda-11.0/targets/x86_64-linux/lib/libnvrtc.so
libnvrtc-builtins.so.11.0 (libc6,x86-64) => /usr/local/cuda-11.0/targets/x86_64-linux/lib/libnvrtc-builtins.so.11.0
# 查询平台内置镜像中的cudnn版本
ldconfig -p | grep cudnn
libcudnn_ops_train.so.8 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8
libcudnn_ops_train.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so
libcudnn_ops_infer.so.8 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8
libcudnn_ops_infer.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so
In the output log above, the number following ".so" is the version number. If you installed CUDA via conda, you can check it using the following command:
conda list | grep cudatoolkit
cudatoolkit 10.1.243 h6bb024c_0 defaults
conda list | grep cudnn
cudnn 7.6.5 cuda10.1_0 defaults
Installing Other Versions of CUDA/cuDNN
Method 1: Install using conda
Advantages: Simple
Drawback: Header files are generally not included; if compilation is required, you must install it using Method 2.
Method:
conda install cudatoolkit==xx.xx
conda install cudnn==xx.xx
If you're unsure what the version number is, you can search for:
conda search cudatoolkit
Loading channels: done
# Name Version Build Channel
cudatoolkit 9.0 h13b8566_0 anaconda/pkgs/main
cudatoolkit 9.2 0 anaconda/pkgs/main
cudatoolkit 10.0.130 0 anaconda/pkgs/main
cudatoolkit 10.1.168 0 anaconda/pkgs/main
cudatoolkit 10.1.243 h6bb024c_0 anaconda/pkgs/main
cudatoolkit 10.2.89 hfd86e86_0 anaconda/pkgs/main
cudatoolkit 10.2.89 hfd86e86_1 anaconda/pkgs/main
cudatoolkit 11.0.221 h6bb024c_0 anaconda/pkgs/main
cudatoolkit 11.3.1 h2bc3f7f_2 anaconda/pkgs/main
Method 2: Install by downloading the installation package
CUDA download link: https://developer.nvidia.com/cuda-toolkit-archive
Installation instructions:
# 下载.run格式的安装包后:
chmod +x xxx.run # 增加执行权限
./xxx.run # 运行安装包,注意只需要安装cuda,不需要安装驱动等。
cuDNN download link: https://developer.nvidia.com/cudnn
Installation instructions:
First, unzip the files, then place the dynamic link libraries and header files in their respective directories.
mv cuda/include/* /usr/local/cuda/include/
chmod +x cuda/lib64/* && mv cuda/lib64/* /usr/local/cuda/lib64/
After installation, add the following environment variables:
echo "export LD_LIBRARY_PATH=/usr/local/cuda/lib64/:${LD_LIBRARY_PATH} \n" >> ~/.bashrc
source ~/.bashrc && ldconfig
Note:
The default images come with the most up-to-date versions of CUDA and cuDNN pre-installed. If you have installed cudatoolkits or similar software yourself, the system will generally prioritize using the cudatoolkits installed via conda by default,
