DEV Community

Janardhan Pulivarthi
Janardhan Pulivarthi

Posted on • Edited on

NVIDIA CUDA setup on Colab

The faster way to CUDA programming. Just open it right now here ↗

or

visit colab.research.google.com for Google Colab for online jupyter notebooks. Make sure to set GPU accelerator in the Runtime -> Change runtime type.

set runtime type to GPU

1. Remove existing CUDA installation

This remove all the nvidia and libnvidia named packages and libraries in the system.

!apt-get --purge remove cuda nvidia* libnvidia-*
!dpkg -l | grep cuda- | awk '{print $2}' | xargs -n1 dpkg --purge
!apt-get remove cuda-*
!apt autoremove
!apt-get update
Enter fullscreen mode Exit fullscreen mode

2. Download and install latest CUDA

Visit https://developer.nvidia.com/cuda-downloads

Installer configuration

Latest example,

!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
!wget https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda-repo-ubuntu2004-11-6-local_11.6.0-510.39.01-1_amd64.deb
!sudo dpkg -i cuda-repo-ubuntu2004-11-6-local_11.6.0-510.39.01-1_amd64.deb
!sudo apt-key add /var/cuda-repo-ubuntu2004-11-6-local/7fa2af80.pub
!sudo apt-get update
!sudo apt-get -y install cuda
Enter fullscreen mode Exit fullscreen mode

3. Check the installation

!nvcc --version
Enter fullscreen mode Exit fullscreen mode

and create simple .cu file

%%writefile /content/main.cu

#include <iostream>

int main() {
    std::cout << "This is from CUDA\n";
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

and compile it.

!nvcc main.cu -o main
Enter fullscreen mode Exit fullscreen mode

Resources

  1. https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html

Top comments (0)