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 struct
MLAPrefillSparseFP8
struct MLAPrefillSparseFP8[KVLUTType: MHAOperand, output_dtype: DType, config: MLASparseConfig[config.qkv_dtype, config.b_topk_, config.num_mbars_, config.q_smem_depth_, config.q_tmem_depth_, config.cta_group_]]
Implemented traitsβ
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDeletable,
Movable,
RegisterPassable,
TrivialRegisterPassable
comptime membersβ
accum_dtypeβ
comptime accum_dtype = DType.float32
B_TOPK_PER_CTAβ
comptime B_TOPK_PER_CTA = (config.B_TOPK // config.cta_group)
Commonβ
comptime Common = MLAPrefillSparseCommon[KVLUTType, output_dtype, config]
CTA_MASKβ
comptime CTA_MASK = UInt16(3) if (config.cta_group == Int(2)) else UInt16(1)
FP8_K_SWIZZLEβ
comptime FP8_K_SWIZZLE = TensorMapSwizzle.SWIZZLE_NONE
FP8_V_SWIZZLEβ
comptime FP8_V_SWIZZLE = TensorMapSwizzle.SWIZZLE_NONE
FULL_Q_TYPEβ
comptime FULL_Q_TYPE = MLAPrefillSparseFP8[KVLUTType, output_dtype, config].SMemType.FULL_Q_TYPE
k_desc_shapeβ
comptime k_desc_shape = Index[Int, Int](Int(1), _gather4_box_width[qkv_dtype, config.qk_depth, TensorMapSwizzle(Int32(3))]())
k_gather_boxβ
comptime k_gather_box = _gather4_box_width[MLAPrefillSparseFP8[KVLUTType, output_dtype, config].qkv_dtype, config.qk_depth, MLAPrefillSparseFP8[KVLUTType, output_dtype, config].k_swizzle_mode]()
k_swizzle_modeβ
comptime k_swizzle_mode = config.k_swizzle_mode
k_tile_heightβ
comptime k_tile_height = MLAPrefillSparseFP8[KVLUTType, output_dtype, config].B_TOPK_PER_CTA
k_tile_shapeβ
comptime k_tile_shape = Index[Int, Int](MLAPrefillSparseFP8[KVLUTType, output_dtype, config].k_tile_height, _gather4_box_width[qkv_dtype, config.qk_depth, TensorMapSwizzle(Int32(3))]())
k_tile_widthβ
comptime k_tile_width = config.qk_depth
k_tma_desc_shape_fp8β
comptime k_tma_desc_shape_fp8 = Index[Int, Int](Int(1), _gather4_box_width[DType.int64, (config // Int(8)), TensorMapSwizzle(Int32(0))]())
k_tma_dtype_fp8β
comptime k_tma_dtype_fp8 = DType.int64
k_tma_gather_box_fp8β
comptime k_tma_gather_box_fp8 = _gather4_box_width[DType.int64, (config // Int(8)), MLAPrefillSparseFP8[KVLUTType, output_dtype, config].k_tma_swizzle_fp8]()
k_tma_swizzle_fp8β
comptime k_tma_swizzle_fp8 = MLAPrefillSparseFP8[KVLUTType, output_dtype, config].FP8_K_SWIZZLE
k_tma_tile_shape_fp8β
comptime k_tma_tile_shape_fp8 = Index[Int, Int](MLAPrefillSparseFP8[KVLUTType, output_dtype, config].k_tile_height, _gather4_box_width[DType.int64, (config // Int(8)), TensorMapSwizzle(Int32(0))]())
k_tma_tile_width_fp8β
comptime k_tma_tile_width_fp8 = (config // Int(8))
NUM_Q_HEADS_PER_CTAβ
comptime NUM_Q_HEADS_PER_CTA = (config // config.cta_group)
NUM_SV_ATOMSβ
comptime NUM_SV_ATOMS = 2
O_ATOM_PHYS_COLSβ
comptime O_ATOM_PHYS_COLS = ((config // Int(2)) // Int(2))
o_desc_shapeβ
comptime o_desc_shape = Index[Int, Int]((config // cta_group_), Int(64))
o_tile_shapeβ
comptime o_tile_shape = Index[Int, Int]((config // cta_group_), config)
O_TMEM_ADDRβ
comptime O_TMEM_ADDR = 0
O_TMEM_ADDR_ATOM2β
comptime O_TMEM_ADDR_ATOM2 = (Int(0) + ((config // Int(2)) // Int(2)))
O_TYPEβ
comptime O_TYPE = MLAPrefillSparseFP8[KVLUTType, output_dtype, config].SMemType.O_TYPE
P_TMEM_ADDRβ
comptime P_TMEM_ADDR = 256
PADDED_HEADS_PER_CTAβ
comptime PADDED_HEADS_PER_CTA = (config // config.cta_group)
q_desc_shapeβ
comptime q_desc_shape = _default_desc_shape[Int(3), MLAPrefillSparseFP8[KVLUTType, output_dtype, config].qkv_dtype, MLAPrefillSparseFP8[KVLUTType, output_dtype, config].q_tile_shape, config.q_swizzle_mode]()
q_smem_depthβ
comptime q_smem_depth = config.q_smem_depth
q_tile_shapeβ
comptime q_tile_shape = Index[Int, Int, Int](Int(1), (config // cta_group_), config)
Q_TMEM_ADDRβ
comptime Q_TMEM_ADDR = (Int(512) - (MLAPrefillSparseFP8[KVLUTType, output_dtype, config].q_tmem_depth // Int(2)))
q_tmem_depthβ
comptime q_tmem_depth = config.q_tmem_depth
QKMMAOpTypeβ
comptime QKMMAOpType = QKMMAOp[MLAPrefillSparseFP8[KVLUTType, output_dtype, config].qkv_dtype, DType.float32, config]
qkv_dtypeβ
comptime qkv_dtype
qkv_dtype_sizeβ
comptime qkv_dtype_size = size_of[MLAPrefillSparseFP8[KVLUTType, output_dtype, config].qkv_dtype]()
SHARED_QKV_TYPEβ
comptime SHARED_QKV_TYPE = MLAPrefillSparseFP8[KVLUTType, output_dtype, config].SMemType.SHARED_QKV_TYPE
SMemTypeβ
comptime SMemType = MLASparseSharedMemory[config]
SV_ATOM_MMA_Nβ
comptime SV_ATOM_MMA_N = (config // Int(2))
SVMMATypeβ
comptime SVMMAType = SVMMAType[MLAPrefillSparseFP8[KVLUTType, output_dtype, config].qkv_dtype, DType.float32, config]
V_BMN_PER_ATOMβ
comptime V_BMN_PER_ATOM = ((config // Int(2)) // config.cta_group)
V_DEPTH_PER_CTAβ
comptime V_DEPTH_PER_CTA = MLAPrefillSparseFP8[KVLUTType, output_dtype, config].SV_ATOM_MMA_N
v_desc_shapeβ
comptime v_desc_shape = Index[Int, Int](Int(1), _gather4_box_width[qkv_dtype, Int((mul ((config // Int(2)) // cta_group_), 2)), TensorMapSwizzle(Int32(3))]())
v_gather_boxβ
comptime v_gather_box = _gather4_box_width[MLAPrefillSparseFP8[KVLUTType, output_dtype, config].qkv_dtype, Int((mul ((config // Int(2)) // cta_group_), 2)), MLAPrefillSparseFP8[KVLUTType, output_dtype, config].v_swizzle_mode]()
V_SMEM_COLS_PER_CTAβ
comptime V_SMEM_COLS_PER_CTA = (((config // Int(2)) // cta_group_) * Int(2))
v_swizzle_modeβ
comptime v_swizzle_mode = TensorMapSwizzle.SWIZZLE_128B
v_tile_heightβ
comptime v_tile_height = (config.B_TOPK // Int(2))
v_tile_shapeβ
comptime v_tile_shape = Index[Int, Int](MLAPrefillSparseFP8[KVLUTType, output_dtype, config].v_tile_height, _gather4_box_width[qkv_dtype, Int((mul ((config // Int(2)) // cta_group_), 2)), TensorMapSwizzle(Int32(3))]())
v_tile_widthβ
comptime v_tile_width = MLAPrefillSparseFP8[KVLUTType, output_dtype, config].V_SMEM_COLS_PER_CTA
v_tma_desc_shape_fp8β
comptime v_tma_desc_shape_fp8 = Index[Int, Int](Int(1), _gather4_box_width[DType.int64, (((config // Int(2)) // cta_group_) // Int(8)), TensorMapSwizzle(Int32(0))]())
v_tma_dtype_fp8β
comptime v_tma_dtype_fp8 = DType.int64
v_tma_gather_box_fp8β
comptime v_tma_gather_box_fp8 = _gather4_box_width[DType.int64, (((config // Int(2)) // cta_group_) // Int(8)), MLAPrefillSparseFP8[KVLUTType, output_dtype, config].v_tma_swizzle_fp8]()
v_tma_swizzle_fp8β
comptime v_tma_swizzle_fp8 = MLAPrefillSparseFP8[KVLUTType, output_dtype, config].FP8_V_SWIZZLE
v_tma_tile_height_fp8β
comptime v_tma_tile_height_fp8 = config.B_TOPK
v_tma_tile_shape_fp8β
comptime v_tma_tile_shape_fp8 = Index[Int, Int](MLAPrefillSparseFP8[KVLUTType, output_dtype, config].v_tma_tile_height_fp8, _gather4_box_width[DType.int64, (((config // Int(2)) // cta_group_) // Int(8)), TensorMapSwizzle(Int32(0))]())
v_tma_tile_width_fp8β
comptime v_tma_tile_width_fp8 = (((config // Int(2)) // cta_group_) // Int(8))
Methodsβ
load_k_fp8_tmaβ
static def load_k_fp8_tma(k_tma_op_fp8: TMATensorTile[DType.int64, Int(2), Self.k_tma_tile_shape_fp8, Self.k_tma_desc_shape_fp8], indices: TileTensor[DType.uint32, Storage=indices.Storage, linear_idx_type=indices.linear_idx_type], kv_lut: KVLUTType, k_smem_fp8_ptr: Pointer[Float8_e4m3fn, address_space=AddressSpace.SHARED, _safe=False], k_fp8_tma_done: Pointer[SharedMemBarrier, address_space=AddressSpace.SHARED, _safe=False], k: UInt32, cta_id: UInt32, warp_idx: UInt32, indices_base: UInt32)
load_k_scales_to_smemβ
static def load_k_scales_to_smem[scale_block_size: Int](scales_ptr: Pointer[Float32, ImmutAnyOrigin, _safe=False], indices: TileTensor[DType.uint32, Storage=indices.Storage, linear_idx_type=indices.linear_idx_type], kv_lut: KVLUTType, k_scales_smem_ptr: Pointer[Float32, address_space=AddressSpace.SHARED, _safe=False], k: UInt32, cta_id: UInt32, indices_base: UInt32, num_kv_rows: Int32)
convert_k_fp8_to_bf16β
static def convert_k_fp8_to_bf16[scale_block_size: Int](k_smem_fp8_ptr: Pointer[Float8_e4m3fn, address_space=AddressSpace.SHARED, _safe=False], k_smem_bf16_ptr: Pointer[Scalar[Self.qkv_dtype], address_space=AddressSpace.SHARED, _safe=False], k_scales_smem_ptr: Pointer[Float32, address_space=AddressSpace.SHARED, _safe=False])
load_v_fp8_tmaβ
static def load_v_fp8_tma(v_tma_op_fp8: TMATensorTile[DType.int64, Int(2), Self.v_tma_tile_shape_fp8, Self.v_tma_desc_shape_fp8], indices: TileTensor[DType.uint32, Storage=indices.Storage, linear_idx_type=indices.linear_idx_type], kv_lut: KVLUTType, v_smem_fp8_ptr: Pointer[Float8_e4m3fn, address_space=AddressSpace.SHARED, _safe=False], v_fp8_tma_done: Pointer[SharedMemBarrier, address_space=AddressSpace.SHARED, _safe=False], k: UInt32, cta_id: UInt32, warp_idx: UInt32, indices_base: UInt32)
load_v_scales_to_smemβ
static def load_v_scales_to_smem[scale_block_size: Int](scales_ptr: Pointer[Float32, ImmutAnyOrigin, _safe=False], indices: TileTensor[DType.uint32, Storage=indices.Storage, linear_idx_type=indices.linear_idx_type], kv_lut: KVLUTType, v_scales_smem_ptr: Pointer[Float32, address_space=AddressSpace.SHARED, _safe=False], k: UInt32, indices_base: UInt32, num_kv_rows: Int32)
convert_v_fp8_to_bf16β
static def convert_v_fp8_to_bf16[scale_block_size: Int](v_smem_fp8_ptr: Pointer[Float8_e4m3fn, address_space=AddressSpace.SHARED, _safe=False], v_smem_bf16_ptr: Pointer[Scalar[Self.qkv_dtype], address_space=AddressSpace.SHARED, _safe=False], v_scales_smem_ptr: Pointer[Float32, address_space=AddressSpace.SHARED, _safe=False], cta_id: UInt32)
kernel_fp8β
static def kernel_fp8[TopKLengthLayout: TensorLayout, IndicesLayout: TensorLayout, scale_block_size: Int](q_tma_op: TMATensorTile[Self.qkv_dtype, Int(3), Self.q_tile_shape, Self.q_desc_shape], k_tma_op_fp8: TMATensorTile[DType.int64, Int(2), Self.k_tma_tile_shape_fp8, Self.k_tma_desc_shape_fp8], v_tma_op_fp8: TMATensorTile[DType.int64, Int(2), Self.v_tma_tile_shape_fp8, Self.v_tma_desc_shape_fp8], o_tma_op: TMATensorTile[output_dtype, Int(2), Self.o_tile_shape, Self.o_desc_shape], topk_lengths: TileTensor[DType.uint32, TopKLengthLayout, MutAnyOrigin], indices: TileTensor[DType.uint32, IndicesLayout, MutAnyOrigin], kv_lut: KVLUTType, scale: Float32, attn_sink_ptr: Optional[Pointer[Float32, ImmutAnyOrigin, _safe=False]], indices_stride: Int32, output_gmem_ptr: Pointer[Scalar[output_dtype], MutAnyOrigin, _safe=False], scales_ptr: Pointer[Float32, ImmutAnyOrigin, _safe=False]) where (Int(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(IndicesLayout.__shape_types), [idx: __mlir_type.index] IndicesLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(IndicesLayout.__shape_types), [idx: __mlir_type.index] IndicesLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(IndicesLayout.__shape_types), [idx: __mlir_type.index] IndicesLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(IndicesLayout.__shape_types), [idx: __mlir_type.index] IndicesLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(IndicesLayout.__shape_types), [idx: __mlir_type.index] IndicesLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(IndicesLayout.__shape_types), [idx: __mlir_type.index] IndicesLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(IndicesLayout.__shape_types), [idx: __mlir_type.index] IndicesLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(IndicesLayout.__shape_types), [idx: __mlir_type.index] IndicesLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))[idx]._ParamListType))[idx]._ParamListType)))) == Int(1)) if (Int(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))[idx]._ParamListType))[idx]._ParamListType)))) == Int(1)) else (Int(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(TopKLengthLayout.__shape_types), [idx: __mlir_type.index] TopKLengthLayout.__shape_types[idx]._ParamListType))[idx]._ParamListType))[idx]._ParamListType))[idx]._ParamListType)))) == Int(1))
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!