Skip to content

Masking and shape utilities: make_causal, tril/triu, fills, transpose #7

Closed

Description

@feitreim

None of these exist. ThunderKittens has all of them on register tiles:

  • make_causal, make_causal_t — causal attention masking
  • tril, triu
  • left_fill, right_fill, upper_fill, lower_fill, upper_right_fill
  • transpose, transpose_sep
  • swap_layout, swap_layout_8 — row-major <-> col-major fragment layouts
  • copy between layouts and element types
  • broadcast_row, broadcast_col

make_causal is the one that hurts today. Every causal attention kernel needs it, and without it the masking is open-coded in the kernel against raw fragment indices — precisely the index math this library exists to delete. value_column() in reg.rs is public for exactly this reason: callers reach in to recover a logical column so they can compare it against a row index and mask by hand.

swap_layout and transpose only become meaningful once RegTile has a layout parameter, which is #1. Until then there is only one layout to swap between.

Suggest landing in two parts: masking and fills first (immediately useful, needs only #1's coordinates), transpose and layout swaps second (needs a second layout impl to be worth anything).

Depends on #1.

Activity

  1. added
    enhancement
    area:compute
    on Jul 26, 2026
  2. feitreim commented on Jul 27, 2026

    @feitreim
    OwnerAuthor

    Scope correction from the examples work (#18): make_causal needs a coordinate origin this issue is not filed with.

    The issue as written treats masking as a function of a tile's own (row, column). That is only true for the diagonal block. In a real flash-attention kernel the tile being masked is a [query_block, key_block] sub-block of a much larger score matrix, and the diagonal within it sits at query_base - key_base, not at row == column.

    So the signature needs the offset:

    pub fn make_causal<const M: usize, const N: usize, L: FragmentLayout<M, N>>(
        tile: &mut RegTile<M, N, L>, lane: u32, diagonal: i32, fill: f32,
    );

    with diagonal = query_base - key_base. A tile entirely above the diagonal is fully masked and one entirely below is untouched — both are the common case in a tiled kernel, and both are wrong under the origin-free version.

    tril / triu have the same requirement, and it is the same parameter.

    Worth getting right at design time: the origin-free form compiles, runs, and produces a subtly wrong mask that only shows up off the diagonal — the failure mode most likely to survive to production.

  3. feitreim commented on Jul 27, 2026

    @feitreim
    OwnerAuthor

    Acceptance: update examples/ as part of closing this.

    flash_forward wants make_causal. See the coordinate-origin correction already commented on this issue — the examples are what surfaced it.

    The examples crate (#18) exists so that "done" is checkable in the terms a kernel author cares about, rather than as a claim about a primitive nobody has tried to hold. Concretely, on closing this:

    • Delete any workaround or GAP fence in examples/src/ that this issue removes the need for, and replace it with the real API.
    • If a kernel becomes fully unblocked, move it from aspirational to compiles: flip its header, take it out of its feature gate, and confirm modal run modal_app.py::build builds it for sm_100a.
    • Update the status table and the blocked-on lists in examples/README.md.

    If the example still does not compile afterwards, that is a finding worth writing down — say what is still missing rather than leaving the README stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:computeenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions