Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
751e7f8
cuda: tree attention and DFlash block attention for every family (tre…
jschmied Oct 12, 2026
de31ba9
cuda/tree_attention: a group's 4 slices write their own partials, the…
jschmied Oct 13, 2026
6c3d49d
cuda/tree_attention: four-warp blocks combine a group's slices themse…
jschmied Oct 13, 2026
197cacc
cuda/tree_attention: one-warp blocks fetch their tiles 2 ahead (3 cp.…
jschmied Oct 13, 2026
403549d
cuda/tree_attention: 512-key groups (4x the warps in flight at one ro…
jschmied Oct 13, 2026
591065e
cuda/tree_attention: the merge issues a chunk's partial loads (16 slo…
jschmied Oct 14, 2026
df0ef6b
cuda: sliding-window attention, sigmoid top-k MoE routing and combine…
jschmied Oct 13, 2026
492716b
cuda/tree_attention: each row's own max flag, so a NaN head leaves ot…
jschmied Oct 17, 2026
f812fbe
cuda/block_attention: keys a row cannot see add nothing, so an infini…
jschmied Oct 17, 2026
d18a720
cuda/tree_attention, block_attention: registered with the kernel cont…
jschmied Oct 17, 2026
ce16098
cuda/window_attention: the tensor-core decode keeps each head's own m…
jschmied Oct 17, 2026
63d1507
cuda/window_attention: the split decode's slots outside the window ho…
jschmied Oct 17, 2026
40de67d
cuda/window_attention: prompt rows' keys a row cannot see add nothing…
jschmied Oct 17, 2026
8f93377
cuda/window_attention, moe_glue, dense_rows: registered with the kern…
jschmied Oct 17, 2026
7d59918
cuda/window_attention: the tensor-core decode's per-head max needs no…
jschmied Oct 17, 2026
0ad4f17
tests/cuda/contract_attn: the reference's constructor frees what it t…
jschmied Oct 17, 2026
2ae3b69
cuda/block_attention: the replay takes every NaN and infinite value o…
jschmied Oct 18, 2026
462d952
cuda/window_attention: the prompt replay takes every NaN and infinite…
jschmied Oct 18, 2026
3c82eb3
cuda/block_attention: the replay's block tile keeps the infinities ad…
jschmied Oct 18, 2026
0facb0f
cuda/tree_attention: a NaN or infinite partial runs again with those …
jschmied Oct 18, 2026
8cba69e
cuda/window_attention: the decode kernels run a NaN or infinite tile …
jschmied Oct 18, 2026
965c8cd
cuda/tree_attention, block_attention: the replay's comments on one li…
jschmied Oct 18, 2026
74b749f
cuda/window_attention: the split decode and its merge move to window_…
jschmied Oct 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cuda/tree_attention, block_attention: the replay's comments on one li…
…ne each
  • Loading branch information
jschmied committed Oct 18, 2026
commit 965c8cd10cd8a6d062c65aa67cb1c5a9414c1021
3 changes: 1 addition & 2 deletions zig/kernels/cuda/block_attention.cu
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ __device__ __forceinline__ uint32_t pack(float lo, float hi) {

__device__ __forceinline__ int sw(int r, int c) { return r * C + (c ^ (r & 7)); }

// One warp's running fold over a 32-key tile: scores masked by `vis(row, key)`, online softmax per row, P x V.
// KEEP: the replay's infinities already in o stay (attn_odd::keep), whatever the rescale.
// One warp's fold over a 32-key tile: scores masked by `vis(row, key)`, online softmax, P x V (KEEP: o's inf stays).
struct Fold {
float o[NB][4];
float m0 = -INFINITY, m1 = -INFINITY, l0 = 0.f, l1 = 0.f;
Expand Down
6 changes: 2 additions & 4 deletions zig/kernels/cuda/tree_attention.cu
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ extern "C" __global__ void tf_tree_paths(const int* __restrict__ parents, int* _
for (int slot = depth - 1; slot >= 0; --slot, cur = parents[cur]) paths[node * MAXD + slot] = cur;
}

// Group gi of key head kh for 16 (row, head) pairs from pair pf (pair m: row rq + m / G, head m % G), one mma tile.
// ODD: every NaN and infinite value leaves the mma, and the pairs add them back at float64's weights.
// !ODD: true (nothing written) when some warp's partial is NaN or infinite: the block runs again as ODD.
// Group gi of key head kh for 16 (row, head) pairs from pf (m: row rq + m / G, head m % G); !ODD true: run tree_odd.
template <int D, int HB, int W, int ST, bool ODD>
__device__ __forceinline__ bool tree_group(
const __nv_bfloat16* __restrict__ q, const __nv_bfloat16* __restrict__ kn, const __nv_bfloat16* __restrict__ vn,
Expand Down Expand Up @@ -323,7 +321,7 @@ __device__ __forceinline__ bool tree_group(
}
}

// A block whose partial is NaN or infinite, run again as ODD (out of the common path).
// A block with a NaN or infinite partial, again as ODD: those values out of the mma, added back at float64's weights.
template <int D, int HB, int W, int ST>
__device__ __noinline__ void tree_odd(
const __nv_bfloat16* q, const __nv_bfloat16* kn, const __nv_bfloat16* vn, const __nv_bfloat16* origin,
Expand Down
3 changes: 1 addition & 2 deletions zig/tests/cuda/contract_block_attn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ pub const Block = struct {
if (self.ns > 1) self.ownMax(1, 7, 23);
}

/// Stream j, key head kh: block key 0 all 8, every other key all -8 with +inf at e, the block's row 0 querying all 2
/// (head 4 kh: weights below float32's least, inf) and all 8 (head 4 kh + 1: float64 weights of 0, NaN).
/// Stream j, key head kh: block key 0 all 8, other keys -8 with +inf at e; row 0 queries 2 (inf) and 8 (NaN).
fn ownMax(self: *Block, j: usize, kh: usize, e: usize) void {
const L = self.len();
const rows = self.ns * L;
Expand Down
6 changes: 2 additions & 4 deletions zig/tests/cuda/contract_tree_attn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ pub const Tree = struct {
return true;
}

/// NaN in a query, +inf and -inf in values (committed and on a path), both in one column, NaN in a committed key;
/// +inf at float64 weights of 0 and below float32's least.
/// NaN in a query, +inf and -inf in values (committed, on a path, in one column), a NaN key, +inf at tiny weights.
fn plant(self: *Tree) void {
const d = self.v.d;
const kv = self.v.hk * d;
Expand All @@ -175,8 +174,7 @@ pub const Tree = struct {
self.under(1, 21);
}

/// Key head kh, row 0: committed key p0 - 1 all 8, its other keys all -8 with +inf at e. Head kh's first query is
/// all 2 (weights below float32's least: inf), its second all 8 (float64 weights of 0, 0 x inf: NaN).
/// Key head kh, row 0: key p0 - 1 all 8, its other keys -8 with +inf at e; queries 2 (inf) and 8 (weight 0: NaN).
fn under(self: *Tree, kh: usize, e: usize) void {
const d = self.v.d;
const kv = self.v.hk * d;
Expand Down