Skip to content

Instantly share code, notes, and snippets.

@zhsh9
Forked from denguir/cuda_install.md
Created November 28, 2024 14:30

Revisions

  1. @denguir denguir revised this gist Oct 13, 2024. 1 changed file with 20 additions and 1 deletion.
    21 changes: 20 additions & 1 deletion cuda_install.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # How to install CUDA & cuDNN on Ubuntu 22.04
    # How to install CUDA / cuDNN / TensorRT on Ubuntu

    ## Install NVIDIA drivers

    @@ -104,4 +104,23 @@ print(torch.cuda.is_available()) # should be True

    t = torch.rand(10, 10).cuda()
    print(t.device) # should be CUDA
    ```


    ## Install TensorRT
    ### Download tensorrt .deb file
    Go to Nvidia webiste [here](https://developer.nvidia.com/tensorrt/download). Select latest TensorRT version that matches your CUDA version and download the DEB file.

    ```shell
    sudo apt install ./<filename.deb>
    sudo apt update
    sudo apt install tensorrt
    ```

    ### Verify trtexec
    Verify that the trtexec utility is present.

    ```shell
    whereis trtexec # should be trtexec: /usr/src/tensorrt/bin/trtexec
    /usr/src/tensorrt/bin/trtexec
    ```
  2. @denguir denguir revised this gist Apr 9, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cuda_install.md
    Original file line number Diff line number Diff line change
    @@ -84,7 +84,7 @@ sudo apt install libcudnn8-samples
    ## Test CUDA on Pytorch


    ### Create a Virtualenv and activate it
    ### Create a virtualenv and activate it
    ```shell
    sudo apt-get install python3-pip
    sudo pip3 install virtualenv
  3. @denguir denguir revised this gist Apr 9, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions cuda_install.md
    Original file line number Diff line number Diff line change
    @@ -74,6 +74,7 @@ sudo cp /var/cudnn-<something>.gpg /usr/share/keyrings/

    My cuDNN version is 8, adapt the following to your version:

    ```shell
    sudo apt update
    sudo apt install libcudnn8
    sudo apt install libcudnn8-dev
  4. @denguir denguir revised this gist Apr 9, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion cuda_install.md
    Original file line number Diff line number Diff line change
    @@ -69,8 +69,10 @@ nvcc --version
    ### Install cuDNN
    ```shell
    sudo apt install ./<filename.deb>

    sudo cp /var/cudnn-<something>.gpg /usr/share/keyrings/
    ```

    My cuDNN version is 8, adapt the following to your version:

    sudo apt update
    sudo apt install libcudnn8
  5. @denguir denguir renamed this gist Apr 9, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt → cuda_install.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # How to install CUDA Ubuntu 22.04
    # How to install CUDA & cuDNN on Ubuntu 22.04

    ## Install NVIDIA drivers

  6. @denguir denguir created this gist Apr 9, 2023.
    104 changes: 104 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,104 @@
    # How to install CUDA Ubuntu 22.04

    ## Install NVIDIA drivers

    ### Update & upgrade
    ```shell
    sudo apt update && sudo apt upgrade
    ```

    ### Remove previous NVIDIA installation
    ```shell
    sudo apt autoremove nvidia* --purge
    ```

    ### Check Ubuntu devices
    ```shell
    ubuntu-drivers devices
    ```
    You will install the NVIDIA driver whose version is tagged with __recommended__


    ### Install Ubuntu drivers
    ```shell
    sudo ubuntu-drivers autoinstall
    ```

    ### Install NVIDIA drivers
    My __recommended__ version is 525, adapt to yours

    ```shell
    sudo apt install nvidia-driver-525
    ```

    ### Reboot & Check
    ```shell
    reboot
    ```
    after restart verify that the following command works
    ```shell
    nvidia-smi
    ```

    ## Install CUDA drivers

    ### Update & upgrade
    ```shell
    sudo apt update && sudo apt upgrade
    ```

    ### Install CUDA toolkit
    ```shell
    sudo apt install nvidia-cuda-toolkit
    ```

    ### Check CUDA install
    ```shell
    nvcc --version
    ```

    ## Install cuDNN

    ### Download cuDNN .deb file
    You can download cuDNN file [here](https://developer.nvidia.com/rdp/cudnn-download). You will need an Nvidia account.
    Select the cuDNN version for the appropriate CUDA version, which is the version that appears when you run:
    ```shell
    nvcc --version
    ```

    ### Install cuDNN
    ```shell
    sudo apt install ./<filename.deb>

    sudo cp /var/cudnn-<something>.gpg /usr/share/keyrings/

    sudo apt update
    sudo apt install libcudnn8
    sudo apt install libcudnn8-dev
    sudo apt install libcudnn8-samples
    ```

    ## Test CUDA on Pytorch


    ### Create a Virtualenv and activate it
    ```shell
    sudo apt-get install python3-pip
    sudo pip3 install virtualenv
    virtualenv -p py3.10 venv
    source venv/bin/activate
    ```

    ### Install pytorch
    ```shell
    pip3 install torch torchvision torchaudio
    ```

    ### Open Python and execute a test
    ```python
    import torch
    print(torch.cuda.is_available()) # should be True

    t = torch.rand(10, 10).cuda()
    print(t.device) # should be CUDA
    ```