Dawn's cuTile backend

A GPU kernel in Dawn is an ordinary function under the !Dev effect. Run it once and every operation it raises is recorded as CUDA Tile IR, which NVIDIA's tileiras assembles into a cubin.

  • !Dev · Tile IR · tileiras
  • 256 golden kernels
  • 3 GPUs on record

Two layers, two effects

The host owns the buffers and the device computes over them; they meet only where the host launches a kernel by name.

the hoststd/gpu.dawn!Gpu
  1. main
  2. launch_entry3
  3. with_gpu_realwith_gpu_fake

std/gpu's Gpu effect: allocate, upload, launch, download. with_gpu_real drives the CUDA driver, with_gpu_fake runs the same program with no GPU.

the devicepackages/tileir!Dev
  1. vadd
  2. record
  3. Tile IR
  4. tileiras
  5. cubin

packages/tileir's Dev effect. One recorded run of a kernel becomes Tile IR text, or bytecode for tileiras.

Writing a kernel

A kernel says where it reads and writes once, on its parameters' markers, and states no shape it could read off its operands. Each piece of code below is cut from the golden kernels when the site is built.

Learn to write one

The markers are the addressing

vadd

In and Out cut each tensor into cells, and the Out cells are the launch grid. The body reads its block's cell and writes its block's cell; it names no offset.

fn vadd(a: Param[Float], b: Param[Float], out: Param[Float]) -> Unit !Dev =  store_cell(out, load_cell(a) + load_cell(b)) "vadd" -> {  let (p, _e) = trace3("vadd", In(F64, run_of(128)), In(F64, run_of(128)), Out(F64, run_of(128)), vadd)  p} fn run_of(tile: Int) -> Cells = cells([DYN_DIM], [tile])

kernels.dawn:52–53 · kernels.dawn:5541–5544 · kernels.dawn:5314 · vadd.mlir

Shapes come from the operands

softmax

No operation takes a shape or a format. A constant, and a reduction of a rank-1 tile, are rank-0 tiles: they widen on their own where they meet a wider operand, and nowhere else.

fn softmax(x: Param[Float], out: Param[Float]) -> Unit !Dev = {  let t = load_cell(x)  let ex = exp(t - reduce_max(t))  store_cell(out, ex / reduce_sum(ex))}

kernels.dawn:228–232 · softmax.mlir

Writes go through Out

matmul

store_cell and store_sub are the only writes an Out takes, and an accumulator starts from zeros of it. Free leaves a dimension for the kernel to pick, here the loop's k.

fn matmul(a: Param[Float], b: Param[Float], c: Param[Float]) -> Unit !Dev =  mm_body(a, b, c, MmTiles { tm = 64, tn = 64, tk = 32 }, mm_shape()) fn mm_body(a: Param[Float], b: Param[Float], c: Param[Float], cfg: MmTiles, shape: MmShape) -> Unit !Dev = {  var acc = zeros(c)  for k in d_range(0, shape.k / cfg.tk) { acc = mma(load_at(a, [k]), load_at(b, [k]), acc) }  store_cell(c, acc)} "matmul" -> {  let (p, _e) = trace3("matmul",    In(F64, cells([MM_M, MM_K], [MM_TM, MM_TK], along = [Axis(0), Free])),    In(F64, cells([MM_K, MM_N], [MM_TK, MM_TN], along = [Free, Axis(1)])),    Out(F64, cells([MM_M, MM_N], [MM_TM, MM_TN])), matmul)  p}

kernels.dawn:446–447 · kernels.dawn:439–443 · kernels.dawn:5705–5711 · matmul.mlir

Shared is the escape hatch

histogram

An atomic is not a cell write, and neither is a scatter whose addresses are data or a block that writes two regions. Those write through Shared, and the marker says so where a reader can find it.

fn histogram(input: Param[I32], hist: Param[I32]) -> Unit !Dev = {  let x = load_cell(input)  let live = tail_mask(tile_at(block_id(0), HIST_TILE), [HIST_TILE], HIST_N)  let ok = (live & in_range(x, 0, HIST_BINS))  atomic_add(hist, (x & i_const(HIST_BINS - 1)), i_const(1), mask = Some(ok))} "histogram" -> {  let (p, _e) = trace2("histogram", In(I32, cells([HIST_N], [HIST_TILE])), Shared(I32), histogram)  p}

