English | 简体中文
A typed tensor language for GPU inference. The shape, dtype, layout and quantization format of every tensor live in its type, operators come from a typed library, and a model is built once into GPU binaries plus a manifest. Thin Python, C++ and Rust hosts are generated from the same signatures.
Status: early preview (0.0.23 on PyPI and crates.io; C++ host deferred). tilefish types GPU kernels
written in Triton, Gluon, CuTe DSL or PTX, pinned cuBLASLt and cuDNN calls and small glue kernels it lowers itself, builds a model's graphs into launch plans
over one arena, and runs the same pinned artefact from Python (via tilefish-py) and Rust (crates/tilefish). The core positioning and roadmap live in
goal.md, scope boundaries in docs/en/scope.md, and the full guide in docs/en/README.md.
In inference code the contract of a kernel is usually written three times and checked by none of them:
- the shape, dtype, alignment and aliasing rules sit in a docstring, a few
asserts and a comment above a C ABI; - a block-scaled weight format (MXFP8, MXFP4, NVFP4) is described in prose, together with the per-architecture byte layout of its scales;
- the same kernel is ported by hand from Triton to CUDA C++ to Rust, and parity tests chase the last ULP (FMA contraction, flush-to-zero, reduction order) after the fact;
- which implementation runs at which
(M, N, K)on which GPU is a table someone measured once.
tilefish moves all of that into types, so the compiler can check it, generate it and reason about it.
import tilefish
from tilefish import Dim, Tensor, InOut, Out, const
from tilefish import bf16, f32
M = Dim("M") # runtime dimension
D = Dim("D", 2560) # static: baked into the binary
T = Dim("T", buckets=[64, 256]) # bucketed: one pinned binary per bucket
H = Dim("H", 1024)
F = Dim("F", 3072)
K = Dim("K", buckets=[1024, 3072], divisible_by=32) # constraint, checked at build time
N = Dim("N", buckets=[1024, 6144], divisible_by=128)
# A kernel whose body tilefish understands: it can be fused, and it is
# lowered to Triton.
@tilefish.kernel
def residual_add_rmsnorm(
x: Tensor[M, D, bf16],
residual: InOut[Tensor[M, D, f32]],
w: Tensor[D, bf16],
*, eps: const[f32] = 1e-6,
) -> Tensor[M, D, bf16]:
r = residual + x.to(f32)
residual[...] = r
rstd = tilefish.rsqrt(tilefish.mean(r * r, axis=-1, keepdims=True) + eps)
return (r * rstd * w.to(f32)).to(bf16) # the only rounding point
# An existing hand-written kernel, unchanged, given a type.
n = Dim("n", divisible_by=16)
# (index_bits=32 is the default: a kernel that offsets with i32 gets a max_elements
# limit of 2**31 - 1 on every tensor, which both hosts check; a kernel that
# indexes in i64 says index_bits=64.)
@tilefish.extern(triton=my_kernels.gelu, num_warps=4,
grid=lambda n: (tilefish.cdiv(n, 1024),))
def gelu(x: Tensor[n, bf16], y: Out[Tensor[n, bf16]],
n_elem: n, BLOCK: const = 1024): ...
# A library operator: pinned cuBLASLt GEMM, f32 accumulator, bf16 operands/output.
@tilefish.library("gemm", acc=f32, impl="cublaslt.gemm")
def gemm(a: Tensor[T, K, bf16], b: Tensor[N, K, bf16]) -> Tensor[T, N, bf16]: ...
# A model is ordinary Python over typed values (plans, exports and runs end to end).
@tilefish.graph
def mlp(x: Tensor[T, H, bf16], w_gu: Tensor[2 * F, H, bf16], w_d: Tensor[H, F, bf16]):
g, u = gemm(x, w_gu).split(F, axis=-1)
a = (tilefish.silu(g.to(f32)) * u.to(f32)).to(bf16)
return gemm(a, w_d)Low-precision & block-scaled quantization (
FP8/MXFP8/MXFP4/NVFP4): First-classMXFP8,MXFP4, andNVFP4presets with compile-time scale-layout contracts (row_majorvscublaslt_128x4), paired(data, __scale[, __global_scale])AOT & static-arenaLaunchPlanlowering, nativeWeightArenaBuilder::push_block_scaled(auto-swizzling 128x4 scales in Rust), andcublaslt.scaled_gemm(scalar_32f,vec32_ue8m0,vec16_ue4m3) are supported end-to-end across Python and Rust.
- Declare. Types (
Dim,Tensor,BlockScaled,DevScalar, views) and four declarations:@tilefish.kernel(a body tilefish lowers to Triton itself),@tilefish.extern(a Triton, Gluon or CuTe DSL kernel, or prebuilt PTX or cubin, given a type),@tilefish.library(a pinned cuBLASLt GEMM or cuDNN convolution) and@tilefish.graph(a model step over them). - Build once.
tilefish.runtime.exporttraces and checks the graph, compiles every kernel ahead of time, pins every library algorithm, and writes the cubins,manifest.jsonand the launch plans (plan.json: every launch of a step over one arena). The manifest's digest covers every binary and pin, the plan's digest the plan and its manifest; a host pins one, and an export is reproducible from any directory and on another machine with the same toolchain and GPU architecture. - Run the same artefact. Python (
replay), the Rust crate and the C/C++ library load the directory, verify it against the pin and check every precondition before a launch.jitruns the same machine code built in memory,referencethe same bodies in torch. - Look inside.
tilefish-explainmaps each SASS instruction to its source line, and SASS assertions are checked at every build; probes time the phases inside a kernel;tilefish-explain --adviseranks the steps of a plan that could be one kernel.
The details of each stage are in the guide.
pip install tilefish # types, tracing, lowering, compile specs: pure Python, no dependencies
pip install "tilefish[gpu]" # torch, Triton and cuda-python: build, jit, replay, plans
pip install "tilefish[sass]" # CUDA 13's nvdisasm, for tilefish-explain and SASS assertions on sm_103
cargo add tilefish # the Rust host (default bindings: cuda-12080; works with CUDA 12.8+ drivers)
cmake -S crates/tilefish-capi -B build && cmake --build build # the C/C++ host, from this repositoryThe Rust and C/C++ hosts default to cuda-12080 bindings (requiring a CUDA 12.8 or newer driver); on Unix, default cuda-12080 prebuilt wheels and crates reuse an already-mapped libcublasLt.so.13 / libcudnn.so.9 (such as torch+cu130 and nvidia.cu13.lib wheels) without dual-loading conflicting system CUDA Toolkit libraries. To target another CUDA driver binding directly (cuda-12040, cuda-13000, cuda-13020), pass --no-default-features --features cuda-12040 (or -DTILEFISH_CARGO_FEATURES=cuda-12040 to CMake).
When building for Blackwell architectures (sm_100+, including B300 sm_103 and RTX 5090 sm_120), tilefish automatically probes triton/backends/nvidia/bin/ptxas-blackwell and torch/bin/ptxas (verifying target support) before falling back to Triton's default ptxas and PATH. If your environment only bundles an older ptxas that cannot target the architecture (such as Triton 3.5.1's CUDA 12.8 ptxas for sm_103a), set TRITON_PTXAS_PATH (which always takes highest priority over auto-detection) to a CUDA 12.9+ ptxas (TILEFISH_PTXAS_PATH remains highest priority for prebuilt PTX assembly). A build that fails for this reason says so, and the GPU tests that build for an architecture the ptxas cannot target skip, naming it.
New to tilefish? docs/en/guide/tutorial.md goes from the install to a small model running from Python, Rust and
C++, step by step, and docs/en/guide/migrate.md is the method for moving a model you already have, with GPT-2 from
transformers as the worked example. The snippets below are the short form.
# x, residual, w: torch tensors on the GPU (residual, an InOut, is updated in place)
y = tilefish.run(residual_add_rmsnorm, x, residual, w) # jit: built in memory
m = tilefish.runtime.export(residual_add_rmsnorm, "build/") # cubins and manifest.json
y = tilefish.run(residual_add_rmsnorm, x, residual, w, mode="replay", manifest="build/", pin=m.digest)
y = tilefish.run(residual_add_rmsnorm, x, residual, w, mode="reference") # the same body in torchA @tilefish.graph exports its launch plan next to the manifest, and tilefish.run(graph, ..., mode="replay", plan="build/", pin=p.digest) replays it (build, plans).
use tilefish::{GreenContext, LaunchPlan, Pin, PinnedHostBuffer, WeightArenaBuilder, DType};
let gctx = GreenContext::split(&ctx, 32)?; // optional SM partition
let mut wb = WeightArenaBuilder::new();
wb.push("w", DType::Bf16, vec![1024, 1024], &weight_bytes)?; // or push_block_scaled(...)
let weights = wb.upload(&primary_stream)?; // zero-copy shared across GreenContexts
let plan = LaunchPlan::load("build/", Pin::Digest("<plan digest>"))?;
let weighted = weights.bind(&plan.instantiate_all(&gctx_stream)?)?;
let mut graph = weighted.capture(&gctx_stream, io_buffers, &[])?; // owns I/O + Arc<WeightArena>, 'static
graph.replay(&gctx_stream)?; // zero-overhead CUDA Graph replayDownstream Rust crates run with #![forbid(unsafe_code)]. tilefish.hosts.rust.emit also writes typed launchers for a pinned manifest (guide, crates/tilefish/README.md).
tilefish from-torch --load model:Block --shape 64x1024:bf16 --out block_tf.py --json
tilefish advise build/ --perf-db perf/ --json
tilefish tune --load race:RACE --arch sm_103 --perf-db perf/ --out-perf perf/team.jsonl --json
tilefish lock write build/ locks/sm_103.lock.json --json && tilefish verify build/ --lock locks/sm_103.lock.json --json#include "tilefish.hpp"
auto ctx = tilefish::Context::primary(0);
auto run = tilefish::LaunchPlan::load("build/", "<the plan's digest>").instantiate(ctx, stream);
run.launch(stream, {{"x", xt}, {"out0", yt}}, {{"n", 64}});find_package(tilefish) after cmake --install; tilefish.hosts.cpp.emit writes typed launchers and plan runners
(guide).
| feature | documented in |
|---|---|
| What tilefish is and is not, and how features are added | docs/en/scope.md |
The build: the steps, jit, reference and replay, pins, reproducible exports, what identifies a binary, the build cache, the TF32 guard, trust |
docs/en/guide/build.md |
| Strided views, device scalars, prebuilt PTX and cubin, Gluon kernels, one implementation per architecture, TMA descriptors, warp-specialised kernels, launch shapes | docs/en/guide/operators.md |
| Pinned cuBLASLt GEMMs (bf16, f16, f32 with TF32 off; four layouts; SM partitions; epilogues) and pinned cuDNN convolutions | docs/en/guide/operators.md |
| CuTe DSL kernels as externs | docs/en/cute.md |
Lowered kernels: masks, indices, argmax, gathers and scatters, integer casts, IEEE math, ordered sums, broadcasts, contiguous, im2col, col2im1d |
docs/en/guide/lowering.md |
| Launch plans: one arena, CUDA graphs, copy and memset steps, weights bound once, plan sets, shared arenas, carried buffers, debug taps | docs/en/guide/plans.md |
| Locked exports: a lock made once on a GPU, then the same files exported on a machine without one (CI, an image build) | docs/en/guide/locked-export.md |
| Fusion of a graph body's arithmetic, epilogue hooks on externs, cuBLASLt epilogues | docs/en/guide/fusion.md |
Rounding points, exact and numerics-changing rewrites, num_warps and FMA contraction |
docs/en/guide/rewrites.md |
| The CUDA math guard and what to check again on a CUDA or torch change | docs/en/numerics.md |
Traces, tilefish-explain and SASS assertions |
docs/en/guide/sass.md, docs/en/explain.md |
| The fusion advisor and the plan profiler | docs/en/advise.md |
| Probes and the instrumented variant | docs/en/instrument.md |
| The Rust host and generated Rust launchers | docs/en/guide/rust.md, crates/tilefish/README.md |
| The C ABI, the C++ wrapper and generated C++ launchers | docs/en/guide/cpp.md, RFC 0002 |
| The files a host reads | docs/en/manifest-schema-3.md, docs/en/plan-schema-1.md |
- Not a kernel compiler. Triton, CuTe DSL, cuTile, Helion and TileLang write kernels. tilefish types them, builds them and hosts them.
- Not a serving runtime. Scheduling, KV cache, batching and request handling stay in the host program. tilefish owns one forward step over buffers it has planned.
- Not a promise to generate every kernel. Hand-tuned attention and GEMMs
enter as
externor library operators and keep their own numerics contract.
Early preview: the API will change.
| package | version | from |
|---|---|---|
tilefish (Python) |
0.0.16 | PyPI |
tilefish (the Rust host) |
0.0.11 | crates.io |
tilefish-capi (C ABI 1.1, tilefish.h and tilefish.hpp) |
0.0.2 | this repository |
The manifest is schema 3 and the plan tilefish.plan.v1. There is no list of features to come. A feature is added when a real
model migration needs it (docs/en/scope.md); the open items are tracked in issue #4,
and #5 (SASS traceability, probes, CuTe DSL externs) is closed. What each release
changed is in CHANGELOG.md, and every document is listed in docs/en/README.md.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.