Repository navigation
Description
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:
- A typed device-side map handle —
TensorMapRef<T: TileBox>wrapping the raw
pointer, carrying the box shape as a type parameter.tma_load_atthen reads
BOX_ROWSoff the map instead of the turbofish, and a mismatched map fails to
typecheck rather than mis-charging. Costs a kernel-parameter type change. - 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>), soBOX_ROWSand the loaded bytes
come from one place. - Cheapest: document the hazard on both methods — that
BOX_ROWSis 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