IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Mojo function

mha_sm90_dispatch

def mha_sm90_dispatch[q_type: DType, KVType: MHAOperand, MaskType: MHAMask, output_type: DType, MaxPromptLenType: OptionallyStaticInt, PartitionType: MHAPartitionScheme, //, config: MHAConfig[config.dtype], group: Int, ragged: Bool, sink: Bool, _is_cache_length_accurate: Bool](output: DeviceBuffer[output_type], q_arg: DeviceBuffer[q_type], k: KVType, v: KVType, num_rows_q: Int, mask_functor: MaskType, valid_length: DeviceBuffer[DType.uint32], max_prompt_len_arg: MaxPromptLenType, max_cache_valid_length_arg: Int, scale: Float32, kv_input_row_offsets: OptionalReg[LayoutTensor[DType.uint32, Layout.row_major(Int(-1)), ImmutAnyOrigin]], batch_size_arg: Int, partition: PartitionType, ctx: DeviceContext, sink_weights: OptionalReg[LayoutTensor[q_type, Layout.row_major(Int(-1)), ImmutAnyOrigin]])

Dispatches the SM90 FlashAttention-3 MHA kernel for a single batch.

Selects a transient, tiled, or queued tile scheduler based on the persistent-kernel configuration, builds the Q/K/V TMA tile descriptors, and forwards the request down the dispatch chain to the enqueued kernel.

Parameters:

  • q_type (DType): The dtype of the query tensor (inferred).
  • KVType (MHAOperand): The K/V operand type encoding dtype, page size, and layout (inferred).
  • MaskType (MHAMask): The mask functor type applied to attention scores (inferred).
  • output_type (DType): The dtype of the output tensor (inferred).
  • MaxPromptLenType (OptionallyStaticInt): The maximum prompt length, possibly known at compile time (inferred).
  • PartitionType (MHAPartitionScheme): The scheme for partitioning attention work across SMs (inferred).
  • config (MHAConfig[config.dtype]): The MHA configuration holding block sizes, head count, depth, and algorithm.
  • group (Int): The query grouping factor, the number of query heads per KV head.
  • ragged (Bool): Whether per-row valid lengths vary and require ragged masking.
  • sink (Bool): Whether attention sink weights are applied.
  • _is_cache_length_accurate (Bool): Whether the supplied cache length is exact and needs no clamping.

Args: