Skip to main content

relayout

Data layout transformations for numpy and DaCe programs, kept outside DaCe's core (as FP-Arena keeps its floating-point types). One request says how a kernel's arrays should be laid out, cast and distributed; relayout checks it, rewrites the program for it (a numpy / mpi4py program or an SDFG) and generates the kernels that convert the data.

Install

From PyPI (the distribution is dace-relayout; the import stays relayout):

pip install dace-relayout                      # add [mpi] for the distributed passes
pip install "dace @ git+https://github.com/spcl/dace.git@extended"   # relayout follows dace's extended branch

PyPI's dace is not the extended branch, so install it from GitHub as above (hpcagent-bench users: its hpcagent-bench setup installs the commit the benchmark pins). From a checkout:

uv sync --extra mpi --group dev        # add --extra fortran for the Fortran kernels (needs LLVM flang)

The fortran and fparena extras need a checkout: dace-fortran and FP-Arena are not on PyPI.

Quickstart: OMEN's self-energy (SC19)

examples/omen_quickstart.py lays out the scattering self-energy kernel of OMEN (Ziogas et al., SC'19) on one node and distributes it as SC19 does:

from relayout.passes.sdfg.apply_requests import apply_requests
from relayout.corpus.omen_sse.sse import sse
from relayout.ops import ArraySpec, lower
from relayout.requests import parse_requests

local = parse_requests({"operations": [
    {"action": "permute", "array": "G", "order": ["i2", "i0", "i1", "i3", "i4"]},   # atom-major G
    {"action": "permute", "array": "dH", "order": ["i0", "i1", "i3", "i4", "i2"]},  # direction innermost
]})
sdfg = sse.to_sdfg(simplify=True)
apply_requests(sdfg, local)       # the SDFG now runs on the laid-out G and dH; arguments keep their layout
sdfg(**arrays, **sizes)           # Sigma equals omen_sse.reference(...)

distributed = parse_requests({"startup": {"grid": ["P"]}, "operations": [
    {"action": "distribute", "array": "G", "grid_dim": 0, "dim": 1, "scheme": "block"},      # energies in
    {"action": "distribute", "array": "Sigma", "grid_dim": 0, "dim": 0, "scheme": "block"},  # momenta out
    *({"action": "replicate", "array": a} for a in ("neigh_idx", "dH", "D")),
]})
lower(distributed.run([ArraySpec(name, 5) for name in ...], ranks=4))   # each array's split per dimension

What is in it

Module What it does
relayout.ops the request: startup (libraries, a processor grid over the rank count P) and operations run top to bottom (cast, format, zip / unzip, the digit cuts block / split / permute / pad / shuffle / linear_shuffle and their inverses, distribute, replicate, place); the lowering of a distribution to one split per dimension
relayout.requests the request's JSON, one to one with relayout.ops, and its JSON Schema (both from pydantic)
relayout.layout IndexMap: one array's layout as index arithmetic, logical index to physical and back; the model everything below reads
relayout.convert conversion kernels: one gather that casts, lays out and changes sparse formats in a single pass, as C with OpenMP and as a CUDA / HIP kernel; numpy forms for tests
relayout.sparse sparse formats (csr, csc, coo, bsr, dia, ell) planned once from a canonical CSR, every format decoded back to it and converted to every other; values move through the gather; boundary calls a program (Python or SDFG) written for one format with another, converting at the call
relayout.rules how a library call absorbs a permuted operand: transpose, einsum, contraction / reduction axes, BLAS transpose flags (gemm, matmul, syrk) and triangles (syrk, symm)
relayout.passes.py Python passes, one module per SDFG pass of the same name and contract (an argument keeps its array, converted in and out; a local is rewritten in place): prepare, relayout_array, zip_arrays / unzip_array (a struct zip is a numpy structured array), cast_array, pack_mpi_buffers (mpi4py buffers, Irecv unpacked after its Wait), unblock_dimensions / untile_blocked_loops, canonicalize_schedule (loops tiled to the blocks, independent nests ordered by stride), apply_requests; shared by them: common, placement, rewrite_accesses
relayout.passes.sdfg SDFG passes, one module each: prepare (untile, canonicalize, packed arrays only), relayout_array (one rewrite for every layout: permute, block, split, pad, shuffle; library nodes by their rules), zip_arrays / unzip_array (along a dimension, data-dependent indices select their part; different element types zip into an array of structs), cast_array (FP-Arena, extra fparena), pack_mpi_buffers (MPI buffers through packed transients), unblock_dimensions / untile_blocked_loops (hand-blocked arrays and tiled loops flattened), canonicalize_schedule (maps tiled to the blocks their arrays are cut into, tiles over flat arrays merged back, map nests ordered by stride), apply_requests (a request's operations, in order); shared by them: common, placement, rewrite_accesses, library_rules
relayout.search which layout each array takes: a program as a line of kernels, each kernel's layouts costed by the LogGP model or measured, one trajectory per array chosen globally (Viterbi DP, with greedy and enumeration as checks) and applied with conversions between segments
relayout.corpus (corpus/) the input programs: the OMEN SSE kernel (Python, Fortran, MPI), the layout witness kernels and Fortran inputs, each with a numpy oracle; the layouts tried on them live in tests/layout_candidates.py

The request format and the lowering are described in docs/layout.md.

Tests

pytest runs everything on one process; the MPI tests also run under mpirun -n 2 pytest -m mpi tests, and the device kernels where cupy finds a GPU.

Metadata

Release files for dace-relayout 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dace-relayout 0.1.1
File Size Uploaded Provenance Actions
dace_relayout-0.1.1.tar.gz 276.0 kB Without provenance Details for dace_relayout-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dace-relayout 0.1.1
File Interpreter ABI Platform Actions
dace_relayout-0.1.1-py3-none-any.whl Python 3 none any Details for dace_relayout-0.1.1-py3-none-any.whl

Total release size: 485.0 kB

Release files / dace_relayout-0.1.1.tar.gz

Download URL dace_relayout-0.1.1.tar.gz
Size 276.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cf65bddfcec39665c4946958942f0cf71a95aa7c0ddbb69e510df3d5318263e4
BLAKE2b-256 checksum
How to use checksums
e73dd8b96e14478d0f8c1a6a85435fcbf0a64a14d21c542df7388dbde2d000ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / dace_relayout-0.1.1-py3-none-any.whl

Download URL dace_relayout-0.1.1-py3-none-any.whl
Size 209.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6b508cb25e57d8acd313780f22c5b30b61be65705cfde15378c33bdd6726720
BLAKE2b-256 checksum
How to use checksums
49708c08fec0548f665d61c623b925284e07c4780bffbb1af4b1753ce623806f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for dace-relayout 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page