Skip to content

Instantly share code, notes, and snippets.

@nanguoyu
Last active August 28, 2022 05:09
Show Gist options
  • Save nanguoyu/bc1e1e1a2c4e01458c2180a28566cfd9 to your computer and use it in GitHub Desktop.
Save nanguoyu/bc1e1e1a2c4e01458c2180a28566cfd9 to your computer and use it in GitHub Desktop.
Ubuntu20.04 CUDA
# Nvidia Driver installation
# sudo apt install nvidia-driver-460
# sudo reboot
# CUDA installation
# Version==11.0.3
# If you want to compile OpenCV with CUDA support,
# please install CUDA11.0.1 by net (method2) and then install CUDA11.0.3 by runfile again and dont override driver.
# Because I find net installtion is different from runfile such as nppi.
# Method 1
# wget https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_450.51.06_linux.run
# sudo sh cuda_11.0.3_450.51.06_linux.run
# Method 2
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
sudo apt-get update
# Please have a look if Nvidia give you the current version
sudo apt-cache madison cuda
sudo apt-get -y install cuda=11.0.3-1
nvcc --version
# install TensorRT
# https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html
# Download TensorRT-7.2.2.3.Ubuntu-18.04.x86_64-gnu.cuda-11.0.cudnn8.0.tar.gz
# nv-tensorrt-repo-ubuntu1804-cuda11.0-trt7.2.2.3-ga-20201211_1-1_amd64.deb
echo "export PATH=$PATH:/usr/src/tensorrt/bin" >> ~/.bashrc
source ~/.bashrc
# Download cuDNN from Nvidia: https://developer.nvidia.com/rdp/cudnn-download for version 10.1
echo "Please download cuDNN from https://developer.nvidia.com/rdp/cudnn-download"
tar -xzvf cudnn-11.2-linux-x64-v8.1.0.77.tgz
sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
# Add the following line to ~/.bashrc
echo "export PATH=$PATH:/usr/local/cuda-11.0/bin" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.0/lib64" >> ~/.bashrc
source ~/.bashrc
# Install Conda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sudo bash ./Miniconda3-latest-Linux-x86_64.sh
echo "export ANACONDA_HOME=/usr/lib/miniconda3/" >> ~/.bashrc
source ~/.bashrc
sudo cp /usr/bin/python /usr/bin/python_bak
sudo rm /usr/bin/python
sudo ln -s /usr/lib/miniconda3/bin/python /usr/bin/python
# Install Pytorch
conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch
# Install Opencv
sudo apt update
sudo apt install libopencv-dev python3-opencv
pip install opencv-python
pip install opencv-contrib-python
# Install ffmpeg 4.0+
sudo snap install ffmpeg
sudo apt-get install -y build-essential python3-dev python3-setuptools make cmake
sudo apt-get install -y libavcodec-dev libavfilter-dev libavformat-dev libavutil-dev
git clone --recursive https://github.com/dmlc/decord
cd decord
mkdir build && cd build
cmake .. -DUSE_CUDA=ON -DCMAKE_BUILD_TYPE=Release
cd build
make
# Download and complie YOLOV4 from ALexeyAB/darknet
git clone https://github.com/AlexeyAB/darknet.git
cd darknet
make
# Download yolov4.weights
wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
# Opensource code for apriltag
pip install apriltag
# tkDNN
sudo apt install libyaml-cpp-dev
echo "export PATH=$PATH:/usr/local/lib" >> ~/.bashrc
#
pip install mmcv-full
# Download COCO dataset
curl -sSO https://gist.githubusercontent.com/nanguoyu/ee345c198500d9acdfdd09a0bcdbdc0b/raw/3a155ee2be7128a8da531c732d3d9c34747dec13/coco.sh && sh coco.sh
# Install torch2trt
git clone https://github.com/NVIDIA-AI-IOT/torch2trt
cd torch2trt
python setup.py install
@nanguoyu
Copy link
Author

nanguoyu commented Feb 3, 2021

Todo:

  • TensorRT 7.1 for Linux

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