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 = %stridesImplementations§
Source§impl<'c> ReinterpretCastOperation<'c>
impl<'c> ReinterpretCastOperation<'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>,
) -> ReinterpretCastOperationBuilder<'c, Unset, Unset, Unset, Unset, Unset, Unset, Unset, Unset>
pub fn builder( context: &'c Context, location: Location<'c>, ) -> ReinterpretCastOperationBuilder<'c, Unset, Unset, Unset, Unset, Unset, Unset, Unset, Unset>
Creates a builder.
pub fn result(&self) -> Result<OperationResult<'c, '_>, Error>
pub fn source(&self) -> Result<Value<'c, '_>, Error>
pub fn offsets(&self) -> Result<impl Iterator<Item = Value<'c, '_>>, Error>
pub fn sizes(&self) -> Result<impl Iterator<Item = Value<'c, '_>>, Error>
pub fn strides(&self) -> Result<impl Iterator<Item = Value<'c, '_>>, Error>
pub fn static_offsets(&self) -> Result<Attribute<'c>, Error>
pub fn set_static_offsets(&mut self, value: Attribute<'c>)
pub fn static_sizes(&self) -> Result<Attribute<'c>, Error>
pub fn set_static_sizes(&mut self, value: Attribute<'c>)
pub fn static_strides(&self) -> Result<Attribute<'c>, Error>
pub fn set_static_strides(&mut self, value: Attribute<'c>)
Trait Implementations§
Source§impl<'c> Clone for ReinterpretCastOperation<'c>
impl<'c> Clone for ReinterpretCastOperation<'c>
Source§fn clone(&self) -> ReinterpretCastOperation<'c>
fn clone(&self) -> ReinterpretCastOperation<'c>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'c> Debug for ReinterpretCastOperation<'c>
impl<'c> Debug for ReinterpretCastOperation<'c>
Source§impl<'b> From<ReinterpretCastOperation<'b>> for MemRefDialectOperation<'b>
impl<'b> From<ReinterpretCastOperation<'b>> for MemRefDialectOperation<'b>
Source§fn from(op: ReinterpretCastOperation<'b>) -> Self
fn from(op: ReinterpretCastOperation<'b>) -> Self
Source§impl<'c> From<ReinterpretCastOperation<'c>> for Operation<'c>
impl<'c> From<ReinterpretCastOperation<'c>> for Operation<'c>
Source§fn from(operation: ReinterpretCastOperation<'c>) -> Self
fn from(operation: ReinterpretCastOperation<'c>) -> Self
Source§impl<'c> PartialEq for ReinterpretCastOperation<'c>
impl<'c> PartialEq for ReinterpretCastOperation<'c>
Source§fn eq(&self, other: &ReinterpretCastOperation<'c>) -> bool
fn eq(&self, other: &ReinterpretCastOperation<'c>) -> bool
self and other values to be equal, and is used by ==.