kernels.dawn:1784–1789 · kernels.dawn:5954–5957 · histogram.mlir

Refused while recording

refused

A kernel is checked when it is recorded: the body runs once, and an operation its shapes or roles cannot support is a panic that names the kernel, the operation's number and the operator as written. It comes before tileiras and before any device, and it names the operator, not a line of your source.

fn into_first_store(x: Param[Float], y: Param[Float]) -> Unit !Dev = {  let base = tile_at(block_id(0), 8)  store(x, base, load(y, base, [8]))}# trace2("w", In(F64, g), Out(F64, g), into_first_store) refuses:# tileir: kernel `w`: op #5 `store`: parameter 0 is an In, and nothing writes an In fn vadd_half(a: Param[Float], b: Param[Float], out: Param[Float]) -> Unit !Dev = {  let base = tile_at(block_id(0), 128)  let ta = load(a, base, [64])  let tb = load(b, base, [128])  store(out, base, add(ta, tb))}# trace_kernel("vadd_half", ..) refuses:# tileir: kernel `vadd_half`: op #6 `+`: rhs is tile<128xf64>, declared tile<64xf64>

prog.dawn:6619–6622 · prog.dawn:6132–6137 · Run it in the Playground

Run on the host, with no GPU

host_launch

The fake device alone calls a host reference registered under the kernel's name. with_gpu_interp runs the recorded Tile IR instead, at the grid each launch names, so one host program goes from trace to numbers on a machine with no card. The numbers are the interpreter's, held to the host references in CI and not to a GPU.

fn vadd(a: Param[Float], b: Param[Float], out: Param[Float]) -> Unit !Dev =  store_cell(out, add(load_cell(a), load_cell(b))) fn vadd_prog() -> TileProg = {  let g = cells([DYN_DIM], [W])  let (p, _e) = trace3("vadd", In(F64, g), In(F64, g), Out(F64, g), vadd)  p} fn run(name: String, grid: Int, bufs: List[List[Float]]) -> Result[List[Float], ForeignError] !Gpu = {  var hs: List[Int] = []  for b in bufs {    let h = gpu_alloc("f64", len(b))?    gpu_copy_from_host(h, encode_floats("f64", b))?    hs = hs ++ [h]  }  gpu_launch(name, grid, 1, 1, list.map(hs, h => Buffer(h)))?  Ok(decode_floats("f64", gpu_copy_to_host(hs[len(hs) - 1])?))} test "a kernel recorded once launches from its recording to its answer on the host" {  let progs = (name: String) => map.get(map.from([("vadd", vadd_prog())]), name)  let xs = floats(3 * W, i => to_float(i) * 0.5)  let ys = floats(3 * W, i => 100.0 - to_float(i))  let r = with_gpu_fake(map.empty(), () => with_gpu_interp(progs, () => run("vadd", 3, [xs, ys, floats(3 * W, _i => 0.0)])))  assert r == Ok(floats(3 * W, i => 100.0 - to_float(i) * 0.5))}

selftest.dawn:27–28 · selftest.dawn:30–34 · selftest.dawn:164–173 · selftest.dawn:197–203 · Run it in the Playground

On sm_86, a 128 by 128 f16 matrix product wants entry_hints(occupancy = Some(2)), which fits two blocks on each SM instead of one. How it was measured.

The package's whole surface · What changed in 0.9.0

One kernel, line by line

A fused attention with BF16 inputs and F32 accumulation, scale and output. The shared [D,A] body keeps the online softmax, sums unrounded probabilities, and rounds to BF16 nearest-even before the second MMA. Numerical helpers select exp2 with FTZ and approximate F32 division; the launch scale changes base once. Three-dimensional cells put heads on grid axis 2 and squeeze to matrix values. This small 32×16 recording has no entry hints. The generic algorithm, numerical policy, host plan and measurement audit keep separate roles. In the Playground, run this instance with the CPU interpreter and inspect its C, JVM and Tile IR views.

flash_attn_bf16_demoone loop, two reductions inside itOpen in Playground

