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
multistage_gemm
def multistage_gemm[c_type: DType, a_type: DType, b_type: DType, //, *, transpose_b: Bool, config: MatmulConfig[a_type, b_type, c_type, transpose_b], elementwise_lambda_fn: Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None] = None](c: TileTensor[c_type, Storage=c.Storage, address_space=c.address_space, linear_idx_type=c.linear_idx_type], a: TileTensor[a_type, Storage=a.Storage, address_space=a.address_space, linear_idx_type=a.linear_idx_type], b: TileTensor[b_type, Storage=b.Storage, address_space=b.address_space, linear_idx_type=b.linear_idx_type], ctx: DeviceContext)
TileTensor overload of multistage_gemm. Converts to LayoutTensor and dispatches to a GEMM kernel.
Parameters:
- βc_type (
DType): DType of the output tilecelements (inferred). - βa_type (
DType): DType of the input tileaelements (inferred). - βb_type (
DType): DType of the input tilebelements (inferred). - βtranspose_b (
Bool): Whetherbis accessed transposed, so its rowyis read asb[y, i]instead ofb[i, y]. - βconfig (
MatmulConfig[a_type, b_type, c_type, transpose_b]): Compile-timeMatmulConfigselecting the block tile, warp tile, MMA shape, and pipeline stages for the kernel. - βelementwise_lambda_fn (
Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None]): Optional epilogue applied to the accumulated value before it is stored toc(defaults toNone, which stores the raw accumulation).
Args:
- βc (
TileTensor[c_type, Storage=c.Storage, address_space=c.address_space, linear_idx_type=c.linear_idx_type]): Output tile of shape(M, N)receiving the matmul result. - βa (
TileTensor[a_type, Storage=a.Storage, address_space=a.address_space, linear_idx_type=a.linear_idx_type]): Input tile of shape(M, K). - βb (
TileTensor[b_type, Storage=b.Storage, address_space=b.address_space, linear_idx_type=b.linear_idx_type]): Input tile of shape(K, N), or(N, K)whentranspose_bis set. - βctx (
DeviceContext): Device context used to enqueue the kernel.
def multistage_gemm[c_type: DType, a_type: DType, b_type: DType, //, *, transpose_b: Bool, config: MatmulConfig[a_type, b_type, c_type, transpose_b], elementwise_lambda_fn: Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None] = None](c: TileTensor[c_type, Storage=c.Storage, address_space=c.address_space, linear_idx_type=c.linear_idx_type], a: TileTensor[a_type, Storage=a.Storage, address_space=a.address_space, linear_idx_type=a.linear_idx_type], b: TileTensor[b_type, Storage=b.Storage, address_space=b.address_space, linear_idx_type=b.linear_idx_type], runtime_config: MatmulConfig[a_type, b_type, c_type, transpose_b], ctx: DeviceContext)
TileTensor overload of multistage_gemm with runtime config. Constrains c to mut=True because split_k_reduce requires a mutable output tensor.
Parameters:
- βc_type (
DType): DType of the output tilecelements (inferred). - βa_type (
DType): DType of the input tileaelements (inferred). - βb_type (
DType): DType of the input tilebelements (inferred). - βtranspose_b (
Bool): Whetherbis accessed transposed, so its rowyis read asb[y, i]instead ofb[i, y]. - βconfig (
MatmulConfig[a_type, b_type, c_type, transpose_b]): Compile-timeMatmulConfigselecting the block tile, warp tile, MMA shape, and pipeline stages for the kernel. - βelementwise_lambda_fn (
Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None]): Optional epilogue applied to the accumulated value before it is stored toc(defaults toNone, which stores the raw accumulation).
Args:
- βc (
TileTensor[c_type, Storage=c.Storage, address_space=c.address_space, linear_idx_type=c.linear_idx_type]): Output tile of shape(M, N)receiving the matmul result; must be mutable becausesplit_k_reducewrites the reduced sum back into it. - βa (
TileTensor[a_type, Storage=a.Storage, address_space=a.address_space, linear_idx_type=a.linear_idx_type]): Input tile of shape(M, K). - βb (
TileTensor[b_type, Storage=b.Storage, address_space=b.address_space, linear_idx_type=b.linear_idx_type]): Input tile of shape(K, N), or(N, K)whentranspose_bis set. - βruntime_config (
MatmulConfig[a_type, b_type, c_type, transpose_b]): RuntimeMatmulConfigcarrying the number of K partitions used for the split-K reduction path; whennum_k_partitionsis greater than 1 the kernel writes partial sums to a workspace and reduces them intoc. - βctx (
DeviceContext): Device context used to enqueue the kernel and allocate the split-K workspace.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!