Skip to content

Instantly share code, notes, and snippets.

@tzvsi
Last active September 21, 2023 06:37
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save tzvsi/222b3b22a847004a729744f89fe31255 to your computer and use it in GitHub Desktop.
Save tzvsi/222b3b22a847004a729744f89fe31255 to your computer and use it in GitHub Desktop.
Installing CUDA 10.2, CuDNN 7.6.5, TensorRT 7.0, Ubuntu 18.04

Step 1: Installing CUDA (~5.5 minutes)

You can also install CUDA directly from the offline installer, but this is a little easier.

sudo apt update
sudo apt upgrade -y

mkdir install ; cd install
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
sudo apt-get update
sudo apt-get -y install cuda-10-2

Step 2: Installing CuDNN (~2 minutes)

Download CuDNN here (BOTH the runtime and dev, deb) from: https://developer.nvidia.com/rdp/cudnn-download

sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb
sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64.deb

Verify installation

This method of installation installs cuda in /usr/include and /usr/lib/cuda/lib64, hence the file you need to look at is in /usr/include/cudnn.h.

cat /usr/include/x86_64-linux-gnu/cudnn_v*.h | grep CUDNN_MAJOR -A 2                                                         

Step 3: Installing TensorRT (~2 minutes)

Download TensorRT here. Use version 7.0.

sudo dpkg -i nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb
sudo apt update
sudo apt install tensorrt libnvinfer7

Step 3: Add to .bashrc

export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH=$CUDA_HOME/lib64:$DYLD_LIBRARY_PATH
export PATH=$CUDA_HOME/bin:$PATH
export C_INCLUDE_PATH=$CUDA_HOME/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=$CUDA_HOME/include:$CPLUS_INCLUDE_PATH
export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH
export LD_RUN_PATH=$CUDA_HOME/lib64:$LD_RUN_PATH
@around-star
Copy link

@tzvsi I am trying this in WSL, but sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb gives the error

dpkg: error: cannot access archive 'libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb': No such file or directory

@Naresh392
Copy link

@around-star
Copy link

@Naresh392 thanks for your reply! I am actually trying these installation in WSL2. I am facing an issue where upon trying to run nvidia-smi it raises an error which says NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

@selvavignesh-2206
Copy link

selvavignesh-2206 commented Jun 14, 2021

sudo apt install tensorrt libnvinfer7 gives me this error;