42 calls 56 operations 68 lines of Tile IR · 1053 bytes · cited by 9 coverage rows · 12 mutants

Dawn sourcekernels.dawn:2363–2395

2363fn flash_attn[D: FloatDtype, A: FloatDtype + ScalarDtype](q: Param[D], k: Param[D], v: Param[D], o: Param[A], scale: Param[A], dt: Dtype[D], math: FaNumerics[A]) -> Unit !Dev = {2364  let tq = load_cell(q)2365  let rows = tile_shape(tq)[0]2366  var m: Tile[A] = full([rows, 1], math.neg_inf)2367  var l: Tile[A] = full([rows, 1], math.zero)2368  var acc = zeros(o)2369  for j in d_range(idx_const(0), blocks_of(k, 1)) {2370    let s: Tile[A] = mma(tq, load_at(k, [j]).transpose(), 0.0) * scalar(scale)2371    let m_new = max(m, reduce_max(s, keepdims = true))2372    let p = fa_exp(math, s - m_new)2373    let alpha = fa_exp(math, m - m_new)2374    l = l * alpha + reduce_sum(p, keepdims = true)2375    acc = mma(p.to(dt), load_at(v, [j]), acc * alpha)2376    m = m_new2377  }2378  store_cell(o, fa_divide(math, acc, l))2379}
Numerical policy and factory support
23802381pub type FaNumerics[A] = { zero: A, neg_inf: A, base2: Bool, exp_ftz: Bool, approx_div: Bool, div_ftz: Bool }2382fn fa_bf16_math() -> FaNumerics[F32] = FaNumerics { zero = f32(0.0), neg_inf = f32(-INFINITY), base2 = true, exp_ftz = true, approx_div = true, div_ftz = true }23832384# Public `!Dev` functions are recorded as calls of their own (`Dev` declares2385# `calls(..)`), so these two keep their call sites separate from the2386# operations in their bodies without writing a mark.2387pub fn fa_exp[A: FloatDtype](math: FaNumerics[A], x: Tile[A], at: Loc = caller()) -> Tile[A] !Dev =2388  if math.base2 { exp2(x, ftz = math.exp_ftz) } else { exp(x) }23892390pub fn fa_divide[A: FloatDtype](math: FaNumerics[A], x: Tile[A], y: Tile[A], at: Loc = caller()) -> Tile[A] !Dev =2391  if math.approx_div { div(x, y, approx = true, ftz = math.div_ftz) } else { x / y }23922393# The two supported instances capture their policy before recording.2394fn fa_kernel[D: FloatDtype, A: FloatDtype + ScalarDtype](dt: Dtype[D], math: FaNumerics[A]) -> fn(Param[D], Param[D], Param[D], Param[A], Param[A]) -> Unit !Dev =2395  (q, k, v, o, scale) => flash_attn(q, k, v, o, scale, dt, math)

the Tile IR it recordedflash_attn_bf16_demo.mlir

