搭建CUDA + tensorflow + CuDnn
几点要注意的
- 不需要装vs也是可以的
- 版本一定要对应,如CUDA11就一定需要tensorflow2.4以上
正常安装流程
-
安装显卡驱动
-
安装cuda
-
下载cudnn
-
解压cudnn,复制 bin, include, lib到 NVIDIA GPU Computing Toolkit\v11.1 目录下,其实本质就是增加扩展
-
然后配置这三个文件夹进入path,bin、lib等
-
前面几步网上基本都有,百度就行了https://zhuanlan.zhihu.com/p/29841665
-
下面的步骤比较关键,这是基于已经有anaconda环境的情况下的步骤
-
conda create -n mytensor --clone base
-
conda activate mytensor
-
python -m ipykernel install --user --name mytensor --display-name=“mytensor-kernel”
-
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
-
pip install tensorflow-gpu==2.4.0
-
到这一步,基本上就安装完了,但是,一定要记得,不要直接用jupyterlab去测试,血的教训,因为不会提示warning
-
首先测试 nvcc -V NVIDIA-smi 这两个cmd命令,查看输出是否正确
-
然后如果正确,在mytensor环境下,运行python
-
from tensorflow.python.client import device_lib
-
print(device_lib.list_local_devices())
-
这两步执行完,如果输出有GPU,那就没事了,如果没有,仔细看输出信息,W代表warning
-
-
代表这个dll没找到,但是,这个属于tensorflow的bug,处理方式是,新建一个软链接到11的那个dll
-
进入到NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin目录下
-
powershell执行 New-Item -ItemType SymbolicLink -Path .\cusolver64_10.dll -Target .\cusolver64_11.dll
-
然后再试试就好了