0% found this document useful (0 votes)
117 views10 pages

8.1 CUDA Setup For Google CoLab

The document provides steps to set up CUDA for GPU programming in Google Colab including installing CUDA, running CUDA C/C++ and Python programs, and examples of vector operations and finding maximum values in arrays.

Uploaded by

Amir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views10 pages

8.1 CUDA Setup For Google CoLab

The document provides steps to set up CUDA for GPU programming in Google Colab including installing CUDA, running CUDA C/C++ and Python programs, and examples of vector operations and finding maximum values in arrays.

Uploaded by

Amir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

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

You might also like