Struct melior::dialect::ods::bufferization::AllocTensorOperation
source · pub struct AllocTensorOperation<'c> { /* private fields */ }
Expand description
An alloc_tensor
operation. Allocate buffer for a tensor.
bufferization.alloc_tensor
materializes an uninitialized tensor with a
given shape (dynamic or static). It always bufferizes to a new buffer
allocation of the given shape. The optional copy
operand specifies the
contents of the tensors. If no copy
operand is specified, reading from the
result of an alloc_tensor
op yields an undefined value.
If copy
is specified, no dynamic sizes should be passed, since they are
the same as the dynamic sizes of the copy
operand.
alloc_tensor
is a helper op for bufferization. The operation is provided
as an anchor that marks the beginning of a new tensor SSA use-def chain. It
can be used to control in-place bufferization decisions during One-Shot
Bufferize: The bufferized result of a bufferization.alloc_tensor
does not
alias with any other buffer, so it can be used to resolve read-after-write
conflicts that would have been introduced by the in-place bufferization of
another op.
The optional memory_space
attribute specifies the memory space when
bufferizing this op. The memory space is inferred from copy
if specified.
If neither copy
nor memory_space
is specified, the default memory space
is used during bufferization.
The optional size_hint
operand specifies the number of non-zero elements
for sparse tensors. The value of size_hint
should be not less than 1 and
not larger than the linear size of the corresponding dense tensor type. If
this requirement is not met, the behavior of the operator is undefined.
Both dense and sparse tensor types are supported. The result of a
bufferization.alloc_tensor
is a tensor value that can be used like any
other tensor value. In practice, it is often used as the “out” operand of
another op. Sparse tensor allocations should always be used in a local
construction operation and never escape the function boundary directly.
Example:
%c = bufferization.alloc_tensor(%d1, %d2) : tensor<?x?xf32, #SparseMatrix>
%0 = linalg.matmul
ins(%a, %b: tensor<?x?xf32, #SparseMatrix>, tensor<?x?xf32, #SparseMatrix>)
outs(%c: tensor<?x?xf32, #SparseMatrix>) -> tensor<?x?xf32, #SparseMatrix>
return %0 : tensor<?x?xf32, #SparseMatrix>
%c = bufferization.alloc_tensor(%d1, %d2) size_hint = %noe
: tensor<?x?xf32, #SparseMatrix>
Note: An alloc_tensor
with a copy
should also be expressed as an
alloc_tensor
without copy
, followed by a copy_tensor
.
Implementations§
source§impl<'c> AllocTensorOperation<'c>
impl<'c> AllocTensorOperation<'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>
) -> AllocTensorOperationBuilder<'c, Unset, Unset>
pub fn builder( context: &'c Context, location: Location<'c> ) -> AllocTensorOperationBuilder<'c, Unset, Unset>
Creates a builder.