Spork: A Tracing DSL for Apple GPUs
Spork is a DSL for writing kernels for Apple GPUs. You can think of it as a Python wrapper on top of Metal, Apple's GPU language. This makes development more convenient, since it makes the kernels live in the same source language as most ML code, and makes it easy to verify correctness against NumPy.
Unlike Triton, Spork is a tracing DSL rather than a parsing-based DSL. This means that a Spork program is fundamentally a Python program that creates a Metal program. Spork can use any Python libraries to aid in metaprogramming.
Installation
Spork runs on Apple Silicon (or any Mac with Metal). Install it from PyPI:
pip install spork-metal
Or with uv:
uv add spork-metal
The package is published as spork-metal on PyPI; the import name is spork:
import spork as sk
Example: Matrix Addition
One of the most basic kernels is a matrix-addition kernel. In Numpy, you could write
shape = (1024, 1024)
A = np.random.randn(*shape).astype(np.float32)
B = np.random.randn(*shape).astype(np.float32)
out = A + B
A Metal kernel to perform this operation would look like this:
#include <metal_stdlib>
using namespace metal;
kernel void matrix_add(
device float *out [[buffer(0)]],
device const float *A [[buffer(1)]],
device const float *B [[buffer(2)]],
uint index [[thread_position_in_grid]])
{
out[index] = A[index] + B[index];
}
Notice that it exists in a separate source file and requires special code to compile, link to, and invoke. An equivalent Spork kernel looks like this:
@sk.jit
def matrix_add(
out : sk.DevicePointer[sk.dt.float32],
A : sk.DevicePointer[sk.dt.float32],
B : sk.DevicePointer[sk.dt.float32],
index : sk.Uint[sk.ThreadPositionInGrid],
):
out[index] = A[index] + B[index]
Notice that we have a direct correspondance here between the Spork kernel and the Metal kernel. We declare the types of our inputs, and we can take the attribute parameters that we take in Metal.
Then to actually invoke and run kernel, we simply call it from Python with Numpy arrays, and like magic it runs your kernel!
matrix_add[
(int(np.prod(shape)) // 128, 1, 1),
(128, 1, 1),
](
C,
A,
B,
)
Notice that in the brackets, we provide two parameters. The first is the Grid size, and the second
is the Warpgroup size. In the parentheses, we supply the Numpy tensors we wish to use. Notice
that here we're taking a pointer to C, which is allocated via Numpy but written to from the
Spork kernel.
Metadata
Release files for spork-metal 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spork_metal-0.4.0.tar.gz | 24.1 kB | With provenance | Details for spork_metal-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spork_metal-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for spork_metal-0.4.0-py3-none-any.whl |
Total release size: 51.2 kB
Release files / spork_metal-0.4.0.tar.gz
| Download URL | spork_metal-0.4.0.tar.gz |
|---|---|
| Size | 24.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
203ac232d75774792973ec597b5ea003a048e815cb9be26ba532dd64aea4b4d7
|
|
BLAKE2b-256 checksum How to use checksums |
d4546ad9a9d5987a3a9beef1a71555b3c0d7be30700da457a1b4aad24c273509
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / spork_metal-0.4.0-py3-none-any.whl
| Download URL | spork_metal-0.4.0-py3-none-any.whl |
|---|---|
| Size | 27.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64028e0ce8a24ea738652ea08dc87ca4204f37c1efed2531a14e15695d10038c
|
|
BLAKE2b-256 checksum How to use checksums |
b4f66bb54a8b54394d7060dba322308bc4395ce3003a16808c043f49033bdf30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logSecurity for spork-metal 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for spork_metal-0.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.