Skip to content

Conversation

@Mr-Anyone
Copy link

Motivation

Change the signature of rock::invertTransform so 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

Copy link
Contributor

Copilot AI left a 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 invertTransforms to return FailureOr<ArrayAttr> instead of ArrayAttr or nullptr
  • Updated failure handling to return LogicalResult::failure() instead of nullptr
  • 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.

Comment on lines 1030 to 1031
ArrayAttr inputThreadSubTile2dViewInv =
invertTransforms(rewriter, loc, inputThreadSubTile2dView);
invertTransforms(rewriter, loc, inputThreadSubTile2dView).value();
Copy link

Copilot AI Jan 16, 2026

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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

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();
Copy link
Contributor

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.

Comment on lines 1030 to 1031
ArrayAttr inputThreadSubTile2dViewInv =
invertTransforms(rewriter, loc, inputThreadSubTile2dView);
invertTransforms(rewriter, loc, inputThreadSubTile2dView).value();
Copy link
Contributor

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();
Copy link
Contributor

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)) {
Copy link
Contributor

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?

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