GPU Driver Installation
Identify your NVIDIA GPU model and download the appropriate driver from NVIDIA's official site. For example, with a GTX 1080 Ti:
Remove any exisitng NVIDIA drivers:
sudo apt-get remove --purge nvidia\*
Disable the open-source nouveau driver by creating a blacklist file:
sudo tee /etc/modprobe.d/blacklist-nouveau.conf <<EOF
blacklist nouveau
options nouveau modeset=0
EOF
Update the initramfs and reboot into text mode:
sudo update-initramfs -u
sudo systemctl stop gdm3 # or lightdm, depending on your display manager
Switch to a TTY (e.g., Ctrl+Alt+F3), navigate to the downloaded driver directory, and install it:
sudo sh NVIDIA-Linux-x86_64-*.run
Reboot and verify installation with:
nvidia-smi
CUDA 9.0 Setup
Run the CUDA installer:
sudo sh cuda_9.0.176_384.81_linux.run
During installation:
- Accept the EULA.
- Skip driver installation (already done).
- Decline OpenGL integration.
- Install the CUDA Toolkit to
/usr/local/cuda.
Add CUDA to your environment by appending to ~/.bashrc:
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
cuDNN Configuration
After downloading cuDNN (e.g., v7.0 for CUDA 9.0), extract and copy files:
tar -xzvf cudnn-7.0-linux-x64-v3.0-prod.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
Fix symbolic links in /usr/local/cuda/lib64:
cd /usr/local/cuda/lib64
sudo rm -f libcudnn.so libcudnn.so.7
sudo ln -s libcudnn.so.7.0.64 libcudnn.so.7
sudo ln -s libcudnn.so.7 libcudnn.so
sudo ldconfig
OpenCV Installation (Required for Darknet)
Install dependencies:
sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config \
libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy \
libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
Build OpenCV from source (using version 2.4.13.5 as an example):
cd opencv-2.4.13.5
mkdir release && cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j$(nproc)
sudo make install
sudo ldconfig
Verify with Python:
import cv2 # Should not raise ImportError
Darknet Compilation with GPU Support
Clone the repository:
git clone https://github.com/pjreddie/darknet
cd darknet
Edit Makefile to enable GPU acceleration:
GPU=1
CUDNN=1
OPENCV=1
Clean and rebuild:
make clean
make
Successful compilation indicates a working Darknet setup ready for YOLO inference or training.