IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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 module

pipeline_storage

Unified Pipeline Storage Framework for SM100 Structured Kernels.

This module provides a single-source-of-truth framework for pipeline storage, where stage count determines barrier count, and tile storage type determines the SMEM layout for input tiles.

All tile storage uses TileTensor natively. Conversion to LayoutTensor only happens at external API boundaries (TMA, MMA) using the {ptr} syntax or explicit LayoutTensor construction.

Design Principles​

  1. Single Source of Truth: Stage count parameterizes barrier count
  2. Single Source of Truth: Tile storage types define array types once
  3. TileTensor Native: All SMEM tiles use TileTensor
  4. Composable: SMEM structs compose storage objects
  5. Extensible: Easy to add new storage types
  6. Escape Hatch: Raw storage access when framework doesn't fit

Architecture​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Tile Storage (defines tile arrays and storage)                     β”‚
β”‚                                                                     β”‚
β”‚  StandardTileStorage[a_type, b_type, a_shape, b_shape, ...]        β”‚
β”‚      β”œβ”€β”€ ATileArray = SMemTileArray2D[...]  # TileTensor-based     β”‚
β”‚      β”œβ”€β”€ BTileArray = SMemTileArray2D[...]  # TileTensor-based     β”‚
β”‚      β”œβ”€β”€ var a_tiles_storage                                        β”‚
β”‚      β”œβ”€β”€ var b_tiles_storage                                        β”‚
β”‚      └── def a_tiles(), b_tiles()  # Returns TileTensor             β”‚
β”‚                                                                     β”‚
β”‚  BlockScaledTileStorage[..., sfa_type, sfb_type, dims, ...]        β”‚
β”‚  BlockwiseFP8TileStorage[..., a_scales_type, dims, ...]            β”‚
β”‚  OutputTileStorage[c_type, c_layout, num_stages]                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Pipeline Storage (defines barriers)                                β”‚
β”‚                                                                     β”‚
β”‚  InputPipelineStorage[num_stages, Payload]                         β”‚
β”‚      └── var barriers: BarrierPair[num_stages]                     β”‚
β”‚                                                                     β”‚
β”‚  OutputPipelineStorage[num_stages]                                 β”‚
β”‚  ClcPipelineStorage[num_stages]                                    β”‚
β”‚  TmemDeallocStorage                                                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  SMEM composes both:                                                β”‚
β”‚                                                                     β”‚
β”‚  struct MySmem:                                                     β”‚
β”‚      var tiles: StandardTileStorage[...]      # Tile storage       β”‚
β”‚      var output_tiles: OutputTileStorage[...] # Output tiles       β”‚
β”‚      var input_pipeline: InputPipelineStorage[...]  # Barriers     β”‚
β”‚      var output_pipeline: OutputPipelineStorage[...]                β”‚
β”‚      var clc_pipeline: ClcPipelineStorage[...]                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Example Usage​

struct MyKernelSmem[config: MyConfig]:
    # Tile storage (single source of truth for tile types)
    comptime Tiles = StandardTileStorage[
        config.a_type, config.b_type,
        IndexList[2](config.BM, config.BK),  # A tile shape
        IndexList[2](config.BN, config.BK),  # B tile shape
        config.num_pipeline_stages,
    ]
    var tiles: Self.Tiles

    # Output tile storage (separate stage count)
    comptime OutputTiles = OutputTileStorage[
        config.c_type, config.c_layout, config.num_output_stages
    ]
    var output_tiles: Self.OutputTiles

    # Pipeline storage (barriers)
    var input_pipeline: InputPipelineStorage[...]
    var output_pipeline: OutputPipelineStorage[...]

    # Accessors delegate to composed storage
    def a_tiles(ref[SHARED] self) -> Self.Tiles.ATileArray:
        return self.tiles.a_tiles()  # Returns TileTensor

    def c_tiles(ref[SHARED] self) -> Self.OutputTiles.CTileArray:
        return self.output_tiles.c_tiles()

Extensibility​

To add a new tile storage type:

  1. Create a new struct with comptime type aliases and storage fields
  2. Add accessors that construct tile arrays from storage
  3. Use in SMEM via composition

Escape Hatch​

When the framework doesn't fit:

  1. Use raw SMemArray for custom tile layouts
  2. Use RawBarrierStorage for non-standard barrier patterns
  3. Add custom storage fields to SMEM struct

comptime values​

MbarPtr​

comptime MbarPtr = UnsafePointer[SharedMemBarrier, MutAnyOrigin, address_space=AddressSpace.SHARED]

Structs​