Arrays on GPUs with

Author

Marie-Hélène Burle

Setup on your computer

This is for your future information only. During the course, we will use a temporary training cluster.

Assuming that you have at least one dedicated GPU, you can run CuPy on your computer.

I suggest installing it with uv:

  • If you already have CUDA 13, you can install CuPy with uv with:
uv init --bare                        # Initiate project
uv add cupy-cuda13x                   # Install CuPy

Replace cupy-cuda13x by cupy-cuda12x if you have CUDA 12.

  • If you don’t have CUDA, install CuPy with a CUDA toolkit as a dependency with:
uv add "cupy-cuda13x[ctk]"

Setup on Alliance clusters

Load module

Check available Python versions:

module spider python

Check requirements to load Python 3.14:

module spider python/3.14.2

Double-check that you already have StdEnv/2023:

module list

Load Python 3.14:

module load python/3.14.2

Virtual environment

For this course, we have already installed cupy in a virtual environment everybody has access to. All you need to do is to activate it:

source /project/def-sponsor00/cupy_env/bin/activate

Create a virtual env:

python -m venv ~/cupy_env

Activate it:

source ~/cupy_env/bin/activate

Update pip from our wheel:

python -m pip install --upgrade --no-index pip

Install cupy from our wheel:

python -m pip install --no-index cupy

Launch interactive job

salloc --time=10

Concepts

CUDA kernel

Devices

Host CPU
Current device

import numpy as np
import cupy as cp