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
mha_sm100_dispatch
def mha_sm100_dispatch[q_type: DType, KVType: MHAOperand, MaskType: MHAMask, output_type: DType, MaxPromptLenType: OptionallyStaticInt, //, config: MHAConfig[config.dtype], group: Int, ragged: Bool, sink: Bool, _is_cache_length_accurate: Bool, pair_cta: Bool](output: DeviceBuffer[output_type], q_arg: Pointer[Scalar[q_type], _safe=False], k: KVType, v: KVType, num_rows_q: Int, mask: MaskType, valid_length: Pointer[UInt32, _safe=False], max_prompt_len_arg: MaxPromptLenType, max_cache_valid_length_arg: Int, scale: Float32, kv_input_row_offsets: OptionalReg[TileTensor[DType.uint32, Layout[*?, *?], ImmutAnyOrigin]], batch_size_arg: Int, ctx: DeviceContext, sink_weights: OptionalReg[TileTensor[q_type, Layout[*?, *?], ImmutAnyOrigin]])
Dispatches the SM100 FA4 flash-attention kernel for a prefill workload.
Selects between the 1Q split-K and 2Q FA4 configurations based on a occupancy and prompt-length heuristic, constructs the Q/K/V/O TMA tile descriptors and transient tile scheduler, threads optional ragged valid-length, KV-row-offset, and sink-attention arguments through to the compiled kernel, and enqueues the launch onto the supplied device context.
Parameters:
- βq_type (
DType): Element type of the query tensor (inferred). - βKVType (
MHAOperand): Key/value operand descriptor with dtype and page size (inferred). - βMaskType (
MHAMask): Attention mask scheme applied to the Q@K' scores (inferred). - βoutput_type (
DType): Element type of the attention output buffer (inferred). - βMaxPromptLenType (
OptionallyStaticInt): Optionally-static type encoding the maximum prompt length (inferred). - βconfig (
MHAConfig[config.dtype]): MHA configuration supplying dtype, head count, depth, and swizzle mode. - βgroup (
Int): Number of query heads per KV head (GQA group size). - βragged (
Bool): Whether to dispatch the variable-length valid-length path. - βsink (
Bool): Whether to thread sink-attention weights into the kernel. - β_is_cache_length_accurate (
Bool): Whether the supplied cache length is accurate, threaded to the compiled kernel. - βpair_cta (
Bool): Whether to launch the pair-CTA configuration with a cluster size of 2.
Args:
- βoutput (
DeviceBuffer[output_type]): Device buffer that receives the attention output rows. - βq_arg (
Pointer[Scalar[q_type], _safe=False]): Pointer to the query tensor data. - βk (
KVType): Key operand descriptor. - βv (
KVType): Value operand descriptor. - βnum_rows_q (
Int): Number of query rows to attend over. - βmask (
MaskType): Attention mask applied to the Q@K' scores. - βvalid_length (
Pointer[UInt32, _safe=False]): Per-row valid KV length pointer, used whenraggedis set. - βmax_prompt_len_arg (
MaxPromptLenType): Maximum prompt length, optionally static. - βmax_cache_valid_length_arg (
Int): Maximum valid KV cache length across the batch. - βscale (
Float32): Scalar applied to the Q@K' product before softmax. - βkv_input_row_offsets (
OptionalReg[TileTensor[DType.uint32, Layout[*?, *?], ImmutAnyOrigin]]): Optional per-row KV input offsets for ragged layouts. - βbatch_size_arg (
Int): Number of sequences in the batch. - βctx (
DeviceContext): Device context used to build TMA descriptors and enqueue the kernel. - βsink_weights (
OptionalReg[TileTensor[q_type, Layout[*?, *?], ImmutAnyOrigin]]): Optional sink-attention weights used whensinkis set.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!