Skip to content

[mlir][linalg] fix segmentation fault in isContractionBody function #108703

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

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ bool mlir::linalg::detail::isContractionBody(
Value contributed = getSourceSkipUnary(
isa<BlockArgument>(reductionLHS) ? reductionRHS : reductionLHS);
Operation *elementwiseOp = contributed.getDefiningOp();
if (elementwiseOp->getNumResults() != 1 ||
if (!elementwiseOp || elementwiseOp->getNumResults() != 1 ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please provide a minimal test for this?

Copy link
Author

@BRUCE11111 BRUCE11111 Sep 18, 2024

Choose a reason for hiding this comment

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

Hi~ Added to existing test for testing this method. This test can reproduce the problem of the current method.

Copy link
Author

Choose a reason for hiding this comment

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

Hello~ Could you please help me to approve this PR? Thanks~

elementwiseOp->getNumOperands() != 2) {
errs << "expected elementwise op to be binary";
return false;
Expand Down
15 changes: 15 additions & 0 deletions mlir/test/Dialect/Linalg/match-ops-interpreter.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,21 @@ module attributes { transform.target_tag = "start_here" } {
} -> tensor<40x10x50x15xf32>
return %result : tensor<40x10x50x15xf32>
}

func.func @generic_min(%arg0: tensor<1x7x4xf32>, %arg1: tensor<4xf32>, %arg2: tensor<1x1x4xf32>) {
linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1 * 2 + d3 * 2, d2)>,
affine_map<(d0, d1, d2, d3) -> (d3)>,
affine_map<(d0, d1, d2, d3) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel", "reduction"]}
ins(%arg0, %arg1 : tensor<1x7x4xf32>, tensor<4xf32>)
outs(%arg2 : tensor<1x1x4xf32>) {
^bb0(%in: f32, %in_1: f32, %out: f32):
%5 = arith.minimumf %out, %in : f32
linalg.yield %5 : f32
} -> tensor<1x1x4xf32>
return
}
}

// -----
Expand Down
Loading