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 GPUvalues = 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.
Where to go
Section titled “Where to go”New to CuNumpyInstallation, then the Quickstart.
Running array code on CPU and GPUThe user guide: backends, backend-agnostic code, data movement, devices, MPI and profiling.
Porting compiled kernels to CUDAStart at Porting kernels to the GPU.
Complete programsWorked examples.
Looking up a functionThe API reference, and the API overview for the module layout.
Using an AI assistantPoint it at the guide for AI assistants, which ships with the package as cunumpy/LLM_GUIDE.md.