Environment configuration:
system | cpu | gpu | CUDA | CUDNN | |
win10 | i5-10210U | MX350 video memory 2GB | 10.2 | v7.6.5 |
1. Install CUDA
1. Confirm the computer graphics card model:
Check the GPU model in the Device Manager (right-click this computer, select Manage, enter the page, and you can see the Device Manager on the left) (with independent graphics)
2. Determine the CUDA version supported by the graphics card:
Open NVIDIA Control Panel→Help→System Information→Components and check the CUDA version
3. Go to NVIDIA official website to download the corresponding CUDA version.
Download address:
https://developer.nvidia.com/cuda-toolkit-archive
Baidu network disk download:
The version I downloaded is CUDA10.2 (online download)
Select the installation environment of CUDA . For the installation type, I will take online installation (network) as an example.
4. Install CUDA:
Double-click to execute the downloaded exe file. The file will be decompressed to a temporary directory (not the installation directory) first. Just keep the default.
5. Installation process:
Select custom
Uncheck Visual Studio Integration. Some tutorials say that the next two Driver Components and Other Components can also be unchecked.
It is recommended to install it on the C drive by default.
It was always at 0% at the beginning and had to wait for a while. My installation process took about 15 minutes (because the online installation is slow)
6. Configure CUDA environment variables
How to open environment variables (My Computer--Right-click--Select Properties--Select Advanced System Settings--Environment Variables)
First check whether the environment variable exists, and then add it manually if it does not exist.
Manually add as follows: Copy and paste the following into the variable value of CUDA_PATH
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\lib\x64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\extras\CUPTI\lib64
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.2\bin\win64
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.2\common\lib\x64
7. Verify whether CUDA is installed successfully
win+R, enter cmd to open the command prompt window, enter nvcc -V
2. Install TensorFlow under conda
-
Install the Python environment. It is recommended here to install the Python 3.7 64-bit version of Anaconda . Anaconda installation package is available here .
-
Open "Anaconda Prompt" in the start menu to enter the Anaconda command line environment, use Anaconda's own conda package manager to create a Conda virtual environment, and enter the virtual environment. Enter at the command line:
conda create --name tf2 python=3.7
# "tf2" is the name of the conda virtual environment you created
conda activate tf2
# Enter the conda virtual environment named "tf2"
3. Use the Python package manager pip to install TensorFlow. Enter at the command line
pip install tensorflow
If the download using the above command is too slow, you can directly specify the mirror download, as follows:
pip install -i https://pypi.douban.com/simple tensorflow
Wait for a moment and the installation will be completed.
You can also use it
conda install tensorflow
to install TensorFlow, but the version of the conda source is often updated slowly, making it difficult to obtain the latest TensorFlow version in the first time;Starting from TensorFlow 2.1, the pip package
tensorflow
also includes GPU support, and there is no needtensorflow-gpu
to install the GPU version through a specific pip package. If you are sensitive to the size of your pip package, you can usetensorflow-cpu
the package to install a CPU-only version of TensorFlow.
3. Installation of CUDA Toolkit and cuDNN
To install CUDA Toolkit and cuDNN, follow the version instructions on the TensorFlow official website . What is installed here is cudatollkit10.1 and cudnn7.6.5 (Note: Enter the two commands into Anaconda Prompt respectively. After one installation is completed, install the other one)
conda install cudatoolkit=10.1
conda install cudnn=7.6.5
Before installation, the version number available in the conda source can be used conda search cudatoolkit
and searched.conda search cudnn
Of course, you can also manually download and install CUDA Toolkit and cuDNN according to the instructions on the TensorFlow official website , but the process will be a little cumbersome.
4. Verify whether TensorFlow is installed successfully
After the installation is complete, let's write a simple program to verify the installation.
At the command line, enter conda activate tf2
the previously created Conda virtual environment with TensorFlow installed, then enter python
the Python environment, and enter the following code line by line:
import tensorflow as tf A = tf.constant([[1, 2], [3, 4]]) B = tf.constant([[5, 6], [7, 8]]) C = tf.matmul(A, B) print(C)
If it can finally output:
tf.Tensor( [[19 22] [43 50]], shape=(2, 2), dtype=int32)
Main references above:
5. Continue to report errors:
21:50:09.172128:W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2021-11-14
21:50:09.172128: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
The file numbers reported in the error may be different, but this is still a version mismatch problem. The solution is as follows: (I personally recommend the third option)
1. Some people say that import tensorflow can run normally after importing scipy first, but I can do it in conda but still not in pycharm.
2. Copy the files with similar names in the cuda installation directory C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin and rename them to the missing files. //This is what I did. I don’t know if there will be any problems. I’ll talk about it later.
3. Or download one from the Internet and put it in // This is the recommended method, but since I couldn’t access the NVIDIA official website during the past few days of installation, I can only use the above method.
https://www.dll-files.com/download/527365cb86fd76a9a7b7e9c75b4842d3/cudart64_110.dll.html?c=VTJuUXgvTENydDYzektxWENSbTZXUT09https://www.dll-files.com/download/527365cb86fd76a9a7b7 e9c75b4842d3/cudart64_110.dll.html?c= VTJuUXgvTENydDYzektxWENSbTZXUT09 https ://www.dll-files.com/download/527365cb86fd76a9a7b7e9c75b4842d3/cudart64_110.dll.html?c=VTJuUXgvTENydDYzektxWENSbTZXUT09