-
Notifications
You must be signed in to change notification settings - Fork 52
Change rock::invertTransform to use FailureOr<T>
#2206
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
base: develop
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This pull request changes the signature of rock::invertTransforms to return FailureOr<ArrayAttr> instead of ArrayAttr, making it explicit that the function can fail. The change updates the function declaration, implementation, and all call sites throughout the codebase.
Changes:
- Modified
invertTransformsto returnFailureOr<ArrayAttr>instead ofArrayAttrornullptr - Updated failure handling to return
LogicalResult::failure()instead ofnullptr - Updated all call sites to check for success/failure and extract values using
.value()
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| transformMapUtils.h | Updated function signature to return FailureOr<ArrayAttr> |
| transformMapUtils.cpp | Changed return type and failure handling in implementation |
| ThreadwiseGemmLowering.cpp | Updated call site with proper failure checking |
| ShuffleGemmForReductions.cpp | Updated call sites with mixed error handling patterns |
| RemoveOutputAlloc.cpp | Updated call site with proper failure checking |
| GridwiseGemmToBlockwise.cpp | Updated multiple call sites, some with unchecked .value() calls |
| BlockwiseLoadTileToThreadwise.cpp | Updated call sites with unchecked .value() calls |
| BlockwiseGemmToThreadwise.cpp | Updated call site with unchecked .value() call |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mlir/lib/Dialect/Rock/Transforms/BlockwiseLoadTileToThreadwise.cpp
Outdated
Show resolved
Hide resolved
mlir/lib/Dialect/Rock/Transforms/BlockwiseLoadTileToThreadwise.cpp
Outdated
Show resolved
Hide resolved
mlir/lib/Dialect/Rock/Transforms/BlockwiseLoadTileToThreadwise.cpp
Outdated
Show resolved
Hide resolved
| ArrayAttr inputThreadSubTile2dViewInv = | ||
| invertTransforms(rewriter, loc, inputThreadSubTile2dView); | ||
| invertTransforms(rewriter, loc, inputThreadSubTile2dView).value(); |
Copilot
AI
Jan 16, 2026
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.
Calling .value() on the result of invertTransforms without checking if the operation succeeded. If invertTransforms fails, this will cause undefined behavior. Add a failure check before calling .value() and return failure if the inversion fails.
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.
We want to do something similar to what you did in ThreadwiseGemmLowering.cpp by calling something like succeeded on the value from invertTransforms.
| TransformMapAttr invertedTrMap = invertTransformMap(b, trMap, loc); | ||
| if (!invertedTrMap) | ||
| return nullptr; | ||
| return LogicalResult::failure(); |
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.
You can just return failure() here. No need for the LogicalResult part.
| ArrayAttr inputThreadSubTile2dViewInv = | ||
| invertTransforms(rewriter, loc, inputThreadSubTile2dView); | ||
| invertTransforms(rewriter, loc, inputThreadSubTile2dView).value(); |
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.
We want to do something similar to what you did in ThreadwiseGemmLowering.cpp by calling something like succeeded on the value from invertTransforms.
| FailureOr<ArrayAttr> inBufferViewsTrAttr = | ||
| invertTransforms(b, loc, inBufferViewsTr.threadSubTile); | ||
| if (failed(inBufferViewsTrAttr)) { | ||
| return failure(); |
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.
Avoid this at all costs. If something fails, we should always inform the user about what failed. return failure(); will just give the user the generic message "Lowering failed." which does not help to understand what failed.
You can use something like:
return op.emitError("invertTransforms failed");
Same goes for the rest of places in this PR where we check if invertTransforms failed.
|
|
||
| FailureOr<ArrayAttr> invertedThreadSubTileViews = | ||
| invertTransforms(rewriter, loc, gemm1OutSubTileViewsTr.threadSubTile); | ||
| if (succeeded(invertedThreadSubTileViews)) { |
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.
Shouldn't we fail here if invertTransforms failed?
Motivation
Change the signature of
rock::invertTransformso that the user knows it can fail.Technical Details
Refactor and change code to use
rock::invertTransform.Resolves https://github.com/ROCm/rocMLIR-internal/issues/1999
Test Plan
Build and check CI.
Test Result
Build locally.
Submission Checklist