• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# RUN: %PYTHON %s | FileCheck %s
2
3from mlir.ir import *
4import mlir.dialects.std as std
5
6def run(f):
7  print("\nTEST:", f.__name__)
8  f()
9
10# CHECK-LABEL: TEST: testSubViewAccessors
11def testSubViewAccessors():
12  ctx = Context()
13  module = Module.parse(r"""
14    func @f1(%arg0: memref<?x?xf32>) {
15      %0 = constant 0 : index
16      %1 = constant 1 : index
17      %2 = constant 2 : index
18      %3 = constant 3 : index
19      %4 = constant 4 : index
20      %5 = constant 5 : index
21      subview %arg0[%0, %1][%2, %3][%4, %5] : memref<?x?xf32> to memref<?x?xf32, offset: ?, strides: [?, ?]>
22      return
23    }
24  """, ctx)
25  func_body = module.body.operations[0].regions[0].blocks[0]
26  subview = func_body.operations[6]
27
28  assert subview.source == subview.operands[0]
29  assert len(subview.offsets) == 2
30  assert len(subview.sizes) == 2
31  assert len(subview.strides) == 2
32  assert subview.result == subview.results[0]
33
34  # CHECK: SubViewOp
35  print(type(subview).__name__)
36
37  # CHECK: constant 0
38  print(subview.offsets[0])
39  # CHECK: constant 1
40  print(subview.offsets[1])
41  # CHECK: constant 2
42  print(subview.sizes[0])
43  # CHECK: constant 3
44  print(subview.sizes[1])
45  # CHECK: constant 4
46  print(subview.strides[0])
47  # CHECK: constant 5
48  print(subview.strides[1])
49
50
51run(testSubViewAccessors)
52