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
softmax_warp
Softmax warp group logic for FA4 (SM100 Flash Attention).
comptime valuesβ
f32x2β
comptime f32x2 = SIMD[DType.float32, SIMDLength(2)]
Functionsβ
- β
fa4_lse_combine_write: LSE-combine two TMEM_O fragments and TMA-store a depth-column slice. - β
fa4_scale_write_output: - β
fa4_softmax: - β
fa4_splitk_combine_write: Split-K pass 2 (reduce-scatter): EVERY partition's WG0 owns the depth-column band[wg_j_offset, wg_j_offset+iters_per_wg)(output blocks). It reads every partition'sO_ctaFOR ITS BAND + every partition's(max,sum), forms the cluster LSEGmax/Gsumand per-row weightsw_p = sum_p*exp2((max_p-Gmax)*c)/Gsum(per-thread scalars -- this thread owns its row, NOwarp.shuffle_idx), weight-sumsO_final = Ξ£_p O_cta_p*w_p(thesum_pcancels theO_ctanormalization), casts to bf16, and TMA-stores its band columns to gmem. - β
fa4_splitk_reduce_scatter_write: Split-K pass 2 dispatch (reduce-scatter): pick THIS partition's depth-column band from the STATIC partition countPand the runtimepartition_idx, then STAGE + publish + combine over it.Pisconfig.splitk_partitions(each split-K kernel is compiled once per staticP), so the band'swg_j_offset/iters_per_wgare already comptime; onlypartition_idxis lifted via a comptime-for over thePpartitions -- one runtime branch taken, the band params comptime per branch. - β
fa4_splitk_stage_partial: Split-K pass 1: LSE-combine the two WG O fragments into this partition's NORMALIZEDO_cta(f32) over the FULL[0, iters)depth range, routing each block by destination. The OWN band[own_off, own_off+own_iters)is written into theo_finalregister array UNSCALED (the combine scales it byw[b]after the publish barrier); every other (PEER-visible) block is stored tostage_smemin the SWIZZLE_NONE block-major, bank-conflict-free layoutfa4_scale_write_outputuses, at f32 width. - β
fa4_tma_store_o_smem: TMA egress of a fully-writteno_smemto gmem: the per-block (tma_blocks_per_op == 0) tail factored out offa4_scale_write_output'selsebranch. - β
fa4_ws_intracta_combine: Intra-CTAm_pack-way LSE combine for the.wsMMA_M=32 datapath. - β
fa4_ws_intracta_combine_partial: T==1 cross-CTA (split-K) partial: the 4-way intra-CTA combine emitting the NORMALIZED per-CTA band intoo_band_norm(registers) + returning(M_cta, L_cta), for the cross-CTA reduce-scatter third level, instead of packing too_smem. - β
fa4_ws_level1_combine: Level 1 of the two-level WS combine: per-warpgroupm_pack-way merge of the packed-TMEM datapath quarters into an UNNORMALIZED partial. - β
fa4_ws_level2_combine_partial: T>=2 cross-CTA (split-K) partial: a fork offa4_ws_level2_reduce_scatter_writethat emits the NORMALIZED per-CTA band intoo_band_norm(registers) + returns(M_cta, L_cta) = (gmax, l_acc)for the cross-CTA reduce-scatter third level, instead of packing too_smem. - β
fa4_ws_level2_reduce_scatter_write: Level 2 of the two-level WS combine: intra-CTA cross-warpgroup reduce-scatter of the two per-WG Level-1 partials into the normalized output. WG0-writes-all (Β§5c step 3 / Β§9.8). - β
fa4_ws_splitk_reduce_scatter_write: Third level (cross-CTA cluster split-K) reduce-scatter combine for the.wsMMA_M=32 datapath: merges the P partition CTAs' per-CTA normalized partials into the final output, each CTA writing only its OWN depth band.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!