Playing with CUDA and GPUs in Google Colab.
- Open a Colab notebook: https://colab.research.google.com/
- Create a new Python 3 notebook
- Change runtime type selecting GPU as hardware accelerator
- Git clone this repository:
!git clone https://github.com/alessandrobessi/cuda-lab.git
- Change permissions:
!chmod 755 cuda-lab/INSTALL.sh
- Install cuda, nvcc, gcc, and g++:
!./cuda-lab/INSTALL.sh
- Add
/usr/local/cuda/bin
toPATH
:
import os
os.environ['PATH'] += ':/usr/local/cuda/bin'
- Compile an existing Cuda source:
!nvcc cuda-lab/add.cu -o add -Wno-deprecated-gpu-targets
- Run the compiled Cuda source using the Nvidia profiler tool:
!nvprof ./add
- or just time it:
!time ./add
You can also create a Cuda source file using the magic command %%writefile <filename.cu>
:
%%writefile snippet.cu
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
...
and then compile and run it!
!nvcc snippet.cu -o snippet -Wno-deprecated-gpu-targets
!nvprof ./snippet