Windows environment Tensorflow 2.3.0 entry guide (about configuring CUDA and CUDNN)

Windows environment Tensorflow 2.3.0 entry guide (about configuring CUDA and CUDNN)

  I use Pycharm for Tensorflow learning, especially here to record the process of environment configuration. (In the beginning, I only installed the Tensorflow 2.3.0 package on Pycharm, and then started to run the program) The result was a bunch of amazing things, but the final correct result appeared:

Sample of this chapter

  First of all, this is the code I ran (very simple, just getting started):

# Author:JinyuZ1996
# Creation date:2020/8/15 11:39

import tensorflow as tf

a = tf.constant([1.0, 2.0], name='a')   #构建一个二维数组常量
b = tf.constant([2.0, 3.0], name='b')

print(a)

Reproduce the problem

  The following things are printed in the Runtime console (a lot of red progress information, this is the log mode of Tensorflow):

  One of his logs starts with W, such as W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library'cublas64_10.dll';........

  This is a reminder that we have not been able to find enough dll runtime libraries for training. In fact, it is caused by not configuring CUDA yet. (There will be the following prompt in the middle of the log):

  W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.

Skipping registering GPU devices... (Skip using GPU)

  Then I saw it skipped the use of GPU and switched to CPU for training. This is not great...Although the results can still be obtained, because it is relatively simple now, but in the future when we want to train more complex models, the efficiency of CPU is far worse than GPU, so it is necessary to spend time exploring how to install And use CUDA to start our GPU for training.

  The use of CUDA requires us to explore our own graphics card, and then start to explain in steps:

Step 1: Go to check your own NVIDIA control panel

  Open your own NVIDIA control panel to check the system information, the purpose is to find the CUDA version of the driver we currently install:

  Then check the system information, your own CUDA version (as shown in the figure):

  My graphics card is GTX 1050Ti. As of the time I write this article, my graphics card driver version is 451.82. From here, we can see that the corresponding version of his CUDA is V11.0. If it is good, we will download a full version. CUDA v11.0 to configure our GPU training.

Step 2: Download the corresponding CUDA version

  Baidu searches for CUDA 11.0, usually the first search result is, or you can download it directly from https://developer.nvidia.com/cuda-downloads . I want to add to everyone here. CUDA contains two versions, one The network version is about fifty or sixty M (in fact, it is a downloader, and you need to download about 3 G of resources to start the installation), and the other is the Local version, which is the offline installation version (close to 3 G, just download it Can be fully installed, I am using this version) The download page is as follows:

  Let me add one more thing. Sometimes the download page will not open. I don’t know why. It may be a problem with my win10 version or my mobile broadband. When I log in and visit Nvidia’s website, I always get stuck. . I went to find a relatively reliable solution:

  You can do this (follow my steps): First, right-click the start menu to search for cmd, open cmd with administrator privileges, and enter the following code:

netsh winsock reset

  Then you will see the following interface: (it prompts us to restart again)

  Then, I personally can access smoothly after the above operations, and the download speed can also reach the state of full resources (I am downloading the local version 2.88G, about 29M/s download speed) Anyway, it's fine, download it Then you can start the installation. Of course, in order to prevent some students from not being able to board, I posted the download link of the network version of CUDA v11.0 here (the free resource is to give you a run): https://download.csdn.net/download/qq_39381654/12720656

  As for the installation process of CUDA, you can refer to this blogger's article https://blog.csdn.net/a583621671/article/details/87272803 , which is also more detailed (in fact, I forgot to take the screenshot during the installation process , It’s not easy to add here, so let’s be lazy and let everyone take a look at the process of installing the 9.0 version of this blogger for reference) Even if we install v11.0, try not to check and install Visio Studio Integration 11.0, it is too slow! And it may cause the entire installation process to fail due to network problems.

  However, you can find that the v11.0 that I guide you in this article does not need to install the upgrade package, it only has a Base Installer. So don’t have to be lucky to install a lot of patches like the blogger just now.

Verify installation

  After the installation is complete, the installation program will actively assign two environment variables. You should be able to verify the success of the installation through cmd. For example, we can enter the code in the command line: nvcc -V to see the installed CUDA v11.0 That means it is installed:.

