Skip to content

Installing unigpu

unigpu is written in pure Python. With NumPy alone, it runs everywhere on its simulator. Each GPU backend adds one Python package, and the GPU's driver.

In short: pip install unigpu, or pip install "unigpu[cuda]" with the option of your hardware (section 4), in a virtual environment (section 3). To get the examples, the notebooks and the tests too, clone the repository (section 2) and install its folder instead (pip install -e .).

Choose your machine

Machine Backends you can get Instructions
Windows, with an NVIDIA, AMD or Intel GPU, or without a GPU cuda, opencl, sim docs/install/windows.md
macOS, Apple Silicon or Intel metal, sim (opencl with conda) docs/install/macos.md
Linux, with an NVIDIA, AMD or Intel GPU, or without a GPU cuda, hip, opencl, sim docs/install/linux.md
Chromebook (Linux development environment) opencl on the CPU, sim docs/install/chromebook.md
iPad metal, sim docs/testing-ipad-colab.md (sections 1 to 5)
Nothing to install: Google Colab, free NVIDIA GPU in the browser cuda, opencl docs/testing-ipad-colab.md

Every page follows the same steps, described in general terms below: Python, the code, a virtual environment, the option for your hardware, then a check.

1. Python

Python 3.10 or newer; 3.12 is recommended (every option is available for it). unigpu alone works from Python 3.9, which is enough on an iPad.

2. Get the code

Only needed for the examples, the notebooks and the tests: unigpu alone comes from PyPI (section 3). With git:

git clone https://github.com/laveneau/unigpu.git
cd unigpu

Without git: on the page of the project, github.com/laveneau/unigpu, Code → Download ZIP, then unzip it. The folder is named unigpu-<branch>; open a terminal in it. No GitHub account is needed.

3. Virtual environment

A virtual environment keeps the packages of unigpu apart from the rest of the machine. It needs no administrator rights.

python3 -m venv .venv            # Windows: py -3.12 -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install unigpu               # unigpu + NumPy, from PyPI: the simulator
pip install -e .                 # or, in the folder of the code: the same, from that folder

Activate the environment again in every new terminal. -e installs the folder itself: the examples and notebooks stay next to the code, and an update of the code (git pull) needs no new installation. From PyPI, pip install --upgrade unigpu updates unigpu.

4. The option for your hardware

Option Command Installs For
none pip install -e . NumPy the simulator, on any machine
opencl pip install -e ".[opencl]" PyOpenCL a GPU or CPU whose OpenCL driver is installed
opencl-cpu pip install -e ".[opencl-cpu]" PyOpenCL + POCL OpenCL on the CPU, without a driver: Linux x86-64 only (elsewhere, PyOpenCL alone)
cuda pip install -e ".[cuda]" numba-cuda and the CUDA 12 libraries an NVIDIA GPU, on Windows or Linux
cuda13 pip install -e ".[cuda13]" numba-cuda and the CUDA 13 libraries the same, when nvidia-smi shows CUDA Version: 13.0 or newer (Colab)
hip pip install -e ".[hip]" numba-hip an AMD GPU, on Linux with ROCm
metal pip install -e ".[metal]" PyObjC (Metal) a Mac
metal-rubicon pip install -e ".[metal-rubicon]" rubicon-objc a Mac, or an iPad app with pip
notebooks pip install -e ".[notebooks]" matplotlib, JupyterLab the notebooks and their charts
docs pip install -e ".[docs]" MkDocs, Material building the documentation site (mkdocs serve)
test, dev pip install -e ".[dev]" pytest, ruff... running the tests

From PyPI, the options are the same: pip install "unigpu[cuda]". Options can be combined: pip install "unigpu[cuda,opencl,notebooks]", or pip install -e ".[cuda,opencl,notebooks]" in the folder of the code. The quotes keep the brackets from the shell (zsh, PowerShell).

5. Check

python -m unigpu.selftest all

Each detected device runs eleven small kernels, compared with NumPy. The expected result ends, for each device, with a line such as:

11/11 checks passed on CPU simulator (Python)

python -c "import unigpu; unigpu.detect()" lists the platforms and devices found, like clinfo or numba.cuda.detect(); so does python examples/00_discovery.py, in the folder of the code. Its last part, Unavailable backends, gives the reason why each missing backend is missing:

Unavailable backends:
  cuda    NVIDIA CUDA (numba-cuda): numba-cuda is not installed (pip install "numba-cuda[cu12]")

The examples (in the folder of the code) take the device as an argument: sim, opencl, cuda, hip, metal, or a precise device such as opencl:0:1 (platform 0, device 1).

python examples/01_vector_addition.py opencl

The UNIGPU_DEVICE environment variable chooses the device of every program the same way (export UNIGPU_DEVICE=opencl; in PowerShell, $env:UNIGPU_DEVICE = "opencl").

If something goes wrong

  • Read the Unavailable backends part of unigpu.detect(): it says what is missing (package, driver, GPU).
  • Each page has a "Problems" section for its system.
  • To ask for help, send the output of python -m unigpu.selftest all and of python -c "import unigpu; unigpu.detect()".