ubuntu cudnn怎么添加到环境变量
时间: 2023-09-02 12:07:11 浏览: 104
1. 打开终端,输入以下命令进入CUDA安装目录:
```
cd /usr/local/cuda-<version>/include
```
其中,`<version>`是你所安装的CUDA版本号,例如:`cd /usr/local/cuda-10.1/include`
2. 查看cudnn.h文件所在的文件夹:
```
ls -l
```
3. 将cudnn.h文件夹路径添加到环境变量中:
```
sudo gedit ~/.bashrc
```
在文件末尾添加以下代码:
```
export LD_LIBRARY_PATH=/usr/local/cuda-<version>/lib64:$LD_LIBRARY_PATH
export CPATH=/usr/local/cuda-<version>/include/cudnn.h:$CPATH
export LD_LIBRARY_PATH=/usr/local/cuda-<version>/extras/CUPTI/lib64:$LD_LIBRARY_PATH
```
其中,`<version>`是你所安装的CUDA版本号,例如:
```
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64:$LD_LIBRARY_PATH
export CPATH=/usr/local/cuda-10.1/include/cudnn.h:$CPATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/extras/CUPTI/lib64:$LD_LIBRARY_PATH
```
4. 保存并关闭bashrc文件,然后输入以下命令使其生效:
```
source ~/.bashrc
```
5. 验证是否添加成功:
```
nvcc -V
```
如果出现以下结果,则说明添加成功:
```
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Oct_12_20:09:46_PDT_2020
Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.r11.1/compiler.29373293_0
```
6. 如果仍然无法使用cudnn,则可以尝试重启计算机或者重新安装cudnn。
阅读全文