Skip to content

Commit ea7ee9d

Browse files
committed
[mlir][sparse] minor reorg of sparse tensor tablegen defs
Reviewed By: Peiming Differential Revision: https://reviews.llvm.org/D150414
1 parent a983ef2 commit ea7ee9d

File tree

1 file changed

+56
-47
lines changed

1 file changed

+56
-47
lines changed

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

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,52 @@ def SparseTensor_ToValuesOp : SparseTensor_Op<"values", [Pure]>,
358358
let hasVerifier = 1;
359359
}
360360

361+
def SparseTensor_NumberOfEntriesOp : SparseTensor_Op<"number_of_entries", [Pure]>,
362+
Arguments<(ins AnySparseTensor:$tensor)>,
363+
Results<(outs Index:$result)> {
364+
let summary = "Returns the number of entries that are stored in the tensor.";
365+
let description = [{
366+
Returns the number of entries that are stored in the given sparse tensor.
367+
Note that this is typically the number of nonzero elements in the tensor,
368+
but since explicit zeros may appear in the storage formats, the more
369+
accurate nomenclature is used.
370+
371+
Example:
372+
373+
```mlir
374+
%noe = sparse_tensor.number_of_entries %tensor : tensor<64x64xf64, #CSR>
375+
```
376+
}];
377+
let assemblyFormat = "$tensor attr-dict `:` type($tensor)";
378+
}
379+
380+
def SparseTensor_ConcatenateOp : SparseTensor_Op<"concatenate", [Pure]>,
381+
Arguments<(ins Variadic<AnyRankedTensor>:$inputs, DimensionAttr:$dimension)>,
382+
Results<(outs AnyRankedTensor:$result)> {
383+
384+
let summary = "Concatenates a list of tensors into a single tensor.";
385+
let description = [{
386+
Concatenates a list input tensors and the output tensor with the same
387+
dimension-rank. The concatenation happens on the specified `dimension`
388+
(0 <= dimension < dimRank). The resulting `dimension` size is the
389+
sum of all the input sizes for that dimension, while all the other
390+
dimensions should have the same size in the input and output tensors.
391+
392+
Only statically-sized input tensors are accepted, while the output tensor
393+
can be dynamically-sized.
394+
395+
Example:
396+
397+
```mlir
398+
%0 = sparse_tensor.concatenate %1, %2 { dimension = 0 : index }
399+
: tensor<64x64xf64, #CSR>, tensor<64x64xf64, #CSR> to tensor<128x64xf64, #CSR>
400+
```
401+
}];
402+
403+
let assemblyFormat = "$inputs attr-dict `:` type($inputs) `to` type($result)";
404+
let hasVerifier = 1;
405+
}
406+
361407
def SparseTensor_ToSliceOffsetOp : SparseTensor_Op<"slice.offset", [Pure]>,
362408
Arguments<(ins AnySparseTensorSlice:$slice, IndexAttr:$dim)>,
363409
Results<(outs Index:$offset)> {
@@ -413,7 +459,12 @@ def SparseTensor_ToSliceStrideOp : SparseTensor_Op<"slice.stride", [Pure]>,
413459
let hasVerifier = 1;
414460
}
415461

416-
def SparseTensor_StorageSpecifierInitOp : SparseTensor_Op<"storage_specifier.init", [Pure]>,
462+
//===----------------------------------------------------------------------===//
463+
// Sparse Tensor Storage Specifier Operations.
464+
//===----------------------------------------------------------------------===//
465+
466+
def SparseTensor_StorageSpecifierInitOp : SparseTensor_Op<"storage_specifier.init",
467+
[Pure]>,
417468
Arguments<(ins Optional<SparseTensorStorageSpecifier>:$source)>,
418469
Results<(outs SparseTensorStorageSpecifier:$result)> {
419470
let summary = "";
@@ -501,52 +552,6 @@ def SparseTensor_SetStorageSpecifierOp : SparseTensor_Op<"storage_specifier.set"
501552
let hasVerifier = 1;
502553
}
503554

504-
def SparseTensor_NumberOfEntriesOp : SparseTensor_Op<"number_of_entries", [Pure]>,
505-
Arguments<(ins AnySparseTensor:$tensor)>,
506-
Results<(outs Index:$result)> {
507-
let summary = "Returns the number of entries that are stored in the tensor.";
508-
let description = [{
509-
Returns the number of entries that are stored in the given sparse tensor.
510-
Note that this is typically the number of nonzero elements in the tensor,
511-
but since explicit zeros may appear in the storage formats, the more
512-
accurate nomenclature is used.
513-
514-
Example:
515-
516-
```mlir
517-
%noe = sparse_tensor.number_of_entries %tensor : tensor<64x64xf64, #CSR>
518-
```
519-
}];
520-
let assemblyFormat = "$tensor attr-dict `:` type($tensor)";
521-
}
522-
523-
def SparseTensor_ConcatenateOp : SparseTensor_Op<"concatenate", [Pure]>,
524-
Arguments<(ins Variadic<AnyRankedTensor>:$inputs, DimensionAttr:$dimension)>,
525-
Results<(outs AnyRankedTensor:$result)> {
526-
527-
let summary = "Concatenates a list of tensors into a single tensor.";
528-
let description = [{
529-
Concatenates a list input tensors and the output tensor with the same
530-
dimension-rank. The concatenation happens on the specified `dimension`
531-
(0 <= dimension < dimRank). The resulting `dimension` size is the
532-
sum of all the input sizes for that dimension, while all the other
533-
dimensions should have the same size in the input and output tensors.
534-
535-
Only statically-sized input tensors are accepted, while the output tensor
536-
can be dynamically-sized.
537-
538-
Example:
539-
540-
```mlir
541-
%0 = sparse_tensor.concatenate %1, %2 { dimension = 0 : index }
542-
: tensor<64x64xf64, #CSR>, tensor<64x64xf64, #CSR> to tensor<128x64xf64, #CSR>
543-
```
544-
}];
545-
546-
let assemblyFormat = "$inputs attr-dict `:` type($inputs) `to` type($result)";
547-
let hasVerifier = 1;
548-
}
549-
550555
//===----------------------------------------------------------------------===//
551556
// Sparse Tensor Management Operations. These operations are "impure" in the
552557
// sense that some behavior is defined by side-effects. These operations provide
@@ -803,6 +808,10 @@ def SparseTensor_OutOp : SparseTensor_Op<"out", []>,
803808
let assemblyFormat = "$tensor `,` $dest attr-dict `:` type($tensor) `,` type($dest)";
804809
}
805810

811+
//===----------------------------------------------------------------------===//
812+
// Sparse Tensor Sorting Operations.
813+
//===----------------------------------------------------------------------===//
814+
806815
def SparseTensor_SortOp : SparseTensor_Op<"sort", [AttrSizedOperandSegments]>,
807816
// TODO: May want to extend tablegen with
808817
// class NonemptyVariadic<Type type> : Variadic<type> { let minSize = 1; }

0 commit comments

Comments
 (0)