Configuration of the CUDNN part

  After configuring CUDA, it’s time to configure CUDNN. The version of CUDNN corresponds to CUDA. If you follow the same process as the author, then you should also need my version of CUDNN (cudnn- 11.0-windows-x64-v8.0.1.13) You can see that the v8.0.1.13 I downloaded corresponds to CUDA v11.0. You will find that it is a lib after it is downloaded, which is actually a supplement to CUDA. You only need to copy and replace the contents of the CUDA subfolder in the downloaded CUDNN folder to the same location in the CUDA folder you just installed. Yes, the download address of the official website is: https://developer.nvidia.com/cudnn  However, this download requires you to log in to the NVIDIA account to download. I registered an NVIDIA developer account on the spot and bound it My previous email address allowed me to download the next step (sometimes he will first investigate why you downloaded CUDNN, and automatically arrive at the download page after filling in the questionnaire):

  After downloading, decompressing should be able to see this directory structure:

  The next step is to copy all the components in this directory to the CUDA subdirectory just installed (for example, if I installed CUDA11 according to the default path, I should find: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11. 0) As shown below:

  Copy all the subdirectories just now (there should be no replacement, just add something to the corresponding subfolder), and you are done.  

  Of course, some students may not be able to download it, so I will put another connection (cudnn-11.0-windows-x64-v8.0.1.13 is still provided for free): https://download.csdn.net/download/qq_39381654/12721693

Additional steps to configure environment variables

  This is the end of the general tutorial, but you will find that Pycharm’s error report is still there, and it still can’t solve the problem of several missing libraries. This is because our Pycharm still can’t find our CUDA library lib. We need to know Pycharm. You can only solve part of the problem by configuring the environment variables. If you still can’t solve it, you can manually add the missing libraries. I will share them in this article.

  First, I will give you the environment variable modification methods mentioned by other bloggers in my collection. First, when we install CUDA, we should give us two environment variables by default: (If you don’t have one, please add these two yourself)

  Then according to my sorting, we also need to add these in the environment variable Path:

Extra circumstances (if still not possible*)

  Most of the students got to this step, and then run Tensorflow 2.3.0 should be able to start the GPU, but I will give a more exaggerated solution, that is, the solution when it still does not work: multiple reasons (First of all, there may be a problem in your Pycharm installation process, and the local environment is not automatically bound, then this is the first case, and secondly, the second case is that the .dll is really missing and not marked, I will give it directly at the end of the article , Just type it yourself)

  Go to configure one more Pycharm IDE environment variable: LD_LIBARARY_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\lib\x64 (Paste this line of code to the location shown in the picture):

  If the IDE is the English version, you should search for File->Setting-> Python Console and enter the code I just gave you under the Environment box (if your CUDA is pressed to another location, don’t make it mechanically, you should fill in the corresponding location of your CUDA directory here).

  If it is the second case, or if you still can’t solve it according to the first solution I just gave, then it’s okay, can we just fill in the missing dll by ourselves? At this time, most of the The dynamic link library CUDA should be brought here, you only need to find those .dll libraries that could not be found in the Tensorflow warning at the beginning of W. (I will give a few libraries that are usually missing at the end of the article. In fact, I still hope that you can find them by yourself. This should not be difficult to find.) I list the ones that are generally missing:

  You will find that I circled the two groups with a box. Why? Because these two groups are missing 64_10, and what I did is to copy 64_11 and change the name, and that's it. It was v11.0 that encapsulated what it needed to 64_11 and Tensorflow2.3.0 didn't know it, so I couldn't find it. Just change it to a lower version name...). But if there are other missing, please go to Baidu to add it yourself. Usually, if CUDA is installed correctly and the environment variable configuration is correct, there should be only a few missing. If it is missing a lot, it should be that CUDA is not configured properly or the environment variables are broken. It doesn't matter, I will give you a few dynamic link libraries that I was missing at the time. You can see if you can meet your needs:

Dynamic link library packages you may use

  https://download.csdn.net/download/qq_39381654/12722120

Guess you like

Origin blog.csdn.net/qq_39381654/article/details/108063967