-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][sparse] remove COO test from trait and encoding #73733
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
Conversation
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 is a minor step towards moving ALL COO related tests into the SparseTensorType class rather than having it all over the place (with risk of becoming inconsistent). Next revision will move ALL COO related methods into this class.
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-sparse Author: Aart Bik (aartbik) ChangesThis is a minor step towards moving ALL COO related tests into the SparseTensorType class rather than Full diff: https://github.com/llvm/llvm-project/pull/73733.diff 3 Files Affected:
diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td
index 1e62d9935d63c32..13f97994a57b8e0 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td
@@ -467,10 +467,6 @@ def SparseTensorStorageSpecifierKindAttr
def IsSparseTensorPred
: CPred<"!!::mlir::sparse_tensor::getSparseTensorEncoding($_self)">;
-def IsCOOPred
- : CPred<"!!::mlir::sparse_tensor::getSparseTensorEncoding($_self) && "
- " ::mlir::sparse_tensor::getSparseTensorEncoding($_self).isCOO()">;
-
def IsSparseTensorSlicePred
: CPred<"!!::mlir::sparse_tensor::getSparseTensorEncoding($_self) && "
" ::mlir::sparse_tensor::getSparseTensorEncoding($_self).isSlice()">;
@@ -478,22 +474,14 @@ def IsSparseTensorSlicePred
class SparseTensorOf<list<Type> allowedTypes>
: TensorOf<allowedTypes, [IsSparseTensorPred], "sparse tensor">;
-class COOSparseTensorOf<list<Type> allowedTypes>
- : TensorOf<allowedTypes, [IsCOOPred], "COO sparse tensor">;
-
class SparseTensorSliceOf<list<Type> allowedTypes>
: TensorOf<allowedTypes, [IsSparseTensorSlicePred], "sparse tensor slice">;
-class RankedSparseTensorOf<list<Type> allowedTypes>
- : RankedTensorOf<allowedTypes, [IsSparseTensorPred], "ranked sparse tensor">;
-
class ScalarLikeOf<list<Type> allowedTypes>
: AnyTypeOf<[0DTensorOf<allowedTypes>, AnyTypeOf<allowedTypes>], "scalar like">;
def AnySparseTensor : SparseTensorOf<[AnyType]>;
-def AnyCOOSparseTensor : COOSparseTensorOf<[AnyType]>;
def AnySparseTensorSlice : SparseTensorSliceOf<[AnyType]>;
-def AnyRankedSparseTensor : RankedSparseTensorOf<[AnyType]>;
def AnyIndexingScalarLike : ScalarLikeOf<[AnySignlessIntegerOrIndex]>;
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td
index 78031f28949a9e5..3127cf1b1bcf696 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td
@@ -921,10 +921,9 @@ def SparseTensor_SortOp : SparseTensor_Op<"sort">,
let summary = "Sorts the arrays in xs and ys lexicographically on the "
"integral values found in the xs list";
let description = [{
- Sparse_tensor.sort sort the `xs` values along with some `ys` values
- that are put in a single linear buffer `xy`.
- The affine map attribute `perm_map` specifies the permutation to be applied on
- the `xs` before comparison, the rank of the permutation map
+ Sorts the `xs` values along with some `ys` values that are put in a single linear
+ buffer `xy`. The affine map attribute `perm_map` specifies the permutation to be
+ applied on the `xs` before comparison, the rank of the permutation map
also specifies the number of `xs` values in `xy`.
The optional index attribute `ny` provides the number of `ys` values in `xy`.
When `ny` is not explicitly specified, its value is 0.
@@ -950,14 +949,14 @@ def SparseTensor_SortOp : SparseTensor_Op<"sort">,
}
def SparseTensor_ReorderCOOOp : SparseTensor_Op<"reorder_coo", [Pure]>,
- Arguments<(ins AnyCOOSparseTensor: $input_coo,
+ Arguments<(ins AnySparseTensor: $input_coo,
SparseTensorSortKindAttr:$algorithm)>,
- Results<(outs AnyCOOSparseTensor: $result_coo)> {
+ Results<(outs AnySparseTensor: $result_coo)> {
let summary = "Reorder the input COO such that it has the the same order as "
"the output COO";
let description = [{
- sparse_tensor.reorder_coo reorder input COO to the same order as specified by
- the output format. E.g., reorder an unordered COO into an ordered one.
+ Reorders the input COO to the same order as specified by the output format.
+ E.g., reorder an unordered COO into an ordered one.
The input and result COO tensor must have the same element type, position type and
coordinate type. At the moment, the operation also only supports ordering
diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index 74d2fd5fd9f829c..51e4b45525a410b 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -1664,14 +1664,18 @@ LogicalResult ReorderCOOOp::verify() {
SparseTensorType srcStt = getSparseTensorType(getInputCoo());
SparseTensorType dstStt = getSparseTensorType(getResultCoo());
+ if (!isCOOType(srcStt.getEncoding(), 0, /*isUnique=*/true) ||
+ !isCOOType(dstStt.getEncoding(), 0, /*isUnique=*/true))
+ emitError("Unexpected non-COO sparse tensors");
+
if (!srcStt.hasSameDimToLvl(dstStt))
emitError("Unmatched dim2lvl map between input and result COO");
if (srcStt.getPosType() != dstStt.getPosType() ||
srcStt.getCrdType() != dstStt.getCrdType() ||
- srcStt.getElementType() != dstStt.getElementType()) {
+ srcStt.getElementType() != dstStt.getElementType())
emitError("Unmatched storage format between input and result COO");
- }
+
return success();
}
|
PeimingLiu
approved these changes
Nov 29, 2023
yinying-lisa-li
approved these changes
Nov 29, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is a minor step towards moving ALL COO related tests into the SparseTensorType class rather than
having it all over the place (with risk of becoming inconsistent). Next revision will move ALL COO related methods into this class.