Skip to main content
Enigma’s layout algebra is inspired by NVIDIA’s CuTe library. A Layout is a (shape, stride) pair that maps multi-dimensional logical coordinates to linear memory offsets. Composing and dividing layouts is how you express tiling, thread-value partitioning, and vectorized access patterns.

The Layout type

A layout with shape=(4, 8) and stride=(1, 4) maps coordinate (r, c) to offset r*1 + c*4.

Total size

Creating layouts

Transforming layouts

coalesce

Merges adjacent modes with compatible strides into a single flat mode. Use after composition to simplify the layout.

complement

Returns the layout that covers the elements not covered by the input layout, within a given total size.

logical_divide and zipped_divide

Split a layout into a (tile, rest) pair. zipped_divide applies the division per mode and returns a layout whose first mode is the tile and second mode is the rest.

composition

Compose two layouts: composition(a, b) treats b as a re-indexing of a.

blocked_product

Compute the blocked outer product of two layouts:

recast_layout

Rescale a layout for a different element bit width. For example, viewing a float32 layout as a float16 layout:

Thread-value layout

make_layout_tv is the central tiling primitive. It takes a thread layout and a value layout and returns:
  1. A tiler describing the tile shape at each level
  2. A TV layout mapping (thread_id, value_id) → tile coordinate

Using TV layouts in @enigma.jit

Tensor operations

Tiling workflow summary

  1. Define thread and value layouts with make_ordered_layout
  2. Call make_layout_tv to get tiler and TV layout
  3. In @enigma.jit, use tensor_zipped_divide to partition the global tensor
  4. Slice per-block with blk = gtensor[((None, None), block_idx)]
  5. Compose with TV layout to get per-thread fragment
  6. Use .load() and .store() on the fragment

Debugging layouts

When a tiling produces unexpected output, print shape and stride at each step:
Invariant: If any tiler dimension exceeds the tensor dimension, Enigma raises an EnigmaError rather than silently producing an invalid layout.