Struct melior::dialect::ods::sparse_tensor::ReduceOperation
source · pub struct ReduceOperation<'c> { /* private fields */ }
Expand description
A reduce
operation. Custom reduction operation utilized within linalg.generic.
Defines a computation with a linalg.generic
operation that takes two
operands and an identity value and reduces all stored values down to a
single result based on the computation in the region.
The region must contain exactly one block taking two arguments. The block must end with a sparse_tensor.yield and the output must match the input argument types.
Note that this operation is only required for custom reductions beyond
the standard reduction operations (add, sub, or, xor) that can be
sparsified by merely reducing the stored values. More elaborate reduction
operations (mul, and, min, max, etc.) would need to account for implicit
zeros as well. They can still be handled using this custom reduction
operation. The linalg.generic
iterator_types
defines which indices
are being reduced. When the associated operands are used in an operation,
a reduction will occur. The use of this explicit reduce
operation
is not required in most cases.
Example of Matrix->Vector reduction using max(product(x_i), 100):
%cf1 = arith.constant 1.0 : f64
%cf100 = arith.constant 100.0 : f64
%C = bufferization.alloc_tensor...
%0 = linalg.generic #trait
ins(%A: tensor<?x?xf64, #SparseMatrix>)
outs(%C: tensor<?xf64, #SparseVector>) {
^bb0(%a: f64, %c: f64) :
%result = sparse_tensor.reduce %c, %a, %cf1 : f64 {
^bb0(%arg0: f64, %arg1: f64):
%0 = arith.mulf %arg0, %arg1 : f64
%cmp = arith.cmpf "ogt", %0, %cf100 : f64
%ret = arith.select %cmp, %cf100, %0 : f64
sparse_tensor.yield %ret : f64
}
linalg.yield %result : f64
} -> tensor<?xf64, #SparseVector>
Implementations§
source§impl<'c> ReduceOperation<'c>
impl<'c> ReduceOperation<'c>
sourcepub fn as_operation(&self) -> &Operation<'c>
pub fn as_operation(&self) -> &Operation<'c>
Returns a generic operation.
sourcepub fn builder(
context: &'c Context,
location: Location<'c>
) -> ReduceOperationBuilder<'c, Unset, Unset, Unset, Unset>
pub fn builder( context: &'c Context, location: Location<'c> ) -> ReduceOperationBuilder<'c, Unset, Unset, Unset, Unset>
Creates a builder.