-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[mlir][amx] Add write side effect to AMX tile creation ops #155403
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
Conversation
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-amx Author: Arun Thangamani (arun-thmn) ChangesUpdating
Below is the example
Full diff: https://github.com/llvm/llvm-project/pull/155403.diff 1 Files Affected:
diff --git a/mlir/include/mlir/Dialect/AMX/AMX.td b/mlir/include/mlir/Dialect/AMX/AMX.td
index 6bbde43e2d011..91fe1bfb5cd35 100644
--- a/mlir/include/mlir/Dialect/AMX/AMX.td
+++ b/mlir/include/mlir/Dialect/AMX/AMX.td
@@ -142,8 +142,9 @@ class AMX_Op<string mnemonic, list<Trait> traits = []> :
// Tile reset.
//
-def TileZeroOp : AMX_Op<"tile_zero", [Pure,
- AMXIntrinsicOpInterface
+def TileZeroOp : AMX_Op<"tile_zero", [
+ AMXIntrinsicOpInterface,
+ MemoryEffects<[MemWrite]>
]> {
let summary = "tile zero operation";
let description = [{
|
@adam-smnk @rengolin Please review this |
Can you add a test? Runs CSE and make sure the tile_zero doesn't get removed. What happens if there isn't a write? |
Not sure if that in particular needs testing. It's a generic feature of memory effect traits. |
For no |
Just that IR on the description through |
Fair enough, doesn't hurt to have extra coverage. @arun-thmn Could you add a new test file under |
This is a variation of https://discourse.llvm.org/t/bug-in-operationequivalence-breaks-cse-on-linalg-index/85773/43. Here, each There are two main lowering strategies here, both bad:
There's a potential "fix" in LLVM's back-end for AMX, to simplify Currently, My advice here is to use |
We have improved similar case before: 6753eb0 |
With Example: |
Good 👍
I think it is in line with the updated semantics we want to achieve. Each tile load/zero serves as a hint to use a separate tile register. User will have to be a bit more deliberate when creating AMX ops and not rely as much on an automatic cleanup. I'd suggest to move forward with |
Updated |
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.
@rengolin Any more comments?
Nope, all good, thanks! |
Adds
MemWrite
side effect toamx.tile_zero
andamx.tile_load
ops.Memory write models hardware populating AMX tiles with specified values through tile zero and load ops.
Making the side effect explicit allows to use multiple op instances as a compilation hint to use different AMX tile registers. This can prevent less efficient lowering through tile store-load copies compared to directly populating tiles with values.
To illustrate the trade off:
Without explicit side effects,
CSE
optimizes twoamx.tile_zero
into a single op which lowers to a copy for the second tile:By keeping the two
amx.tile_zero
ops and, thus, lowering to two separate intrinsic invocations, the two tile registers are zeroed out directly without the additional round trip through memory:The same principle applies to
amx.tile_load
ops.