Testing | |
Code Quality | |
Package |
nvcc4jupyter is a Jupyter Notebook plugin that provides cell and line magics to allow running CUDA C++ code from a notebook. This is especially useful when combined with a hosted service such a Google's Colab which provide CUDA capable GPUs and you can start learning CUDA C++ without having to install anything or even to own a GPU yourself.
Here are just a few of the things that nvcc4jupyter does well:
- Easily run CUDA C++ code
- Profile your code with NVIDIA Nsight Compute or Nsight Systems
- Compile your code with external libraries (e.g. OpenCV)
- Share code between different programs in the same notebook / split your code into multiple files for improved readability
The installer for the latest released version is available at the Python Package Index (PyPI).
pip install nvcc4jupyter
First, load the extension to enable the magic commands:
%load_ext nvcc4jupyter
Running a quick CUDA Hello World program:
%%cuda
#include <stdio.h>
__global__ void hello(){
printf("Hello from block: %u, thread: %u\n", blockIdx.x, threadIdx.x);
}
int main(){
hello<<<2, 2>>>();
cudaDeviceSynchronize();
}
For more advanced use cases, see the documentation.
The official documentation is hosted on readthedocs.
The recommended setup for development is using the devcontainer in GitHub Codespaces or locally in VSCode.
If not using the devcontainer you need to install the package with the development dependencies and install the pre-commit hook before commiting any changes:
pip install -e .[dev]
pre-commit install