Summary
Ship a Python package that compiles WarpForth sources to PTX and launches kernels against CUDA buffers (numpy/DLPack/torch), so users do not hand-roll PyCUDA wrappers.
Motivation
Adoption currently requires:
- Build C++ tools
- Run
warpforthc
- Custom host code (
demo/warpforth.py with PyCUDA) or the C++ runner
The GPT-2 demo works but is not a reusable product surface. A small warpforth Python API would make the compiler usable from ML workflows and is the natural layer above the JSON runner redesign (#50).
Proposed API (sketch)
import warpforth as wf
import torch
kernel = wf.compile("attention.forth", arch="sm_80")
# or wf.compile_source(src)
q, k, v, o = ... # torch CUDA tensors
kernel.launch(
grid=(seq_len, 1, 1),
block=(threads, 1, 1),
params={"Q": q, "K": k, "V": v, "O": o, "SEQ_LEN": seq_len, "HEAD_DIM": head_dim},
)
Features
- Discover params from header or emitted metadata (see metadata issue)
- Accept torch tensors / DLPack / cuda-python buffers without host round-trips
- Optional: compile from string; cache PTX by source hash
- Errors: compile diagnostics and launch failures as Python exceptions
Packaging
pip install / uv add with optional CUDA extra
- May wrap
warpforthc binary or embed via bindings; start with subprocess + cuda-python
Acceptance criteria
Related
Summary
Ship a Python package that compiles WarpForth sources to PTX and launches kernels against CUDA buffers (numpy/DLPack/torch), so users do not hand-roll PyCUDA wrappers.
Motivation
Adoption currently requires:
warpforthcdemo/warpforth.pywith PyCUDA) or the C++ runnerThe GPT-2 demo works but is not a reusable product surface. A small
warpforthPython API would make the compiler usable from ML workflows and is the natural layer above the JSON runner redesign (#50).Proposed API (sketch)
Features
Packaging
pip install/uv addwith optional CUDA extrawarpforthcbinary or embed via bindings; start with subprocess + cuda-pythonAcceptance criteria
pyproject.toml(or documented extra)warpforth.pyRelated