Install cuda, cudnn, cudatoolkit in Linux offline state

1. Download and Installation Instructions

  • Toolkit download address

    • CUDA historical version download address: https://developer.nvidia.com/cuda-toolkit-archive
    • cuDNN historical version download address: https://developer.nvidia.com/rdp/cudnn-archive
    • Download address of each version of cudatoolkit: https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/
  • version requirements

    pytorch, cuda, and cuDNN are strictly corresponding, and cuda_10.2.89_440.33.01_linux.run is installed here, and the corresponding cudnn version is 10.2-linux-x64-v7.6.5.32

  • File Upload

    Upload the downloaded installation package to the folder where files are stored under offline Linux, and upload it here to the files folder in the home directory.

2. CUDA installation

**Note: **Here, take installing cuda into the software folder as an example to complete the following installation steps:

  • Copy the cuda toolkit installer in the files folder to the software folder

    cp files/cuda_10.2.89_440.33.01_linux.run ~/software/
    

    Enter the directory where the cuda toolkit installer is placed (/data/users/CHHDHPC/2017901437/software/), and execute ls to view the files in the current directory:
    insert image description here

  • Modify the running permission of the cuda toolkit installer

    chmod +x cuda_10.2.89_440.33.01_linux.run
    
  • Run the cuda toolkit installer

    ./cuda_10.2.89_440.33.01_linux.run
    

    insert image description here

  • Type accept and press Enter. The following appears:
    insert image description here

  • Only check the CUDA Toolkit option. If other version installation packages have other options, only check the CUDA Toolkit option.
    insert image description here

  • Move the cursor to Options and press Enter to modify the installation directory. After pressing Enter, the following figure appears:
    insert image description here
    Here we need to modify the paths of Toolkit Options and Library install path.

  • Modify Toolkit Options path

    • Move the cursor to Toolkit Options and press Enter
      insert image description here
    • Uncheck all checked options as shown below
      insert image description here
    • Move the cursor to Change Toolkit Install Path and press Enter
      insert image description here
    • Change the installation path to the path in your own home directory, here it is changed to " /data/users/CHDHPC/2017901437/software/cuda-10.2/ ", where 2017901437 is the user account.
      insert image description here
    • Press the Enter key to confirm, the following content appears
      insert image description here
    • Move the cursor to Doen, press Enter to return, and the following content appears
      insert image description here
  • Modify the Library install path path

    • Move the cursor to the Library install path, and press the Enter key, the following content appears
      insert image description here
    • Enter the modified path, which is modified here to " /data/users/CHHDHPC/2017901437/software/cuda-10.2/ ", as shown below
      insert image description here
    • Press the Enter key to confirm, the following content appears
      insert image description here
    • Move the cursor to Done, press Enter to confirm, and the path modification is completed
  • Start the installation: move the cursor to Install, and press Enter to start the installation, as follows
    insert image description here

  • The installation is complete: the following installation information appears, indicating that the installation is successful
    insert image description here

  • Modify environment variables

    • Open the bashrc configuration file

      # 打开bashrc配置文件
      vim ~/.bashrc
      
    • Then, add the following to it:

      # cuda env
      export CUDA_HOME=$CUDA_HOME:/data/users/CHDHPC/2017901437/software/cuda-10.2
      export PATH=$PATH:/data/users/CHDHPC/2017901437/software/cuda-10.2/bin
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/users/CHDHPC/2017901437/software/cuda-10.2/lib64
      
    • The addition is complete, as shown in the figure below:
      insert image description here

    • Execute wq, save and exit

  • activate environment variable

    source ~/.bashrc
    
  • The test installation was successful
    insert image description here

  • The installation is complete

3. cuDNN installation

  • Copy the cuDNN toolkit installer in the files folder to the software folder

    cp cudnn-10.2-linux-x64-v7.6.5.32.tgz ~/software/
    

    Enter the directory where the cuDNN toolkit installer is placed (/data/users/CHHDHPC/2017901437/software/), and execute ls to view the files in the current directory:
    insert image description here

  • Unzip the downloaded cuDNN

    tar -zxvf cudnn-10.2-linux-x64-v7.6.5.32.tgz
    

    insert image description here

  • Copy the cuDNN pressurized file to the CUDA installation directory

    cp cuda/include/cudnn*  cuda-10.2/include/
    cp cuda/lib64/libcudnn* cuda-10.2/lib64/
    
  • Modify the permissions of copied files

    chmod a+r cuda-10.2/include/cudnn* cuda-10.2/lib64/libcudnn*
    
  • After the installation is complete, delete the decompressed cuda folder and other installation packages under the installation directory software.

4. cudatoolkit installation

  • Copy the cudatoolkit toolkit installer in the files folder to the software folder

    cp cudatoolkit-10.2.89-hfd86e86_1.tar.bz2 ~/software/
    

    Enter the directory where the cudatoolkit toolkit installer is placed (/data/users/CHDHPC/2017901437/software/), and execute ls to view the files in the current directory:
    insert image description here

  • Activate the python virtual environment to configure the environment in anaconda. The default environment is configured here, that is, the base virtual environment is activated. If the environment is already active, skip this step.

    conda activate base
    
  • Use the conda installation command to package the cudatoolkit tool in the currently activated virtual environment. (The conda install installation command can only install packages in the currently activated python virtual environment)

    conda install --offline cudatoolkit-10.2.89-hfd86e86_1.tar.bz2
    
  • The installation is complete as shown below
    insert image description here

5. The test installation is successful

  • Activate the virtual environment

    conda activate base
    
  • Enter the python interpreter and enter the following code to test the successful installation of pytorch and cuda.

    import torch
    print(torch.version.cuda)
    

    insert image description here

Guess you like

Origin blog.csdn.net/qq_43522889/article/details/130351532