Skip to content

Instantly share code, notes, and snippets.

@lukicdarkoo
Last active January 9, 2024 22:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukicdarkoo/feffa76b69f0142a4a20de6e3d5f4539 to your computer and use it in GitHub Desktop.
Save lukicdarkoo/feffa76b69f0142a4a20de6e3d5f4539 to your computer and use it in GitHub Desktop.
Computer Vision with NVIDIA eGPU Configuration
# This script prepares your machine for computer vision challenges (with NVIDIA).
# Tested with Ubuntu 20.04 LTS and NVIDIA GeForce GTX 1070 (Aorus Gaming Box enclosure).
# Reddit post: https://www.reddit.com/r/eGPU/comments/io94qq/linux_aorus_gaming_box_for_robotics_and_computer/
#
# The script does the following:
# * Installs NVIDIA driver
# * Installs NVIDIA CUDA Toolkit (`nvcc`)
# * Installs NVIDIA CUDA Deep Neural Network library (cuDNN)
# * Installs OpenCV with CUDA support (WIP)
# * Installs TensorFlow with CUDA support
# * Installs PyTorch with CUDA support
# * Configures X11 to utilize the eGPU
# Install NVIDIA driver
sudo apt install nvidia-driver-455
# Install `nvcc`
sudo apt install nvidia-cuda-toolkit
# Install cuDNN 7
sudo apt install libcudnn7-dev
# Install OpenCV (WIP)
# Reference: https://docs.opencv.org/3.4/d7/d9f/tutorial_linux_install.html
sudo apt-get install \
build-essential \
cmake \
git \
libgtk2.0-dev \
pkg-config \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
python3-dev \
python3-numpy \
libtbb2 \
libtbb-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libjasper-dev \
libdc1394-22-dev
git clone --depth=1 https://github.com/opencv/opencv_contrib.git
git clone --depth=1 https://github.com/opencv/opencv.git
# apply fix https://github.com/opencv/opencv/issues/6050#issuecomment-251684917
mkdir opencv/build
cd opencv/build
cmake \
-DCMAKE_C_COMPILER=$(which gcc-8) \
-DCMAKE_CXX_COMPILER=$(which g++-8) \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
make -j4
# Install TensorFlow (and test)
pip3 install tensorflow
python3 -c 'import tensorflow as tf; print(tf.test.is_built_with_cuda(), tf.test.is_gpu_available(cuda_only=False, min_cuda_compute_capability=None))'
# Install PyTorch (and test)
pip3 install torch torchvision
python3 -c 'import torch; print(torch.cuda.is_available())'
# Configure X11 and apply new configuration
#BUS_ID=$(nvidia-smi --query-gpu=pci.bus --format=csv,noheader | cut -c3-4 | bc)
#sudo bash -c 'cat > /etc/X11/xorg.conf' << EOF
#Section "Module"
# Load "modesetting"
#EndSection
#
#Section "Device"
# Identifier "nvidia"
# Driver "nvidia"
# BusID "PCI:${BUS_ID}:0:0"
# Option "AllowEmptyInitialConfiguration"
# Option "AllowExternalGpus"
#EndSection
#EOF
sudo add-apt-repository ppa:hertg/egpu-switcher
sudo apt update
sudo apt install egpu-switcher
sudo egpu-switcher setup
sudo egpu-switcher switch egpu
sudo systemctl restart display-manager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment