pub struct ToTensorOperation<'c> { /* private fields */ }
Expand description

A to_tensor operation. Create a tensor from a memref.

An operation that creates a tensor from a memref. The result value is a tensor whose shape and element type match the memref operand.

The opposite of this op is to_memref. Together, these two ops are useful for source/target materializations when doing type conversions involving tensors and memrefs.

Example:

// Produces a value of tensor<4x?xf32> type.
%t = bufferization.to_tensor %m : memref<4x?xf32, #layout, 0>

If the writable unit attribute is set, the produced tensor is considered “writable” during bufferization. Otherwise, every OpOperand that bufferizes to a write to the future buffer of the resulting tensor (or an alias thereof) will bufferize out-of-place to prevent emitting any writes to memref during bufferization.

If the given memref does not alias with any other memref passed to another to_tensor op, the restrict unit attribute can be set. Only such operations are supported by One-Shot Bufferize. (Otherwise, potential memref aliasing relationships would have to be captured in One-Shot Bufferize.)

Example:

%t = bufferization.to_tensor %m restrict writable : memref<4xf32>

// %t is writable, so the tensor.insert may bufferize in-place in the
// absence of other conflicts.
%r = tensor.insert %f into %t[%idx] : tensor<4xf32>

to_tensor ops are not bufferized. They are expected to fold away after bufferization. If there are non-bufferizable ops in the IR and allowUnknownOps is set, they may be part of the resulting IR and not fold away. However, such IR is no longer bufferizable with One-Shot Bufferize.

Implementations§

source§

impl<'c> ToTensorOperation<'c>

source

pub fn name() -> &'static str

Returns a name.

source

pub fn as_operation(&self) -> &Operation<'c>

Returns a generic operation.

source

pub fn builder( context: &'c Context, location: Location<'c> ) -> ToTensorOperationBuilder<'c, Unset, Unset>

Creates a builder.

source

pub fn result(&self) -> Result<OperationResult<'c, '_>, Error>

source

pub fn memref(&self) -> Result<Value<'c, '_>, Error>

source

pub fn restrict(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_restrict(&mut self, value: Attribute<'c>)

source

pub fn remove_restrict(&mut self) -> Result<(), Error>

source

pub fn writable(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_writable(&mut self, value: Attribute<'c>)

source

pub fn remove_writable(&mut self) -> Result<(), Error>

Trait Implementations§

source§

impl<'c> From<ToTensorOperation<'c>> for Operation<'c>

source§

fn from(operation: ToTensorOperation<'c>) -> Self

Converts to this type from the input type.
source§

impl<'c> TryFrom<Operation<'c>> for ToTensorOperation<'c>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(operation: Operation<'c>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'c> RefUnwindSafe for ToTensorOperation<'c>

§

impl<'c> !Send for ToTensorOperation<'c>

§

impl<'c> !Sync for ToTensorOperation<'c>

§

impl<'c> Unpin for ToTensorOperation<'c>

§

impl<'c> UnwindSafe for ToTensorOperation<'c>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.