Skip to content

Commit 110f927

Browse files
authored
[mlir][sparse] refactor sparse tensor traits (#73726)
Slightly refactors the order of the sparse tensor traits, and usage. Also makes minor doc improvements.
1 parent d6783c7 commit 110f927

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,6 @@ def IsSparseTensorSlicePred
475475
: CPred<"!!::mlir::sparse_tensor::getSparseTensorEncoding($_self) && "
476476
" ::mlir::sparse_tensor::getSparseTensorEncoding($_self).isSlice()">;
477477

478-
// The following four follow the same idiom as `TensorOf`, `AnyTensor`,
479-
// `RankedTensorOf`, `AnyRankedTensor`.
480-
481478
class SparseTensorOf<list<Type> allowedTypes>
482479
: TensorOf<allowedTypes, [IsSparseTensorPred], "sparse tensor">;
483480

@@ -487,17 +484,17 @@ class COOSparseTensorOf<list<Type> allowedTypes>
487484
class SparseTensorSliceOf<list<Type> allowedTypes>
488485
: TensorOf<allowedTypes, [IsSparseTensorSlicePred], "sparse tensor slice">;
489486

490-
def AnySparseTensor : SparseTensorOf<[AnyType]>;
491-
def AnyCOOSparseTensor : COOSparseTensorOf<[AnyType]>;
492-
def AnySparseTensorSlice : SparseTensorSliceOf<[AnyType]>;
493-
494487
class RankedSparseTensorOf<list<Type> allowedTypes>
495488
: RankedTensorOf<allowedTypes, [IsSparseTensorPred], "ranked sparse tensor">;
496489

497-
def AnyRankedSparseTensor : RankedSparseTensorOf<[AnyType]>;
498-
499490
class ScalarLikeOf<list<Type> allowedTypes>
500-
: AnyTypeOf<[0DTensorOf<allowedTypes>, AnyTypeOf<allowedTypes>]>;
491+
: AnyTypeOf<[0DTensorOf<allowedTypes>, AnyTypeOf<allowedTypes>], "scalar like">;
492+
493+
def AnySparseTensor : SparseTensorOf<[AnyType]>;
494+
def AnyCOOSparseTensor : COOSparseTensorOf<[AnyType]>;
495+
def AnySparseTensorSlice : SparseTensorSliceOf<[AnyType]>;
496+
def AnyRankedSparseTensor : RankedSparseTensorOf<[AnyType]>;
497+
def AnyIndexingScalarLike : ScalarLikeOf<[AnySignlessIntegerOrIndex]>;
501498

502499
//===----------------------------------------------------------------------===//
503500
// Sparse Tensor Sorting Algorithm Attribute.

mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def SparseTensor_AssembleOp : SparseTensor_Op<"assemble", [Pure]>,
5858
Arguments<(ins TensorOf<[AnyType]>:$values,
5959
Variadic<TensorOf<[AnySignlessIntegerOrIndex]>>:$levels)>,
6060
Results<(outs AnySparseTensor: $result)> {
61-
let summary = "Returns a sparse tensor from the given values, levels";
61+
let summary = "Returns a sparse tensor assembled from the given values and levels";
6262

6363
let description = [{
6464
Assembles the values and per-level coordinate or postion arrays into a sparse tensor.
@@ -71,7 +71,7 @@ def SparseTensor_AssembleOp : SparseTensor_Op<"assemble", [Pure]>,
7171
each supplies the sparse tensor coordinates scheme in the sparse tensor for
7272
the corresponding level as specifed by `sparse_tensor::StorageLayout`.
7373

74-
This operation can be used to materialize a sparse tensor from external
74+
This operation can be used to assemble a sparse tensor from external
7575
sources; e.g., when passing two numpy arrays from Python.
7676

7777
Disclaimer: This is the user's responsibility to provide input that can be
@@ -82,7 +82,6 @@ def SparseTensor_AssembleOp : SparseTensor_Op<"assemble", [Pure]>,
8282
dimOrdering/higherOrdering mappings. However, the current implementation
8383
does not yet support them.
8484

85-
8685
Example:
8786

8887
```mlir
@@ -109,16 +108,17 @@ def SparseTensor_DisassembleOp : SparseTensor_Op<"disassemble", [Pure, SameVaria
109108
Variadic<TensorOf<[AnySignlessIntegerOrIndex]>>:$out_levels)>,
110109
Results<(outs TensorOf<[AnyType]>:$ret_values,
111110
Variadic<TensorOf<[AnySignlessIntegerOrIndex]>>:$ret_levels,
112-
ScalarLikeOf<[AnySignlessIntegerOrIndex]>:$val_len,
113-
Variadic<ScalarLikeOf<[AnySignlessIntegerOrIndex]>>:$lvl_lens)> {
114-
let summary = "Returns the (values, coordinates) pair unpacked from the input tensor";
111+
AnyIndexingScalarLike:$val_len,
112+
Variadic<AnyIndexingScalarLike>:$lvl_lens)> {
113+
let summary = "Returns the (values, coordinates) pair disassembled from the input tensor";
115114

116115
let description = [{
117-
The disassemble operation is the inverse of `sparse_tensor::assemble`. It returns
118-
the values and per-level position and coordinate array to the user
119-
from the sparse tensor along with the actual length of the memory used in
120-
each returned buffer. This operation can be used for returning an
121-
unpacked MLIR sparse tensor to frontend; e.g., returning two numpy arrays to Python.
116+
The disassemble operation is the inverse of `sparse_tensor::assemble`.
117+
It returns the values and per-level position and coordinate array to the
118+
user from the sparse tensor along with the actual length of the memory used
119+
in each returned buffer. This operation can be used for returning an
120+
disassembled MLIR sparse tensor to frontend; e.g., returning two numpy arrays
121+
to Python.
122122

123123
Disclaimer: This is the user's responsibility to allocate large enough buffers
124124
to hold the sparse tensor. The sparsifier simply copies each fields

0 commit comments

Comments
 (0)