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 module
attention_utils
Shared SM100 attention primitives used by both MHA and MLA kernels.
This module contains generic SM100 (Blackwell) GPU primitives including:
- TMEM access helpers (TMemTile, STMatrixLayout)
- Pipeline synchronization (StagedPipeline, RolePipeline, etc.)
- FTZ arithmetic (add_ftz, sub_ftz, mul_ftz, etc.)
- Barrier helpers (FA4MiscMBars)
- MMA building blocks (bulk_mma, SM100TensorAccumulator)
- Masking utilities (apply_mask, apply_oob_mask)
comptime valuesβ
ConsumerPipelineβ
comptime ConsumerPipeline = RolePipeline[_, False, _, _, _]
FP32_EXP_BIASβ
comptime FP32_EXP_BIAS = 127
KConsumerPipelineβ
comptime KConsumerPipeline = TMAConsumerPipeline[_, _]
KPipelineβ
comptime KPipeline = StagedPipeline[_, _]
KProducerPipelineβ
comptime KProducerPipeline = TMAProducerPipeline[_, _]
KVPipelineβ
comptime KVPipeline = StagedPipeline[_, _]
LocalLTβ
comptime LocalLT[dtype: DType, layout: Layout, element_layout: Layout = Layout(IntTuple(Int(1)), IntTuple(Int(1)))] = LayoutTensor[dtype, layout, MutAnyOrigin, address_space=AddressSpace.LOCAL, element_layout=element_layout]
Parametersβ
LocalTensorβ
comptime LocalTensor[dtype: DType, layout: Layout[shape_types, stride_types]] = TileTensor[dtype, Layout[shape_types, stride_types], MutUntrackedOrigin, address_space=AddressSpace.LOCAL]
Parametersβ
- βdtype (
DType): - βlayout (
Layout[shape_types, stride_types]):
MBarTypeβ
comptime MBarType = Pointer[SharedMemBarrier, MutAnyOrigin, address_space=AddressSpace.SHARED, _safe=False]
ProducerPipelineβ
comptime ProducerPipeline = RolePipeline[_, producer_sub_stages=_, consumer_sub_stages=_, cta_group=_]
SharedMemPointerβ
comptime SharedMemPointer[type: AnyType] = Pointer[type, MutAnyOrigin, address_space=AddressSpace.SHARED, _safe=False]
Parametersβ
- βtype (
AnyType):
SharedMemTensorβ
comptime SharedMemTensor[dtype: DType, layout: Layout[shape_types, stride_types]] = TileTensor[dtype, Layout[shape_types, stride_types], MutUntrackedOrigin, address_space=AddressSpace.SHARED]
Parametersβ
- βdtype (
DType): - βlayout (
Layout[shape_types, stride_types]):
VConsumerPipelineβ
comptime VConsumerPipeline = TMAConsumerPipeline[_, _, False]
VPipelineβ
comptime VPipeline = StagedPipeline[_]
VProducerPipelineβ
comptime VProducerPipeline = TMAProducerPipeline[_, _, False]
Structsβ
- β
FA4MiscMBars: Manages all mbarrier resources for FA4. - β
MBarPipeline: Manages a paired set of producer/consumer mbarriers for pipeline synchronization. - β
RolePipeline: Unified producer/consumer pipeline for barrier synchronization. - β
SM100TensorAccumulator: Performs theC = A @ Btensor contraction on SM100 usingtcgen05.mmainstructions. - β
StagedPipeline: Unified pipeline for K, V, and KV tile barrier management. - β
STMatrixLayout: Layout for usingst_matrixfor writing the final accumulator to smem. - β
STMatrixOffsets: Precomputed TMEM and local-fragment offsets for onest_matrixrepeat column. - β
TMAConsumerPipeline: Unified consumer pipeline for K and V TMA consumption. - β
TMADestination: Pairs a shared memory TileTensor with a barrier for TMA operations. - β
TMAProducerPipeline: Unified producer pipeline for K and V TMA loading. - β
TMemTile: Represents a tile in SM100 tensor memory (TMEM) and provides async load/store helpers.
Functionsβ
- β
add_ftz: Returns the flush-to-zero sum of two float32 values. - β
add_ftz_rm: Returns the round-to-nearest-even flush-to-zero sum of twof32x2vectors. - β
apply_mask: Applies bitmask, computed, and out-of-bounds masking strategies to a row ofBNattention scores. - β
apply_oob_mask: Applies the out-of-bounds key mask to a pair of attention scores. - β
break_into_powers_of_two: Callsfuncfor each power-of-two-sized chunk ofN, plus a finalpow_two=0call for pipeline cleanup. - β
bulk_mma: Issues a full-tile SS (both operands in SMEM) non-warp-specializedtcgen05.mmacontraction. - β
bulk_mma_partial: Issues a partial-K TS contraction for a partially-loaded last KV tile, non-warp-specialized. - β
bulk_mma_ss_partial: Issues a partial-K SS contraction for a partially-loaded last KV tile, non-warp-specialized. - β
bulk_mma_ws: Issues a full-tile SS (both operands in SMEM) warp-specializedtcgen05.mma.wscontraction. - β
bulk_mma_ws_partial: Issues a partial-K SS warp-specialized contraction for a partially-loaded last KV tile. - β
bulk_mma_ws_ts: Issues a full-tile TS (A in TMEM, B in SMEM) warp-specializedtcgen05.mma.wscontraction. - β
bulk_mma_ws_ts_partial: Issues a partial-K TS warp-specialized contraction for a partially-loaded last KV tile. - β
cluster_remote_smem_addr: Map a local.sharedbyte address to peerpeer_rank's window in the cluster. - β
clusters_per_wave: Number of size-cluster_sizethread-block clusters that fit on the target Blackwell datacenter GPU in ONE wave, honoring GPC co-residency. - β
combine_pack_o_row: LSE-combineown * scale_own + peer * scale_peerovernf32 O lanes, cast to the 2-byteoutput_type, and pack inton // 2u32 lanes. - β
cumulative_power_of_two: Returns the cumulative sum of the firstipower-of-two components ofN. - β
elect_mma_arrive: Arrive at the mbar pointer for the MMA instruction. - β
exp2_emulation: Computes2^xfor anf32x2vector via a degree-3 polynomial approximation. - β
expect_bytes_pred: Issuembarrier.arrive.expect_tx.shared::cta.b64predicated onpred != 0. - β
extract_power_of_two: Returns thei-th power-of-two component when decomposingNinto decreasing powers of two. - β
fma_ftz: - β
intrin: Wraps a ternary float32 PTX intrinsic (e.g.max.f32). - β
intrin_ftz: Wraps a flush-to-zero (FTZ) binary float32 PTX intrinsic. - β
intrin_ftz_x2: Wraps a flush-to-zero (FTZ) binaryf32x2PTX intrinsic. - β
llvm_opaque_tid: Returns the opaque thread ID via thellvm.nvvm.read.ptx.sreg.tid.xintrinsic. - β
load_cluster_smem: Loadwidthelements from peerpeer_rank's shared memory atlocal_ptr. - β
mask_select8: Masks 8 contiguous scores against one byte of a 32-column bitmask. - β
max_ftz: Returns the flush-to-zero maximum of two float32 values. - β
maximum: ReducesBNfloat32 scores intowidthlane-maxima using FTZ max. - β
mul_ftz: Returns the flush-to-zero product of two float32 values. - β
o_store_tma_blocks_per_op: Box size (swizzle-granularity blocks per batched O-store TMA). - β
pack_row: Cast thewf32 O laneso_vals[start : start + w]tooutput_typeand pack them into one 16 B SWIZZLE_NONE store register (exactly four u32). - β
peel_mask: Determine which mask strategy applies to the peeled first iteration. - β
scale_pack_o_row: Scale thewf32 O laneso_vals[start : start + w]byinv_row_sum, cast to the 2-byteoutput_type, and pack intow // 2u32 lanes (the row-major 16 B SWIZZLE_NONE store register). - β
splitk_partition_idx: This CTA's split-K partition index[0, splitk_partitions). - β
splitk_window: Front-loaded balanced split of the combined K-tile range[0, T). - β
st_shared_v4_b32: Explicit 16 Bst.shared.v4.b32(oneSTS.128) todst[elem_off]. - β
store_cluster_smem: Storevalinto peerpeer_rank's shared memory atlocal_ptr. - β
sub_ftz: Returns the flush-to-zero difference of two float32 values. - β
sum: Reduces aBN-element local tensor into a width-2 SIMD vector via vectorized accumulation.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!