Skip to content

tma_load_at's BOX_ROWS is an uninferrable const the caller restates, and it scales the returned TransactionBytes #168

Open

Description

@feitreim

What

SharedTile::tma_load_at::<BOX_ROWS> (and its cluster twin
tma_load_2d_at_arriving_at::<BOX_ROWS>) make the caller restate the tensor
map's box height as a const generic that nothing can infer and nothing checks
against the map — and that value is what scales the returned
TransactionBytes:

pub unsafe fn tma_load_at<const BOX_ROWS: usize>(...) -> TransactionBytes {
    const { assert!(BOX_ROWS <= R, "a box taller than the tile cannot land in it") };
    // ... one cp.async.bulk.tensor.3d per subtile ...
    TransactionBytes::new(Self::SUBTILES * BOX_ROWS * S::ATOM_BYTES)
}

So a caller that writes ::<R> where the map's box is R/2 type-checks, passes
the const assert, issues exactly the right loads, and then over-charges the
barrier by 2x — a hang. Writing it too small under-charges and flips the
barrier before the bytes land. This is precisely the failure mode
TransactionBytes was introduced to make unreachable: everywhere else the
charge is derived from the transfer the method issued, and here it is derived
from a number the caller wrote down.

tma_load has no such hole — its charge comes from R, which is the tile's own.

Where I hit it

Porting oxide-train's flash-attn kernels to ferro-kittens
(feitreim/oxide-train#66). Eight call sites stack two 64-row boxes into one
128-row operand, so every one had to gain a ::<TILE> turbofish whose only
correctness argument is "the host built the map with FLASH_TILE rows, in
another file". The old tma_load_at took no const generic and the caller wrote
the byte count out by hand, so this is not a regression — but it is the one
place the new receipt type does not actually close the loop.

Possible shapes for a fix

The box height is known host-side: GlobalLayout::tensor_map::<T: TileBox>
builds the descriptor from a SharedTile<E, R, C, S>, so R is in the type
at the moment of encoding and is erased by the time the kernel holds a
*const TmaDescriptor. Options, roughly in order of how much they cost:

  1. A typed device-side map handle — TensorMapRef<T: TileBox> wrapping the raw
    pointer, carrying the box shape as a type parameter. tma_load_at then reads
    BOX_ROWS off the map instead of the turbofish, and a mismatched map fails to
    typecheck rather than mis-charging. Costs a kernel-parameter type change.
  2. Keep the const generic but stop it from reaching the charge: return the
    charge for the box the map describes by having the caller pass the source
    tile type (tma_load_at::<Src: TileBox>), so BOX_ROWS and the loaded bytes
    come from one place.
  3. Cheapest: document the hazard on both methods — that BOX_ROWS is the
    map's box height and not a free choice, and that getting it wrong is a
    silent mis-charge rather than a wrong address.

I did not touch this repo; filing rather than fixing.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions