Repository navigation
[GlobalOptimization] Add target-aware layout materialization - #24969
Merged
Merged
Conversation
This was referenced Sep 28, 2026
maxbartel
force-pushed
the
users/maxbartel/layout/target-aware-layouts
branch
from
September 28, 2026 15:35
ce83d74 to
4e37723
Compare
maxbartel
marked this pull request as ready for review
September 28, 2026 17:04
maxbartel
requested review from
AGindinson,
Manewing,
benvanik,
devtbi,
egebeysel,
jschuhmacher,
phemashekar,
schuermans-roofline and
ziereis
as code owners
September 28, 2026 17:04
maxbartel
force-pushed
the
users/maxbartel/layout/target-aware-layouts
branch
from
September 29, 2026 08:33
4e37723 to
bc225d5
Compare
maxbartel
added a commit
that referenced
this pull request
Oct 5, 2026
#24965) Contractions with several contiguous M, N, K or batch dimensions can miss data-tiling encodings because dimension collapsing currently runs inside dispatches. Add a function pass that reuses the existing collapse rules outside dispatches and restores the original tensor shapes at the op boundaries. Leave existing dispatches (regions and workgroups) and ops with a preset compilation info or lowering config alone, since those configurations refer to the original loops. No pipeline runs the pass yet. #24969 adds it to the experimental early data-tiling route. This is one of five PRs adding an experimental CPU path that materializes data-tiling layouts before dispatch creation, so that `linalg.mmt4d` and data-tiled convolutions fuse with their elementwise epilogues and result unpacks. Assisted by AI.
maxbartel
force-pushed
the
users/maxbartel/layout/target-aware-layouts
branch
from
October 5, 2026 12:39
bc225d5 to
19b04e2
Compare
maxbartel
added a commit
that referenced
this pull request
Oct 6, 2026
#24966) Encoding propagation is currently tied to dispatch hoisting, which prevents layout assignment from using the same rewrite rules on the surrounding tensor graph. Separate where propagation may happen from the rewrites themselves, and add the function pass `iree-dispatch-creation-propagate-data-tiling-encodings` for propagation outside dispatches. Hoisting keeps its existing behavior. The new pass stops at existing dispatches and block boundaries, and constant CSE stays disabled because Flow regions do not materialize constants themselves. - `iree-dispatch-creation-propagate-encodings` runs in the dispatch-time data-tiling pipeline and only swaps `set_encoding` with `tensor.cast` producers, so adding these rewrites to it would change that pipeline. They stay separate until bubbling through generic ops goes through the encoding propagation interfaces (TODO(#20179)). - Bubbling now stops at `set_encoding` ops whose encoding is not an `EncodingAttr`, such as `#iree_encoding.padding`, instead of crashing. `iree-dispatch-creation-hoist-encoding-ops` could already hit this within dispatches; both passes have a regression test. No pipeline runs the new pass yet. #24969 adds it to the experimental early data-tiling route. This is one of five PRs adding an experimental CPU path that materializes data-tiling layouts before dispatch creation, so that `linalg.mmt4d` and data-tiled convolutions fuse with their elementwise epilogues and result unpacks. Assisted by AI.
maxbartel
force-pushed
the
users/maxbartel/layout/target-aware-layouts
branch
from
October 13, 2026 08:03
19b04e2 to
a659fd0
Compare
maxbartel
added a commit
that referenced
this pull request
Oct 13, 2026
…#24967) Packed contractions lose their fused epilogues when they arrive at dispatch formation as mmt4d or a data-tiled convolution. The result unpack can also become a separate dispatch. Add opt-in fusion (`fuse-mmt4d`, `fuse-data-tiled-convolution`) of layout-preserving elementwise consumers and the result unpack. Notes for review: - Epilogues must read the contraction result and write their own result through identity maps. Epilogues that update the result through their init operand are not matched. - Only the unpack layouts that data-tiling materialization produces are matched. For mmt4d that is the row-major form and the narrow-N transposed form. For convolutions it is NHWC, NCHW and batchless HWC; batchless CHW is not matched. - The result unpack is the last op of the group, so a consumer of a claimed unpack gets its own dispatch instead of fusing with the unpack. - An unpack that its root does not claim becomes a root at its own position in program order, as without the options, so it fuses with its own consumers as before. - A group holds pack-like ops (`linalg.pack`, `set_encoding`) or the result unpack, but not both, whichever joins first. A unit-batch collapse only joins together with the unpack that consumes it, so a group never ends in the collapse. - The matchers hardcode the CPU layouts; a TODO describes moving the layout decision into its own component that dispatch formation queries. No pipeline enables the options until #24969. This is one of five PRs adding an experimental CPU path that materializes data-tiling layouts before dispatch creation, so that `linalg.mmt4d` and data-tiled convolutions fuse with their elementwise epilogues and result unpacks. Co-authored-by: Claude Opus 5.5 <[email protected]>
maxbartel
force-pushed
the
users/maxbartel/layout/target-aware-layouts
branch
from
October 13, 2026 14:38
a659fd0 to
950422f
Compare
Base automatically changed from
users/maxbartel/layout/materialized-layout-target
to
main
October 18, 2026 17:59
devtbi
pushed a commit
that referenced
this pull request
Oct 18, 2026
…#24968) Once tensor layouts have been materialized for a device, dispatch creation must neither assign encodings to them again nor compile them for another device. Assigning encodings again re-encodes data-tiled convolutions when convolutions are data-tiled, and tile shapes chosen for one CPU can be unsupported or slow on another. Record the target in the `iree.encoding.materialized_layout_target` module attribute. Typed accessors live in `DispatchCreation/MaterializedLayoutTarget.h`; `Encoding/Utils` cannot depend on HAL because HAL/IR depends on Stream/IR, which depends on `Encoding/Utils`. The header lists every behavior the attribute changes. - `iree-dispatch-creation-assign-data-tiling-encodings` skips such modules. It is a module pass so that no function pass has to read the attribute. Its options carry the operation families and encoding strategy, so printed pipelines and crash reproducers keep them. The default operation families now come from one helper, `getDefaultDataTilingOpTypes`. - `iree-dispatch-creation-verify-materialized-layout-target` runs first in the dispatch-creation pipeline, independent of the data-tiling options. It rejects modules compiled for a different target, for several targets or for none. Resuming with `--compile-from` reuses the serialized device targets, so a normal `iree-compile` flow does not retarget. The check guards hand-edited IR and tools that rewrite device targets. Nothing sets the attribute until #24969. This is one of five PRs adding an experimental CPU path that materializes data-tiling layouts before dispatch creation, so that `linalg.mmt4d` and data-tiled convolutions fuse with their elementwise epilogues and result unpacks. Assisted by AI. Co-authored-by: Claude Opus 5.5 <[email protected]>
devtbi
force-pushed
the
users/maxbartel/layout/target-aware-layouts
branch
from
October 18, 2026 17:59
950422f to
ebaed25
Compare
jschuhmacher
left a comment
Contributor
There was a problem hiding this comment.
@maxbartel Thanks! LGTM in principle. An issue for the TODOs and extra documentation would be helpful.
The PR descriptions here and in #24968 explain the target commitment and its safeguards, perhaps it could be added into optimization-options.md? That currently describes only two paths and says global-opt data tiling is being deprecated for retargetability/modularity reasons. Documenting how this experimental path differs, its scope, rationale, and its flag precedence would be helpful.
Dispatch-time data tiling assigns layouts inside dispatches, so the phases before dispatch creation cannot see or propagate them. Materializing the layouts during global optimization makes that phase target aware on purpose: layouts propagate through the surrounding tensor graph, and the packed contractions still fuse with their epilogues and result unpacks. Add the experimental --iree-opt-experimental-early-data-tiling flag. It takes precedence over the other data-tiling placement flags, so conflicting data-tiling flags are not an error when it is set, and the route uses the operation families and encoding strategy of dispatch-time data tiling. The route applies to modules with a single llvm-cpu target on x86_64 or AArch64 that uses the CPU encoding resolver without inner-tiled layouts, and only with the default encoding strategy. For these modules, global optimization propagates reshapes, normalizes contraction dimensions, assigns and propagates encodings, and materializes them on the host. It then records the target on the module, even if nothing was data-tiled. Dispatch creation therefore skips encoding assignment for the whole module, always fuses data-tiled ops with their epilogues and result unpacks, and keeps the loop order of data-tiled convolutions. Other modules keep dispatch-time data tiling. The enable_inner_tiled check moves from the CPU encoding models to the Codegen utilities, so that the eligibility check can share it. On an Apple M3 Max (local-task, f32, median of 10), the route is within noise of dispatch-time data tiling for a matmul with bias and ReLU, a batch matmul with ReLU and a convolution with ReLU. x86_64 has not been measured. The optimization options reference documents the route, its limits and the flag precedence. The layout decision is split over several passes, supports one CPU target per module, and adds HAL and Codegen dependencies to the global phases. The TODOs describe moving it into its own component that decides per affinity. Co-Authored-By: Claude Opus 5.5 <[email protected]>
maxbartel
force-pushed
the
users/maxbartel/layout/target-aware-layouts
branch
from
November 4, 2026 15:22
ebaed25 to
28b6b2f
Compare
devtbi
added a commit
that referenced
this pull request
Nov 11, 2026
…arget (#25234) The tests - early_data_tiling.mlir, early_data_tiling_convolution.mlir, early_data_tiling_dynamic.mlir, added in #24969 - roundeven_native.mlir, added in #25219 (also riscv64), compile for aarch64. byo_llvm.sh builds LLVM with only the X86 target, so iree-compile stops with "createTargetMachine(...) failed" and the tests fail linux_x64_clang_byollvm job. Add these tests in the same way as #25221: CMake adds them only if iree_compiler_targeting_iree_arch() is true for their architecture. Theaarch64 and riscv64 RUN lines move into *_aarch64.mlir and *_riscv64.mlir files, which copy the IR. ci-extra: linux_x64_clang_byollvm --------- Signed-off-by: Tobias Fuchs <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
8 tasks done
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Dispatch-time data tiling assigns layouts inside dispatches, so the phases before dispatch creation cannot see or propagate them. Materializing layouts during global optimization makes that phase target aware on purpose: layouts propagate through the surrounding tensor graph, and the packed contractions still fuse with their epilogues and result unpacks.
Add
--iree-opt-experimental-early-data-tiling. For a module with a single target that supports host encoding materialization (isHostEncodingMaterializationSupported: llvm-cpu on x86_64 or AArch64 with the CPU encoding resolver and without inner-tiled layouts), and with the default encoding strategy, the new pass:Other modules, and the padding encoding strategy, keep dispatch-time data tiling. The route takes its operation families and encoding strategy from the dispatch-creation data-tiling flags, passed down from
Pipelines.cpp, because unsupported modules fall back to that route.Behavior changes that are easy to miss.
BubbleUpExpandShapesandSinkReshapeson eligible modules.fuse-mmt4dandfuse-data-tiled-convolution([DispatchCreation] Fuse packed contractions with epilogues and unpack #24967), even if they are set to false, and keeps the loop order of data-tiled convolutions.Relation to existing paths.
--iree-global-opt-data-tilingwith early materialization also materializes on the host, but it has no contraction normalization or propagation, and its mmt4d ops are not fused with their epilogues. Like that path, this one relies onMaterializeHostEncodingPassand is restricted to single-target modules. The layout decision is split between this pass,isHostEncodingMaterializationSupportedand the dispatch-creation passes that read the attribute, and it adds HAL and Codegen dependencies to the global phases. TODOs (#25031) describe moving it into its own component that decides per affinity.Performance on an Apple M3 Max (local-task, f32,
--iree-llvmcpu-target-cpu=host, median of 10). HAL dispatches in parentheses. x86_64 has not been measured.--iree-global-opt-data-tilingOn these workloads the new path is within noise of dispatch-time data tiling, which already fuses epilogues inside encoded dispatches. *The global-opt row does not data-tile the convolution, because
--iree-dispatch-creation-experimental-set-data-tiling-opsonly affects dispatch creation. On this machine the existing experimental convolution data tiling is slower than direct convolution codegen, independent of this PR.This is one of five PRs adding an experimental CPU path that materializes data-tiling layouts before dispatch creation, so that
linalg.mmt4dand data-tiled convolutions fuse with their elementwise epilogues and result unpacks.Assisted by AI.