Skip to content
Projects

cunumpy

One Python code base on NumPy (CPU) or CuPy (NVIDIA GPU). Replace import numpy as np with import cunumpy as xp.

CuNumpy lets one Python code base run on NumPy (CPU) or CuPy (NVIDIA GPU). Replace import numpy as np with import cunumpy as xp, choose a backend, and the array code you already have runs on the selected device. For codes whose time is spent in compiled loops, CuNumpy adds a kernel layer to port those kernels to CUDA one at a time, with the CPU version kept as the tested reference.

import cunumpy as xp
xp.set_backend("cupy") # falls back to NumPy without a usable GPU
values = xp.arange(1_000)
print(xp.sum(values**2), xp.get_backend())

Install with python -m pip install cunumpy, plus a CuPy wheel matching your CUDA version for GPU use. Start with the Quickstart.