1cuda_tile.module @m {2  entry @flash_attn_bf16_demo(%arg0: tile<ptr<bf16>>, %arg1: tile<ptr<bf16>>, %arg2: tile<ptr<bf16>>, %arg3: tile<ptr<f32>>, %arg4: tile<f32>) {3    %0 = make_token : token4    %1 = assume div_by<16>, %arg0 : tile<ptr<bf16>>5    %2 = make_tensor_view %1, shape = [1, 64, 32], strides = [2048, 32, 1] : tensor_view<1x64x32xbf16, strides=[2048, 32, 1]>6    %3 = make_partition_view %2 : partition_view<tile=(1x32x32), padding_value = zero, tensor_view<1x64x32xbf16, strides=[2048, 32, 1]>, dim_map=[0, 1, 2]>7    %4, %5, %6 = get_tile_block_id : tile<i32>8    %7, %8, %9 = get_tile_block_id : tile<i32>9    %10, %11, %12 = get_tile_block_id : tile<i32>10    %13, %14 = load_view_tko weak %3[%6, %7, %11] token=%0 : partition_view<tile=(1x32x32), padding_value = zero, tensor_view<1x64x32xbf16, strides=[2048, 32, 1]>, dim_map=[0, 1, 2]>, tile<i32> -> tile<1x32x32xbf16>, token11    %15 = reshape %13 : tile<1x32x32xbf16> -> tile<32x32xbf16>12    %16 = constant <f32: -Infinity> : tile<32x1xf32>13    %17 = constant <f32: 0.0> : tile<32x1xf32>14    %18 = constant <f32: 0.0> : tile<32x32xf32>15    %19 = constant <i32: 0> : tile<i32>16    %20 = constant <i32: 4> : tile<i32>17    %21 = constant <i32: 1> : tile<i32>18    %22, %23, %24 = for %25 in (%19 to %20, step %21) : tile<i32> iter_values(%26 = %16, %27 = %17, %28 = %18) -> (tile<32x1xf32>, tile<32x1xf32>, tile<32x32xf32>) {19      %29 = assume div_by<16>, %arg1 : tile<ptr<bf16>>20      %30 = make_tensor_view %29, shape = [1, 64, 32], strides = [2048, 32, 1] : tensor_view<1x64x32xbf16, strides=[2048, 32, 1]>21      %31 = make_partition_view %30 : partition_view<tile=(1x16x32), padding_value = zero, tensor_view<1x64x32xbf16, strides=[2048, 32, 1]>, dim_map=[0, 1, 2]>22      %32, %33 = load_view_tko weak %31[%6, %25, %11] token=%0 : partition_view<tile=(1x16x32), padding_value = zero, tensor_view<1x64x32xbf16, strides=[2048, 32, 1]>, dim_map=[0, 1, 2]>, tile<i32> -> tile<1x16x32xbf16>, token23      %34 = reshape %32 : tile<1x16x32xbf16> -> tile<16x32xbf16>24      %35 = permute %34 [1, 0] : tile<16x32xbf16> -> tile<32x16xbf16>25      %36 = constant <f32: 0.0> : tile<32x16xf32>26      %37 = mmaf %15, %35, %36 : tile<32x32xbf16>, tile<32x16xbf16>, tile<32x16xf32>27      %38 = reshape %arg4 : tile<f32> -> tile<1x1xf32>28      %39 = broadcast %38 : tile<1x1xf32> -> tile<32x16xf32>29      %40 = mulf %37, %39 rounding<nearest_even> : tile<32x16xf32>30      %41 = reduce %40 dim=1 identities=[-Infinity : f32] : tile<32x16xf32> -> tile<32xf32> (%42: tile<f32>, %43: tile<f32>) {31        %44 = maxf %42, %43 : tile<f32>32        yield %44 : tile<f32>33      }34      %45 = reshape %41 : tile<32xf32> -> tile<32x1xf32>35      %46 = maxf %26, %45 : tile<32x1xf32>36      %47 = broadcast %46 : tile<32x1xf32> -> tile<32x16xf32>37      %48 = subf %40, %47 rounding<nearest_even> : tile<32x16xf32>38      %49 = exp2 %48 flush_to_zero : tile<32x16xf32>39      %50 = subf %26, %46 rounding<nearest_even> : tile<32x1xf32>40      %51 = exp2 %50 flush_to_zero : tile<32x1xf32>41      %52 = mulf %27, %51 rounding<nearest_even> : tile<32x1xf32>42      %53 = reduce %49 dim=1 identities=[0.0 : f32] : tile<32x16xf32> -> tile<32xf32> (%54: tile<f32>, %55: tile<f32>) {43        %56 = addf %54, %55 rounding<nearest_even> : tile<f32>44        yield %56 : tile<f32>45      }46      %57 = reshape %53 : tile<32xf32> -> tile<32x1xf32>47      %58 = addf %52, %57 rounding<nearest_even> : tile<32x1xf32>48      %59 = ftof %49 rounding<nearest_even> : tile<32x16xf32> -> tile<32x16xbf16>49      %60 = assume div_by<16>, %arg2 : tile<ptr<bf16>>50      %61 = make_tensor_view %60, shape = [1, 64, 32], strides = [2048, 32, 1] : tensor_view<1x64x32xbf16, strides=[2048, 32, 1]>51      %62 = make_partition_view %61 : partition_view<tile=(1x16x32), padding_value = zero, tensor_view<1x64x32xbf16, strides=[2048, 32, 1]>, dim_map=[0, 1, 2]>52      %63, %64 = load_view_tko weak %62[%6, %25, %11] token=%0 : partition_view<tile=(1x16x32), padding_value = zero, tensor_view<1x64x32xbf16, strides=[2048, 32, 1]>, dim_map=[0, 1, 2]>, tile<i32> -> tile<1x16x32xbf16>, token53      %65 = reshape %63 : tile<1x16x32xbf16> -> tile<16x32xbf16>54      %66 = broadcast %51 : tile<32x1xf32> -> tile<32x32xf32>55      %67 = mulf %28, %66 rounding<nearest_even> : tile<32x32xf32>56      %68 = mmaf %59, %65, %67 : tile<32x16xbf16>, tile<16x32xbf16>, tile<32x32xf32>57      continue %46, %58, %68 : tile<32x1xf32>, tile<32x1xf32>, tile<32x32xf32>58    }59    %69 = broadcast %23 : tile<32x1xf32> -> tile<32x32xf32>60    %70 = divf %24, %69 rounding<approx> flush_to_zero : tile<32x32xf32>61    %71 = reshape %70 : tile<32x32xf32> -> tile<1x32x32xf32>62    %72 = assume div_by<16>, %arg3 : tile<ptr<f32>>63    %73 = make_tensor_view %72, shape = [1, 64, 32], strides = [2048, 32, 1] : tensor_view<1x64x32xf32, strides=[2048, 32, 1]>64    %74 = make_partition_view %73 : partition_view<tile=(1x32x32), padding_value = zero, tensor_view<1x64x32xf32, strides=[2048, 32, 1]>, dim_map=[0, 1, 2]>65    %75 = store_view_tko weak %71, %74[%6, %7, %11] token=%0 : tile<1x32x32xf32>, partition_view<tile=(1x32x32), padding_value = zero, tensor_view<1x64x32xf32, strides=[2048, 32, 1]>, dim_map=[0, 1, 2]>, tile<i32> -> token66    return67  }68}

