Install
The package is plain Python: the phobos directory and nothing to build. It
runs phobos-compile to compile and the CUDA driver to launch, and it needs
no third-party module for either.
What you need
Section titled “What you need”- Python 3. The package is tested with Python 3.12.
- An NVIDIA GPU and driver as for the rest of Phobos: compute capability 7.5 or newer and a driver from the CUDA 13 line, R580 or newer (Install). Compiling a kernel needs no GPU.
- numpy, for the autotuner only: it compares each variant’s outputs on the host.
- An array library for your data, such as torch or CuPy, or none. A launch
takes any object that offers
__cuda_array_interface__, and the package’s ownphobos.DeviceArrayis one.
Get the package
Section titled “Get the package”From a release
Section titled “From a release”A release holds the
package in python/phobos, beside the binaries. Put its python directory
on the path:
export PYTHONPATH=/path/to/phobos-VERSION-linux-x64/pythonOn Windows, in PowerShell: $env:PYTHONPATH = "C:\path\to\phobos-VERSION-windows-x64\python".
The package runs the phobos-compile in the release directory, two levels
above it.
From a checkout
Section titled “From a checkout”Build the compiler, then put the checkout’s python directory on the path:
cargo build --release -p phobos-compileexport PYTHONPATH=$PWD/pythonThe package runs the phobos-compile the checkout built under
target/release.
To run another compiler, set PHOBOS_COMPILE to its path. The package looks
for the compiler in this order:
PHOBOS_COMPILE.phobos-compileon thePATH.- The one beside
python/in a release. - The checkout’s
target/releasebuild, then itstarget/debugone.
Check it works
Section titled “Check it works”Without a GPU, translate a kernel and compile it:
from __future__ import annotations
import phobos.lang as ph
@ph.kerneldef double(x: ph.tensor[ph.f32][N]): i: ph.let = ph.ctx.block.x * ph.ctx.threads + ph.ctx.thread if i < N: x[i] = 2.0 * x[i]
print(double.source) # the Phobos it spellsprint(double.compile(chip="sm_75").chip) # compiles with phobos-compileOn a machine with a GPU, launch it on an array:
import torch
x = torch.ones(1024, device="cuda")double[lambda meta: (meta["N"] // 256,)](x)torch.cuda.synchronize()print(x[:4]) # tensor([2., 2., 2., 2.], device='cuda:0')The first launch compiles the kernel for the card’s chip and keeps it in the kernel cache; later launches, in this process or another, load it from there.