GPU Programming
NVIDIA - CUDA setup For Google CoLab
GPU Programming
• CUDA setup For Google CoLab
• CUDA C/C++
• CUDA Python
• Example Programs in CUDA-C & CUDA-Python
CUDA-C/C++ setup For Google CoLab
• Step 1: remove old setup
!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
CUDA-C/C++ setup For Google CoLab
• Step 2: install latest cuda
1. Checking ubuntu version on colab :
!lsb_release -a
2. Getting setup code from nvidia koolkit site for Ubuntu 20.04.5 LTS
https://developer.nvidia.com/cuda-downloads
or search for specific version
CUDA-C/C++ setup For Google CoLab
• Step 2: install latest cuda
3. Run the following commands obtained from the official site (for cuda 11.3)
!wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/
cuda-ubuntu2004.pinsudo
!mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
!wget https://developer.download.nvidia.com/compute/cuda/11.3.0/local_installers/cuda-
repo-ubuntu2004-11-3-local_11.3.0-465.19.01-1_amd64.debsudo
!dpkg -i cuda-repo-ubuntu2004-11-3-local_11.3.0-465.19.01-1_amd64.debsudo
!apt-key add /var/cuda-repo-ubuntu2004-11-3-local/7fa2af80.pubsudo
!apt-get updatesudo
!apt-get -y install cuda
CUDA-C/C++ setup For Google CoLab
• Step 3: check cuda version
!nvcc --version
• Step 4: extension to run nvcc from the Notebook cells.
!pip install git+https://github.com/andreinechaev/nvcc4jupyter.git
• Step 5:load the extension
%load_ext nvcc_plugin
CUDA-C/C++ setup For Google CoLab
• Step 6: test run code
%%cu
#include <iostream>
int main()
{
std::cout << "Welcome To GeeksforGeeks\n";
return 0;
}
CUDA-C Example Programs
• Vector Addition in CUDA-C
https://github.com/olcf-tutorials/vector_addition_cuda
• Finding maximum value in an array
How To Run CUDA C/C++ on Jupyter notebook in Google Colaboratory
https://www.geeksforgeeks.org/how-to-run-cuda-c-c-on-jupyter-notebook-in-google-colaboratory/
CUDA-Python setup For Google CoLab
• Step # 1 : One line is required
!pip install pycuda # install cuda
Tutorial : Introduction to CUDA and PyCUDA
https://colab.research.google.com/github/vellamike/pycuda/blob/master/
pycuda_workshop.ipynb#scrollTo=FA_YN7HlGRP5
Five different ways to sum vectors in PyCUDA
https://vitalitylearning.medium.com/five-different-ways-to-sum-vectors-in-
pycuda-3f2d9409b139
CUDA-Python Example Programs
Tutorial : Introduction to CUDA and PyCUDA
https://colab.research.google.com/github/vellamike/pycuda/blob/
master/pycuda_workshop.ipynb#scrollTo=FA_YN7HlGRP5
Five different ways to sum vectors in PyCUDA
https://vitalitylearning.medium.com/five-different-ways-to-sum-
vectors-in-pycuda-3f2d9409b139