You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Element carries MMA kind and conversion, ready for sub-bf16 types #2
Groundwork so sub-bf16 element types drop in cleanly later, without committing to them now.
What Element is today
pubtraitElement{constBYTES:usize;}pubstructBf16;
Byte width only. Everything else about bf16 is hardcoded elsewhere: mma.rs names Bf16 concretely and calls tcgen05_mma_f16, and ldst.rs hardcodes the cvt_f32x2_bf16x2 pack.
What cuda-oxide actually gives us at the pinned rev (b099f64) — better than assumed:
Need
Status
Generic MMA over element kind
tcgen05_mma_shared / tcgen05_mma_tensor take a KIND const: 0=f16, 1=tf32, 2=f8f6f4, 3=i8
Landed. Element now carries type Unpacked, BYTES, a derived PER_WORD, and fn pack; MmaElement: Element carries MMA_KIND: u32. Bf16 remains the only impl.
Two decisions worth recording:
pack arity via associated type, with the restriction on the function rather than the trait.store_fragment<E: Element<Unpacked = [f32; 2]>> — the 2-per-word limit belongs to stmatrix.m8n8.x2 (two b16 matrices), not to elements. A 4-per-word element gets a type error at the call site instead of silently packing half its bytes.
mma.rs is generic over E: MmaElement with const { assert_two_byte_element::<E>() } guarding the bf16-shaped chunk geometry. Note that post-monomorphization const asserts fire at codegen, not cargo check — weaker than the type bound store_fragment gets.
Concrete follow-on from #8: an impl Element for F32 is ~15 lines and unblocks the global layout for fp32 buffers.
#8 landed GlobalLayout<E: Element, const RANK: usize>, which is generic over the element but reachable only for bf16 — because Element is implemented only for Bf16. So layernorm's fp32 parameter vectors are still undescribable, and that is now one impl away rather than a hardcode.
Nothing hard is hiding in it: Unpacked = [f32; 1], BYTES = 4, and pack/unpack are identity bit-casts. Worth noting that unlike Bf16::pack — which is cvt_f32x2_bf16x2, a device intrinsic whose host body is unreachable!() and therefore untestable off a GPU — an fp32 element would be fully host-testable. The TensorMapElement impl on top is one line (CU_TENSOR_MAP_DATA_TYPE_FLOAT32).
But it will not unblock layernorm on its own, and the reason is worth recording here so nobody expects it to. TileBox — the trait that supplies a tensor map's box shape — is implemented only for SharedTile, and SharedTile const-asserts a whole swizzle atom per row. The narrowest fp32 tile it admits is 32 columns and swizzled; gamma/beta want an unswizzled[1, N] box. Swizzle has no "none" mode, and inventing one is a shared-memory-layout decision rather than an element-type one.
That second half is #13 (shared vectors), already filed and already on layernorm's blocked-on list. Whatever #13 lands as a shared-vector type is the natural second TileBox impl, and it will want an unswizzled mode beside it.
So the split is: the element work belongs here and is mechanical; the thing actually gating layernorm is #13.
Activity
feitreim commentedon Jul 26, 2026
Landed.
Elementnow carriestype Unpacked,BYTES, a derivedPER_WORD, andfn pack;MmaElement: ElementcarriesMMA_KIND: u32.Bf16remains the only impl.Two decisions worth recording:
packarity via associated type, with the restriction on the function rather than the trait.store_fragment<E: Element<Unpacked = [f32; 2]>>— the 2-per-word limit belongs tostmatrix.m8n8.x2(two b16 matrices), not to elements. A 4-per-word element gets a type error at the call site instead of silently packing half its bytes.MMA_KIND: u32, notu8— cuda-oxide'stcgen05_mma_sharedtakesconst KIND: u32, so MMA: AtB/AtBt walks, mm entry points, generic KIND routing #12 is a substitution rather than a cast.mma.rsis generic overE: MmaElementwithconst { assert_two_byte_element::<E>() }guarding the bf16-shaped chunk geometry. Note that post-monomorphization const asserts fire at codegen, notcargo check— weaker than the type boundstore_fragmentgets.feitreim commentedon Jul 27, 2026
Concrete follow-on from #8: an
impl Element for F32is ~15 lines and unblocks the global layout for fp32 buffers.#8 landed
GlobalLayout<E: Element, const RANK: usize>, which is generic over the element but reachable only for bf16 — becauseElementis implemented only forBf16. So layernorm's fp32 parameter vectors are still undescribable, and that is now one impl away rather than a hardcode.Nothing hard is hiding in it:
Unpacked = [f32; 1],BYTES = 4, andpack/unpackare identity bit-casts. Worth noting that unlikeBf16::pack— which iscvt_f32x2_bf16x2, a device intrinsic whose host body isunreachable!()and therefore untestable off a GPU — an fp32 element would be fully host-testable. TheTensorMapElementimpl on top is one line (CU_TENSOR_MAP_DATA_TYPE_FLOAT32).But it will not unblock layernorm on its own, and the reason is worth recording here so nobody expects it to.
TileBox— the trait that supplies a tensor map's box shape — is implemented only forSharedTile, andSharedTileconst-asserts a whole swizzle atom per row. The narrowest fp32 tile it admits is 32 columns and swizzled;gamma/betawant an unswizzled[1, N]box.Swizzlehas no "none" mode, and inventing one is a shared-memory-layout decision rather than an element-type one.That second half is #13 (shared vectors), already filed and already on layernorm's blocked-on list. Whatever #13 lands as a shared-vector type is the natural second
TileBoximpl, and it will want an unswizzled mode beside it.So the split is: the element work belongs here and is mechanical; the thing actually gating layernorm is #13.
TileBox's second impl: a vector's box is its whole length, unswizzled
Shared vectors: an unswizzled run of elements, and the box to deliver…
Global to and from registers, with no descriptor in the way (#11)
Global to and from registers, with no descriptor in the way (#11) (#59)
Fold four warps into one number, and the fp32 element under it (#3)