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
load_AB
def load_AB[a_type: DType, b_type: DType, a_tile_rank: Int, a_tile_shape: IndexList[a_tile_rank], a_desc_shape: IndexList[a_tile_rank], b_tile_rank: Int, b_tile_shape: IndexList[b_tile_rank], b_desc_shape: IndexList[b_tile_rank], a_dim0: Int, a_dim1: Int, a_num_tiles: Int, a_swizzle_bytes: Int, b_dim0: Int, b_dim1: Int, b_num_tiles: Int, b_swizzle_bytes: Int, num_pipeline_stages: Int, //, *, block_tile_shape: IndexList[Int(3)], mma_shape: IndexList[Int(3)], cta_group: Int = Int(1), a_plane_splits: IndexList[Int(2)] = Index[Int, Int](Int(0), Int(0))](expert_ids: Pointer[Int32, _safe=False], a_tma_op: TMATensorTile[a_type, a_tile_rank, a_tile_shape, a_desc_shape], b_tma_op: TMATensorTile[b_type, b_tile_rank, b_tile_shape, b_desc_shape], a_smem_tiles: SMemTileArray2D[a_type, a_dim0, a_dim1, a_num_tiles, a_swizzle_bytes], b_smem_tiles: SMemTileArray2D[b_type, b_dim0, b_dim1, b_num_tiles, b_swizzle_bytes], mma_mbar: Pointer[SharedMemBarrier, address_space=AddressSpace.SHARED, _safe=False], tma_mbar: Pointer[SharedMemBarrier, address_space=AddressSpace.SHARED, _safe=False], producer_phase: PipelineState[num_pipeline_stages], peer_cta_coord: Tuple[Int, Int, Int], work_tile_coord: Tuple[Int, Int], a_multicast_mask: UInt16, b_multicast_mask: UInt16, iter_idx: UInt32, elect_one_cta: Bool, scheduler: TileScheduler[static_MN=scheduler.static_MN, tile_shape=scheduler.tile_shape, cluster=scheduler.cluster, cta_group=scheduler.cta_group, swizzle=scheduler.swizzle, swapAB=scheduler.swapAB], qkv_plane_stride: Int = Int(0))
Loads A and B tiles from global memory into shared memory via TMA multicast.
Issues asynchronous multicast TMA loads for the current pipeline stage, addressing the expert-local slice of A and the shared B slice, then signals completion through the TMA mbarrier.
Parameters:
- βa_type (
DType): Element type of the A operand tiles (inferred). - βb_type (
DType): Element type of the B operand tiles (inferred). - βa_tile_rank (
Int): Rank of the A TMA tile descriptor (inferred). - βa_tile_shape (
IndexList[a_tile_rank]): Element shape of one A TMA tile (inferred). - βa_desc_shape (
IndexList[a_tile_rank]): Descriptor shape of the A TMA tile, used to compute per-load element counts and row stride (inferred). - βb_tile_rank (
Int): Rank of the B TMA tile descriptor (inferred). - βb_tile_shape (
IndexList[b_tile_rank]): Element shape of one B TMA tile (inferred). - βb_desc_shape (
IndexList[b_tile_rank]): Descriptor shape of the B TMA tile, used to compute per-load element counts and row stride (inferred). - βa_dim0 (
Int): Number of rows in one A shared-memory tile (inferred). - βa_dim1 (
Int): Number of columns in one A shared-memory tile (inferred). - βa_num_tiles (
Int): Number of pipeline stages in the A shared-memory tile array (inferred). - βa_swizzle_bytes (
Int): Swizzle granularity in bytes for A shared-memory tiles (inferred). - βb_dim0 (
Int): Number of rows in one B shared-memory tile (inferred). - βb_dim1 (
Int): Number of columns in one B shared-memory tile (inferred). - βb_num_tiles (
Int): Number of pipeline stages in the B shared-memory tile array (inferred). - βb_swizzle_bytes (
Int): Swizzle granularity in bytes for B shared-memory tiles (inferred). - βnum_pipeline_stages (
Int): Number of double-buffered pipeline stages for A and B shared-memory tiles (inferred). - βblock_tile_shape (
IndexList[Int(3)]): Block tile shape[BM, BN, BK]partitioning the GEMM into work tiles. - βmma_shape (
IndexList[Int(3)]): MMA instruction shape[MMA_M, MMA_N, MMA_K]. - βcta_group (
Int): Number of CTAs cooperating per MMA along the M dimension (defaults to 1). - βa_plane_splits (
IndexList[Int(2)]): Per-plane split sizes for fused LoRA QKV A-plane row offsetting;(0, 0)disables it (defaults to(0, 0)).
Args:
- βexpert_ids (
Pointer[Int32, _safe=False]): Pointer to the per-group expert id array; used to offset the A global-memory slice by the expert's local M base. - βa_tma_op (
TMATensorTile[a_type, a_tile_rank, a_tile_shape, a_desc_shape]): TMA tile descriptor for loading A tiles from global to shared memory. - βb_tma_op (
TMATensorTile[b_type, b_tile_rank, b_tile_shape, b_desc_shape]): TMA tile descriptor for loading B tiles from global to shared memory. - βa_smem_tiles (
SMemTileArray2D[a_type, a_dim0, a_dim1, a_num_tiles, a_swizzle_bytes]): Shared-memory tile array of staged A tiles, one per pipeline stage. - βb_smem_tiles (
SMemTileArray2D[b_type, b_dim0, b_dim1, b_num_tiles, b_swizzle_bytes]): Shared-memory tile array of staged B tiles, one per pipeline stage. - βmma_mbar (
Pointer[SharedMemBarrier, address_space=AddressSpace.SHARED, _safe=False]): Pointer to the MMA mbarrier array, one per pipeline stage, waited on to confirm the consumer has freed the prior stage's shared memory. - βtma_mbar (
Pointer[SharedMemBarrier, address_space=AddressSpace.SHARED, _safe=False]): Pointer to the TMA mbarrier array, one per pipeline stage, signaled when the TMA load for a stage is complete. - βproducer_phase (
PipelineState[num_pipeline_stages]): Producer pipeline state tracking the stage index and phase bit. - βpeer_cta_coord (
Tuple[Int, Int, Int]):(peer_id, mma_coord_m, mma_coord_n)tuple giving the peer CTA's coordinates within the cluster. - βwork_tile_coord (
Tuple[Int, Int]):(m, n)element coordinates of the current work tile returned by the scheduler. - βa_multicast_mask (
UInt16): Bitmask of CTAs participating in the A TMA multicast load. - βb_multicast_mask (
UInt16): Bitmask of CTAs participating in the B TMA multicast load. - βiter_idx (
UInt32): Current K-dimension iteration index within the work tile. - βelect_one_cta (
Bool): Whether this CTA is the elected leader that sets the expected bytes on the TMA mbarrier. - βscheduler (
TileScheduler[static_MN=scheduler.static_MN, tile_shape=scheduler.tile_shape, cluster=scheduler.cluster, cta_group=scheduler.cta_group, swizzle=scheduler.swizzle, swapAB=scheduler.swapAB]): Tile scheduler providing the current group index and static M/N bounds. - βqkv_plane_stride (
Int): Row stride between fused QKV planes used to compute the A-plane row offset (defaults to 0).
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!