BF16 implementation and launch plans

The current implementation uses BF16 inputs and F32 output. The host plan selects architecture-specific tiles and hints before recording, with no runtime search. This page's small layout demonstrates online updates over four key blocks; production launch plans use their own layouts. Historical measurements remain in the internal audit directory and do not measure this three-axis layout or this sample.

What the backend covers

Every public opcode, type tag and attribute value of the Tile IR release has a row, a status and its evidence. Point at a card to see the rows that are not implemented.

102/105public opcodes implemented3 structuralfeatures.txt
  • entry structural · 3
  • global structural · T7
  • module structural · 3
24type tags implementedtypes.txt
53attribute values implementedattrs.txt
256golden kernels, each pinned as text and as bytecodetile-golden/

Three gates

Each layer catches what the one before it cannot, and each has to turn its own mutants red. Each dot is one of them, at the gate it was written against.

  1. 0

    Text and bytes

    76 mutants caught here

    Every golden kernel is traced twice and held to its recorded text and bytecode, byte for byte. It says whether anything changed, not whether it is right.

    scripts/tile-golden/run.sh
  2. 1

    The assembler accepts

    98 mutants caught here

    tileiras has to assemble every bytecode golden into a cubin that names its kernel. It catches encoding and type errors, not wrong answers.

    scripts/tile-golden/run.sh
  3. 2

    The device agrees

    49 mutants caught here

    On a GPU, every output buffer is held to a host reference, bit for bit or within a stated tolerance. Each run appends a ledger line, and CI refuses a tree the last line did not test.

    scripts/tile-gpu-diff/run.sh

On real hardware

The last line of each machine's ledger. CI reads the first; the sm_90 and sm_100 ledgers reach the fp8, fp4 and block-scaled rows an Ampere card cannot load.

GPUdatedrivertileirasresultbit for bitwithin tolerancetree
sm_862026-11-16617.4213.5.37pass13348ab1ec116dbc9
sm_902026-11-16580.95.0513.5.37pass13648ab1ec116dbc9
sm_1002026-11-16580.159.0413.5.37pass14648ab1ec116dbc9

Kernels compared, by tier, summed over the line's families.