Skip to main content

Mojo function

blocked_product

blocked_product[BlockLayoutType: TensorLayout, TilerLayoutType: TensorLayout, //](block: BlockLayoutType, tiler: TilerLayoutType) -> Layout[*?, *?]

Creates a blocked layout by combining a block and tiler layout.

This function creates a hierarchical blocked layout where each element of the tiler layout is replaced by a block. This is useful for creating tiled layouts for efficient cache utilization.

Example:

from layout.tile_layout import row_major, blocked_product

# Create a 2x2 block layout
var block = row_major[2, 2]()
# Create a 2x3 tiler (2 rows, 3 cols of blocks)
var tiler = row_major[2, 3]()
# Create blocked layout
var blocked = blocked_product(block, tiler)
# Result: shape ((2,2), (2,3)), stride ((2,12), (1,4))

Parameters:

  • BlockLayoutType (TensorLayout): The type of the block layout.
  • TilerLayoutType (TensorLayout): The type of the tiler layout.

Args:

  • block (BlockLayoutType): The inner layout defining the structure of each tile.
  • tiler (TilerLayoutType): The outer layout defining the arrangement of tiles.

Returns:

Layout: A new layout representing the blocked structure.

blocked_product[BlockLayoutType: TensorLayout, TilerLayoutType: TensorLayout, //, *, coalesce_output: Bool](block: BlockLayoutType, tiler: TilerLayoutType) -> Layout[*?, *?]

Creates a blocked layout with optional output coalescing.

This overload accepts a coalesce_output keyword parameter. When True, contiguous inner/outer dimension pairs are merged into flat dimensions, reducing the layout rank where possible.

Example:

from layout.tile_layout import row_major, blocked_product

var block = row_major[4]()
var tiler = row_major[3]()
# Coalesced: shape (12,), stride (1,) instead of ((4,), (3,))
var coalesced = blocked_product[coalesce_output=True](block, tiler)

Parameters:

  • BlockLayoutType (TensorLayout): The type of the block layout.
  • TilerLayoutType (TensorLayout): The type of the tiler layout.
  • coalesce_output (Bool): When True, merge contiguous inner/outer pairs.

Args:

  • block (BlockLayoutType): The inner layout defining the structure of each tile.
  • tiler (TilerLayoutType): The outer layout defining the arrangement of tiles.

Returns:

Layout: A new layout representing the blocked structure, coalesced if requested.

Was this page helpful?