Usage of Google Colab
Video tutorials
First steps
-
Go to Google Colab
-
Runtime -> Chang Runtime Type -> Select T4 TPU
-
Click Connect (upper right corner)
-
Type
▷ !nvcc --version
in the code cell to get the version of nvcc. A code cell is executed by clicking on the triangle on its left side.
As Colab expects python commands by default, one has to prefix shell commands with an exclamation mark.
-
A new code cell is inserted by clicking +Code.
-
Copy-paste this CUDA code in the new code cell. The first line %%writefile test.cu saves the file in test.cu.
-
Compile with
▷ !nvcc test.cu
Output is written to a.out.
-
Execute program with
▷ !./a.out
The ./ is necessary because the current directory is not on the path.
-
If you get an error message cudaErrorUnsupportedPtxVersion then compile with
▷ !nvcc -arch=sm_75 test.cu
The reason is that the version of the compiler is newer than the version of the CUDA driver.
Get the GPU architecture used by Colab with
▷ !nvidia-smi --query-gpu=name --format=csv,noheader
and match it
here to get the compute capability of the GPU. For example, if the GPU is NVIDIA T4, then the
compute capability is 7.5 and you have to compile with flag -arch=sm75.