IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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:

Was this page helpful?