Skip to main content
All layout functions operate on enigma.Layout objects. Layouts are (shape, stride) pairs that map multi-dimensional coordinates to linear memory offsets. See Layout Algebra for a conceptual introduction.

Layout type


Creating layouts

enigma.Layout(shape, stride)

Explicit constructor:

enigma.make_layout(shape, stride=None)

Alias for Layout. If stride is omitted, defaults to row-major:

enigma.make_ordered_layout(shape, order)

Creates a layout with strides determined by dimension ordering. order[0] is the fastest-varying dimension:

enigma.make_identity_layout(shape)

Column-major layout (mode 0 varies fastest):

Querying layouts

enigma.size(layout, mode=None)

Total number of logical elements:

Transforming layouts

enigma.coalesce(layout)

Merges adjacent modes with compatible strides into a single flat mode:

enigma.complement(layout, size=None)

Returns the layout covering the elements not covered by layout within size total elements:

enigma.composition(a, b)

Compose a and b: treats b as a re-indexing of a:

enigma.logical_divide(layout, tiler)

Divide a layout into (tile, rest). Returns a layout where mode 0 is the tile and mode 1 is the outer count:

enigma.zipped_divide(layout, tiler)

Like logical_divide but applies division per mode and zips the result:

enigma.blocked_product(a, b)

Compute the blocked outer product of two layouts:

enigma.recast_layout(new_bits, old_bits, layout)

Rescale strides for a different element bit width:

Thread-value layout

enigma.make_layout_tv(thread_layout, value_layout)

The central tiling primitive. Returns a (tiler, tv_layout) pair:
  • tiler_mn — tile shape at each level
  • tv_layout — maps (thread_id, value_id) → tile coordinate

Tensor operations

These are used inside @enigma.jit bodies:

enigma.tensor_zipped_divide(tensor, tiler)

Partition a Tensor into tiles:

enigma.tensor_composition(tensor, tv_layout, tiler)

Map thread-value indices to a tensor fragment:

tensor.load() / tensor.store(value)

Vectorized load/store of a thread fragment:

Tuple utilities