Skip to content

Instantly share code, notes, and snippets.

@arsho
Last active March 29, 2024 08:08
Show Gist options
  • Save arsho/c2ba21e4fc398a8855f3379bb97a8e5b to your computer and use it in GitHub Desktop.
Save arsho/c2ba21e4fc398a8855f3379bb97a8e5b to your computer and use it in GitHub Desktop.
Install CUDA 12.0 or CUDA 11.4 in Ubuntu 23.04
  • Check versions of gcc, g++, and nvcc:
gcc --version
gcc (Ubuntu 13.2.0-4ubuntu3) 13.2.0
g++ --version
g++ (Ubuntu 13.2.0-4ubuntu3) 13.2.0
nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Aug_15_22:02:13_PDT_2023
Cuda compilation tools, release 12.2, V12.2.140
Build cuda_12.2.r12.2/compiler.33191640_0
  • Scenario: Running CUDA code may raise the following errors:
/usr/include/bits/floatn.h(86): error: invalid combination of type specifiers
  typedef __float128 _Float128;

or

error -- unsupported gcc version! gcc versions later than 12.2 are not supported!

Solution

  • Install g++-12:
sudo apt install g++-12
  • Add the following line in ~\..zshrc file (edit ~\.bashrc if you use bash as default shell):
export NVCC_PREPEND_FLAGS='-ccbin /usr/bin/g++-12'

References

Install CUDA 11.4 in Ubuntu 23.04

  • Remove existing CUDA softwares:
sudo apt-get remove --purge '^nvidia-.*'
  • In Ubuntu Additional Drivers, select nvidia-driver-470
  • Follow the following procedure. Make sure that you uncheck NVIDIA Driver option:
sudo apt install build-essential
nvidia-smi
sudo apt -y install gcc-10 g++-10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 1000
# select gcc 10
wget https://developer.download.nvidia.com/compute/cuda/11.4.3/local_installers/cuda_11.4.3_470.82.01_linux.run
sudo sh cuda_11.4.3_470.82.01_linux.run --override
nvcc --version
nvidia-smi
echo 'export PATH=/usr/local/cuda-11.4/bin:$PATH' >> ~/.zshrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-11.4/lib64:$LD_LIBRARY_PATH' >> ~/.zshrc
source ~/.zshrc
sudo ldconfig
nvcc --version
nvidia-smi

References

  • Remove existing CUDA softwares:
sudo apt-get remove --purge '^nvidia-.*'
  • In Ubuntu Additional Drivers, select nvidia-driver-470 and restart machine
  • Do the following
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10
# Select gcc 12
sudo update-alternatives --config gcc
# Download CUDA and install it without driver
wget https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda_12.0.0_525.60.13_linux.run
sudo sh cuda_12.0.0_525.60.13_linux.run

# Add the following paths in ~/.zshrc
export PATH=/usr/local/cuda-12.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-12.0/lib64:$LD_LIBRARY_PATH
export Thrust_DIR=/usr/local/cuda-12.0/lib64/cmake/thrust
export CUDACXX=/usr/local/cuda-12.2/bin/nvcc
# Activate the paths
source ~/.zshrc
nvcc --version
nvidia-smi

CLION setup

  • Added -DCMAKE_CUDA_COMPILER=/usr/local/cuda-12.2/bin/nvcc to Settings>Build, Execution, Deployment > CMake > CMake options.

References

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