[AI study notes] TensorFlow GPU version installation (super detailed)

1. Confirm whether the graphics card supports CUDA

Before installation, we must first confirm whether the existing or planned discrete graphics card supports CUDA. The specific operations are as follows:

  1. Check the graphics card that supports CUDA, as shown in the figure below:
    For details, please go to the website https://developer.nvidia.com/cuda-gpus .

insert image description here

  1. Check the graphics card
    Open the task manager (Ctrl+Shift+Esc) --> "Performance" --> click "GPU" to view the name of the graphics card (the upper right corner of the picture below)

    With the name of the graphics card, you can refer to the above picture for comparison to see if it supports CUDA.
    insert image description here

2. Install CUDA

After we confirm that the system has installed a graphics card that supports CUDA, we can install CUDA. The specific steps are as follows:

  1. Download and install CUDA
    Download CUDA from NVIDIA official website: https://developer.nvidia.com/cuda-downloads
    insert image description here
    Note: Installer Type The difference between the two installation methods:
    ·exe(network): The file is relatively small when downloading, and it will be reinstalled after subsequent installation Download the rest.
    ·exe(local): When downloading, it is completely downloaded, and there is no need to download it when performing subsequent installations.

  2. Set the staging directory for the unpacked installer
    insert image description here
    Wait
    insert image description here

  3. Agree to the agreement and continue
    insert image description here

  4. Choose Compact Install
    insert image description here

  5. Warning Visual Studio is not installed
    CUDA can be developed with Visual Studio. The interface warns that Visual Studio is not installed.
    Since we will use Python to develop later, there is no need to install Visual Studio.
    insert image description here

  6. Download the CUDA interface
    insert image description here

  7. confirm installation
    insert image description here

  8. The installation is complete
    insert image description here

3. Install cuDNN

Then install cuDNN, as follows:

3.1 install cudnn

  1. Download cuDNN
    Download cuDNN from NVIDIA official website: https://developer.nvidia.com/cudnn .
    insert image description here

  2. Become a member
    To download cuDNN, you must become a member of the Accelerated Computer Developers Program.
    insert image description here

  3. Enter the download page
    After becoming a member and logging in, enter the download page.
    insert image description here

  4. View the downloaded file
    The downloaded file is a ZIP compressed file, which can be directly decompressed and opened in Windows 10.
    insert image description here
    insert image description here
    Rename it to "cuda"
    insert image description here
    Then place cuda in a suitable location, if you don't know how to put it, you can refer to step 5

  5. Copy to another directory
    Here I directly placed cuda in a directory on my D drive.
    insert image description here

  6. View cudnn64_8.dll
    in D:\CS\Code\Jupyter\cuda\bin (that is, in the .../cuda/bin directory) and you can see cudnn64_8.dll. This is the dynamic link library through which other programs can use the functions of cuDNN.
    insert image description here

3.2 Add the storage location of cudnn64_8.dll to the Path environment variable

In order to let the Windows system know the directory where cuDNN is installed, the Path environment variable must be set, so that other programs can access cudnn64_8.dll through this setting

  1. Open the system environment variable
    First click "Settings", and then do the following:
    insert image description here

  2. Edit the user variable in the environment variable
    Add "D:\CS\Code\Jupyter\cuda\bin" to the Path environment variable (that is, the installation directory of cudnn64_8.dll)
    insert image description here

insert image description here

4. Install TensorFlow GPU version

4.1 Establish TensorFlow GPU virtual environment in Anaconda

  1. Restart the Command Prompt program and change to the working directory.
    insert image description here

  2. Create TensorFlow GPU virtual environment in Anaconda
    Create command: conda create --name tensorflow-gpu python=3.9 anaconda
    insert image description here
    insert image description here

    After pressing the y key, the Anaconda virtual environment will be installed and various packages will be installed. After the installation is complete, the screen display interface is as follows:
    insert image description here

Order illustrate
create condas Create a virtual environment
–name tensorflow-gpu The name of the virtual environment is tensorflow-gpu
python=3.9 Python version is 3.9
anaconda Add this command option, when creating a virtual environment, other Python software packages will also be installed at the same time, such as Jupyter Notebook, Numpy, SciPy, Matplotlib, Pandas, for data analysis
  1. Enable the TensorFlow GPU virtual environment
    Start the Anaconda virtual environment: activate tensorflow-gpu
    insert image description here

4.2 Install Tensorflow-gpu

Next, install the TensorFlow GPU version in the TensorFlow GPU virtual environment
. Installation command: pip install tensorflow-gpu
insert image description here

4.3 Install Keras

Then install Keras
Installation command: pip install keras
insert image description here

Summarize

In this article, we mainly introduced how to install CUDA and cuDNN, established a TensorFlow GPU virtual environment, and installed the TensorFlow GPU version and Keras in the virtual environment.

Supplement:
If you don't understand Step 4: Installing the TensorFlow GPU version, you can refer to the installation of the TensorFlow CPU version in the Anaconda virtual environment.
For details, please refer to: [AI Study Notes] Installation of TensorFlow and Keras (Windows Anaconda Virtual Environment Edition)

For the powerful function of testing GPU in TensorFlow GPU virtual environment, I will continue to update in the follow-up.

Guess you like

Origin blog.csdn.net/weixin_45954198/article/details/128076082