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 function
depth512_load
def depth512_load[KVLUTType: MHAOperand, MaskType: MHAMask, qkv_dtype: DType, config: Depth512SM100Config[qkv_dtype], ValidLengthType: OptionalPointer, _is_cache_length_accurate: Bool, MaxSeqLenType: OptionallyStaticInt, is_leader: Bool](smem: Depth512AttentionSMem[config], score_row: UInt32, num_keys: UInt32, seq_info: SeqInfo, max_seq_len: MaxSeqLenType, mask: MaskType, q_tma_op: TMATensorTile[KVLUTType.dtype, Int(4) if config.fuse_gqa else Int(3), _padded_shape[Int(4) if config.fuse_gqa else Int(3), KVLUTType.dtype, q_smem_shape[KVLUTType.dtype, config.swizzle_mode, BM=config.BM, group=config.group, depth=config.qk_depth, decoding=False, fuse_gqa=config.fuse_gqa, num_qk_stages=config.num_qk_stages](), config.swizzle_mode](), _ragged_shape[Int(4) if config.fuse_gqa else Int(3), KVLUTType.dtype, q_smem_shape[KVLUTType.dtype, config.swizzle_mode, BM=config.BM, group=config.group, depth=config.qk_depth, decoding=False, fuse_gqa=config.fuse_gqa, num_qk_stages=config.num_qk_stages](), config.swizzle_mode]()], k_tma_op: TMATensorTile[KVLUTType.dtype, Int(3), _padded_shape[Int(3), KVLUTType.dtype, IndexList(kv_sub_tile_rows((config // Int(2)), KVLUTType.page_size), Int(1), config, __list_literal__=NoneType(None)), config.swizzle_mode](), _ragged_shape[Int(3), KVLUTType.dtype, IndexList(kv_sub_tile_rows((config // Int(2)), KVLUTType.page_size), Int(1), config, __list_literal__=NoneType(None)), config.swizzle_mode]()], v_tma_op: TMATensorTile[KVLUTType.dtype, Int(3), _padded_shape[Int(3), KVLUTType.dtype, IndexList(kv_sub_tile_rows(config.BK1, KVLUTType.page_size), Int(1), config, __list_literal__=NoneType(None)), config.swizzle_mode](), _ragged_shape[Int(3), KVLUTType.dtype, IndexList(kv_sub_tile_rows(config.BK1, KVLUTType.page_size), Int(1), config, __list_literal__=NoneType(None)), config.swizzle_mode]()], kv_lut: KVLUTType)
Issues TMA loads for one pair-CTA attention tile's Q, K, and V data.
Drives the producer side of the staged KV pipeline for a single
attention tile, loading Q (per-CTA), K (per-CTA half of BN), and V
(depth-split sub-tiles) into SMEM via non-multicast TMA copies.
The peeled-first iteration co-arrives Q with the first K depth stage
on a shared barrier so the MMA can start immediately; the main loop
issues full-tile K/V loads; the peeled-last iteration handles
partial pages when page_size < BN. Mask checks use PairBM so both
CTAs make identical skip decisions and pipeline barriers stay
synchronized.
Parameters:
- βKVLUTType (
MHAOperand): Paged key-value lookup table type supplying the elementdtype,page_size, and row-to-page mappings used bykv_lut. - βMaskType (
MHAMask): Attention mask type driving per-tile skip and load decisions viastart_column,last_masked_set_end, andstatusqueries. - βqkv_dtype (
DType): ElementDTypeof the Q, K, and V tensors; must matchKVLUTType.dtypeandconfig.qkv_dtype. - βconfig (
Depth512SM100Config[qkv_dtype]): Depth-512 SM100 pair-CTA attention configuration providing tile sizes (BM,BN,BK0,BK1), stage counts, swizzle mode, GQA grouping, andsplit_ocontrols. - βValidLengthType (
OptionalPointer): Optional pointer type for per-sequence valid lengths;is_nullisFalsefor ragged variable-length sequences. - β_is_cache_length_accurate (
Bool): Whether the reported KV cache length exactly matches the count of valid tokens. - βMaxSeqLenType (
OptionallyStaticInt): Type of the maximum sequence length, either a comptime staticIntor a runtime value; selects the decoding vs. prefill path via_is_decoding. - βis_leader (
Bool): Whether this CTA is the leader (even-ranked) CTA in the pair-CTA cluster; the leader issuesexpect_bytesand selects the first half of K/V rows.
Args:
- βsmem (
Depth512AttentionSMem[config]): Shared-memory allocator and stage buffers for the kernel. - βscore_row (
UInt32): Starting row of the Q tile within the current sequence. - βnum_keys (
UInt32): Number of valid KV keys for the current sequence. - βseq_info (
SeqInfo): Per-sequence metadata (prompt index, head index, etc.). - βmax_seq_len (
MaxSeqLenType): Maximum sequence length (static or dynamic). - βmask (
MaskType): Attention mask driving per-tile skip/load decisions. - βq_tma_op (
TMATensorTile[KVLUTType.dtype, Int(4) if config.fuse_gqa else Int(3), _padded_shape[Int(4) if config.fuse_gqa else Int(3), KVLUTType.dtype, q_smem_shape[KVLUTType.dtype, config.swizzle_mode, BM=config.BM, group=config.group, depth=config.qk_depth, decoding=False, fuse_gqa=config.fuse_gqa, num_qk_stages=config.num_qk_stages](), config.swizzle_mode](), _ragged_shape[Int(4) if config.fuse_gqa else Int(3), KVLUTType.dtype, q_smem_shape[KVLUTType.dtype, config.swizzle_mode, BM=config.BM, group=config.group, depth=config.qk_depth, decoding=False, fuse_gqa=config.fuse_gqa, num_qk_stages=config.num_qk_stages](), config.swizzle_mode]()]): TMA descriptor for Q tile loads. - βk_tma_op (
TMATensorTile[KVLUTType.dtype, Int(3), _padded_shape[Int(3), KVLUTType.dtype, IndexList(kv_sub_tile_rows((config // Int(2)), KVLUTType.page_size), Int(1), config, __list_literal__=NoneType(None)), config.swizzle_mode](), _ragged_shape[Int(3), KVLUTType.dtype, IndexList(kv_sub_tile_rows((config // Int(2)), KVLUTType.page_size), Int(1), config, __list_literal__=NoneType(None)), config.swizzle_mode]()]): TMA descriptor for K tile loads (per-CTA half). - βv_tma_op (
TMATensorTile[KVLUTType.dtype, Int(3), _padded_shape[Int(3), KVLUTType.dtype, IndexList(kv_sub_tile_rows(config.BK1, KVLUTType.page_size), Int(1), config, __list_literal__=NoneType(None)), config.swizzle_mode](), _ragged_shape[Int(3), KVLUTType.dtype, IndexList(kv_sub_tile_rows(config.BK1, KVLUTType.page_size), Int(1), config, __list_literal__=NoneType(None)), config.swizzle_mode]()]): TMA descriptor for V tile loads (per-sub-tile). - βkv_lut (
KVLUTType): Paged key-value lookup table supplying row-to-page mappings.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!