-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][sparse] Fix bug in new syntax parser #66024
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
Conversation
Currently, dimlvlmap with identity Affine map will be treated as empty Affine map. But the new syntax would treat it as an actual identity Affine map such as {d0} -> {d0}. This mismatch could raise error in reshape rewriting.
@llvm/pr-subscribers-mlir-sparse ChangesCurrently, dimlvlmap with identity affine map will be treated as empty affine map. But the new syntax would treat it as an actual identity affine map such as {d0} -> {d0}. This mismatch could raise error in reshape rewriting.Full diff: https://github.com/llvm/llvm-project/pull/66024.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp index 81302f200f686bb..05fce96043826f1 100644 --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp @@ -348,7 +348,9 @@ AffineMap DimLvlMap::getDimToLvlMap(MLIRContext *context) const { lvlAffines.reserve(getLvlRank()); for (const auto &lvlSpec : lvlSpecs) lvlAffines.push_back(lvlSpec.getExpr().getAffineExpr()); - return AffineMap::get(getDimRank(), getSymRank(), lvlAffines, context); + auto map = AffineMap::get(getDimRank(), getSymRank(), lvlAffines, context); + if (map.isIdentity()) return AffineMap(); + return map; } AffineMap DimLvlMap::getLvlToDimMap(MLIRContext *context) const { @@ -356,7 +358,9 @@ AffineMap DimLvlMap::getLvlToDimMap(MLIRContext *context) const { dimAffines.reserve(getDimRank()); for (const auto &dimSpec : dimSpecs) dimAffines.push_back(dimSpec.getExpr().getAffineExpr()); - return AffineMap::get(getLvlRank(), getSymRank(), dimAffines, context); + auto map = AffineMap::get(getLvlRank(), getSymRank(), dimAffines, context); + if (map.isIdentity()) return AffineMap(); + return map; } void DimLvlMap::dump() const { |
@llvm/pr-subscribers-mlir-core ChangesCurrently, dimlvlmap with identity affine map will be treated as empty affine map. But the new syntax would treat it as an actual identity affine map such as {d0} -> {d0}. This mismatch could raise error in reshape rewriting.Full diff: https://github.com/llvm/llvm-project/pull/66024.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp index 81302f200f686bb..05fce96043826f1 100644 --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp @@ -348,7 +348,9 @@ AffineMap DimLvlMap::getDimToLvlMap(MLIRContext *context) const { lvlAffines.reserve(getLvlRank()); for (const auto &lvlSpec : lvlSpecs) lvlAffines.push_back(lvlSpec.getExpr().getAffineExpr()); - return AffineMap::get(getDimRank(), getSymRank(), lvlAffines, context); + auto map = AffineMap::get(getDimRank(), getSymRank(), lvlAffines, context); + if (map.isIdentity()) return AffineMap(); + return map; } AffineMap DimLvlMap::getLvlToDimMap(MLIRContext *context) const { @@ -356,7 +358,9 @@ AffineMap DimLvlMap::getLvlToDimMap(MLIRContext *context) const { dimAffines.reserve(getDimRank()); for (const auto &dimSpec : dimSpecs) dimAffines.push_back(dimSpec.getExpr().getAffineExpr()); - return AffineMap::get(getLvlRank(), getSymRank(), dimAffines, context); + auto map = AffineMap::get(getLvlRank(), getSymRank(), dimAffines, context); + if (map.isIdentity()) return AffineMap(); + return map; } void DimLvlMap::dump() const { |
@llvm/pr-subscribers-mlir ChangesCurrently, dimlvlmap with identity affine map will be treated as empty affine map. But the new syntax would treat it as an actual identity affine map such as {d0} -> {d0}. This mismatch could raise error in reshape rewriting.Full diff: https://github.com/llvm/llvm-project/pull/66024.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp index 81302f200f686bb..05fce96043826f1 100644 --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp @@ -348,7 +348,9 @@ AffineMap DimLvlMap::getDimToLvlMap(MLIRContext *context) const { lvlAffines.reserve(getLvlRank()); for (const auto &lvlSpec : lvlSpecs) lvlAffines.push_back(lvlSpec.getExpr().getAffineExpr()); - return AffineMap::get(getDimRank(), getSymRank(), lvlAffines, context); + auto map = AffineMap::get(getDimRank(), getSymRank(), lvlAffines, context); + if (map.isIdentity()) return AffineMap(); + return map; } AffineMap DimLvlMap::getLvlToDimMap(MLIRContext *context) const { @@ -356,7 +358,9 @@ AffineMap DimLvlMap::getLvlToDimMap(MLIRContext *context) const { dimAffines.reserve(getDimRank()); for (const auto &dimSpec : dimSpecs) dimAffines.push_back(dimSpec.getExpr().getAffineExpr()); - return AffineMap::get(getLvlRank(), getSymRank(), dimAffines, context); + auto map = AffineMap::get(getLvlRank(), getSymRank(), dimAffines, context); + if (map.isIdentity()) return AffineMap(); + return map; } void DimLvlMap::dump() const { |
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.
Nice job Yinying!
Only change I would request is in the description, since the bug will show up anywhere we do a comparison on the encoding (the reshaping test was just one that exposed it). But good to go once you make that tiny change.
Currently, dimlvlmap with identity affine map will be treated as empty affine map. But the new syntax would treat it as an actual identity affine map such as {d0} -> {d0}. This mismatch could raise an error when we are comparing sparse encodings.
Currently, dimlvlmap with identity affine map will be treated as empty affine map. But the new syntax would treat it as an actual identity affine map such as {d0} -> {d0}. This mismatch could raise an error when we are comparing sparse encodings.
Currently, dimlvlmap with identity affine map will be treated as empty affine map. But the new syntax would treat it as an actual identity affine map such as {d0} -> {d0}. This mismatch could raise an error when we are comparing sparse encodings.