For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo struct
DenseALoader
struct DenseALoader[dtype: DType, a_layout: TensorLayout, BK: Int = Int(16), SG_M: Int = Int(32), use_x2: Bool = False, b_dtype: DType = dtype]
Plain-GEMM A loader: holds the pre-tiled (SG_M, K) slab.
The run wrapper bakes the simdgroup's slab base once (see its docstring for
the hoist rationale); the hot-loop .tile[SG_M, BK](0, k_strip) here only
adds this strip's k_strip * BK K offset. The strip sub-tiles are
type-identical to the per-strip form, so MmaOpApple.mma is unchanged.
BK/SG_M are explicit params (not re-derived from a fresh default
AppleM5MatMul[dtype]) so a non-default block_k/sg_m -- e.g. use_x2's
block_k=32 -- isn't silently ignored; run passes Self.BK/Self.SG_M.
b_dtype sets the B/weight operand fed to the MMA (defaults to dtype, the
dense case). The W8A16 FP8 path constructs this loader with b_dtype=fp8:
the A slab stays bf16 and only b_sub / mma_op widen to the native-fp8 MMA
(KGEN lowers the fp8 B fragment to AIR <8 x i8>); the K-loop and
accumulation order are byte-for-byte the dense path.
Lifetime: the a_slab view is held with UntrackedOrigin (struct fields
cannot expose an AnyOrigin); the kernel arg it derives from outlives the
K-loop, so this is the explicit-lifetime case the field-origin rule allows.
Parametersβ
- βdtype (
DType): Element type of the A operand (fp16, bf16, fp32). - βa_layout (
TensorLayout):TensorLayoutof the pre-tiled A slab held by the loader. - βBK (
Int): K-strip depth per accumulate step; must match the body'sBKtiling (defaults to 16). - βSG_M (
Int): Simdgroup subtile rowsSG_M; the.tile[SG_M, BK]extent used per strip (defaults to 32). - βuse_x2 (
Bool): Use the NT "double-strip" dense MMA (mma_dense_x2,block_k=32) instead of the single-stripmma(defaults to False). - βb_dtype (
DType): Element type of the B/weight operand fed to the MMA (defaults todtype, the dense case).
Fieldsβ
- βa_slab (
TileTensor[dtype, a_layout, ImmUntrackedOrigin]):
Implemented traitsβ
AOperandLoader,
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDeletable,
Movable
comptime membersβ
b_typeβ
comptime b_type = b_dtype
in_typeβ
comptime in_type = dtype
num_m_mmasβ
comptime num_m_mmas = 2
num_n_mmasβ
comptime num_n_mmas = 2
Methodsβ
accumulate_stripβ
def accumulate_strip[bounded: Bool, b_layout: TensorLayout](mut self, mut mma_op: MmaOpApple[DType.float32, Self.in_type, Int(2), Int(2), b_type=Self.b_type], mut accum: Array[SIMD[DType.float32, SIMDLength(8)], MmaOpApple[DType.float32, Self.in_type, Int(2), Int(2), b_type=Self.b_type].num_accum], b_sub: TileTensor[Self.b_type, b_layout, ImmutAnyOrigin], conv: ConvIm2colParams, k_strip: Int32, *, a_valid_rows: Int32, b_valid_cols: Int, k_valid: Int)
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!