Skip to content

[DispatchCreation] Preserve the target of materialized tensor layouts - #24968

Merged
devtbi merged 1 commit into
mainfrom
users/maxbartel/layout/materialized-layout-target
Oct 18, 2026
Merged

devtbi merged 1 commit into
mainfrom
users/maxbartel/layout/materialized-layout-target

Conversation

@maxbartel

@maxbartel maxbartel commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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.

@maxbartel
maxbartel force-pushed the users/maxbartel/layout/materialized-layout-target branch from ae9d5e8 to cd1c4e8 Compare September 28, 2026 15:35
@maxbartel
maxbartel added this pull request to stack #24970 September 28, 2026 16:31
@maxbartel
maxbartel marked this pull request as ready for review September 28, 2026 17:04
@maxbartel
maxbartel force-pushed the users/maxbartel/layout/materialized-layout-target branch 2 times, most recently from 71e6ec5 to b736228 Compare October 5, 2026 12:39
@maxbartel
maxbartel force-pushed the users/maxbartel/layout/materialized-layout-target branch from b736228 to 5afa87b Compare October 13, 2026 08:03
Base automatically changed from users/maxbartel/layout/packed-contraction-fusion to main October 13, 2026 14:38
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 a module attribute. Skip dispatch-time encoding
assignment for such modules, and reject them at the start of dispatch
creation when they are compiled for a different target, for several
targets, or for none. Modules without the attribute keep the existing
assignment, now wrapped in a module pass so that no function pass has
to read the attribute. Its options carry the operation families and
encoding strategy, so that printed pipelines and crash reproducers keep
them.

Nothing sets the attribute yet. A follow-up sets it in an experimental
route that materializes layouts during global optimization.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@maxbartel
maxbartel force-pushed the users/maxbartel/layout/materialized-layout-target branch from 5afa87b to fbe9eab Compare October 13, 2026 14:38

@jschuhmacher jschuhmacher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@devtbi
devtbi merged commit 4bab48f into main Oct 18, 2026
60 checks passed
@devtbi
devtbi deleted the users/maxbartel/layout/materialized-layout-target branch October 18, 2026 17:59
maxbartel added a commit that referenced this pull request Nov 6, 2026
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:

1. normalizes contraction dimensions,
2. assigns and propagates encodings,
3. materializes them on the host,
4. records the target (#24968).

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.**
- The flag takes precedence over the other data-tiling placement flags,
so conflicting data-tiling flags are not an error when it is set.
- The target is recorded even when nothing was data-tiled, so
dispatch-time assignment stays off for that module.
- The early pipeline also runs `BubbleUpExpandShapes` and `SinkReshapes`
on eligible modules.
- For modules with the attribute, dispatch creation always enables
`fuse-mmt4d` and `fuse-data-tiled-convolution` (#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-tiling` with
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 on
`MaterializeHostEncodingPass` and is restricted to single-target
modules. The layout decision is split between this pass,
`isHostEncodingMaterializationSupported` and 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.

| workload | dispatch-time data tiling | this PR |
`--iree-global-opt-data-tiling` |
|---|---|---|---|
| matmul 512x1024x1024 + bias + ReLU | 1.49 ms (4) | 1.50 ms (3) | 1.43
ms (4) |
| batch_matmul 16x256x512x256 + ReLU | 1.69 ms (3) | 1.68 ms (3) | 1.75
ms (4) |
| conv NHWC 1x58x58x64, 3x3x64x64 + ReLU | 10.5 ms (3) | 10.5 ms (3) |
5.68 ms (1)* |

On 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-ops` only 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.mmt4d` and data-tiled convolutions fuse with their elementwise
epilogues and result unpacks.

Assisted by AI.
@devtbi devtbi mentioned this pull request Nov 16, 2026
8 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants