-
Notifications
You must be signed in to change notification settings - Fork 46
Add stream-dse fused SwiGLU-prefill operator #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
71f92d0
iron/common: forward full-ELF aiecc flags
asyms 51e637a
iron/common: add TiledStridedLayout for tiled-strided operand layouts
asyms c6503a0
ci: package stream-dse for stream-backed operators
asyms c242e90
swiglu_prefill_stream: stream-dse-backed SwiGLU-prefill operator (k=1…
asyms 3ae6ab8
ci: require stream-dse>=1.13.7 so stream-setup-aie stops clobbering m…
asyms b02f47d
swiglu_prefill_stream: generate the workload and mapping in IRON
asyms bf0482a
iron/common/stream: make the exporter translation optional per op
asyms 845500f
swiglu_prefill_stream: name the design from the golden reference
asyms 06c09ff
iron/common/stream: place layers by array column, not by core id
asyms ff9c3b1
swiglu_prefill_stream: name the weights from the golden reference
asyms 1aacdc8
swiglu_prefill_stream: deploy the block at any fusion granularity
asyms 58b36e3
ci: require stream-dse>=1.13.9
asyms 63b7215
swiglu_prefill_stream: read whole rows in the layer-by-layer elementw…
asyms 964c5a5
sequence: configure an empty device to close the re-entrancy gap
asyms 4a10562
ci: require stream-dse>=1.13.10
asyms bacaeb3
iron/common: build and configure a design once when operators share it
asyms 49e536f
iron/common/stream: take the MAC tile the kernel object is compiled for
asyms 26149f8
swiglu_prefill_stream: choose the kernel tile per fusion granularity
asyms 51092df
swiglu_prefill_stream: document the flow, the k modes and the numbers
asyms 5e07f42
ci: require stream-dse>=1.13.11
asyms 14e890c
swiglu_prefill_stream: time the dispatches that reuse the callable
asyms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,3 +22,4 @@ id_ed25519.pub | |
| .cline_storage | ||
| *.egg-info | ||
| **/*.prj/** | ||
| /outputs/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # SPDX-FileCopyrightText: Copyright (C) 2026 KU Leuven (MICAS). All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Tiled-strided memory layouts for IRON operators. | ||
|
|
||
| A tiled-strided layout describes how a logical multi-dimensional tensor is laid | ||
| out in memory as a hierarchy of tiles, each level carrying its own ``(step, | ||
| bound)`` stride. It is the layout model AIE kernels are written against: a GEMM | ||
| microkernel, for example, reads its ``MxK`` operand as ``mt x kt`` tiles of | ||
| ``r x s`` elements, which is exactly a two-level tiled-strided layout. | ||
|
|
||
| The types here mirror ``snaxc.ir.tsl`` (``Stride`` -> ``TiledStride`` -> | ||
| ``TiledStridedLayout``) so an IRON-authored layout can be handed to stream-dse's | ||
| code generation verbatim via :meth:`TiledStridedLayout.to_snaxc`. They carry no | ||
| stream-dse / snaxc / xdsl dependency themselves -- the snaxc import is lazy and | ||
| confined to ``to_snaxc`` -- so they are usable (and testable) in a plain IRON | ||
| install with no AIE codegen toolchain present. | ||
|
|
||
| This is a common primitive: it is meant to be shared across operators as the one | ||
| place a kernel's operand layouts are defined, rather than re-derived per operator | ||
| or hand-copied into stream-dse. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class Stride: | ||
| """One stride level: ``bound`` elements spaced ``step`` apart. | ||
|
|
||
| ``step``/``bound`` may be ``None`` to denote a dynamic (run-time) value, | ||
| matching snaxc's convention. | ||
| """ | ||
|
|
||
| step: int | None | ||
| bound: int | None | ||
|
|
||
|
|
||
| @dataclass | ||
| class TiledStride: | ||
| """The strides of a single tensor dimension, outermost tile first. | ||
|
|
||
| A simple (untiled) dimension has one stride; one level of tiling has two | ||
| (the outer tile stride followed by the inner element stride), and so on. | ||
| """ | ||
|
|
||
| strides: tuple[Stride, ...] | ||
|
|
||
| def __post_init__(self) -> None: | ||
| self.strides = tuple(self.strides) | ||
|
|
||
|
|
||
| @dataclass | ||
| class TiledStridedLayout: | ||
| """A tiled-strided layout: one :class:`TiledStride` per tensor dimension.""" | ||
|
|
||
| tstrides: tuple[TiledStride, ...] | ||
| offset: int = 0 | ||
|
|
||
| def __post_init__(self) -> None: | ||
| self.tstrides = tuple(self.tstrides) | ||
|
|
||
| def to_snaxc(self): | ||
| """Return the equivalent ``snaxc.ir.tsl.TiledStridedLayout``. | ||
|
|
||
| The snaxc import is deferred to here so this module stays usable without | ||
| the AIE codegen toolchain installed. Used to feed IRON-authored layouts | ||
| into stream-dse code generation. | ||
| """ | ||
| from snaxc.ir.tsl import ( | ||
| Stride as SnaxStride, | ||
| TiledStride as SnaxTiledStride, | ||
| TiledStridedLayout as SnaxTiledStridedLayout, | ||
| ) | ||
|
|
||
| return SnaxTiledStridedLayout( | ||
| [ | ||
| SnaxTiledStride([SnaxStride(s.step, s.bound) for s in ts.strides]) | ||
| for ts in self.tstrides | ||
| ], | ||
| offset=self.offset, | ||
| ) | ||
|
|
||
|
|
||
| def tiled_2d(rows: int, cols: int, row_unit: int, col_unit: int) -> TiledStridedLayout: | ||
| """Two-level tiled-strided layout for a ``rows x cols`` tensor. | ||
|
|
||
| The tensor is tiled into ``(rows // row_unit) x (cols // col_unit)`` tiles of | ||
| ``row_unit x col_unit`` elements, the tiles laid out row-major and each tile | ||
| stored row-major internally. This reproduces stream-dse's GEMM/elementwise | ||
| operand layouts (the intrinsic ``row_unit``/``col_unit`` are the kernel's MAC | ||
| tile dimensions). | ||
| """ | ||
| rows_t, cols_t = rows // row_unit, cols // col_unit | ||
| return TiledStridedLayout( | ||
| ( | ||
| TiledStride( | ||
| ( | ||
| Stride(row_unit * col_unit * cols_t, rows_t), | ||
| Stride(col_unit, row_unit), | ||
| ) | ||
| ), | ||
| TiledStride((Stride(row_unit * col_unit, cols_t), Stride(1, col_unit))), | ||
| ) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # SPDX-FileCopyrightText: Copyright (C) 2026 KU Leuven (MICAS). All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Building blocks for stream-dse-backed operators. | ||
|
|
||
| An operator supplies a reference ``nn.Module`` and a placement; these modules turn | ||
| that into everything stream-dse needs: | ||
|
|
||
| * :mod:`~iron.common.stream.ops` -- the registry binding a torch ATen op to its ONNX | ||
| form, its stream-dse kernel and IRON's ``aie_kernels`` source. | ||
| * :mod:`~iron.common.stream.workload` -- ``torch.export`` of the module into the ONNX | ||
| workload stream-dse optimizes. | ||
| * :mod:`~iron.common.stream.mapping` -- the mapping YAML, named from that same graph. | ||
|
|
||
| The submodules are not re-exported here: they need ``onnx``/``pyyaml`` (installed | ||
| with stream-dse, see ``requirements_stream.txt``), so importing an operator must not | ||
| pull them in. Import them directly from the module that builds the design. | ||
| """ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good for now, opened issue #143 to get a long-term fix into MLIR-AIE