tilelang.cuda.language.gemm_opΒΆ
CUDA dialect of the GEMM operators.
Shadows the common gemm / gemm_blockscaled / gemm_sp with
CUDA-specific parameters and hosts the explicit, instruction-pinned CUDA
variants (wgmma_gemm, tcgen05_gemm, tcgen05_gemm_blockscaled,
mma_gemm_blockscaled) that have no target-neutral meaning.
FunctionsΒΆ
|
TileLang GEMM operator for CUDA. |
|
Block-scaled GEMM for CUDA: |
|
Sparse GEMM (2:4 structured sparsity) for CUDA. |
|
Explicit Hopper WGMMA GEMM without an implicit wait. |
|
Explicit Blackwell TCGEN05 GEMM without an implicit wait. |
|
Explicit Blackwell TCGEN05 block-scaled GEMM without an implicit wait. |
|
Explicit SM120 warp-level block-scaled MMA GEMM. |
|
Build the TMEM store layout for the C accumulator of a block-scaled GEMM. |
Module ContentsΒΆ
- tilelang.cuda.language.gemm_op.gemm(A, B, C, transpose_A=False, transpose_B=False, policy=GemmWarpPolicy.Square, clear_accum=False, mbar=None, annotations=None)ΒΆ
TileLang GEMM operator for CUDA.
Same semantics as the common
tilelang.language.gemm_op.gemm(): the default synchronous GEMM. On Hopper, if the compiler selects WGMMA lowering, TileLang inserts the corresponding wait implicitly. On Blackwell TCGEN5MMA, TileLang inserts the correspondingmbarrier_wait_parity(...)implicitly after issue.For manual asynchronous scheduling, use
T.wgmma_gemm(...)withT.wait_wgmma(...)on Hopper, orT.tcgen05_gemm(...)withT.mbarrier_wait_parity(...)on Blackwell.- Parameters:
A (BufferLikeType, i.e. Buffer | BufferLoad | BufferRegion, or Var) β Input buffer A.
B (BufferLikeType) β Input buffer B.
C (BufferLikeType) β Output buffer C.
transpose_A (bool) β Whether to transpose A. Defaults to False.
transpose_B (bool) β Whether to transpose B. Defaults to False.
policy (GemmWarpPolicy) β GEMM warp partition policy.
clear_accum (bool) β Whether to clear the accumulator.
mbar (BarrierType, i.e. Buffer | BufferLoad, or Var, optional) β Mbarrier in Blackwell. Required when this GEMM lowers to TCGEN5MMA. Defaults to None.
annotations (Optional[dict]) β Additional annotations.
- Returns:
A handle to the GEMM operation.
- Return type:
tirx.Call
- tilelang.cuda.language.gemm_op.gemm_blockscaled(A, B, C, SFA, SFB, transpose_A=False, transpose_B=False, policy=GemmWarpPolicy.Square, clear_accum=False, *, k_start, sf_a_granularity_k, sf_b_granularity_k, mbar=None, use_2cta=False, sf_layout=None, annotations=None)ΒΆ
Block-scaled GEMM for CUDA:
C (+)= (A * SFA) @ (B * SFB).Extends
tilelang.language.gemm_op.gemm_blockscaled()with CUDA completion and scale-layout parameters. LikeT.gemm, this is the synchronous interface. The compiler selects the block-scaled instruction from the target and operand scopes:Blackwell SM100,
Cin tensor memory: TCGEN05kind::mxf8f6f4.block_scale. A/B are FP8/FP6/FP4 in shared memory, and SFA/SFB are E8M0 scale factors already in tensor memory.mbaris required: the MMA posts completion to it and TileLang inserts the matchingmbarrier_wait_parityimplicitly after issue, so the barrier must flip once per call.use_2cta=Truerequestscta_group::2and requirescluster_dimsof(2,1,1)or(1,2,1).SM120,
Cin a fragment: synchronousmma.sync.m16n8k64.kind::mxf4nvf4.block_scalewith E2M1 operands, UE4M3 scale factors and FP32 accumulation. A/B and packed scale words reside in shared memory.sf_layoutdescribes the scale words; this path ignoresmbar.
Unsupported combinations fail compilation instead of dropping scales. Use
T.tcgen05_gemm_blockscaledfor explicit asynchronous TCGEN05 scheduling without the implicit wait, orT.mma_gemm_blockscaledto pin the warp-level path.- Parameters:
A (tilelang._typing.BufferLikeType) β Left operand tile in shared memory.
B (tilelang._typing.BufferLikeType) β Right operand tile in shared memory.
C (tilelang._typing.BufferLikeType) β Accumulator in tensor memory on SM100 or a fragment on SM120.
SFA (tilelang._typing.BufferLikeType) β Scale factors for A.
SFB (tilelang._typing.BufferLikeType) β Scale factors for B.
transpose_A (bool) β Whether to transpose A. Defaults to False.
transpose_B (bool) β Whether to transpose B. Defaults to False.
policy (tilelang.language.gemm_op.GemmWarpPolicy) β Warp partition policy for the warp-level path.
clear_accum (bool) β Whether to zero the accumulator before accumulating.
k_start (int | tvm.tirx.PrimExpr) β Logical K-axis start offset of this tile.
sf_a_granularity_k (int) β K elements covered by one A scale factor.
sf_b_granularity_k (int) β K elements covered by one B scale factor.
mbar (tilelang.language.gemm_op.BarrierType | None) β Completion barrier, required by TCGEN05; waited on implicitly.
use_2cta (bool) β Request the 2CTA TCGEN05 variant.
sf_layout (str | None) β SM120 scale layout,
"rowmajor"or"blockscaled_chunk_kmajor".annotations (dict | None) β Additional annotations.
- Return type:
tvm.tirx.PrimExpr
- tilelang.cuda.language.gemm_op.gemm_sp(A_sparse, E, B, C, transpose_A=False, transpose_E=False, transpose_B=False, policy=GemmWarpPolicy.Square, clear_accum=False, wg_wait=0, annotations=None)ΒΆ
Sparse GEMM (2:4 structured sparsity) for CUDA.
Same semantics as the common
tilelang.language.experimental.gemm_sp_op.gemm_sp().wg_waitis the Hopper warpgroup wait count consumed when the WGMMA SP lowering is selected (-1defers the wait to an explicitT.wait_wgmma); it rides in the tile-op annotations.- Parameters:
A_sparse (tilelang._typing.BufferLikeType | tvm.tirx.Var) β Compressed sparse matrix containing only non-zero elements.
E (tilelang._typing.BufferLikeType | tvm.tirx.Var) β Metadata tensor encoding the sparsity pattern of A.
B (tilelang._typing.BufferLikeType | tvm.tirx.Var) β Dense input matrix.
C (tilelang._typing.BufferLikeType | tvm.tirx.Var) β Output accumulator matrix.
transpose_A (bool) β Whether to transpose A. Defaults to False.
transpose_E (bool) β Whether to transpose E. Defaults to False.
transpose_B (bool) β Whether to transpose B. Defaults to False.
policy (tilelang.language.gemm_op.GemmWarpPolicy) β Warp partition policy. Defaults to GemmWarpPolicy.Square.
clear_accum (bool) β Whether to zero the accumulator before computation. Defaults to False.
wg_wait (int) β Warp group wait count. Defaults to 0.
annotations (dict | None) β Additional annotations; values in it take precedence.
- Returns:
A handle to the sparse GEMM operation.
- Return type:
tirx.Call
- tilelang.cuda.language.gemm_op.wgmma_gemm(A, B, C, transpose_A=False, transpose_B=False, policy=GemmWarpPolicy.Square, clear_accum=False, annotations=None)ΒΆ
Explicit Hopper WGMMA GEMM without an implicit wait.
This is the explicit asynchronous Hopper WGMMA counterpart to the default synchronous T.gemm(β¦) interface, with two stricter guarantees: - it always requests the WGMMA lowering path - it never auto-emits an inlined warpgroup_wait
If the current target or operand pattern cannot use Hopper WGMMA, compilation fails instead of silently falling back to MMA.
- tilelang.cuda.language.gemm_op.tcgen05_gemm(A, B, C, transpose_A=False, transpose_B=False, policy=GemmWarpPolicy.Square, clear_accum=False, *, mbar, use_2cta=False, annotations=None)ΒΆ
Explicit Blackwell TCGEN05 GEMM without an implicit wait.
This is the explicit asynchronous Blackwell TCGEN5MMA counterpart to the default synchronous T.gemm(β¦) interface, with two stricter guarantees: - it always requests the TCGEN5MMA lowering path - it never auto-emits an inlined mbarrier_wait_parity
mbar=Noneomits the completion arrival for an intermediate issue. A later TCGEN05 operation remains ordered in the same issue stream and may publish the completion event for the whole sequence.When
use_2cta=True, the instruction is lowered to the 2CTA variant which requirescluster_dimsto be(2,1,1)or(1,2,1).If the current target or operand pattern cannot use Blackwell TCGEN5MMA, compilation fails instead of silently falling back to another GEMM path.
- Parameters:
A (tilelang._typing.BufferLikeType)
B (tilelang._typing.BufferLikeType)
C (tilelang._typing.BufferLikeType)
transpose_A (bool)
transpose_B (bool)
policy (tilelang.language.gemm_op.GemmWarpPolicy)
clear_accum (bool)
mbar (tilelang.language.gemm_op.BarrierType | None)
use_2cta (bool)
annotations (dict | None)
- Return type:
tvm.tirx.PrimExpr
- tilelang.cuda.language.gemm_op.tcgen05_gemm_blockscaled(A, B, C, SFA_tmem, SFB_tmem, transpose_A=False, transpose_B=False, clear_accum=False, wg_wait=0, mbar=None, *, k_start, sf_a_granularity_k, sf_b_granularity_k, use_2cta=False)ΒΆ
Explicit Blackwell TCGEN05 block-scaled GEMM without an implicit wait.
This is the explicit counterpart of T.gemm_blockscaled(β¦) for Blackwell TCGEN5MMA, with the same guarantees as T.tcgen05_gemm(β¦): it always requests the TCGEN5MMA lowering path and compilation fails instead of silently falling back if that path is unavailable. It never auto-emits an inlined mbarrier_wait_parity.
mbar=Noneomits the completion arrival for this issue. The caller must publish completion with a later TCGEN05 operation or an explicitT.tcgen05_mma_arrivebefore waiting and consuming the result.With
use_2cta=True, this lowers to the true 2CTA block-scaled TCGEN05 path only; there is no fallback or emulation. That mode requirescluster_dimsto be(2,1,1)or(1,2,1).A and B are FP8/FP6/FP4 mxf8f6f4 operands in shared memory, C is the accumulator in tensor memory, and SFA/SFB are E8M0 scale factors already resident in tensor memory. The API is explicit-async: it issues the MMA and leaves synchronization to the user schedule.
k_startis the logical K-axis start offset for this MMA tile.sf_a_granularity_kandsf_b_granularity_kdescribe how many K elements one packed scale factor covers. The compiler derives the PTX scale-factor A/B IDs for each internal K32 MMA atom from these values.- Parameters:
A (tilelang._typing.BufferLikeType) β FP8/FP6/FP4 input buffer A in shared memory.
B (tilelang._typing.BufferLikeType) β FP8/FP6/FP4 input buffer B in shared memory.
C (tilelang._typing.BufferLikeType) β Accumulator in tensor memory.
SFA_tmem (tilelang._typing.BufferLikeType) β Scale factors for A in tensor memory.
SFB_tmem (tilelang._typing.BufferLikeType) β Scale factors for B in tensor memory.
transpose_A (bool) β Whether A is MN-major. Default: False (K-major).
transpose_B (bool) β Whether B is K-major. Default: False (MN-major).
clear_accum (bool) β Whether to zero the accumulator.
wg_wait (int) β Warp group wait identifier.
mbar (tilelang.language.gemm_op.BarrierType | None) β Completion barrier, or None to defer the completion arrival.
k_start (int | tvm.tirx.PrimExpr) β Logical K-axis start offset for this MMA tile.
sf_a_granularity_k (int) β K elements covered by one A scale factor.
sf_b_granularity_k (int) β K elements covered by one B scale factor.
use_2cta (bool) β Whether to request true
cta_group::2lowering.
- Return type:
tvm.tirx.PrimExpr
- tilelang.cuda.language.gemm_op.mma_gemm_blockscaled(A, B, C, SFA, SFB, transpose_A=False, transpose_B=False, policy=GemmWarpPolicy.Square, clear_accum=False, *, k_start, sf_a_granularity_k, sf_b_granularity_k, sf_layout=None)ΒΆ
Explicit SM120 warp-level block-scaled MMA GEMM.
This is the explicit counterpart of T.gemm_blockscaled(β¦) for the SM120 warp-level path and follows the same scale-factor model: users pass the scale tensors, logical
k_start, and K granularity, while the lowering derives the low-level scale addressing. Unlike TCGEN05, this path is synchronous warp-levelmma.syncand does not use tensor memory or mbarriers, soCmust be a fragment.The current supported instruction is SM120 NVF4:
m16n8k64.kind::mxf4nvf4.block_scale.scale_vec::4Xwith E2M1 operands, FP32 accumulation, and UE4M3 scale factors.- Parameters:
A (tilelang._typing.BufferLikeType)
B (tilelang._typing.BufferLikeType)
C (tilelang._typing.BufferLikeType)
SFA (tilelang._typing.BufferLikeType)
SFB (tilelang._typing.BufferLikeType)
transpose_A (bool)
transpose_B (bool)
policy (tilelang.language.gemm_op.GemmWarpPolicy)
clear_accum (bool)
k_start (int | tvm.tirx.PrimExpr)
sf_a_granularity_k (int)
sf_b_granularity_k (int)
sf_layout (str | None)
- Return type:
tvm.tirx.PrimExpr
- tilelang.cuda.language.gemm_op.make_blockscaled_gemm_layout(C, A, transpose_A=False)ΒΆ
Build the TMEM store layout for the C accumulator of a block-scaled GEMM.
Users must call
T.annotate_layout({C_tmem: layout})with the returned layout so that subsequentT.copy(C_tmem, ...)can be lowered correctly.- Parameters:
C (tilelang._typing.BufferLikeType) β The TMEM accumulator buffer (block_M, block_N).
A (tilelang._typing.BufferLikeType) β The FP8 operand A buffer (used to infer K and dtype).
transpose_A (bool) β Whether A is MN-major.
- Returns:
A Layout object for Cβs TMEM storage.
- Return type:
tilelang.layout.Layout