-
Notifications
You must be signed in to change notification settings - Fork 28
add recursive symmetry checks + check for existing attr #1626
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
Open
gaurav-arya
wants to merge
12
commits into
main
Choose a base branch
from
symmetry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0b437e1
Mark SymmOp output as guaranteed symmetric
gaurav-arya 1d4c46b
Add recursive symmetry check for transpose and dot_general
gaurav-arya 3bf9140
Add test of new symmetry detection
gaurav-arya 6de3935
Get rid of constants from symmetry test
gaurav-arya 3437823
Test input IR annotation
gaurav-arya b4a4313
Replace lapack.symm with blas.symm
gaurav-arya e3cd107
Move boolAttr checks in each analysis to shared check in localGuarant…
gaurav-arya 573167a
Fix test
gaurav-arya 59e2c0c
Remove DotGeneralOp and SymmOp symmetry checks
gaurav-arya 99a8647
Rename test file
gaurav-arya 1659f78
Add symmetry propagation for DotGeneralOp on A * A
gaurav-arya 173903f
Format
gaurav-arya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -660,13 +660,22 @@ SymmetricResultAnalysis::State SymmetricResultAnalysis::localGuaranteed( | |
| } | ||
| } | ||
|
|
||
| if (isa<enzymexla::SymmOp>(op)) { | ||
| return State::GUARANTEED; | ||
| } | ||
|
|
||
| bool recursiveCheck = false; | ||
|
|
||
| // elementwise ops | ||
| if (stablehlo::hasTraitElementwise(op)) { | ||
| recursiveCheck = true; | ||
| } | ||
|
|
||
| if (isa<stablehlo::TransposeOp>(op), isa<stablehlo::DotGeneralOp>(op)) { | ||
|
||
| // All operands symmetric => symmetric result | ||
| recursiveCheck = true; | ||
| } | ||
|
|
||
| /** | ||
| * TODO | ||
| * - check if its * 0 -> symmetric | ||
|
|
@@ -739,13 +748,6 @@ NoNanResultAnalysis::localGuaranteed(Operation *op, | |
| PatternRewriter &rewriter) { | ||
| assert(op); | ||
|
|
||
| if (auto boolAttr = op->getAttrOfType<BoolAttr>(getAttrName())) { | ||
| if (boolAttr.getValue()) | ||
| return State::GUARANTEED; | ||
| else | ||
| return State::NOTGUARANTEED; | ||
| } | ||
|
|
||
| DenseElementsAttr denseAttr; | ||
| if (matchPattern(op, m_Constant(&denseAttr))) { | ||
| if (guaranteedConstantOp(op, denseAttr, rewriter)) { | ||
|
|
@@ -882,13 +884,6 @@ FiniteResultAnalysis::localGuaranteed(Operation *op, | |
| PatternRewriter &rewriter) { | ||
| assert(op); | ||
|
|
||
| if (auto boolAttr = op->getAttrOfType<BoolAttr>(getAttrName())) { | ||
| if (boolAttr.getValue()) | ||
| return State::GUARANTEED; | ||
| else | ||
| return State::NOTGUARANTEED; | ||
| } | ||
|
|
||
| DenseElementsAttr denseAttr; | ||
| if (matchPattern(op, m_Constant(&denseAttr))) { | ||
| if (guaranteedConstantOp(op, denseAttr, rewriter)) { | ||
|
|
@@ -995,13 +990,6 @@ NonNegativeResultAnalysis::State NonNegativeResultAnalysis::localGuaranteed( | |
| PatternRewriter &rewriter) { | ||
| assert(op); | ||
|
|
||
| if (auto boolAttr = op->getAttrOfType<BoolAttr>(getAttrName())) { | ||
| if (boolAttr.getValue()) | ||
| return State::GUARANTEED; | ||
| else | ||
| return State::NOTGUARANTEED; | ||
| } | ||
|
|
||
| DenseElementsAttr denseAttr; | ||
| if (matchPattern(op, m_Constant(&denseAttr))) { | ||
| if (guaranteedConstantOp(op, denseAttr, rewriter)) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test/lit_tests/structured_tensors/propagate_symmetric.mlir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // RUN: enzymexlamlir-opt --enzyme-hlo-generate-td="patterns=transpose_symmetric_simplify" --transform-interpreter --enzyme-hlo-remove-transform %s | FileCheck %s | ||
|
|
||
| func.func @pass1(%arg0: tensor<2x2xf32>, %arg1: tensor<2x2xf32>, %arg2: tensor<2x2xf32>) -> tensor<2x2xf32> { | ||
| %alpha = stablehlo.constant dense<2.0> : tensor<f32> | ||
| %beta = stablehlo.constant dense<3.0> : tensor<f32> | ||
| %0 = enzymexla.blas.symm %arg0, %arg1, %arg2, %alpha, %beta {side = #enzymexla.side<left>, uplo = #enzymexla.uplo<U>} : (tensor<2x2xf32>, tensor<2x2xf32>, tensor<2x2xf32>, tensor<f32>, tensor<f32>) -> tensor<2x2xf32> | ||
| %1 = stablehlo.reshape %arg0 {enzymexla.guaranteed_symmetric = true} : (tensor<2x2xf32>) -> tensor<2x2xf32> | ||
| %2 = stablehlo.subtract %1, %0 : tensor<2x2xf32> | ||
| %3 = stablehlo.dot_general %2, %1, contracting_dims = [1] x [0], precision = [DEFAULT, DEFAULT] : (tensor<2x2xf32>, tensor<2x2xf32>) -> tensor<2x2xf32> | ||
| %4 = stablehlo.transpose %3, dims = [1, 0] : (tensor<2x2xf32>) -> tensor<2x2xf32> | ||
| return %4 : tensor<2x2xf32> | ||
| } | ||
|
|
||
| // CHECK: func.func @pass1(%arg0: tensor<2x2xf32>, %arg1: tensor<2x2xf32>, %arg2: tensor<2x2xf32>) -> tensor<2x2xf32> { | ||
| // CHECK-NEXT: %cst = stablehlo.constant dense<2.000000e+00> : tensor<f32> | ||
| // CHECK-NEXT: %cst_0 = stablehlo.constant dense<3.000000e+00> : tensor<f32> | ||
| // CHECK-NEXT: %0 = enzymexla.blas.symm %arg0, %arg1, %arg2, %cst, %cst_0 {enzymexla.guaranteed_symmetric = true, side = #enzymexla.side<left>, uplo = #enzymexla.uplo<U>} : (tensor<2x2xf32>, tensor<2x2xf32>, tensor<2x2xf32>, tensor<f32>, tensor<f32>) -> tensor<2x2xf32> | ||
| // CHECK-NEXT: %1 = stablehlo.reshape %arg0 {enzymexla.guaranteed_symmetric = true} : (tensor<2x2xf32>) -> tensor<2x2xf32> | ||
| // CHECK-NEXT: %2 = stablehlo.subtract %1, %0 : tensor<2x2xf32> | ||
| // CHECK-NEXT: %3 = stablehlo.dot_general %2, %1, contracting_dims = [1] x [0], precision = [DEFAULT, DEFAULT] {enzymexla.guaranteed_symmetric = true} : (tensor<2x2xf32>, tensor<2x2xf32>) -> tensor<2x2xf32> | ||
| // CHECK-NEXT: return %3 : tensor<2x2xf32> | ||
| // CHECK-NEXT: } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this generally true? it is true for syrk but not for symm if B is not symmetric
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.
yup you're right, there's no op for
syrkyet right?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.
correct