diff --git a/mlir/test/Dialect/Tensor/bufferize.mlir b/mlir/test/Dialect/Tensor/bufferize.mlir --- a/mlir/test/Dialect/Tensor/bufferize.mlir +++ b/mlir/test/Dialect/Tensor/bufferize.mlir @@ -1,16 +1,4 @@ -// RUN: mlir-opt %s -tensor-bufferize -cse | FileCheck %s - - // CHECK-DAG: #[[$MAP0:.*]] = affine_map<(d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)> - // CHECK-DAG: #[[$MAP1:.*]] = affine_map<(d0, d1)[s0] -> (d0 * 20 + s0 + d1)> - // CHECK-DAG: #[[$MAP2:.*]] = affine_map<(d0, d1, d2, d3)[s0] -> (d0 * 140 + d1 * 20 + d2 * 5 + d3 + s0)> - // CHECK-DAG: #[[$MAP3:.*]] = affine_map<(d0) -> (d0 + 1)> - // CHECK-DAG: #[[$MAP4:.*]] = affine_map<() -> (1)> - // CHECK-DAG: #[[$MAP5:.*]] = affine_map<(d0, d1) -> (d0 * 2 + d1)> - // CHECK-DAG: #[[$MAP6:.*]] = affine_map<(d0) -> (d0 * 2)> - // CHECK-DAG: #[[$MAP7:.*]] = affine_map<(d0, d1, d2)[s0] -> (d0 * 8 + s0 + d1 * 4 + d2)> - // CHECK-DAG: #[[$MAP8:.*]] = affine_map<(d0)[s0] -> (d0 * 4 + s0)> - // CHECK-DAG: #[[$MAP9:.*]] = affine_map<()[s0] -> (s0)> - // CHECK-DAG: #[[$MAP10:.*]] = affine_map<(d0)[s0] -> (d0 + s0)> +// RUN: mlir-opt %s -tensor-bufferize -cse -split-input-file | FileCheck %s // CHECK-LABEL: func @dim( // CHECK-SAME: %[[TENSOR:.*]]: tensor, @@ -23,6 +11,8 @@ return %0 : index } +// ----- + // CHECK-LABEL: func @rank( // CHECK-SAME: %[[TENSOR:.*]]: tensor<*xf32>) -> index { // CHECK: %[[MEMREF:.*]] = bufferization.to_memref %[[TENSOR]] @@ -32,6 +22,8 @@ return %0 : index } +// ----- + // CHECK-LABEL: func @tensor.cast( // CHECK-SAME: %[[TENSOR:.*]]: tensor) -> tensor<2xindex> { // CHECK: %[[MEMREF:.*]] = bufferization.to_memref %[[TENSOR]] @@ -43,6 +35,8 @@ return %0 : tensor<2xindex> } +// ----- + // CHECK-LABEL: func @tensor.cast_from_unranked( // CHECK-SAME: %[[TENSOR:.*]]: tensor<*xf32>) -> tensor<2xf32> { // CHECK: %[[MEMREF:.*]] = bufferization.to_memref %[[TENSOR]] : memref<*xf32> @@ -54,6 +48,8 @@ return %0 : tensor<2xf32> } +// ----- + // CHECK-LABEL: func @tensor.cast_to_unranked( // CHECK-SAME: %[[TENSOR:.*]]: tensor<2xf32>) -> tensor<*xf32> { // CHECK: %[[MEMREF:.*]] = bufferization.to_memref %[[TENSOR]] : memref<2xf32> @@ -65,6 +61,8 @@ return %0 : tensor<*xf32> } +// ----- + // CHECK-LABEL: func @tensor.extract( // CHECK-SAME: %[[TENSOR:.*]]: tensor, // CHECK-SAME: %[[IDX:.*]]: index) -> f32 { @@ -77,6 +75,8 @@ return %0 : f32 } +// ----- + // CHECK-LABEL: func @tensor.from_elements_0d( // CHECK-SAME: %[[ELEM0:.*]]: index) -> tensor { // CHECK: %[[MEMREF:.*]] = memref.alloc() {{.*}} : memref @@ -88,6 +88,8 @@ return %0 : tensor } +// ----- + // CHECK-LABEL: func @tensor.from_elements_1d( // CHECK-SAME: %[[ELEM0:.*]]: index, // CHECK-SAME: %[[ELEM1:.*]]: index) -> tensor<2xindex> { @@ -103,6 +105,8 @@ return %0 : tensor<2xindex> } +// ----- + // CHECK-LABEL: func @tensor.from_elements_2d( // CHECK-SAME: %[[ELEM0:.*]]: index, %[[ELEM1:.*]]: index) // CHECK-SAME: -> tensor<3x2xindex> { @@ -124,6 +128,8 @@ return %0 : tensor<3x2xindex> } +// ----- + // CHECK-LABEL: func @tensor.from_elements_3d( // CHECK-SAME: %[[F0:.*]]: f32 @@ -177,6 +183,8 @@ return %0 : tensor<3x2x2xf32> } +// ----- + // CHECK-LABEL: func @tensor.generate( // CHECK-SAME: %[[ARG:.*]]: tensor<*xf32>, // CHECK-SAME: %[[DYNAMIC_EXTENT:.*]]: index) -> tensor { @@ -201,6 +209,8 @@ return %result : tensor } +// ----- + // Additional test that checks the logic for intermixed static and dynamic // extents. // @@ -227,6 +237,8 @@ return %result : tensor<16x?xindex> } +// ----- + // CHECK-LABEL: func @tensor.generate_unknown_ops_in_body func.func @tensor.generate_unknown_ops_in_body(%arg0: index) -> tensor { // CHECK-NOT: tensor.generate @@ -239,12 +251,16 @@ return %tensor : tensor } +// ----- + + // CHECK-DAG: #[[$MAP0a:.*]] = affine_map<(d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)> + // CHECK-LABEL: func @tensor.extract_slice( // CHECK-SAME: %[[t1:.*]]: tensor, %[[idx1:.*]]: index, %[[idx2:.*]]: index func.func @tensor.extract_slice( %t1: tensor, %idx1: index, %idx2: index) -> tensor { // CHECK: %[[m:.*]] = bufferization.to_memref %[[t1]] : memref - // CHECK: %[[r:.*]] = memref.subview %[[m]][5, %[[idx2]]] [%[[idx1]], 10] [1, 1] : memref to memref + // CHECK: %[[r:.*]] = memref.subview %[[m]][5, %[[idx2]]] [%[[idx1]], 10] [1, 1] : memref to memref %0 = tensor.extract_slice %t1[5, %idx2][%idx1, 10][1, 1] : tensor to tensor // CHECK: %[[r_tensor:.*]] = bufferization.to_tensor %[[r]] @@ -252,13 +268,17 @@ return %0 : tensor } +// ----- + +// CHECK-DAG: #[[$MAP0b:.*]] = affine_map<(d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)> + // CHECK-LABEL: func @tensor.extract_slice_rank_reducing( // CHECK-SAME: %[[t1:.*]]: tensor, %[[idx1:.*]]: index, // CHECK-SAME: %[[idx2:.*]]: index func.func @tensor.extract_slice_rank_reducing( %t1: tensor, %idx1: index, %idx2: index) -> tensor { // CHECK: %[[m1:.*]] = bufferization.to_memref %[[t1]] : memref - // CHECK: %[[r:.*]] = memref.subview %[[m1]][5, %[[idx1]], 10] [%[[idx2]], 1, 15] [1, 1, 1] : memref to memref + // CHECK: %[[r:.*]] = memref.subview %[[m1]][5, %[[idx1]], 10] [%[[idx2]], 1, 15] [1, 1, 1] : memref to memref %0 = tensor.extract_slice %t1[5, %idx1, 10][%idx2, 1, 15][1, 1, 1] : tensor to tensor // CHECK: %[[r_tensor:.*]] = bufferization.to_tensor %[[r]] @@ -266,6 +286,8 @@ return %0 : tensor } +// ----- + // CHECK-LABEL: func @tensor.insert_slice( // CHECK-SAME: %[[t1:.*]]: tensor, %[[t2:.*]]: tensor, // CHECK-SAME: %[[idx1:.*]]: index, %[[idx2:.*]]: index @@ -289,6 +311,8 @@ return %0 : tensor } +// ----- + // CHECK-LABEL: func @tensor.insert( // CHECK-SAME: %[[t1:.*]]: tensor<5xf32>, %[[idx1:.*]]: index, // CHECK-SAME: %[[f:.*]]: f32 @@ -304,6 +328,8 @@ return %0 : tensor<5xf32> } +// ----- + // CHECK-LABEL: func @tensor.expand_shape( // CHECK-SAME: %[[t1:.*]]: tensor func.func @tensor.expand_shape(%t1: tensor) -> tensor<2x?x10xf32> { @@ -318,16 +344,21 @@ return %0 : tensor<2x?x10xf32> } +// ----- + +// CHECK-DAG: #[[$MAP1b:.*]] = affine_map<(d0, d1)[s0] -> (d0 * 20 + s0 + d1)> +// CHECK-DAG: #[[$MAP2b:.*]] = affine_map<(d0, d1, d2, d3)[s0] -> (d0 * 140 + d1 * 20 + d2 * 5 + d3 + s0)> + // CHECK-LABEL: func @tensor.expand_shape_of_slice( // CHECK-SAME: %[[t1:.*]]: tensor func.func @tensor.expand_shape_of_slice( %t1: tensor, %o1: index, %s1: index) -> tensor { // CHECK: %[[m1:.*]] = bufferization.to_memref %[[t1]] : memref - // CHECK: %[[subview:.*]] = memref.subview %[[m1]][%{{.*}}, 5] [%{{.*}}, 10] [1, 1] : memref to memref + // CHECK: %[[subview:.*]] = memref.subview %[[m1]][%{{.*}}, 5] [%{{.*}}, 10] [1, 1] : memref to memref %0 = tensor.extract_slice %t1[%o1, 5][%s1, 10][1, 1] : tensor to tensor // CHECK: %[[expanded:.*]] = memref.expand_shape %[[subview]] [ - // CHECK-SAME: [0, 1], [2, 3]] : memref into memref + // CHECK-SAME: [0, 1], [2, 3]] : memref into memref %1 = tensor.expand_shape %0 [[0, 1], [2, 3]] : tensor into tensor // CHECK: %[[r:.*]] = bufferization.to_tensor %[[expanded]] @@ -335,6 +366,11 @@ return %1 : tensor } +// ----- + +// CHECK-DAG: #[[$MAP9:.*]] = affine_map<()[s0] -> (s0)> +// CHECK-DAG: #[[$MAP10:.*]] = affine_map<(d0)[s0] -> (d0 + s0)> + // CHECK-LABEL: func @tensor.expand_shape_of_scalar_slice( // CHECK-SAME: %[[t1:.*]]: tensor func.func @tensor.expand_shape_of_scalar_slice( @@ -349,6 +385,8 @@ return %1 : tensor<1xf32> } +// ----- + // CHECK-LABEL: func @tensor.collapse_shape( // CHECK-SAME: %[[t1:.*]]: tensor<2x?x?xf32> func.func @tensor.collapse_shape(%t1: tensor<2x?x?xf32>) -> tensor { @@ -363,6 +401,8 @@ return %0 : tensor } +// ----- + // CHECK-LABEL: func @tensor.collapse_shape_to_scalar( // CHECK-SAME: %[[t1:.*]]: tensor<1x1x1xf32> func.func @tensor.collapse_shape_to_scalar(%t1: tensor<1x1x1xf32>) -> tensor { @@ -376,6 +416,11 @@ return %0 : tensor } +// ----- + +// CHECK-DAG: #[[$MAP3:.*]] = affine_map<(d0) -> (d0 + 1)> +// CHECK-DAG: #[[$MAP4:.*]] = affine_map<() -> (1)> + // CHECK-LABEL: func @tensor.collapse_shape_of_slice( func.func @tensor.collapse_shape_of_slice(%arg0: tensor<2xi32>) -> tensor { // CHECK: memref.subview %{{.*}}[1] [1] [1] : memref<2xi32> to memref<1xi32, #[[$MAP3]]> @@ -385,6 +430,8 @@ return %1 : tensor } +// ----- + // CHECK-LABEL: func @tensor.collapse_shape_of_slice2( func.func @tensor.collapse_shape_of_slice2( %arg0: tensor, %o1: index, %o2: index, %o3: index, %o4: index) @@ -402,6 +449,11 @@ return %1 : tensor<87x63648xi64> } +// ----- + +// CHECK-DAG: #[[$MAP5:.*]] = affine_map<(d0, d1) -> (d0 * 2 + d1)> +// CHECK-DAG: #[[$MAP6:.*]] = affine_map<(d0) -> (d0 * 2)> + // CHECK-LABEL: func @tensor.collapse_shape_of_slice3( // CHECK-SAME: %[[t1:.*]]: tensor<1x2xf32> func.func @tensor.collapse_shape_of_slice3(%t1: tensor<1x2xf32>) -> tensor<1xf32> { @@ -413,6 +465,11 @@ return %1 : tensor<1xf32> } +// ----- + +// CHECK-DAG: #[[$MAP7:.*]] = affine_map<(d0, d1, d2)[s0] -> (d0 * 8 + s0 + d1 * 4 + d2)> +// CHECK-DAG: #[[$MAP8:.*]] = affine_map<(d0)[s0] -> (d0 * 4 + s0)> + // CHECK-LABEL: func @tensor.collapse_shape_of_slice4( // CHECK-SAME: %[[t1:.*]]: tensor, // CHECK-SAME: %[[OFFSET:.*]]: index) -> tensor<8xf32> { @@ -425,6 +482,8 @@ return %ret: tensor<8xf32> } +// ----- + // CHECK-LABEL: func @tensor.reshape( // CHECK-SAME: %[[t1:.*]]: tensor func.func @tensor.reshape(%t1: tensor) -> tensor<2x2x5xf32> {