How to get tensorflow-gpu v2 working on Windows with NVidia GPU

落爺英雄遲暮 提交于 2021-02-15 07:39:45

问题


What are the steps to get tensorflow-gpu 2.x Python package working on Windows with an NVidia GPU?

I.e. how can I get rid of Could not find 'cudart64_101.dll' and then Could not find 'cudnn64_7.dll'?


回答1:


Steps

  • Requires specific versions according to the error messages you see, not latest versions!

1. Download and install latest NVidia driver

https://www.nvidia.com/Download/index.aspx

2. Install Tensorflow Python package

pip uninstall tensorflow
pip install tensorflow-gpu

3. Test

At first the following test will fail, pay attention to version of missing file e.g. Could not find 'cudart64_101.dll'

import tensorflow

tensorflow.test.is_built_with_gpu_support() # Test install of pip package, should output True
tensorflow.test.is_gpu_available() # Should output True
tensorflow.test.gpu_device_name() # Should output something like /device:GPU:0

4. Download and install CUDA Toolkit 10.1 local setup

  • The version you need is the one not found e.g. cudart64_101.dll --> version 10.1.
  • You will need to unselect components because setup contains an older driver, in network setup this doesn't work right

https://developer.nvidia.com/cuda-10.1-download-archive-base?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal

Select custom setup and:

  • Unselect CUDA / Visual Studio Integration
  • Unselect Driver components

5. Make sure these folders have been added to path:

  • And no other versions of CUDA
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp;

6. Test again

  • Restart your IDE for it to receive new environment variables (including PATH)

Will fail, pay attention to version of missing file e.g. Could not find 'cudnn64_7.dll'

7. Download and manually install CUDNN 7.6.5 for CUDA 10.1

  • The version you need is the one not found e.g. cudnn64_7.dll --> version 7.x for CUDA 10.1 (or the version of CUDA you needed)

https://developer.nvidia.com/rdp/cudnn-archive

  • Unzip and copy content of cuda folder into: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\ (or the version you downloaded and installed)
  • If you have any conflicts, skip duplicate files

8. Test again

  • Should work this time, assuming you downloaded the correct versions


来源:https://stackoverflow.com/questions/65524505/how-to-get-tensorflow-gpu-v2-working-on-windows-with-nvidia-gpu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!