Last active
September 18, 2024 06:34
-
-
Save charlie-x/9d7fef61a25beeabe51b5759b5da7b63 to your computer and use it in GitHub Desktop.
nvidia drivers on ubuntu 24.xxx cuda 12.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usual stuff | |
sudo apt update -y | |
sudo apt upgrade -y | |
# for the latest versions | |
sudo apt install ubuntu-drivers-common -y | |
# setup all the disallow lists etc | |
sudo ubuntu-drivers autoinstall | |
sudo reboot | |
# reconnect | |
#check card and and cuda version | |
nvidia-smi | |
# | NVIDIA-SMI 535.183.01 Driver Version: 535.183.01 CUDA Version: 12.2 | | |
########################## | |
# to install a specific version of cuda, 12.1 | |
# usually needs gcc and make (see notes later about gcc-12) | |
sudo apt-get gcc make -y | |
# latest is installed by ubuntu-drivers | |
#wget https://developer.download.nvidia.com/compute/cuda/12.5.1/local_installers/cuda_12.5.1_555.42.06_linux.run | |
#sudo sh ./cuda_12.5.1_555.42.06_linux.run --no-drm --no-man-page --override --toolkit --silent | |
# you can't install 12.1 driver on 24.xx ubuntu due to kernel changes. so don't select the driver, use the one from ubuntu-drivers autoinstall | |
# or manuallly install a 24.xx driver | |
# after 4.4.168 kernel changes , compile won't work | |
# select continue, upgrade and deselect drivers for 24.xx | |
wget https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda_12.1.0_530.30.02_linux.run | |
sudo sh ./cuda_12.1.0_530.30.02_linux.run | |
# add options as needed | |
# --no-drm --no-man-page --override --toolkit --silent | |
# if gcc version fails, use --override to skip the test , see notes about kernel | |
#note ldconfig notes from install | |
Please make sure that | |
- PATH includes /usr/local/cuda-12.1/bin | |
- LD_LIBRARY_PATH includes /usr/local/cuda-12.1/lib64, or, add /usr/local/cuda-12.1/lib64 to /etc/ld.so.conf and run ldconfig as root | |
# update path if needed | |
export PATH=$PATH:<cuda__path>/bin | |
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<cuda_path>/lib64 | |
export PATH=$PATH:/usr/local/cuda-12.1/bin | |
# drivers ok? | |
nvidia-smi | |
# you'll need gcc-12, might want to remove any existing gcc versions | |
# add ppa for install | |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test | |
sudo apt update | |
# install gcc-12 as you can't use nvcc 12.1 with gcc-12+ | |
sudo apt install gcc-12 g++-12 | |
# set it as default compiler | |
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 60 --slave /usr/bin/g++ g++ /usr/bin/g++-12 | |
sudo update-alternatives --config gcc | |
#select option 1 | |
# test with gcc --version | |
gcc --version | |
gcc (Ubuntu 12.3.0-17ubuntu1) 12.3.0 | |
# test cuda versions | |
# save following as check_cuda.cu (don't include --- ) | |
-------- | |
#include <iostream> | |
#include <cuda_runtime.h> | |
int main() | |
{ | |
int driver_version = 0, runtime_version = 0; | |
cudaDriverGetVersion(&driver_version); | |
cudaRuntimeGetVersion(&runtime_version); | |
std::cout << "CUDA Driver Version: " << driver_version/1000 << "." << (driver_version%100)/10 << std::endl; | |
std::cout << "CUDA Runtime Version: " << runtime_version/1000 << "." << (runtime_version%100)/10 << std::endl; | |
return 0; | |
} | |
---- | |
# compile with | |
nvcc -o check_cuda_version check_cuda.cu | |
# if nvcc fails to be found, you didn't add /usr/local/cuda12.1/bin to the path | |
# run it | |
./check_cuda_version | |
CUDA Driver Version: 12.2 | |
CUDA Runtime Version: 12.1 | |
# other notes | |
# purging | |
# remove all the nvidia drivers, won't fully remove ubuntu-drivers type install | |
sudo apt purge '^nvidia-.*' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment