IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Mojo function

tile_alignment

def tile_alignment[dtype: DType, ws: Int, target: StringSpan[ImmStaticOrigin]]() -> Int

Alignment, in elements, a row-wise body's store β€” or its input_fn's load β€” may assume for a width-ws tile of dtype on target.

The unit is elements, not bytes: every caller forwards this value into the element_alignment parameter of a tensor load/store, which multiplies it by align_of[dtype]() to get the byte alignment it promises the backend. Returning a byte count here therefore squares the intended alignment, and an alignment the address does not keep is a fault rather than a missed optimization β€” a float64 tile promised 64 bytes loads through vmovapd.

Single source of truth for the rule. 1 on CPU (element-natural: the CPU tiers walk a row at the tensor's own stride, and an input tensor may be an imported buffer, so neither a tile base nor the step between tiles is guaranteed SIMD-aligned). ws on GPU (SIMD-natural β€” ws * align_of[dtype]() bytes: folds the access into one vector transaction (LDG.128/STG.128), safe because a body only ever gets a ws > 1 tile on a SIMD-aligned offset (block tier requires row_size % simd == 0; the warp tier matches via the same guard, else falls through to the block tier)). The two coincide at ws == 1.

Both Context.element_alignment (the store) and the public-op wrappers' synthesized input_fn (the load) call this, so the rule lives in one place.

Parameters:

  • ​dtype (DType): The tile's element dtype.
  • ​ws (Int): The tile's SIMD width.
  • ​target (StringSpan[ImmStaticOrigin]): "cpu" or "gpu".

Returns:

Int: The alignment in elements.