Skip to content

[DT] Improve encoding hoisting pass. - #21275

Merged
hanhanW merged 4 commits into
iree-org:mainfrom
hanhanW:hoisting
Jul 8, 2025
Merged

hanhanW merged 4 commits into
iree-org:mainfrom
hanhanW:hoisting

Conversation

@hanhanW

@hanhanW hanhanW commented Jul 3, 2025 •

Copy link
Copy Markdown
Contributor

The revision runs ConstExprHoistingPolicy and hoist the chain ops outside dispatch if they are const-exprs. Furthermore, it allows hoisting tensor.extract_slice ops when they are mappable into Flow ops. It also allows constant-like ops because the ConstExpr analysis has an assumption that any root op is already hoisted to initializers. The rest of operations are not allowed to be hoisted out atm.

The hoistEncodingsForConstExpr is dropped because it is no longer needed. It was created for padding strategy.

The pass is changed to ModuleOp scope because it requires the analysis for const-exprs. Otherwise, it causes a thread race condition.

Fixes #21100

The revision runs ConstExprHoistingPolicy and hoist the chain ops
outside dispatch if they are const-exprs. Furthermore, it allows
hoisting tensor.extract_slice ops when they are mappable into Flow ops.

The linalg and LinalgExt ops are disallowed because it requires new
dispatches.

Signed-off-by: hanhanW <[email protected]>
@hanhanW
hanhanW requested a review from Max191 July 3, 2025 03:02
@hanhanW

hanhanW commented Jul 3, 2025

Copy link
Copy Markdown
Contributor Author

cc @egebeysel who might be interested in it.

Signed-off-by: hanhanW <[email protected]>

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

Thank you for the ping and the PR :) I think it looks good! One thing I was curious about: we're unable to do const evaluation after dispatch creation. Why was that exactly and does/could these changes maybe relate to that?

P.S.: I tagged this on another issue but on a second look, didn't look at the other one carefully at first, so it's irrelevant.

strides, srcShape);
}

// Compute ops are not hoistable after dispatch formation.

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.

nit: might make sense to have a utility function isComputeOp and use it here as well, so that we're also sure they're aligned.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd like to be careful about it because global utils could make it harder for dialects/phases to change independently, and that can be a good thing, especially when the function is simple. E.g., we can incrementally add support in different dialects under a flag without plumbing through the whole stack. Different backends can support the case in their timeline; it won't become a blocker if any backend can't support the feature and we don't have resources for it.

For the compute op, I think the assumption is that it is a compute op if it implements TilingInterface. There could be outliers like ukernel ops, but it is codegen specific.

Comment on lines +157 to +158
return !isa<linalg::LinalgDialect, IREE::LinalgExt::IREELinalgExtDialect>(
op->getDialect());

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.

Is it safe to hoist all non linalg/linalg_ext ops like this? Would it be better to check for specific dialects that we want to hoist rather than dialects that we don't want to hoist?

Maybe it is okay because of some assumptions we can make about dispatch formation, but we should be careful about leaking the dispatch formation assumptions into other passes (at the very least I think we should document the assumptions in the comments).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, maybe it should be an allow-list because people may add more operations that we don't expect, e.g., tensor_ext.bitcast ops. Let me run an experiment in #21181, and I'll circle back.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The current allow-list is okay for integration tests, I think we can go with the current version. PTAL

@hanhanW

hanhanW commented Jul 7, 2025

Copy link
Copy Markdown
Contributor Author

Thank you for the ping and the PR :) I think it looks good! One thing I was curious about: we're unable to do const evaluation after dispatch creation. Why was that exactly and does/could these changes maybe relate to that?

P.S.: I tagged this on another issue but on a second look, didn't look at the other one carefully at first, so it's irrelevant.

One of the answers is that they will be hoisted into initializers; we'll run it only once when we start the execution, e.g., iree-benchmark-module, etc.

IMHO, we should be able to support const-eval after dispatch creation in the future, but I'm not sure how the layering'd look like atm.

Signed-off-by: hanhanW <[email protected]>
@hanhanW
hanhanW requested a review from Max191 July 7, 2025 20:37
@hanhanW
hanhanW merged commit db97528 into iree-org:main Jul 8, 2025
@hanhanW
hanhanW deleted the hoisting branch July 8, 2025 20:32
@hanhanW

hanhanW commented Jul 8, 2025

Copy link
Copy Markdown
Contributor Author

cc @jtuyls who recently looks at hoisting and propagation as well.

AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
The revision runs ConstExprHoistingPolicy and hoist the chain ops
outside dispatch if they are const-exprs. Furthermore, it allows
hoisting tensor.extract_slice ops when they are mappable into Flow ops.
It also allows constant-like ops because the ConstExpr analysis has an
assumption that any root op is already hoisted to initializers. The rest
of operations are not allowed to be hoisted out atm.

The hoistEncodingsForConstExpr is dropped because it is no longer
needed. It was created for padding strategy.

The pass is changed to ModuleOp scope because it requires the analysis
for const-exprs. Otherwise, it causes a thread race condition.

Fixes #21100

---------

Signed-off-by: hanhanW <[email protected]>
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.

[DispatchCreation] Failed to hoist out of dispatch in DT-fusion

3 participants