diff options
author | Aart Bik <ajcbik@google.com> | 2023-05-11 18:43:47 -0700 |
---|---|---|
committer | Aart Bik <ajcbik@google.com> | 2023-05-12 09:06:56 -0700 |
commit | ea7ee9d924cedfefe8b5574adf445cafe938c8eb (patch) | |
tree | b7fd5eb0b7bb91d465e2004cce8e9e78e8e3969c /mlir/include | |
parent | a983ef2c1743d8c8240b83ab307d7adcbaa73693 (diff) | |
download | llvm-ea7ee9d924cedfefe8b5574adf445cafe938c8eb.tar.gz |
[mlir][sparse] minor reorg of sparse tensor tablegen defs
Reviewed By: Peiming
Differential Revision: https://reviews.llvm.org/D150414
Diffstat (limited to 'mlir/include')
-rw-r--r-- | mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td | 103 |
1 files changed, 56 insertions, 47 deletions
diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td index ab630b80a794..180bd8bfd1f5 100644 --- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td +++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td @@ -358,6 +358,52 @@ def SparseTensor_ToValuesOp : SparseTensor_Op<"values", [Pure]>, let hasVerifier = 1; } +def SparseTensor_NumberOfEntriesOp : SparseTensor_Op<"number_of_entries", [Pure]>, + Arguments<(ins AnySparseTensor:$tensor)>, + Results<(outs Index:$result)> { + let summary = "Returns the number of entries that are stored in the tensor."; + let description = [{ + Returns the number of entries that are stored in the given sparse tensor. + Note that this is typically the number of nonzero elements in the tensor, + but since explicit zeros may appear in the storage formats, the more + accurate nomenclature is used. + + Example: + + ```mlir + %noe = sparse_tensor.number_of_entries %tensor : tensor<64x64xf64, #CSR> + ``` + }]; + let assemblyFormat = "$tensor attr-dict `:` type($tensor)"; +} + +def SparseTensor_ConcatenateOp : SparseTensor_Op<"concatenate", [Pure]>, + Arguments<(ins Variadic<AnyRankedTensor>:$inputs, DimensionAttr:$dimension)>, + Results<(outs AnyRankedTensor:$result)> { + + let summary = "Concatenates a list of tensors into a single tensor."; + let description = [{ + Concatenates a list input tensors and the output tensor with the same + dimension-rank. The concatenation happens on the specified `dimension` + (0 <= dimension < dimRank). The resulting `dimension` size is the + sum of all the input sizes for that dimension, while all the other + dimensions should have the same size in the input and output tensors. + + Only statically-sized input tensors are accepted, while the output tensor + can be dynamically-sized. + + Example: + + ```mlir + %0 = sparse_tensor.concatenate %1, %2 { dimension = 0 : index } + : tensor<64x64xf64, #CSR>, tensor<64x64xf64, #CSR> to tensor<128x64xf64, #CSR> + ``` + }]; + + let assemblyFormat = "$inputs attr-dict `:` type($inputs) `to` type($result)"; + let hasVerifier = 1; +} + def SparseTensor_ToSliceOffsetOp : SparseTensor_Op<"slice.offset", [Pure]>, Arguments<(ins AnySparseTensorSlice:$slice, IndexAttr:$dim)>, Results<(outs Index:$offset)> { @@ -413,7 +459,12 @@ def SparseTensor_ToSliceStrideOp : SparseTensor_Op<"slice.stride", [Pure]>, let hasVerifier = 1; } -def SparseTensor_StorageSpecifierInitOp : SparseTensor_Op<"storage_specifier.init", [Pure]>, +//===----------------------------------------------------------------------===// +// Sparse Tensor Storage Specifier Operations. +//===----------------------------------------------------------------------===// + +def SparseTensor_StorageSpecifierInitOp : SparseTensor_Op<"storage_specifier.init", + [Pure]>, Arguments<(ins Optional<SparseTensorStorageSpecifier>:$source)>, Results<(outs SparseTensorStorageSpecifier:$result)> { let summary = ""; @@ -501,52 +552,6 @@ def SparseTensor_SetStorageSpecifierOp : SparseTensor_Op<"storage_specifier.set" let hasVerifier = 1; } -def SparseTensor_NumberOfEntriesOp : SparseTensor_Op<"number_of_entries", [Pure]>, - Arguments<(ins AnySparseTensor:$tensor)>, - Results<(outs Index:$result)> { - let summary = "Returns the number of entries that are stored in the tensor."; - let description = [{ - Returns the number of entries that are stored in the given sparse tensor. - Note that this is typically the number of nonzero elements in the tensor, - but since explicit zeros may appear in the storage formats, the more - accurate nomenclature is used. - - Example: - - ```mlir - %noe = sparse_tensor.number_of_entries %tensor : tensor<64x64xf64, #CSR> - ``` - }]; - let assemblyFormat = "$tensor attr-dict `:` type($tensor)"; -} - -def SparseTensor_ConcatenateOp : SparseTensor_Op<"concatenate", [Pure]>, - Arguments<(ins Variadic<AnyRankedTensor>:$inputs, DimensionAttr:$dimension)>, - Results<(outs AnyRankedTensor:$result)> { - - let summary = "Concatenates a list of tensors into a single tensor."; - let description = [{ - Concatenates a list input tensors and the output tensor with the same - dimension-rank. The concatenation happens on the specified `dimension` - (0 <= dimension < dimRank). The resulting `dimension` size is the - sum of all the input sizes for that dimension, while all the other - dimensions should have the same size in the input and output tensors. - - Only statically-sized input tensors are accepted, while the output tensor - can be dynamically-sized. - - Example: - - ```mlir - %0 = sparse_tensor.concatenate %1, %2 { dimension = 0 : index } - : tensor<64x64xf64, #CSR>, tensor<64x64xf64, #CSR> to tensor<128x64xf64, #CSR> - ``` - }]; - - let assemblyFormat = "$inputs attr-dict `:` type($inputs) `to` type($result)"; - let hasVerifier = 1; -} - //===----------------------------------------------------------------------===// // Sparse Tensor Management Operations. These operations are "impure" in the // sense that some behavior is defined by side-effects. These operations provide @@ -803,6 +808,10 @@ def SparseTensor_OutOp : SparseTensor_Op<"out", []>, let assemblyFormat = "$tensor `,` $dest attr-dict `:` type($tensor) `,` type($dest)"; } +//===----------------------------------------------------------------------===// +// Sparse Tensor Sorting Operations. +//===----------------------------------------------------------------------===// + def SparseTensor_SortOp : SparseTensor_Op<"sort", [AttrSizedOperandSegments]>, // TODO: May want to extend tablegen with // class NonemptyVariadic<Type type> : Variadic<type> { let minSize = 1; } |