diff options
author | Andy Davis <andydavis@google.com> | 2019-11-06 08:53:39 -0800 |
---|---|---|
committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-11-06 08:54:12 -0800 |
commit | c38dca7f4b697f9876b165acc9a6704f756d1173 (patch) | |
tree | 73f6b767bb8d025ffffff74a9c09ac656edb286c /mlir/test/IR | |
parent | 0d545921ead96a025541dda145ce502a1c4adc06 (diff) | |
download | bcm5719-llvm-c38dca7f4b697f9876b165acc9a6704f756d1173.tar.gz bcm5719-llvm-c38dca7f4b697f9876b165acc9a6704f756d1173.zip |
Add ViewOp to the StandardOps dialect, which casts a 1D/i8 element type memref type to an N-D memref type.
Proposed in RFC: https://groups.google.com/a/tensorflow.org/forum/#!searchin/mlir/std.view%7Csort:date/mlir/-wKHANzDNTg/4K6nUAp8AAAJ
Supports creating the N-D memref type with dynamic sizes and at a dynamic offset within the 1D base memref.
This change contains op definition/parsing/printing and tests. Follow up changes will handle constant shape/layout map folding and llvm lowering.
PiperOrigin-RevId: 278869990
Diffstat (limited to 'mlir/test/IR')
-rw-r--r-- | mlir/test/IR/core-ops.mlir | 32 | ||||
-rw-r--r-- | mlir/test/IR/invalid-ops.mlir | 52 |
2 files changed, 84 insertions, 0 deletions
diff --git a/mlir/test/IR/core-ops.mlir b/mlir/test/IR/core-ops.mlir index 417068a7fac..977ec661646 100644 --- a/mlir/test/IR/core-ops.mlir +++ b/mlir/test/IR/core-ops.mlir @@ -10,6 +10,8 @@ // CHECK-DAG: #[[map_proj_d0d1_d0:map[0-9]+]] = (d0, d1) -> (d0) // CHECK-DAG: #[[map_proj_d0d1_d1:map[0-9]+]] = (d0, d1) -> (d1) // CHECK-DAG: #[[map_proj_d0d1_d1d0:map[0-9]+]] = (d0, d1) -> (d1, d0) +// CHECK-DAG: #[[VIEW_MAP0:map[0-9]+]] = (d0, d1)[s0] -> (d0 * 4 + d1 + s0) +// CHECK-DAG: #[[VIEW_MAP1:map[0-9]+]] = (d0, d1) -> (d0 * 4 + d1) // CHECK-LABEL: func @func_with_ops(%arg0: f32) { func @func_with_ops(f32) { @@ -472,6 +474,36 @@ func @memref_cast(%arg0: memref<4xf32>, %arg1 : memref<?xf32>) { return } +// CHECK-LABEL: func @memref_view(%arg0 +func @memref_view(%arg0 : index, %arg1 : index, %arg2 : index) { + %0 = alloc() : memref<2048xi8> + // Test two dynamic sizes and dynamic offset. + // CHECK: %{{.*}} = std.view %0[%arg0, %arg1][%arg2] : memref<2048xi8> to memref<?x?xf32, #[[VIEW_MAP0]]> + %1 = view %0[%arg0, %arg1][%arg2] + : memref<2048xi8> to memref<?x?xf32, (d0, d1)[s0] -> (d0 * 4 + d1 + s0)> + + // Test two dynamic sizes and static offset. + // CHECK: %{{.*}} = std.view %0[%arg0, %arg1][] : memref<2048xi8> to memref<?x?xf32, #[[VIEW_MAP1]]> + %2 = view %0[%arg0, %arg1][] + : memref<2048xi8> to memref<?x?xf32, (d0, d1) -> (d0 * 4 + d1)> + + // Test one dynamic size and dynamic offset. + // CHECK: %{{.*}} = std.view %0[%arg1][%arg2] : memref<2048xi8> to memref<4x?xf32, #[[VIEW_MAP0]]> + %3 = view %0[%arg1][%arg2] + : memref<2048xi8> to memref<4x?xf32, (d0, d1)[s0] -> (d0 * 4 + d1 + s0)> + + // Test one dynamic size and static offset. + // CHECK: %{{.*}} = std.view %0[%arg0][] : memref<2048xi8> to memref<?x16xf32, #[[VIEW_MAP1]]> + %4 = view %0[%arg0][] + : memref<2048xi8> to memref<?x16xf32, (d0, d1) -> (d0 * 4 + d1)> + + // Test static sizes and static offset. + // CHECK: %{{.*}} = std.view %0[][] : memref<2048xi8> to memref<64x4xf32, #[[VIEW_MAP1]]> + %5 = view %0[][] + : memref<2048xi8> to memref<64x4xf32, (d0, d1) -> (d0 * 4 + d1)> + return +} + // CHECK-LABEL: func @test_dimop(%arg0 func @test_dimop(%arg0: tensor<4x4x?xf32>) { // CHECK: %0 = dim %arg0, 2 : tensor<4x4x?xf32> diff --git a/mlir/test/IR/invalid-ops.mlir b/mlir/test/IR/invalid-ops.mlir index be44a6bff39..4d45d95222d 100644 --- a/mlir/test/IR/invalid-ops.mlir +++ b/mlir/test/IR/invalid-ops.mlir @@ -901,3 +901,55 @@ func @invalid_splat(%v : f32) { // expected-note {{prior use here}} // expected-error@-1 {{expects different type than prior uses}} return } + +// ----- + +func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) { + %0 = alloc() : memref<2048xi8> + // expected-error@+1 {{incorrect number of operands for type}} + %1 = view %0[%arg0, %arg1][] + : memref<2048xi8> to memref<?x?xf32, (d0, d1)[s0] -> (d0 * 4 + d1 + s0)> + return +} + +// ----- + +func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) { + %0 = alloc() : memref<2048xi8> + // expected-error@+1 {{is not strided}} + %1 = view %0[%arg0, %arg1][] + : memref<2048xi8> to memref<?x?xf32, (d0, d1)[s0] -> (d0, d1, s0)> + return +} + +// ----- + +func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) { + %0 = alloc() : memref<2048xf32> + // expected-error@+1 {{unsupported shape for base memref}} + %1 = view %0[%arg0, %arg1][] + : memref<2048xf32> to memref<?x?xf32, (d0, d1)[s0] -> (d0 * 4 + d1 + s0)> + return +} + +// ----- + +func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) { + %0 = alloc() : memref<2048xi8, (d0) -> (d0 floordiv 8, d0 mod 8)> + // expected-error@+1 {{unsupported map for base memref}} + %1 = view %0[%arg0, %arg1][] + : memref<2048xi8, (d0) -> (d0 floordiv 8, d0 mod 8)> to + memref<?x?xf32, (d0, d1)[s0] -> (d0 * 4 + d1 + s0)> + return +} + +// ----- + +func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) { + %0 = alloc() : memref<2048xi8, 2> + // expected-error@+1 {{different memory spaces}} + %1 = view %0[%arg0, %arg1][] + : memref<2048xi8, 2> to + memref<?x?xf32, (d0, d1)[s0] -> (d0 * 4 + d1 + s0), 1> + return +} |