mlir.dialects._memref_ops_gen ============================= .. py:module:: mlir.dialects._memref_ops_gen Attributes ---------- .. autoapisummary:: mlir.dialects._memref_ops_gen._ods_ir Classes ------- .. autoapisummary:: mlir.dialects._memref_ops_gen._Dialect mlir.dialects._memref_ops_gen.AssumeAlignmentOp mlir.dialects._memref_ops_gen.AtomicRMWOp mlir.dialects._memref_ops_gen.AtomicYieldOp mlir.dialects._memref_ops_gen.CopyOp mlir.dialects._memref_ops_gen.DistinctObjectsOp mlir.dialects._memref_ops_gen.GenericAtomicRMWOp mlir.dialects._memref_ops_gen.LoadOp mlir.dialects._memref_ops_gen.AllocOp mlir.dialects._memref_ops_gen.AllocaOp mlir.dialects._memref_ops_gen.AllocaScopeOp mlir.dialects._memref_ops_gen.AllocaScopeReturnOp mlir.dialects._memref_ops_gen.CastOp mlir.dialects._memref_ops_gen.CollapseShapeOp mlir.dialects._memref_ops_gen.DeallocOp mlir.dialects._memref_ops_gen.DimOp mlir.dialects._memref_ops_gen.DmaStartOp mlir.dialects._memref_ops_gen.DmaWaitOp mlir.dialects._memref_ops_gen.ExpandShapeOp mlir.dialects._memref_ops_gen.ExtractAlignedPointerAsIndexOp mlir.dialects._memref_ops_gen.ExtractStridedMetadataOp mlir.dialects._memref_ops_gen.GetGlobalOp mlir.dialects._memref_ops_gen.GlobalOp mlir.dialects._memref_ops_gen.MemorySpaceCastOp mlir.dialects._memref_ops_gen.PrefetchOp mlir.dialects._memref_ops_gen.RankOp mlir.dialects._memref_ops_gen.ReallocOp mlir.dialects._memref_ops_gen.ReinterpretCastOp mlir.dialects._memref_ops_gen.ReshapeOp mlir.dialects._memref_ops_gen.StoreOp mlir.dialects._memref_ops_gen.TransposeOp mlir.dialects._memref_ops_gen.ViewOp mlir.dialects._memref_ops_gen.SubViewOp Functions --------- .. autoapisummary:: mlir.dialects._memref_ops_gen.assume_alignment mlir.dialects._memref_ops_gen.atomic_rmw mlir.dialects._memref_ops_gen.atomic_yield mlir.dialects._memref_ops_gen.copy mlir.dialects._memref_ops_gen.distinct_objects mlir.dialects._memref_ops_gen.generic_atomic_rmw mlir.dialects._memref_ops_gen.load mlir.dialects._memref_ops_gen.alloc mlir.dialects._memref_ops_gen.alloca mlir.dialects._memref_ops_gen.alloca_scope mlir.dialects._memref_ops_gen.alloca_scope_return mlir.dialects._memref_ops_gen.cast mlir.dialects._memref_ops_gen.collapse_shape mlir.dialects._memref_ops_gen.dealloc mlir.dialects._memref_ops_gen.dim mlir.dialects._memref_ops_gen.dma_start mlir.dialects._memref_ops_gen.dma_wait mlir.dialects._memref_ops_gen.expand_shape mlir.dialects._memref_ops_gen.extract_aligned_pointer_as_index mlir.dialects._memref_ops_gen.extract_strided_metadata mlir.dialects._memref_ops_gen.get_global mlir.dialects._memref_ops_gen.global_ mlir.dialects._memref_ops_gen.memory_space_cast mlir.dialects._memref_ops_gen.prefetch mlir.dialects._memref_ops_gen.rank mlir.dialects._memref_ops_gen.realloc mlir.dialects._memref_ops_gen.reinterpret_cast mlir.dialects._memref_ops_gen.reshape mlir.dialects._memref_ops_gen.store mlir.dialects._memref_ops_gen.transpose mlir.dialects._memref_ops_gen.view mlir.dialects._memref_ops_gen.subview Module Contents --------------- .. py:data:: _ods_ir .. py:class:: _Dialect(descriptor: object) Bases: :py:obj:`_ods_ir` .. py:attribute:: DIALECT_NAMESPACE :value: 'memref' .. py:class:: AssumeAlignmentOp(memref, alignment, *, results=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``assume_alignment`` operation takes a memref and an integer alignment value. It returns a new SSA value of the same memref type, but associated with the assumption that the underlying buffer is aligned to the given alignment. If the buffer isn't aligned to the given alignment, its result is poison. This operation doesn't affect the semantics of a program where the alignment assumption holds true. It is intended for optimization purposes, allowing the compiler to generate more efficient code based on the alignment assumption. The optimization is best-effort. .. py:attribute:: OPERATION_NAME :value: 'memref.assume_alignment' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: memref() -> _ods_ir .. py:method:: alignment() -> _ods_ir .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: assume_alignment(memref, alignment, *, results=None, loc=None, ip=None) -> _ods_ir .. py:class:: AtomicRMWOp(kind, value, memref, indices, *, results=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``memref.atomic_rmw`` operation provides a way to perform a read-modify-write sequence that is free from data races. The kind enumeration specifies the modification to perform. The value operand represents the new value to be applied during the modification. The memref operand represents the buffer that the read and write will be performed against, as accessed by the specified indices. The arity of the indices is the rank of the memref. The result represents the latest value that was stored. Example: .. code:: mlir %x = memref.atomic_rmw "addf" %value, %I[%i] : (f32, memref<10xf32>) -> f32 .. py:attribute:: OPERATION_NAME :value: 'memref.atomic_rmw' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: value() -> _ods_ir .. py:method:: memref() -> _ods_ir .. py:method:: indices() -> _ods_ir .. py:method:: kind() -> _ods_ir .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: atomic_rmw(kind, value, memref, indices, *, results=None, loc=None, ip=None) -> _ods_ir .. py:class:: AtomicYieldOp(result, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` "memref.atomic_yield" yields an SSA value from a GenericAtomicRMWOp region. .. py:attribute:: OPERATION_NAME :value: 'memref.atomic_yield' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: atomic_yield(result, *, loc=None, ip=None) -> AtomicYieldOp .. py:class:: CopyOp(source, target, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` Copies the data from the source to the destination memref. Usage: .. code:: mlir memref.copy %arg0, %arg1 : memref to memref Source and destination are expected to have the same element type and shape. Otherwise, the result is undefined. They may have different layouts. .. py:attribute:: OPERATION_NAME :value: 'memref.copy' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: target() -> _ods_ir .. py:function:: copy(source, target, *, loc=None, ip=None) -> CopyOp .. py:class:: DistinctObjectsOp(operands_, *, results=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``distinct_objects`` operation takes a list of memrefs and returns the same memrefs, with the additional assumption that accesses to them will never alias with each other. This means that loads and stores to different memrefs in the list can be safely reordered. If the memrefs do alias, the load/store behavior is undefined. This operation doesn't affect the semantics of a valid program. It is intended for optimization purposes, allowing the compiler to generate more efficient code based on the non-aliasing assumption. The optimization is best-effort. Example: .. code:: mlir %1, %2 = memref.distinct_objects %a, %b : memref, memref .. py:attribute:: OPERATION_NAME :value: 'memref.distinct_objects' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: operands_() -> _ods_ir .. py:method:: results_() -> _ods_ir .. py:function:: distinct_objects(operands_, *, results=None, loc=None, ip=None) -> Union[_ods_ir, _ods_ir, DistinctObjectsOp] .. py:class:: GenericAtomicRMWOp(result, memref, indices, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``memref.generic_atomic_rmw`` operation provides a way to perform a read-modify-write sequence that is free from data races. The memref operand represents the buffer that the read and write will be performed against, as accessed by the specified indices. The arity of the indices is the rank of the memref. The result represents the latest value that was stored. The region contains the code for the modification itself. The entry block has a single argument that represents the value stored in ``memref[indices]`` before the write is performed. No side-effecting ops are allowed in the body of ``GenericAtomicRMWOp``. Example: .. code:: mlir %x = memref.generic_atomic_rmw %I[%i] : memref<10xf32> { ^bb0(%current_value : f32): %c1 = arith.constant 1.0 : f32 %inc = arith.addf %c1, %current_value : f32 memref.atomic_yield %inc : f32 } .. py:attribute:: OPERATION_NAME :value: 'memref.generic_atomic_rmw' .. py:attribute:: _ODS_REGIONS :value: (1, True) .. py:method:: memref() -> _ods_ir .. py:method:: indices() -> _ods_ir .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:method:: atomic_body() -> _ods_ir .. py:function:: generic_atomic_rmw(result, memref, indices, *, loc=None, ip=None) -> _ods_ir .. py:class:: LoadOp(memref, indices, *, nontemporal=None, alignment=None, results=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``load`` op reads an element from a memref at the specified indices. The number of indices must match the rank of the memref. The indices must be in-bounds: ``0 <= idx < dim_size``. Lowerings of ``memref.load`` may emit attributes, e.g. ``inbouds`` + ``nuw`` when converting to LLVM's ``llvm.getelementptr``, that would cause undefined behavior if indices are out of bounds or if computing the offset in the memref would cause signed overflow of the ``index`` type. The single result of ``memref.load`` is a value with the same type as the element type of the memref. A set ``nontemporal`` attribute indicates that this load is not expected to be reused in the cache. For details, refer to the `LLVM load instruction `_. An optional ``alignment`` attribute allows to specify the byte alignment of the load operation. It must be a positive power of 2. The operation must access memory at an address aligned to this boundary. Violations may lead to architecture-specific faults or performance penalties. A value of 0 indicates no specific alignment requirement. Example: .. code:: mlir %0 = memref.load %A[%a, %b] : memref<8x?xi32, #layout, memspace0> .. py:attribute:: OPERATION_NAME :value: 'memref.load' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: memref() -> _ods_ir .. py:method:: indices() -> _ods_ir .. py:method:: nontemporal() -> Optional[_ods_ir] .. py:method:: alignment() -> Optional[_ods_ir] .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: load(memref, indices, *, nontemporal=None, alignment=None, results=None, loc=None, ip=None) -> _ods_ir .. py:class:: AllocOp(memref, dynamicSizes, symbolOperands, *, alignment=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``alloc`` operation allocates a region of memory, as specified by its memref type. Example: .. code:: mlir %0 = memref.alloc() : memref<8x64xf32, 1> The optional list of dimension operands are bound to the dynamic dimensions specified in its memref type. In the example below, the ssa value '%d' is bound to the second dimension of the memref (which is dynamic). .. code:: mlir %0 = memref.alloc(%d) : memref<8x?xf32, 1> The optional list of symbol operands are bound to the symbols of the memrefs affine map. In the example below, the ssa value '%s' is bound to the symbol 's0' in the affine map specified in the allocs memref type. .. code:: mlir %0 = memref.alloc()[%s] : memref<8x64xf32, affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>, 1> This operation returns a single ssa value of memref type, which can be used by subsequent load and store operations. The optional ``alignment`` attribute may be specified to ensure that the region of memory that will be indexed is aligned at the specified byte boundary. .. code:: mlir %0 = memref.alloc()[%s] {alignment = 8} : memref<8x64xf32, affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>, 1> .. py:attribute:: OPERATION_NAME :value: 'memref.alloc' .. py:attribute:: _ODS_OPERAND_SEGMENTS .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: dynamicSizes() -> _ods_ir .. py:method:: symbolOperands() -> _ods_ir .. py:method:: alignment() -> Optional[_ods_ir] .. py:method:: memref() -> _ods_ir .. py:function:: alloc(memref, dynamic_sizes, symbol_operands, *, alignment=None, loc=None, ip=None) -> _ods_ir .. py:class:: AllocaOp(memref, dynamicSizes, symbolOperands, *, alignment=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``alloca`` operation allocates memory on the stack, to be automatically released when control transfers back from the region of its closest surrounding operation with an ```AutomaticAllocationScope`` <../Traits/#automaticallocationscope>`_ trait. The amount of memory allocated is specified by its memref and additional operands. For example: .. code:: mlir %0 = memref.alloca() : memref<8x64xf32> The optional list of dimension operands are bound to the dynamic dimensions specified in its memref type. In the example below, the SSA value '%d' is bound to the second dimension of the memref (which is dynamic). .. code:: mlir %0 = memref.alloca(%d) : memref<8x?xf32> The optional list of symbol operands are bound to the symbols of the memref's affine map. In the example below, the SSA value '%s' is bound to the symbol 's0' in the affine map specified in the allocs memref type. .. code:: mlir %0 = memref.alloca()[%s] : memref<8x64xf32, affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>> This operation returns a single SSA value of memref type, which can be used by subsequent load and store operations. An optional alignment attribute, if specified, guarantees alignment at least to that boundary. If not specified, an alignment on any convenient boundary compatible with the type will be chosen. .. py:attribute:: OPERATION_NAME :value: 'memref.alloca' .. py:attribute:: _ODS_OPERAND_SEGMENTS .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: dynamicSizes() -> _ods_ir .. py:method:: symbolOperands() -> _ods_ir .. py:method:: alignment() -> Optional[_ods_ir] .. py:method:: memref() -> _ods_ir .. py:function:: alloca(memref, dynamic_sizes, symbol_operands, *, alignment=None, loc=None, ip=None) -> _ods_ir .. py:class:: AllocaScopeOp(results_, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``memref.alloca_scope`` operation represents an explicitly-delimited scope for the alloca allocations. Any ``memref.alloca`` operations that are used within this scope are going to be cleaned up automatically once the control-flow exits the nested region. For example: .. code:: mlir memref.alloca_scope { %myalloca = memref.alloca(): memref<4x3xf32> ... } Here, ``%myalloca`` memref is valid within the explicitly delimited scope and is automatically deallocated at the end of the given region. Conceptually, ``memref.alloca_scope`` is a passthrough operation with ``AutomaticAllocationScope`` that spans the body of the region within the operation. ``memref.alloca_scope`` may also return results that are defined in the nested region. To return a value, one should use ``memref.alloca_scope.return`` operation: .. code:: mlir %result = memref.alloca_scope -> f32 { %value = arith.constant 1.0 : f32 ... memref.alloca_scope.return %value : f32 } If ``memref.alloca_scope`` returns no value, the ``memref.alloca_scope.return `` can be left out, and will be inserted implicitly. .. py:attribute:: OPERATION_NAME :value: 'memref.alloca_scope' .. py:attribute:: _ODS_REGIONS :value: (1, True) .. py:method:: results_() -> _ods_ir .. py:method:: bodyRegion() -> _ods_ir .. py:function:: alloca_scope(results_, *, loc=None, ip=None) -> Union[_ods_ir, _ods_ir, AllocaScopeOp] .. py:class:: AllocaScopeReturnOp(results_, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` ``memref.alloca_scope.return`` operation returns zero or more SSA values from the region within ``memref.alloca_scope``. If no values are returned, the return operation may be omitted. Otherwise, it has to be present to indicate which values are going to be returned. For example: .. code:: mlir memref.alloca_scope.return %value : f32 .. py:attribute:: OPERATION_NAME :value: 'memref.alloca_scope.return' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: results_() -> _ods_ir .. py:function:: alloca_scope_return(results_, *, loc=None, ip=None) -> AllocaScopeReturnOp .. py:class:: CastOp(dest, source, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``memref.cast`` operation converts a memref from one type to an equivalent type with a compatible shape. The source and destination types are compatible if: a. Both are ranked memref types with the same element type, address space, and rank and: #. Both have the same layout or both have compatible strided layouts. #. The individual sizes (resp. offset and strides in the case of strided memrefs) may convert constant dimensions to dynamic dimensions and vice-versa. If the cast converts any dimensions from an unknown to a known size, then it acts as an assertion that fails at runtime if the dynamic dimensions disagree with resultant destination size. Example: .. code:: mlir // Assert that the input dynamic shape matches the destination static shape. %2 = memref.cast %1 : memref to memref<4x4xf32> // Erase static shape information, replacing it with dynamic information. %3 = memref.cast %1 : memref<4xf32> to memref // The same holds true for offsets and strides. // Assert that the input dynamic shape matches the destination static stride. %4 = memref.cast %1 : memref<12x4xf32, strided<[?, ?], offset: ?>> to memref<12x4xf32, strided<[4, 1], offset: 5>> // Erase static offset and stride information, replacing it with // dynamic information. %5 = memref.cast %1 : memref<12x4xf32, strided<[4, 1], offset: 5>> to memref<12x4xf32, strided<[?, ?], offset: ?>> b. Either or both memref types are unranked with the same element type, and address space. Example: .. code:: mlir // Cast to concrete shape. %4 = memref.cast %1 : memref<*xf32> to memref<4x?xf32> // Erase rank information. %5 = memref.cast %1 : memref<4x?xf32> to memref<*xf32> .. py:attribute:: OPERATION_NAME :value: 'memref.cast' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: dest() -> _ods_ir .. py:function:: cast(dest, source, *, loc=None, ip=None) -> _ods_ir .. py:class:: CollapseShapeOp(result, src, reassociation, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``memref.collapse_shape`` op produces a new view with a smaller rank whose sizes are a reassociation of the original ``view``. The operation is limited to such reassociations, where subsequent, contiguous dimensions are collapsed into a single dimension. Such reassociations never require additional allocs or copies. Collapsing non-contiguous dimensions is undefined behavior. When a group of dimensions can be statically proven to be non-contiguous, collapses of such groups are rejected in the verifier on a best-effort basis. In the general case, collapses of dynamically-sized dims with dynamic strides cannot be proven to be contiguous or non-contiguous due to limitations in the memref type. A reassociation is defined as a continuous grouping of dimensions and is represented with an array of DenseI64ArrayAttr attribute. Note: Only the dimensions within a reassociation group must be contiguous. The remaining dimensions may be non-contiguous. The result memref type can be zero-ranked if the source memref type is statically shaped with all dimensions being unit extent. In such a case, the reassociation indices must be empty. Examples: .. code:: mlir // Dimension collapse (i, j) -> i' and k -> k' %1 = memref.collapse_shape %0 [[0, 1], [2]] : memref into memref For simplicity, this op may not be used to cast dynamicity of dimension sizes and/or strides. I.e., a result dimension must be dynamic if and only if at least one dimension in the corresponding reassociation group is dynamic. Similarly, the stride of a result dimension must be dynamic if and only if the corresponding start dimension in the source type is dynamic. Note: This op currently assumes that the inner strides are of the source/result layout map are the faster-varying ones. .. py:attribute:: OPERATION_NAME :value: 'memref.collapse_shape' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: src() -> _ods_ir .. py:method:: reassociation() -> _ods_ir .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: collapse_shape(result, src, reassociation, *, loc=None, ip=None) -> _ods_ir .. py:class:: DeallocOp(memref, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``dealloc`` operation frees the region of memory referenced by a memref which was originally created by the ``alloc`` operation. The ``dealloc`` operation should not be called on memrefs which alias an alloc'd memref (e.g. memrefs returned by ``view`` operations). Example: .. code:: mlir %0 = memref.alloc() : memref<8x64xf32, affine_map<(d0, d1) -> (d0, d1)>, 1> memref.dealloc %0 : memref<8x64xf32, affine_map<(d0, d1) -> (d0, d1)>, 1> .. py:attribute:: OPERATION_NAME :value: 'memref.dealloc' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: memref() -> _ods_ir .. py:function:: dealloc(memref, *, loc=None, ip=None) -> DeallocOp .. py:class:: DimOp(source, index, *, results=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``dim`` operation takes a memref and a dimension operand of type ``index``. It returns the size of the requested dimension of the given memref. If the dimension index is out of bounds the behavior is undefined. The specified memref type is that of the first operand. Example: .. code:: mlir // Always returns 4, can be constant folded: %c0 = arith.constant 0 : index %x = memref.dim %A, %c0 : memref<4 x ? x f32> // Returns the dynamic dimension of %A. %c1 = arith.constant 1 : index %y = memref.dim %A, %c1 : memref<4 x ? x f32> // Equivalent generic form: %x = "memref.dim"(%A, %c0) : (memref<4 x ? x f32>, index) -> index %y = "memref.dim"(%A, %c1) : (memref<4 x ? x f32>, index) -> index .. py:attribute:: OPERATION_NAME :value: 'memref.dim' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: index() -> _ods_ir .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: dim(source, index, *, results=None, loc=None, ip=None) -> _ods_ir .. py:class:: DmaStartOp(operands_, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` Syntax: .. code:: operation ::= `memref.dma_start` ssa-use`[`ssa-use-list`]` `,` ssa-use`[`ssa-use-list`]` `,` ssa-use `,` ssa-use`[`ssa-use-list`]` (`,` ssa-use `,` ssa-use)? `:` memref-type `,` memref-type `,` memref-type DmaStartOp starts a non-blocking DMA operation that transfers data from a source memref to a destination memref. The source and destination memref need not be of the same dimensionality, but need to have the same elemental type. The operands include the source and destination memref's each followed by its indices, size of the data transfer in terms of the number of elements (of the elemental type of the memref), a tag memref with its indices, and optionally at the end, a stride and a number_of_elements_per_stride arguments. The tag location is used by a DmaWaitOp to check for completion. The indices of the source memref, destination memref, and the tag memref have the same restrictions as any load/store. The optional stride arguments should be of 'index' type, and specify a stride for the slower memory space (memory space with a lower memory space id), transferring chunks of number_of_elements_per_stride every stride until %num_elements are transferred. Either both or no stride arguments should be specified. If the source and destination locations overlap the behavior of this operation is not defined. For example, a DmaStartOp operation that transfers 256 elements of a memref '%src' in memory space 0 at indices [%i, %j] to memref '%dst' in memory space 1 at indices [%k, %l], would be specified as follows: .. code:: mlir %num_elements = arith.constant 256 : index %idx = arith.constant 0 : index %tag = memref.alloc() : memref<1 x i32, affine_map<(d0) -> (d0)>, 2> memref.dma_start %src[%i, %j], %dst[%k, %l], %num_elements, %tag[%idx] : memref<40 x 128 x f32, affine_map<(d0, d1) -> (d0, d1)>, 0>, memref<2 x 1024 x f32, affine_map<(d0, d1) -> (d0, d1)>, 1>, memref<1 x i32, affine_map<(d0) -> (d0)>, 2> If %stride and %num_elt_per_stride are specified, the DMA is expected to transfer %num_elt_per_stride elements every %stride elements apart from memory space 0 until %num_elements are transferred. .. code:: mlir memref.dma_start %src[%i, %j], %dst[%k, %l], %num_elements, %tag[%idx], %stride, %num_elt_per_stride : * TODO: add additional operands to allow source and destination striding, and multiple stride levels. * TODO: Consider replacing src/dst memref indices with view memrefs. .. py:attribute:: OPERATION_NAME :value: 'memref.dma_start' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: operands_() -> _ods_ir .. py:function:: dma_start(operands_, *, loc=None, ip=None) -> DmaStartOp .. py:class:: DmaWaitOp(tagMemRef, tagIndices, numElements, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` DmaWaitOp blocks until the completion of a DMA operation associated with the tag element '%tag[%index]'. %tag is a memref, and %index has to be an index with the same restrictions as any load/store index. %num_elements is the number of elements associated with the DMA operation. Example: .. code:: mlir memref.dma_start %src[%i, %j], %dst[%k, %l], %num_elements, %tag[%index] : memref<2048 x f32, affine_map<(d0) -> (d0)>, 0>, memref<256 x f32, affine_map<(d0) -> (d0)>, 1>, memref<1 x i32, affine_map<(d0) -> (d0)>, 2> ... ... dma_wait %tag[%index], %num_elements : memref<1 x i32, affine_map<(d0) -> (d0)>, 2> .. py:attribute:: OPERATION_NAME :value: 'memref.dma_wait' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: tagMemRef() -> _ods_ir .. py:method:: tagIndices() -> _ods_ir .. py:method:: numElements() -> _ods_ir .. py:function:: dma_wait(tag_mem_ref, tag_indices, num_elements, *, loc=None, ip=None) -> DmaWaitOp .. py:class:: ExpandShapeOp(result, src, reassociation, output_shape, static_output_shape, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``memref.expand_shape`` op produces a new view with a higher rank whose sizes are a reassociation of the original ``view``. The operation is limited to such reassociations, where a dimension is expanded into one or multiple contiguous dimensions. Such reassociations never require additional allocs or copies. A reassociation is defined as a grouping of dimensions and is represented with an array of DenseI64ArrayAttr attributes. Example: .. code:: mlir %r = memref.expand_shape %0 [[0, 1], [2]] output_shape [%sz0, %sz1, 32] : memref into memref If an op can be statically proven to be invalid (e.g, an expansion from ``memref<10xf32>`` to ``memref<2x6xf32>``), it is rejected by the verifier. If it cannot statically be proven invalid (e.g., the full example above; it is unclear whether the first source dimension is divisible by 5), the op is accepted by the verifier. However, if the op is in fact invalid at runtime, the behavior is undefined. The source memref can be zero-ranked. In that case, the reassociation indices must be empty and the result shape may only consist of unit dimensions. For simplicity, this op may not be used to cast dynamicity of dimension sizes and/or strides. I.e., if and only if a source dimension is dynamic, there must be a dynamic result dimension in the corresponding reassociation group. Same for strides. The representation for the output shape supports a partially-static specification via attributes specified through the ``static_output_shape`` argument. A special sentinel value ``ShapedType::kDynamic`` encodes that the corresponding entry has a dynamic value. There must be exactly as many SSA inputs in ``output_shape`` as there are ``ShapedType::kDynamic`` entries in ``static_output_shape``. Note: This op currently assumes that the inner strides are of the source/result layout map are the faster-varying ones. .. py:attribute:: OPERATION_NAME :value: 'memref.expand_shape' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: src() -> _ods_ir .. py:method:: output_shape() -> _ods_ir .. py:method:: reassociation() -> _ods_ir .. py:method:: static_output_shape() -> _ods_ir .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: expand_shape(result, src, reassociation, output_shape, static_output_shape, *, loc=None, ip=None) -> _ods_ir .. py:class:: ExtractAlignedPointerAsIndexOp(source, *, results=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` Extracts the underlying aligned pointer as an index. This operation is useful for lowering to lower-level dialects while still avoiding the need to define a pointer type in higher-level dialects such as the memref dialect. This operation is intended solely as step during lowering, it has no side effects. A reverse operation that creates a memref from an index interpreted as a pointer is explicitly discouraged. Example: .. code:: %0 = memref.extract_aligned_pointer_as_index %arg : memref<4x4xf32> -> index %1 = arith.index_cast %0 : index to i64 %2 = llvm.inttoptr %1 : i64 to !llvm.ptr call @foo(%2) : (!llvm.ptr) ->() .. py:attribute:: OPERATION_NAME :value: 'memref.extract_aligned_pointer_as_index' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: aligned_pointer() -> _ods_ir .. py:function:: extract_aligned_pointer_as_index(source, *, results=None, loc=None, ip=None) -> _ods_ir .. py:class:: ExtractStridedMetadataOp(source, *, results=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` Extracts a base buffer, offset and strides. This op allows additional layers of transformations and foldings to be added as lowering progresses from higher-level dialect to lower-level dialects such as the LLVM dialect. The op requires a strided memref source operand. If the source operand is not a strided memref, then verification fails. This operation is also useful for completeness to the existing memref.dim op. While accessing strides, offsets and the base pointer independently is not available, this is useful for composing with its natural complement op: ``memref.reinterpret_cast``. Intended Use Cases: The main use case is to expose the logic for manipulate memref metadata at a higher level than the LLVM dialect. This makes lowering more progressive and brings the following benefits: * not all users of MLIR want to lower to LLVM and the information to e.g. lower to library calls---like libxsmm---or to SPIR-V was not available. * foldings and canonicalizations can happen at a higher level in MLIR: before this op existed, lowering to LLVM would create large amounts of LLVMIR. Even when LLVM does a good job at folding the low-level IR from a performance perspective, it is unnecessarily opaque and inefficient to send unkempt IR to LLVM. Example: .. code:: mlir %base, %offset, %sizes:2, %strides:2 = memref.extract_strided_metadata %memref : memref<10x?xf32> -> memref, index, index, index, index, index // After folding, the type of %m2 can be memref<10x?xf32> and further // folded to %memref. %m2 = memref.reinterpret_cast %base to offset: [%offset], sizes: [%sizes#0, %sizes#1], strides: [%strides#0, %strides#1] : memref to memref> .. py:attribute:: OPERATION_NAME :value: 'memref.extract_strided_metadata' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: base_buffer() -> _ods_ir .. py:method:: offset() -> _ods_ir .. py:method:: sizes() -> _ods_ir .. py:method:: strides() -> _ods_ir .. py:function:: extract_strided_metadata(source, *, results=None, loc=None, ip=None) -> Union[_ods_ir, _ods_ir, ExtractStridedMetadataOp] .. py:class:: GetGlobalOp(result, name, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``memref.get_global`` operation retrieves the memref pointing to a named global variable. If the global variable is marked constant, writing to the result memref (such as through a ``memref.store`` operation) is undefined. Example: .. code:: mlir %x = memref.get_global @foo : memref<2xf32> .. py:attribute:: OPERATION_NAME :value: 'memref.get_global' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: name() -> _ods_ir Returns the fully qualified name of the operation. .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: get_global(result, name, *, loc=None, ip=None) -> _ods_ir .. py:class:: GlobalOp(sym_name, type_, *, sym_visibility=None, initial_value=None, constant=None, alignment=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``memref.global`` operation declares or defines a named global memref variable. The backing memory for the variable is allocated statically and is described by the type of the variable (which should be a statically shaped memref type). The operation is a declaration if no ``initial_value`` is specified, else it is a definition. The ``initial_value`` can either be a unit attribute to represent a definition of an uninitialized global variable, or an elements attribute to represent the definition of a global variable with an initial value. The global variable can also be marked constant using the ``constant`` unit attribute. Writing to such constant global variables is undefined. The global variable can be accessed by using the ``memref.get_global`` to retrieve the memref for the global variable. Note that the memref for such global variable itself is immutable (i.e., memref.get_global for a given global variable will always return the same memref descriptor). Example: .. code:: mlir // Private variable with an initial value. memref.global "private" @x : memref<2xf32> = dense<[0.0, 2.0]> // Private variable with an initial value and an alignment (power of 2). memref.global "private" @x : memref<2xf32> = dense<[0.0, 2.0]> {alignment = 64} // Declaration of an external variable. memref.global "private" @y : memref<4xi32> // Uninitialized externally visible variable. memref.global @z : memref<3xf16> = uninitialized // Externally visible constant variable. memref.global constant @c : memref<2xi32> = dense<[1, 4]> .. py:attribute:: OPERATION_NAME :value: 'memref.global' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: sym_name() -> _ods_ir .. py:method:: sym_visibility() -> Optional[_ods_ir] .. py:method:: type_() -> _ods_ir .. py:method:: initial_value() -> Optional[_ods_ir] .. py:method:: constant() -> bool .. py:method:: alignment() -> Optional[_ods_ir] .. py:function:: global_(sym_name, type_, *, sym_visibility=None, initial_value=None, constant=None, alignment=None, loc=None, ip=None) -> GlobalOp .. py:class:: MemorySpaceCastOp(dest, source, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` This operation casts memref values between memory spaces. The input and result will be memrefs of the same types and shape that alias the same underlying memory, though, for some casts on some targets, the underlying values of the pointer stored in the memref may be affected by the cast. The input and result must have the same shape, element type, rank, and layout. If the source and target address spaces are the same, this operation is a noop. Finally, if the target memory-space is the generic/default memory-space, then it is assumed this cast can be bubbled down safely. See the docs of ``MemorySpaceCastOpInterface`` interface for more details. Example: .. code:: mlir // Cast a GPU private memory attribution into a generic pointer %2 = memref.memory_space_cast %1 : memref to memref // Cast a generic pointer to workgroup-local memory %4 = memref.memory_space_cast %3 : memref<5x4xi32> to memref<5x34xi32, 3> // Cast between two non-default memory spaces %6 = memref.memory_space_cast %5 : memref<*xmemref, 5> to memref<*xmemref, 3> .. py:attribute:: OPERATION_NAME :value: 'memref.memory_space_cast' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: dest() -> _ods_ir .. py:function:: memory_space_cast(dest, source, *, loc=None, ip=None) -> _ods_ir .. py:class:: PrefetchOp(memref, indices, isWrite, localityHint, isDataCache, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The "prefetch" op prefetches data from a memref location described with subscript indices similar to memref.load, and with three attributes: a read/write specifier, a locality hint, and a cache type specifier as shown below: .. code:: mlir memref.prefetch %0[%i, %j], read, locality<3>, data : memref<400x400xi32> The read/write specifier is either 'read' or 'write', the locality hint ranges from locality<0> (no locality) to locality<3> (extremely local keep in cache). The cache type specifier is either 'data' or 'instr' and specifies whether the prefetch is performed on data cache or on instruction cache. .. py:attribute:: OPERATION_NAME :value: 'memref.prefetch' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: memref() -> _ods_ir .. py:method:: indices() -> _ods_ir .. py:method:: isWrite() -> _ods_ir .. py:method:: localityHint() -> _ods_ir .. py:method:: isDataCache() -> _ods_ir .. py:function:: prefetch(memref, indices, is_write, locality_hint, is_data_cache, *, loc=None, ip=None) -> PrefetchOp .. py:class:: RankOp(memref, *, results=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``memref.rank`` operation takes a memref operand and returns its rank. Example: .. code:: mlir %0 = memref.rank %arg0 : memref<*xf32> %1 = memref.rank %arg1 : memref .. py:attribute:: OPERATION_NAME :value: 'memref.rank' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: memref() -> _ods_ir .. py:function:: rank(memref, *, results=None, loc=None, ip=None) -> _ods_ir .. py:class:: ReallocOp(result, source, *, dynamicResultSize=None, alignment=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``realloc`` operation changes the size of a memory region. The memory region is specified by a 1D source memref and the size of the new memory region is specified by a 1D result memref type and an optional dynamic Value of ``Index`` type. The source and the result memref must be in the same memory space and have the same element type. The operation may move the memory region to a new location. In this case, the content of the memory block is preserved up to the lesser of the new and old sizes. If the new size if larger, the value of the extended memory is undefined. This is consistent with the ISO C realloc. The operation returns an SSA value for the memref. Example: .. code:: mlir %0 = memref.realloc %src : memref<64xf32> to memref<124xf32> The source memref may have a dynamic shape, in which case, the compiler will generate code to extract its size from the runtime data structure for the memref. .. code:: mlir %1 = memref.realloc %src : memref to memref<124xf32> If the result memref has a dynamic shape, a result dimension operand is needed to spefify its dynamic dimension. In the example below, the ssa value '%d' specifies the unknown dimension of the result memref. .. code:: mlir %2 = memref.realloc %src(%d) : memref to memref An optional ``alignment`` attribute may be specified to ensure that the region of memory that will be indexed is aligned at the specified byte boundary. This is consistent with the fact that memref.alloc supports such an optional alignment attribute. Note that in ISO C standard, neither alloc nor realloc supports alignment, though there is aligned_alloc but not aligned_realloc. .. code:: mlir %3 = memref.realloc %src {alignment = 8} : memref<64xf32> to memref<124xf32> Referencing the memref through the old SSA value after realloc is undefined behavior. .. code:: mlir %new = memref.realloc %old : memref<64xf32> to memref<124xf32> %4 = memref.load %new[%index] : memref<124xf32> // ok %5 = memref.load %old[%index] : memref<64xf32> // undefined behavior .. py:attribute:: OPERATION_NAME :value: 'memref.realloc' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: dynamicResultSize() -> Optional[_ods_ir] .. py:method:: alignment() -> Optional[_ods_ir] .. py:function:: realloc(result, source, *, dynamic_result_size=None, alignment=None, loc=None, ip=None) -> _ods_ir .. py:class:: ReinterpretCastOp(result, source, offsets, sizes, strides, static_offsets, static_sizes, static_strides, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` 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. .. code:: mlir %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: .. code:: mlir [[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: .. code:: mlir [[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``: .. code:: mlir [[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: .. code:: mlir memref.reinterpret_cast %ranked to offset: [0], sizes: [%size0, 10], strides: [1, %stride1] : memref to memref> memref.reinterpret_cast %unranked to offset: [%offset], sizes: [%size0, %size1], strides: [%stride0, %stride1] : memref<*xf32> to memref> 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: .. code:: mlir %dst = memref.reinterpret_cast %src to offset: [%offset], sizes: [%sizes], strides: [%strides] : memref<*xf32> to memref> means that ``%dst``'s descriptor will be: .. code:: mlir %dst.base = %src.base %dst.aligned = %src.aligned %dst.offset = %offset %dst.sizes = %sizes %dst.strides = %strides .. py:attribute:: OPERATION_NAME :value: 'memref.reinterpret_cast' .. py:attribute:: _ODS_OPERAND_SEGMENTS .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: offsets() -> _ods_ir .. py:method:: sizes() -> _ods_ir .. py:method:: strides() -> _ods_ir .. py:method:: static_offsets() -> _ods_ir .. py:method:: static_sizes() -> _ods_ir .. py:method:: static_strides() -> _ods_ir .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: reinterpret_cast(result, source, offsets, sizes, strides, static_offsets, static_sizes, static_strides, *, loc=None, ip=None) -> _ods_ir .. py:class:: ReshapeOp(result, source, shape, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``reshape`` operation converts a memref from one type to an equivalent type with a provided shape. The data is never copied or modified. The source and destination types are compatible if both have the same element type, same number of elements, address space and identity layout map. The following combinations are possible: a. Source type is ranked or unranked. Shape argument has static size. Result type is ranked. .. code:: mlir // Reshape statically-shaped memref. %dst = memref.reshape %src(%shape) : (memref<4x1xf32>, memref<1xi32>) -> memref<4xf32> %dst0 = memref.reshape %src(%shape0) : (memref<4x1xf32>, memref<2xi32>) -> memref<2x2xf32> // Flatten unranked memref. %dst = memref.reshape %src(%shape) : (memref<*xf32>, memref<1xi32>) -> memref b. Source type is ranked or unranked. Shape argument has dynamic size. Result type is unranked. .. code:: mlir // Reshape dynamically-shaped 1D memref. %dst = memref.reshape %src(%shape) : (memref, memref) -> memref<*xf32> // Reshape unranked memref. %dst = memref.reshape %src(%shape) : (memref<*xf32>, memref) -> memref<*xf32> .. py:attribute:: OPERATION_NAME :value: 'memref.reshape' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: shape() -> _ods_ir .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: reshape(result, source, shape, *, loc=None, ip=None) -> _ods_ir .. py:class:: StoreOp(value, memref, indices, *, nontemporal=None, alignment=None, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``store`` op stores an element into a memref at the specified indices. The number of indices must match the rank of the memref. The indices must be in-bounds: ``0 <= idx < dim_size``. Lowerings of ``memref.store`` may emit attributes, e.g. ``inbouds`` + ``nuw`` when converting to LLVM's ``llvm.getelementptr``, that would cause undefined behavior if indices are out of bounds or if computing the offset in the memref would cause signed overflow of the ``index`` type. A set ``nontemporal`` attribute indicates that this store is not expected to be reused in the cache. For details, refer to the `LLVM store instruction `_. An optional ``alignment`` attribute allows to specify the byte alignment of the store operation. It must be a positive power of 2. The operation must access memory at an address aligned to this boundary. Violations may lead to architecture-specific faults or performance penalties. A value of 0 indicates no specific alignment requirement. Example: .. code:: mlir memref.store %val, %A[%a, %b] : memref<8x?xi32, #layout, memspace0> .. py:attribute:: OPERATION_NAME :value: 'memref.store' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: value() -> _ods_ir .. py:method:: memref() -> _ods_ir .. py:method:: indices() -> _ods_ir .. py:method:: nontemporal() -> Optional[_ods_ir] .. py:method:: alignment() -> Optional[_ods_ir] .. py:function:: store(value, memref, indices, *, nontemporal=None, alignment=None, loc=None, ip=None) -> StoreOp .. py:class:: TransposeOp(result, in_, permutation, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``transpose`` op produces a strided memref whose sizes and strides are a permutation of the original ``in`` memref. This is purely a metadata transformation. Example: .. code:: mlir %1 = memref.transpose %0 (i, j) -> (j, i) : memref to memref (d1 * s0 + d0)>> .. py:attribute:: OPERATION_NAME :value: 'memref.transpose' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: in_() -> _ods_ir .. py:method:: permutation() -> _ods_ir .. py:function:: transpose(result, in_, permutation, *, loc=None, ip=None) -> _ods_ir .. py:class:: ViewOp(result, source, byte_shift, sizes, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The "view" operation extracts an N-D contiguous memref with empty layout map with arbitrary element type from a 1-D contiguous memref with empty layout map of i8 element type. The ViewOp supports the following arguments: * A single dynamic byte-shift operand must be specified which represents a a shift of the base 1-D memref pointer from which to create the resulting contiguous memref view with identity layout. * A dynamic size operand that must be specified for each dynamic dimension in the resulting view memref type. The "view" operation gives a structured indexing form to a flat 1-D buffer. Unlike "subview" it can perform a type change. The type change behavior requires the op to have special semantics because, e.g. a byte shift of 3 cannot be represented as an offset on f64. For now, a "view" op: #. Only takes a contiguous source memref with 0 offset and empty layout. #. Must specify a byte_shift operand (in the future, a special integer attribute may be added to support the folded case). #. Returns a contiguous memref with 0 offset and empty layout. Example: .. code:: mlir // Allocate a flat 1D/i8 memref. %0 = memref.alloc() : memref<2048xi8> // ViewOp with dynamic offset and static sizes. %1 = memref.view %0[%offset_1024][] : memref<2048xi8> to memref<64x4xf32> // ViewOp with dynamic offset and two dynamic size. %2 = memref.view %0[%offset_1024][%size0, %size1] : memref<2048xi8> to memref .. py:attribute:: OPERATION_NAME :value: 'memref.view' .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: byte_shift() -> _ods_ir .. py:method:: sizes() -> _ods_ir .. py:function:: view(result, source, byte_shift, sizes, *, loc=None, ip=None) -> _ods_ir .. py:class:: SubViewOp(result, source, offsets, sizes, strides, static_offsets, static_sizes, static_strides, *, loc=None, ip=None) Bases: :py:obj:`_ods_ir` The ``subview`` operation converts a memref type to a memref type which represents a reduced-size view of the original memref as specified by the operation's offsets, sizes and strides arguments. The ``subview`` operation supports the following arguments: * source: the "base" memref on which to create a "view" memref. * offsets: memref-rank number of offsets into the "base" memref at which to create the "view" memref. * sizes: memref-rank number of sizes which specify the sizes of the result "view" memref type. * strides: memref-rank number of strides that compose multiplicatively with the base memref strides in each dimension. The representation based on offsets, sizes and strides support a partially-static specification via attributes specified through the ``static_offsets``, ``static_sizes`` and ``static_strides`` arguments. A special sentinel value ``ShapedType::kDynamic`` encodes that the corresponding entry has a dynamic value. A ``subview`` operation may additionally reduce the rank of the resulting view by removing dimensions that are statically known to be of size 1. In the absence of rank reductions, the resulting memref type is computed as follows: .. code:: result_sizes[i] = size_operands[i] result_strides[i] = src_strides[i] * stride_operands[i] result_offset = src_offset + dot_product(offset_operands, src_strides) The offset, size and stride operands must be in-bounds with respect to the source memref. When possible, the static operation verifier will detect out-of-bounds subviews. Subviews that cannot be confirmed to be in-bounds or out-of-bounds based on compile-time information are valid. However, performing an out-of-bounds subview at runtime is undefined behavior. Example 1: Consecutive ``subview`` 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. .. code:: mlir %result1 = memref.subview %arg0[1, 1][4, 4][2, 2] : memref<8x8xf32, strided<[8, 1], offset: 0>> to memref<4x4xf32, strided<[16, 2], offset: 9>> %result2 = memref.subview %result1[1, 1][2, 2][2, 2] : memref<4x4xf32, strided<[16, 2], offset: 9>> to memref<2x2xf32, strided<[32, 4], offset: 27>> The underlying memory of ``%arg0`` consists of a linear sequence of integers from 1 to 64. Its memref has the following 8x8 elements: .. code:: mlir [[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 ``subview``, the strided memref elements of ``%result1`` are: .. code:: mlir [[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 strided memref of ``%arg0`` (compare to the corresponding ``reinterpret_cast`` example). The second ``subview`` results in the following strided memref for ``%result2``: .. code:: mlir [[28, 32], [60, 64]] Unlike the ``reinterpret_cast``, the values are relative to the strided memref of the input (``%result1`` in this case) and not its underlying memory. Example 2: .. code:: mlir // Subview of static memref with strided layout at static offsets, sizes // and strides. %1 = memref.subview %0[4, 2][8, 2][3, 2] : memref<64x4xf32, strided<[7, 9], offset: 91>> to memref<8x2xf32, strided<[21, 18], offset: 137>> Example 3: .. code:: mlir // Subview of static memref with identity layout at dynamic offsets, sizes // and strides. %1 = memref.subview %0[%off0, %off1][%sz0, %sz1][%str0, %str1] : memref<64x4xf32> to memref> Example 4: .. code:: mlir // Subview of dynamic memref with strided layout at dynamic offsets and // strides, but static sizes. %1 = memref.subview %0[%off0, %off1][4, 4][%str0, %str1] : memref> to memref<4x4xf32, strided<[?, ?], offset: ?>> Example 5: .. code:: mlir // Rank-reducing subviews. %1 = memref.subview %0[0, 0, 0][1, 16, 4][1, 1, 1] : memref<8x16x4xf32> to memref<16x4xf32> %3 = memref.subview %2[3, 4, 2][1, 6, 3][1, 1, 1] : memref<8x16x4xf32> to memref<6x3xf32, strided<[4, 1], offset: 210>> Example 6: .. code:: mlir // Identity subview. The subview is the full source memref. %1 = memref.subview %0[0, 0, 0] [8, 16, 4] [1, 1, 1] : memref<8x16x4xf32> to memref<8x16x4xf32> .. py:attribute:: OPERATION_NAME :value: 'memref.subview' .. py:attribute:: _ODS_OPERAND_SEGMENTS .. py:attribute:: _ODS_REGIONS :value: (0, True) .. py:method:: source() -> _ods_ir .. py:method:: offsets() -> _ods_ir .. py:method:: sizes() -> _ods_ir .. py:method:: strides() -> _ods_ir .. py:method:: static_offsets() -> _ods_ir .. py:method:: static_sizes() -> _ods_ir .. py:method:: static_strides() -> _ods_ir .. py:method:: result() -> _ods_ir Shortcut to get an op result if it has only one (throws an error otherwise). .. py:function:: subview(result, source, offsets, sizes, strides, static_offsets, static_sizes, static_strides, *, loc=None, ip=None) -> _ods_ir