Summary and Setup
This is the GPU programming lesson.
The GPU programming lesson can be taught using Jupyter Notebook, a programming environment that runs in a web browser. For this to work you we need a reasonably up-to-date browser. The current versions of the Chrome, Safari and Firefox browsers are all supported (some older browsers, including Internet Explorer version 9 and below, are not).
In case you do not have any GPU available on your laptop, a good alternative is to use Google Colab.
To setup locally, depending on how you installed Python, there are
two alternatives: - use
pip if you installed Python
normally using your OS’s package manager or app store, - use
mamba if you installed the conda
distribution of Python.
In case you don’t have Python installed, we recommend you start with
a variant of the conda distribution: mambaforge.
mambaforge by default sets the
channel as the default, and provides the alternative package manager
mamba is a lot more performant compared
conda, making the user experience significantly
Whichever case it is for you, the first step is to create an isolated environment for the workshop, this way you won’t interfere with your existing setup. You can install all the dependencies for the workshop within this environment. In the Python ecosystem, this kind of isolated environments are known as virtual environments.
To create a virtual environment using
pip, you need to
virtualenv package using your OS’s package
manager (it may have alternate names like
python3-virtualenv). After you have done this, you can
follow the steps below:
cd /path/to/workshop/dir python -m virtualenv --prompt gpu-workshop venv source venv/bin/activate pip install -U pip # it is good to update pip to the latest version pip install cupy-cuda11x numba jupyterlab matplotlib scipy astropy
We are installing the precompiled
compiled against the latest version of CUDA. This is always faster to
install, but if you want to use a custom CUDA installation, you can
pip install cupy instead. Also note, if you also want the
nvcc, you have to install the CUDA toolkit
manually. However, this is not required to follow the workshop. More
information can be found in the
mamba have support for virtual
environments built-in. You can create a new virtual environment with
mamba create -n gpu-workshop mamba activate gpu-workshop mamba install cupy numba jupyterlab matplotlib scipy astropy
If you are using
conda, you can simply replace
conda in the commands above.
Now you can start your Jupyter server as shown below, which will open a tab with Jupyter in your default browser:
If you do not want Jupyter to open a tab in your browser automatically, you can use the alternative below:
This will print out a url in your terminal, which you can then open in the browser of your choice.