summaryrefslogtreecommitdiffstats
path: root/mlir/test/Dialect/VectorOps
diff options
context:
space:
mode:
authorNicolas Vasilache <ntv@google.com>2019-11-19 12:22:00 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-11-19 12:22:34 -0800
commitee95f6f2594e9089990024208d01634fd81d2da2 (patch)
tree3f3b18b1536d65837739d09a77c5ca9c33489884 /mlir/test/Dialect/VectorOps
parent3732ba4def17af34567966276898fcdca11730c2 (diff)
downloadbcm5719-llvm-ee95f6f2594e9089990024208d01634fd81d2da2.tar.gz
bcm5719-llvm-ee95f6f2594e9089990024208d01634fd81d2da2.zip
Add VectorOps.StridedSliceOp
The `vector.strided_slice` takes an n-D vector, k-D `offsets` integer array attribute, a k-D `sizes` integer array attribute, a k-D `strides` integer array attribute and extracts the n-D subvector at the proper offset. Returns an n-D vector where the first k-D dimensions match the `sizes` attribute. The returned subvector contains the elements starting at offset `offsets` and ending at `offsets + sizes`. Example: ``` %1 = vector.strided_slice %0 {offsets : [0, 2], sizes : [2, 4], strides : [1, 1]}: vector<4x8x16xf32> // returns a vector<2x4x16xf32> ``` This op will be useful for progressive lowering within the VectorOp dialect. PiperOrigin-RevId: 281352749
Diffstat (limited to 'mlir/test/Dialect/VectorOps')
-rw-r--r--mlir/test/Dialect/VectorOps/invalid.mlir64
-rw-r--r--mlir/test/Dialect/VectorOps/ops.mlir7
2 files changed, 71 insertions, 0 deletions
diff --git a/mlir/test/Dialect/VectorOps/invalid.mlir b/mlir/test/Dialect/VectorOps/invalid.mlir
index 2db4cf53384..d8ebb9808b9 100644
--- a/mlir/test/Dialect/VectorOps/invalid.mlir
+++ b/mlir/test/Dialect/VectorOps/invalid.mlir
@@ -231,6 +231,7 @@ func @test_vector.transfer_write(%arg0: memref<?x?xf32>) {
// expected-error@+1 {{requires a projected permutation_map (at most one dim or the zero constant can appear in each result)}}
vector.transfer_write %cst, %arg0[%c3, %c3] {permutation_map = (d0, d1)->(d0 + 1)} : vector<128xf32>, memref<?x?xf32>
}
+
// -----
func @test_vector.transfer_write(%arg0: memref<?x?x?xf32>) {
@@ -239,3 +240,66 @@ func @test_vector.transfer_write(%arg0: memref<?x?x?xf32>) {
// expected-error@+1 {{requires a permutation_map that is a permutation (found one dim used more than once)}}
vector.transfer_write %cst, %arg0[%c3, %c3, %c3] {permutation_map = (d0, d1, d2)->(d0, d0)} : vector<3x7xf32>, memref<?x?x?xf32>
}
+
+// -----
+
+func @strided_slice(%arg0: vector<4x8x16xf32>) {
+ // expected-error@+1 {{expected offsets, sizes and strides attributes of same size}}
+ %1 = vector.strided_slice %arg0 {offsets = [100], sizes = [2, 2], strides = [1, 1]} : vector<4x8x16xf32> to vector<2x2x16xf32>
+}
+
+// -----
+
+func @strided_slice(%arg0: vector<4x8x16xf32>) {
+ // expected-error@+1 {{expected offsets attribute of rank smaller than vector rank}}
+ %1 = vector.strided_slice %arg0 {offsets = [2, 2, 2, 2], sizes = [2, 2, 2, 2], strides = [1, 1, 1, 1]} : vector<4x8x16xf32> to vector<2x2x16xf32>
+}
+
+// -----
+
+func @strided_slice(%arg0: vector<4x8x16xf32>) {
+ // expected-error@+1 {{expected offsets attribute of rank smaller than vector rank}}
+ %1 = vector.strided_slice %arg0 {offsets = [2, 2, 2, 2], sizes = [2, 2, 2, 2], strides = [1, 1, 1, 1]} : vector<4x8x16xf32> to vector<2x2x16xf32>
+}
+
+// -----
+
+func @strided_slice(%arg0: vector<4x8x16xf32>) {
+ // expected-error@+1 {{op expected offsets to be confined to [0, 4)}}
+ %1 = vector.strided_slice %arg0 {offsets = [100], sizes = [100], strides = [100]} : vector<4x8x16xf32> to vector<100x8x16xf32>
+}
+
+// -----
+
+func @strided_slice(%arg0: vector<4x8x16xf32>) {
+ // expected-error@+1 {{op expected sizes to be confined to [1, 5)}}
+ %1 = vector.strided_slice %arg0 {offsets = [2], sizes = [100], strides = [100]} : vector<4x8x16xf32> to vector<100x8x16xf32>
+}
+
+// -----
+
+func @strided_slice(%arg0: vector<4x8x16xf32>) {
+ // expected-error@+1 {{op expected strides to be confined to [1, 2)}}
+ %1 = vector.strided_slice %arg0 {offsets = [2], sizes = [1], strides = [100]} : vector<4x8x16xf32> to vector<1x8x16xf32>
+}
+
+// -----
+
+func @strided_slice(%arg0: vector<4x8x16xf32>) {
+ // expected-error@+1 {{op expected strides to be confined to [1, 2)}}
+ %1 = vector.strided_slice %arg0 {offsets = [2], sizes = [1], strides = [100]} : vector<4x8x16xf32> to vector<1x8x16xf32>
+}
+
+// -----
+
+func @strided_slice(%arg0: vector<4x8x16xf32>) {
+ // expected-error@+1 {{op expected sum(offsets, sizes) to be confined to [1, 5)}}
+ %1 = vector.strided_slice %arg0 {offsets = [2], sizes = [3], strides = [1]} : vector<4x8x16xf32> to vector<3x8x16xf32>
+}
+
+// -----
+
+func @strided_slice(%arg0: vector<4x8x16xf32>) {
+ // expected-error@+1 {{op expected result type to be 'vector<2x8x16xf32>'}}
+ %1 = vector.strided_slice %arg0 {offsets = [2], sizes = [2], strides = [1]} : vector<4x8x16xf32> to vector<3x1xf32>
+}
diff --git a/mlir/test/Dialect/VectorOps/ops.mlir b/mlir/test/Dialect/VectorOps/ops.mlir
index 77d40f5e84d..7ad46c28339 100644
--- a/mlir/test/Dialect/VectorOps/ops.mlir
+++ b/mlir/test/Dialect/VectorOps/ops.mlir
@@ -41,3 +41,10 @@ func @outerproduct(%arg0: vector<4xf32>, %arg1: vector<8xf32>, %arg2: vector<4x8
%1 = vector.outerproduct %arg0, %arg1, %arg2 : vector<4xf32>, vector<8xf32>
return %1 : vector<4x8xf32>
}
+
+// CHECK-LABEL: strided_slice
+func @strided_slice(%arg0: vector<4x8x16xf32>) -> vector<2x2x16xf32> {
+ // CHECK: vector.strided_slice %{{.*}} {offsets = [2, 2], sizes = [2, 2], strides = [1, 1]} : vector<4x8x16xf32>
+ %1 = vector.strided_slice %arg0 {offsets = [2, 2], sizes = [2, 2], strides = [1, 1]} : vector<4x8x16xf32> to vector<2x2x16xf32>
+ return %1: vector<2x2x16xf32>
+}
OpenPOWER on IntegriCloud