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
BlockwiseFP8TileWriter
struct BlockwiseFP8TileWriter[c_type: DType, c_smem_dim0: Int, c_smem_dim1: Int, accum_type: DType, accum_num_stages: Int, accum_num_elements: Int, /, *, block_tile_shape: IndexList[Int(3)], mma_shape: IndexList[Int(3)], is_lower_frag_required: Bool, cta_group: Int, num_output_stages: Int, num_output_warps: Int, c_swizzle: TensorMapSwizzle]
Write register accumulators to GMEM via SMEM and TMA.
Parametersβ
- βc_type (
DType): Element type of the C output tensor. - βc_smem_dim0 (
Int): M dimension of the C shared-memory tile. - βc_smem_dim1 (
Int): N dimension of the C shared-memory tile. - βaccum_type (
DType): Element type of the accumulator registers. - βaccum_num_stages (
Int): Number of accumulator pipeline stages to drain. - βaccum_num_elements (
Int): Number of elements per accumulator fragment set. - βblock_tile_shape (
IndexList[Int(3)]): Block tile shape as (BM, BN, BK). - βmma_shape (
IndexList[Int(3)]): MMA instruction shape as (MMA_M, MMA_N, MMA_K). - βis_lower_frag_required (
Bool): Whether the lower register fragment is populated. - βcta_group (
Int): Number of CTAs cooperating per output tile. - βnum_output_stages (
Int): Number of SMEM buffer stages for the output epilogue. - βnum_output_warps (
Int): Number of warps participating in the output epilogue. - βc_swizzle (
TensorMapSwizzle): TMA swizzle pattern applied to the C shared-memory tile.
Implemented traitsβ
comptime membersβ
bitsβ
comptime bits = 256
BMβ
comptime BM = block_tile_shape[Int(0)]
BNβ
comptime BN = block_tile_shape[Int(1)]
c_smem_layoutβ
comptime c_smem_layout = row_major[c_smem_dim0, c_smem_dim1]()
CTileArrayβ
comptime CTileArray = SMemTileArray2DRowMajor[c_type, c_smem_dim0, c_smem_dim1, num_output_stages]
data_pathsβ
comptime data_paths = 16
epcβ
comptime epc = EpilogueConfig.create(MMA_M=mma_shape[Int(0)], MMA_N=mma_shape[Int(1)], stageN=Int((mul (accum_num_elements // (Int(128) // _resolve_warp_size())), 8)), cta_group=cta_group, transpose_c=False, BM=block_tile_shape[Int(0)], BN=block_tile_shape[Int(1)])
fragment_sizeβ
comptime fragment_size = (Int(128) // _resolve_warp_size())
fragments_per_stageβ
comptime fragments_per_stage = ((Int(128) // _resolve_warp_size()) * (accum_num_elements // (Int(128) // _resolve_warp_size())))
MMA_Mβ
comptime MMA_M = mma_shape[Int(0)]
MMA_Nβ
comptime MMA_N = mma_shape[Int(1)]
num_elementsβ
comptime num_elements = accum_num_elements
num_elements_per_loadβ
comptime num_elements_per_load = 8
num_stagesβ
comptime num_stages = accum_num_stages
repeatsβ
comptime repeats = (BlockwiseFP8TileWriter[c_type, c_smem_dim0, c_smem_dim1, accum_type, accum_num_stages, accum_num_elements, block_tile_shape=block_tile_shape, mma_shape=mma_shape, is_lower_frag_required=is_lower_frag_required, cta_group=cta_group, num_output_stages=num_output_stages, num_output_warps=num_output_warps, c_swizzle=c_swizzle].num_elements // (Int(128) // _resolve_warp_size()))
SMEMWriterβ
comptime SMEMWriter = TMEMToSMemWriter[c_type, accum_type, c_smem_dim0, c_smem_dim1, BlockwiseFP8TileWriter[c_type, c_smem_dim0, c_smem_dim1, accum_type, accum_num_stages, accum_num_elements, block_tile_shape=block_tile_shape, mma_shape=mma_shape, is_lower_frag_required=is_lower_frag_required, cta_group=cta_group, num_output_stages=num_output_stages, num_output_warps=num_output_warps, c_swizzle=c_swizzle].epc, num_output_warps, c_swizzle]
stageNβ
comptime stageN = ((accum_num_elements // (Int(128) // _resolve_warp_size())) * Int(8))
Methodsβ
writeβ
static def write[c_rank: Int, c_tile_shape: IndexList[c_rank], c_desc_shape: IndexList[c_rank], cluster_size: Int](accum: BlockwiseFP8Accumulator[accum_type, accum_num_stages, accum_num_elements, is_lower_frag_required, block_tile_shape, mma_shape, cluster_size], c_tiles: SMemTileArray2DRowMajor[c_type, c_smem_dim0, c_smem_dim1, num_output_stages], c_tma_op: TMATensorTile[c_type, c_rank, c_tile_shape, c_desc_shape], c_coord: Tuple[Int, Int])
Write accumulated register tiles to GMEM via double-buffered SMEM.
Parameters:
- βc_rank (
Int): Rank of the C output tensor. - βc_tile_shape (
IndexList[c_rank]): Tile shape of the C output tensor. - βc_desc_shape (
IndexList[c_rank]): Descriptor shape of the C output tensor. - βcluster_size (
Int): Size of the threadblock cluster for the matmul.
Args:
- βaccum (
BlockwiseFP8Accumulator[accum_type, accum_num_stages, accum_num_elements, is_lower_frag_required, block_tile_shape, mma_shape, cluster_size]): Blockwise FP8 accumulator holding upper and lower register tiles. - βc_tiles (
SMemTileArray2DRowMajor[c_type, c_smem_dim0, c_smem_dim1, num_output_stages]): Double-buffered SMEM tile array for C output. - βc_tma_op (
TMATensorTile[c_type, c_rank, c_tile_shape, c_desc_shape]): TMA tensor tile descriptor for the C store. - βc_coord (
Tuple[Int, Int]): (M, N) tile coordinate of this C tile in the output tensor.
write_absolute_with_bounds_checkβ
static def write_absolute_with_bounds_check[c_tensor_layout: TensorLayout, cluster_size: Int](accum: BlockwiseFP8Accumulator[accum_type, accum_num_stages, accum_num_elements, is_lower_frag_required, block_tile_shape, mma_shape, cluster_size], c_tiles: SMemTileArray2DRowMajor[c_type, c_smem_dim0, c_smem_dim1, num_output_stages], m_abs: UInt32, n_abs: UInt32, m_end: UInt32, expert_scale: Float32, c_tensor: TileTensor[c_type, c_tensor_layout, MutAnyOrigin])
Write accumulated register tiles to GMEM with bounds checking.
Parameters:
- βc_tensor_layout (
TensorLayout): Layout of the C output tensor in GMEM used for bounds-checked element stores. - βcluster_size (
Int): Number of CTAs in the threadblock cluster for the matmul.
Args:
- βaccum (
BlockwiseFP8Accumulator[accum_type, accum_num_stages, accum_num_elements, is_lower_frag_required, block_tile_shape, mma_shape, cluster_size]): Blockwise FP8 accumulator with upper/lower register tiles. - βc_tiles (
SMemTileArray2DRowMajor[c_type, c_smem_dim0, c_smem_dim1, num_output_stages]): SMEM tile array for C output. - βm_abs (
UInt32): Absolute M coordinate (start of tile in token space). - βn_abs (
UInt32): Absolute N coordinate (start of tile). - βm_end (
UInt32): End offset for bounds checking (exclusive). - βexpert_scale (
Float32): Per-expert output scaling factor. - βc_tensor (
TileTensor[c_type, c_tensor_layout, MutAnyOrigin]): C tensor in GMEM (TileTensor for bounds-checked stores).
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!