Skip to content

[schedule][mlir] consumer fusion - #112

Open
liamsemeria wants to merge 3 commits into
xtc-tools:mainfrom
liamsemeria:dev/sliam/mlir-fuse-consumer
Open

[schedule][mlir] consumer fusion#112
liamsemeria wants to merge 3 commits into
xtc-tools:mainfrom
liamsemeria:dev/sliam/mlir-fuse-consumer

Conversation

@liamsemeria

@liamsemeria liamsemeria commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Motivation

Adds consumer fusion to the mlir backend.

Description

Implements fuse_consumer_at() for the mlir backend, the main use case being fusing relus that come after matmuls or conv2ds. It makes use of the new xtc-mlir python bindings, and a new xtc-mlir transform op FuseConsumerOp.

It only works when using the tensor dialect, the same as producer fusion.

Originally it took the name of the consumer as input, but I modified it to only fuse the first output to match how the tvm fuse_consumer_at is being implemented.

@liamsemeria liamsemeria added the enhancement New feature or request label Aug 4, 2026
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.70968% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/xtc/backends/mlir/MlirCompilerPasses.py 85.10% 1 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

@liamsemeria
liamsemeria force-pushed the dev/sliam/mlir-fuse-consumer branch from faa2da7 to 07f8b08 Compare August 6, 2026 11:37
@liamsemeria
liamsemeria force-pushed the dev/sliam/mlir-fuse-consumer branch from 07f8b08 to 5f3b31b Compare August 13, 2026 08:10
@liamsemeria
liamsemeria requested a review from guillon August 13, 2026 08:21
Comment on lines +415 to +416
for i, loop_dim in enumerate(schedule.permutation[fuse_root]):
transform.AnnotateOp(op.new_loops[i], loop_dim)

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.

nice

@qaco qaco 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.

Great

consumer_handles = find_consumer_handles(
self._mlir_program.mlir_module, schedule.node_ident
)
consumer_id = consumer_handles[0]

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.

What if consumer_handles is empty? aka the current op is the last one of the graph

assert self._named_sequence is not None

fuse_root = parent_name(schedule.fused_consumers[0])
for fuse_axis in schedule.fused_consumers:

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.

The loop over schedule.fused_consumers suggests multiple axes are supported, but it's only correct for one: fuse_root and the consumer handle are derived from [0] for every iteration, and sched_state.all_loops isn't refreshed after FuseConsumerOp, so a second iteration would reuse loop handles the first fusion may have invalidated (the fresh ones are in op.new_loops).

@qaco qaco 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.

Great work, thanks for doing this! See the requested changes above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants