@@ -762,81 +762,32 @@ def SparseTensor_OutOp : SparseTensor_Op<"out", []>,
762
762
// Sparse Tensor Sorting Operations.
763
763
//===----------------------------------------------------------------------===//
764
764
765
- def SparseTensor_SortOp : SparseTensor_Op<"sort", [AttrSizedOperandSegments]>,
766
- Arguments<(ins Index:$n,
767
- Variadic<StridedMemRefRankOf<[AnyInteger, Index], [1]>>:$xs,
768
- Variadic<StridedMemRefRankOf<[AnyType], [1]>>:$ys,
769
- SparseTensorSortKindAttr:$algorithm)> {
770
- string summary = "Sorts the arrays in xs and ys lexicographically on the "
771
- "integral values found in the xs list";
772
- string description = [{
773
- Lexicographically sort the first `n` values in `xs` along with the values in
774
- `ys`. Conceptually, the values being sorted are tuples produced by
775
- `zip(zip(xs), zip(ys))`. In particular, values in `ys` needed to be sorted
776
- along with values in `xs`, but values in `ys` don't affect the
777
- lexicographical order. The order in which arrays appear in `xs` affects the
778
- sorting result. The operator updates `xs` and `ys` in place with the result
779
- of the sorting.
780
-
781
- For example, assume x1=[4, 3], x2=[1, 2], y1=[10, 5], then the output of
782
- "sort 2, x1, x2 jointly y1" are x1=[3, 4], x2=[2, 1], y1=[5, 10] while the
783
- output of "sort 2, x2, x1, jointly y1" are x2=[1, 2], x1=[4, 3], y1=[10, 5].
784
-
785
- Buffers in `xs` needs to have the same integral element type while buffers
786
- in `ys` can have different numeric element types. All buffers in `xs` and
787
- `ys` should have a dimension not less than `n`. The behavior of the operator
788
- is undefined if this condition is not met. The operator requires at least
789
- one buffer in `xs` while `ys` can be empty.
790
-
791
- The enum attribute `algorithm` indicates the sorting algorithm used to
792
- implement the operator: hybrid_quick_sort, insertion_sort_stable,
793
- quick_sort, or heap_sort.
794
-
795
- Note that this operation is "impure" in the sense that its behavior is
796
- solely defined by side-effects and not SSA values.
797
-
798
- Example:
799
-
800
- ```mlir
801
- sparse_tensor.sort insertion_sort_stable %n, %x1, %x2 jointly y1, %y2
802
- : memref<?xindex>, memref<?xindex> jointly memref<?xindex>, memref<?xf32>
803
- ```
804
-
805
- ```mlir
806
- sparse_tensor.sort hybrid_quick_sort %n, %x1, %x2 jointly y1, %y2
807
- { alg=1 : index}
808
- : memref<?xindex>, memref<?xindex> jointly memref<?xindex>, memref<?xf32>
809
- ```
810
- }];
811
- let assemblyFormat = "$algorithm $n `,` $xs (`jointly` $ys^)? attr-dict"
812
- "`:` type($xs) (`jointly` type($ys)^)?";
813
- let hasVerifier = 1;
814
- }
815
-
816
765
def SparseTensor_SortCooOp : SparseTensor_Op<"sort_coo">,
817
766
Arguments<(ins Index:$n, StridedMemRefRankOf<[AnyInteger, Index], [1]>:$xy,
818
767
Variadic<StridedMemRefRankOf<[AnyType], [1]>>:$ys,
819
- OptionalAttr<IndexAttr>:$nx , OptionalAttr<IndexAttr>:$ny,
768
+ AffineMapAttr:$perm_map , OptionalAttr<IndexAttr>:$ny,
820
769
SparseTensorSortKindAttr:$algorithm)> {
821
770
let summary = "Sorts the arrays in xs and ys lexicographically on the "
822
771
"integral values found in the xs list";
823
772
let description = [{
824
- Sparse_tensor.sort_coo is similar to sparse_tensor.sort, except that all the
825
- `xs` values and some `ys` values are put in the linear buffer `xy`. The
826
- optional index attribute `nx` provides the number of `xs` values in `xy`.
827
- When `nx` is not explicitly specified, its value is 1. The optional index
828
- attribute `ny` provides the number of `ys` values in `xy`. When `ny` is not
829
- explicitly specified, its value is 0. This instruction supports a more
830
- efficient way to store the COO definition in sparse tensor type.
831
-
832
- The buffer xy should have a dimension not less than n * (nx + ny) while the
773
+ Sparse_tensor.sort_coo sort the `xs` values along with some `ys` values
774
+ that are put in a single linear buffer `xy`.
775
+ The affine map attribute `perm_map` specifies the permutation to be applied on
776
+ the `xs` before comparison, the rank of the permutation map
777
+ also specifies the number of `xs` values in `xy`.
778
+ The optional index attribute `ny` provides the number of `ys` values in `xy`.
779
+ When `ny` is not explicitly specified, its value is 0.
780
+ This instruction supports a more efficient way to store the COO definition
781
+ in sparse tensor type.
782
+
783
+ The buffer xy should have a dimension not less than n * (rank(perm_map) + ny) while the
833
784
buffers in `ys` should have a dimension not less than `n`. The behavior of
834
785
the operator is undefined if this condition is not met.
835
786
836
787
Example:
837
788
838
789
```mlir
839
- sparse_tensor.sort_coo insertion_sort_stable %n, %x { nx = 2 : index }
790
+ sparse_tensor.sort_coo insertion_sort_stable %n, %x { perm_map = affine_map<(i,j) -> (j,i)> }
840
791
: memref<?xindex>
841
792
```
842
793
0 commit comments