Skip to content

Generalize RegTile to a logical shape with a layout parameter #1

Closed

Description

@feitreim

RegTile is indexed by a thread's physical fragment footprint, not by the tile's logical shape:

pub struct RegTile<const SLOTS: usize, const VALUES: usize>(pub [[f32; VALUES]; SLOTS]);
pub type Fragment = RegTile<2, 4>;

SLOTS is owned rows, VALUES is owned values per row. The doc comment calls the logical shape [16*SLOTS-ish, 4*VALUES] — the "-ish" is the problem. value_column() exists solely to recover a logical column from a physical value index by hand.

ThunderKittens has rt<T, M, N, layout>: logical rows, logical cols, and a layout parameter that owns the (lane, register) -> (row, col) map. Every op is written against M/N; the layout is what varies.

Why first. Every op in #5, #6, and #7 has to name a coordinate. Written against SLOTS/VALUES they all bake in the base-LDTM 16x256b map, and adding a second layout later means rewriting them, not extending them. This is the one type in the crate that is a rewrite rather than a widening — reg.rs is 392 lines and roughly half of it is affected.

Shape

  • trait FragmentLayout carrying the ownership map as associated consts (owned rows per 16-row block, value column offsets, rows-per-thread) plus the lane arithmetic.
  • RegTile<const M: usize, const N: usize, L: FragmentLayout> with per-thread storage sized from L and M/N.
  • Fragment becomes an alias for the base-LDTM layout at the shape one TMEM drain returns, preserving today's call sites.
  • The ownership contract currently documented in the reg.rs module header moves onto the layout impl, where it can be asserted.

Only one layout impl is needed to close this. The point is that the signatures stop lying about shape.

Activity

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

    @feitreim
    OwnerAuthor

    Landed. RowLayout<M> / FragmentLayout<M, N> with BaseLdtm as the sole impl; RegTile<M, N, L> and RegVec<M, L> now carry logical shapes. Storage is an associated type per shape (macro-generated), avoiding generic_const_exprs.

    Derived SLOTS = M/8, VALUES = N/4, per warp — so Fragment is a logical 16x16 and the flash accumulator is 32x128. Confirmed against a B200 in #4: the drain probe indexes accumulator rows as 32*warp + row, i.e. one warp owns 32 accumulator rows, exactly this reading. The old "4 rows of a 64-row warpgroup tile" prose was not reconcilable with per-warp arithmetic and has been replaced.

    Both hardware-validated paths (fragment_tile interleaving, store_fragment stmatrix addressing) are byte-identical. Also fixed a wrong doc claim in TmemTile::fragment: the low simd carries column offsets {0,1} of both rows, not the lane/4 row.

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:typesenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions