ReinterpretCastOperation

Struct ReinterpretCastOperation 

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

A reinterpret_cast operation. Memref reinterpret cast operation.

Modify offset, sizes and strides of an unranked/ranked memref.

Example 1:

Consecutive reinterpret_cast operations on memref’s with static dimensions.

We distinguish between underlying memory — the sequence of elements as they appear in the contiguous memory of the memref — and the strided memref, which refers to the underlying memory interpreted according to specified offsets, sizes, and strides.

%result1 = memref.reinterpret_cast %arg0 to
  offset: [9],
  sizes: [4, 4],
  strides: [16, 2]
: memref<8x8xf32, strided<[8, 1], offset: 0>> to
  memref<4x4xf32, strided<[16, 2], offset: 9>>

%result2 = memref.reinterpret_cast %result1 to
  offset: [0],
  sizes: [2, 2],
  strides: [4, 2]
: memref<4x4xf32, strided<[16, 2], offset: 9>> to
  memref<2x2xf32, strided<[4, 2], offset: 0>>

The underlying memory of %arg0 consists of a linear sequence of integers from 1 to 64. Its memref has the following 8x8 elements:

[[1,  2,  3,  4,  5,  6,  7,  8],
[9,  10, 11, 12, 13, 14, 15, 16],
[17, 18, 19, 20, 21, 22, 23, 24],
[25, 26, 27, 28, 29, 30, 31, 32],
[33, 34, 35, 36, 37, 38, 39, 40],
[41, 42, 43, 44, 45, 46, 47, 48],
[49, 50, 51, 52, 53, 54, 55, 56],
[57, 58, 59, 60, 61, 62, 63, 64]]

Following the first reinterpret_cast, the strided memref elements of %result1 are:

[[10, 12, 14, 16],
[26, 28, 30, 32],
[42, 44, 46, 48],
[58, 60, 62, 64]]

Note: The offset and strides are relative to the underlying memory of %arg0.

The second reinterpret_cast results in the following strided memref for %result2:

[[1, 3],
[5, 7]]

Notice that it does not matter if you use %result1 or %arg0 as a source for the second reinterpret_cast operation. Only the underlying memory pointers will be reused.

The offset and stride are relative to the base underlying memory of the memref, starting at 1, not at 10 as seen in the output of %result1. This behavior contrasts with the subview operator, where values are relative to the strided memref (refer to subview examples). Consequently, the second reinterpret_cast behaves as if %arg0 were passed directly as its argument.

Example 2:

memref.reinterpret_cast %ranked to
  offset: [0],
  sizes: [%size0, 10],
  strides: [1, %stride1]
: memref<?x?xf32> to memref<?x10xf32, strided<[1, ?], offset: 0>>

memref.reinterpret_cast %unranked to
  offset: [%offset],
  sizes: [%size0, %size1],
  strides: [%stride0, %stride1]
: memref<*xf32> to memref<?x?xf32, strided<[?, ?], offset: ?>>

This operation creates a new memref descriptor using the base of the source and applying the input arguments to the other metadata. In other words:

%dst = memref.reinterpret_cast %src to
  offset: [%offset],
  sizes: [%sizes],
  strides: [%strides] :
  memref<*xf32> to memref<?x?xf32, strided<[?, ?], offset: ?>>

means that %dst’s descriptor will be:

%dst.base = %src.base
%dst.aligned = %src.aligned
%dst.offset = %offset
%dst.sizes = %sizes
%dst.strides = %strides

Implementations§

Source§

impl<'c> ReinterpretCastOperation<'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>, ) -> ReinterpretCastOperationBuilder<'c, Unset, Unset, Unset, Unset, Unset, Unset, Unset, Unset>

Creates a builder.

Source

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

Source

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

Source

pub fn offsets(&self) -> Result<impl Iterator<Item = Value<'c, '_>>, Error>

Source

pub fn sizes(&self) -> Result<impl Iterator<Item = Value<'c, '_>>, Error>

Source

pub fn strides(&self) -> Result<impl Iterator<Item = Value<'c, '_>>, Error>

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Trait Implementations§

Source§

impl<'c> Clone for ReinterpretCastOperation<'c>

Source§

fn clone(&self) -> ReinterpretCastOperation<'c>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'c> Debug for ReinterpretCastOperation<'c>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'b> From<ReinterpretCastOperation<'b>> for MemRefDialectOperation<'b>

Source§

fn from(op: ReinterpretCastOperation<'b>) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl<'c> PartialEq for ReinterpretCastOperation<'c>

Source§

fn eq(&self, other: &ReinterpretCastOperation<'c>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

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.
Source§

impl<'c> Eq for ReinterpretCastOperation<'c>

Source§

impl<'c> StructuralPartialEq for ReinterpretCastOperation<'c>

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.