Skip to content
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

Fix ASAN/UBSAN issues in DimAnalysis #3052

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

jorickert
Copy link
Collaborator

  • Fixes a memory leak
  • Fixes an integer overflow caused by a dynamic shape
  • Fixes reshape to wrong type in LIT tests

- Fixes a memory leak
- Fixes an integer overflow caused by a dynamic shape
- Fixes reshape to wrong type in LIT tests

Signed-off-by: Rickert, Jonas <[email protected]>
@jorickert jorickert force-pushed the jrickert.upstream.asan_dim_analysis branch from 8f49028 to 7ad9f4f Compare January 28, 2025 16:22
@AlexandreEichenberger
Copy link
Collaborator

@tungld do you mind reviewing this PR, its in dim analysis. Thanks

@@ -361,11 +361,11 @@ static bool exploreSameDimsUsingShapeHelper(const DimAnalysis::DimT &dim,
ONNXOpShapeHelper *shapeHelper =
shape_op.getShapeHelper(op, {}, nullptr, nullptr);
// If no shape helper, or unimplemented, just abort.
if (!shapeHelper || !shapeHelper->isImplemented())
if (!shapeHelper)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you explain what's wrong with calling shapeHelper->isImplemented()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is nothing wrong with it, but if the shape helper is not implemented we still need to delete it or we will leak it's memory. This happens a few lines down

Copy link
Collaborator

Choose a reason for hiding this comment

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

I got it! That's why we have to distinguish the two conditions. Thanks for the explanation!

}
for (int64_t i = 0; i < outputType.getRank(); ++i) {
outputStaticSize *=
outputType.isDynamicDim(i) ? -1 : outputType.getShape()[i];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing this!

%0 = "onnx.Reshape"(%arg0, %shape) {allowzero = 0 : si64} : (tensor<8x?x16x4xf32>, tensor<3xi64>) -> tensor<?x4x32xf32>
%1 = "onnx.MatMul"(%arg0, %0) : (tensor<8x?x16x4xf32>, tensor<?x4x32xf32>) -> tensor<8x?x16x32xf32>
"onnx.Return"(%1) : (tensor<8x?x16x32xf32>) -> ()
%0 = "onnx.Reshape"(%arg0, %shape) {allowzero = 0 : si64} : (tensor<8x?x16x4xf32>, tensor<3xi64>) -> tensor<?x4x128xf32>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing this!

Copy link
Collaborator

@tungld tungld left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -361,11 +361,11 @@ static bool exploreSameDimsUsingShapeHelper(const DimAnalysis::DimT &dim,
ONNXOpShapeHelper *shapeHelper =
shape_op.getShapeHelper(op, {}, nullptr, nullptr);
// If no shape helper, or unimplemented, just abort.
if (!shapeHelper || !shapeHelper->isImplemented())
if (!shapeHelper)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I got it! That's why we have to distinguish the two conditions. Thanks for the explanation!

@tungld tungld merged commit 2a8b111 into onnx:main Jan 29, 2025
7 checks passed
@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #16169 [push] Fix ASAN/UBSAN issues in... started at 01:59

@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #15199 [push] Fix ASAN/UBSAN issues in... started at 03:19

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #16172 [push] Fix ASAN/UBSAN issues in... started at 03:00

@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #16169 [push] Fix ASAN/UBSAN issues in... passed after 1 hr 23 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #16172 [push] Fix ASAN/UBSAN issues in... passed after 1 hr 40 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #15199 [push] Fix ASAN/UBSAN issues in... passed after 2 hr 32 min

christopherlmunoz pushed a commit to christopherlmunoz/onnx-mlir that referenced this pull request Jan 30, 2025
- Fixes a memory leak
- Fixes an integer overflow caused by a dynamic shape
- Fixes reshape to wrong type in LIT tests

Signed-off-by: Rickert, Jonas <[email protected]>
christopherlmunoz pushed a commit to christopherlmunoz/onnx-mlir that referenced this pull request Feb 6, 2025
- Fixes a memory leak
- Fixes an integer overflow caused by a dynamic shape
- Fixes reshape to wrong type in LIT tests

Signed-off-by: Rickert, Jonas <[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.

4 participants