The following packages have unmet dependencies:
tensorrt : Depends: libnvinfer-dev (= 7.1.3-1+cuda10.2) but 8.0.0-1+cuda11.3 is to be installed
Depends: libnvinfer-plugin-dev (= 7.1.3-1+cuda10.2) but 8.0.0-1+cuda11.3 is to be installed
Depends: libnvparsers-dev (= 7.1.3-1+cuda10.2) but 8.0.0-1+cuda11.3 is to be installed
Depends: libnvonnxparsers-dev (= 7.1.3-1+cuda10.2) but 8.0.0-1+cuda11.3 is to be installed
Depends: libnvinfer-samples (= 7.1.3-1+cuda10.2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

I have followed all your steps but I am not able to resolve this.

@pra-dan
Copy link

pra-dan commented Jul 19, 2021

@selvavignesh-2206 I recommend using

# For CUDA 10.2
$sudo apt-get install libnvinfer7=7.0.0-1+cuda10.2 libnvonnxparsers7=7.0.0-1+cuda10.2 libnvparsers7=7.0.0-1+cuda10.2 libnvinfer-plugin7=7.0.0-1+cuda10.2 libnvinfer-dev=7.0.0-1+cuda10.2 libnvonnxparsers-dev=7.0.0-1+cuda10.2 libnvparsers-dev=7.0.0-1+cuda10.2 libnvinfer-plugin-dev=7.0.0-1+cuda10.2 python-libnvinfer=7.0.0-1+cuda10.2 python3-libnvinfer=7.0.0-1+cuda10.2
$sudo apt-mark hold libnvinfer7 libnvonnxparsers7 libnvparsers7 libnvinfer-plugin7 libnvinfer-dev libnvonnxparsers-dev libnvparsers-dev libnvinfer-plugin-dev python-libnvinfer python3-libnvinfer

@Myron1996
Copy link

Myron1996 commented Jul 21, 2021

I Tried **sudo apt install tensorrt libnvinfer7**

I got following error.

myron@myron:~/Downloads$ sudo apt install tensorrt libnvinfer7
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libnvinfer-dev : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 libnvinfer-plugin7 : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 libnvonnxparsers7 : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 libnvparsers7 : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 python-libnvinfer : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 python3-libnvinfer : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 tensorrt : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
            Depends: libnvinfer-bin (= 7.0.0-1+cuda10.2) but it is not going to be installed
            Depends: libnvinfer-doc (= 7.0.0-1+cuda10.2) but it is not going to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

I tried below commands too and I got following error.

Commands

$sudo apt-get install libnvinfer7=7.0.0-1+cuda10.2 libnvonnxparsers7=7.0.0-1+cuda10.2 libnvparsers7=7.0.0-1+cuda10.2 libnvinfer-plugin7=7.0.0-1+cuda10.2 libnvinfer-dev=7.0.0-1+cuda10.2 libnvonnxparsers-dev=7.0.0-1+cuda10.2 libnvparsers-dev=7.0.0-1+cuda10.2 libnvinfer-plugin-dev=7.0.0-1+cuda10.2 python-libnvinfer=7.0.0-1+cuda10.2 python3-libnvinfer=7.0.0-1+cuda10.2
$sudo apt-mark hold libnvinfer7 libnvonnxparsers7 libnvparsers7 libnvinfer-plugin7 libnvinfer-dev libnvonnxparsers-dev libnvparsers-dev libnvinfer-plugin-dev python-libnvinfer python3-libnvinfer

Error

python3-libnvinfer
libnvinfer7 set on hold.
libnvonnxparsers7 set on hold.
libnvparsers7 set on hold.
libnvinfer-plugin7 set on hold.
libnvinfer-dev set on hold.
libnvonnxparsers-dev set on hold.
libnvparsers-dev set on hold.
libnvinfer-plugin-dev set on hold.
python-libnvinfer set on hold.
python3-libnvinfer set on hold.

@pra-dan

@pra-dan
Copy link

pra-dan commented Jul 23, 2021

This is not error

python3-libnvinfer
libnvinfer7 set on hold.
libnvonnxparsers7 set on hold.
libnvparsers7 set on hold.
libnvinfer-plugin7 set on hold.

It just logs that the plugins were set on hold so that other packages don't upgrade them

@Myron1996
Copy link

Myron1996 commented Jul 25, 2021

@pra-dan
That has been resolved . How about following error ?

myron@myron:~/Downloads$ sudo apt install tensorrt **libnvinfer7**
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libnvinfer-dev : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 libnvinfer-plugin7 : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 libnvonnxparsers7 : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 libnvparsers7 : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 python-libnvinfer : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 python3-libnvinfer : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
 tensorrt : Depends: libnvinfer7 (= 7.0.0-1+cuda10.2) but 7.2.3-1+cuda11.1 is to be installed
            Depends: libnvinfer-bin (= 7.0.0-1+cuda10.2) but it is not going to be installed
            Depends: libnvinfer-doc (= 7.0.0-1+cuda10.2) but it is not going to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

@khoapham2801
Copy link

@pra-dan
Hi, thank you for your work here. I successfully installed tensorRT as you guided, but my Anaconda virtual env can't be able to recognize tensorRT. Do you know how to let my env know tensorRT had been installed? Thank you.

@ndtands
Copy link

ndtands commented Jun 1, 2022

You need check nvidia-driver and cuda version by: nvidia-smi
=> Step1: Download CUDA Toolkit with version above. You should deb(local)
=> Step 2: Download CuDNN + install CuDNN
=> Step 3: Download TensorRT + install
Good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment