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
shape=(4, 8) and stride=(1, 4) maps coordinate (r, c) to offset r*1 + c*4.
Total size
Creating layouts
| Function | Description |
|---|---|
enigma.Layout(shape, stride) | Explicit shape and stride |
enigma.make_layout(shape, stride=None) | Alias; omit stride for row-major default |
enigma.make_ordered_layout(shape, order) | Custom dimension ordering |
enigma.make_identity_layout(shape) | Column-major (order = (0, 1, ...)) |
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:
- A tiler describing the tile shape at each level
- A TV layout mapping
(thread_id, value_id)→ tile coordinate
Using TV layouts in @enigma.jit
Tensor operations
| Function | Description |
|---|---|
enigma.tensor_zipped_divide(tensor, tiler) | Partition tensor into tiles |
enigma.tensor_composition(tensor, tv, tiler) | Map thread-value indices to tensor |
tensor.load() | Vectorized load of a thread fragment |
tensor.store(value) | Vectorized store |
Tiling workflow summary
- Define thread and value layouts with
make_ordered_layout - Call
make_layout_tvto get tiler and TV layout - In
@enigma.jit, usetensor_zipped_divideto partition the global tensor - Slice per-block with
blk = gtensor[((None, None), block_idx)] - Compose with TV layout to get per-thread fragment
- Use
.load()and.store()on the fragment
Debugging layouts
When a tiling produces unexpected output, print shape and stride at each step:EnigmaError rather than silently producing an invalid layout.