1
1
// RUN: mlir-opt -split-input-file -test-tensor-transform-patterns="test-simplify-pack-unpack-patterns" %s | FileCheck %s
2
2
3
- // CHECK: func.func @single_dim_packing(
4
- // CHECK-SAME: %[[ARG0:.+]]: tensor<256xf32>)
5
- // CHECK: %[[EXPANDED:.+]] = tensor.expand_shape %[[ARG0]] {{\[}}[0, 1]] : tensor<256xf32> into tensor<8x32xf32>
6
- // CHECK: return %[[EXPANDED]] : tensor<8x32xf32>
3
+ // CHECK-LABEL : func.func @single_dim_packing(
4
+ // CHECK-SAME: %[[ARG0:.+]]: tensor<256xf32>)
5
+ // CHECK: %[[EXPANDED:.+]] = tensor.expand_shape %[[ARG0]] {{\[}}[0, 1]] : tensor<256xf32> into tensor<8x32xf32>
6
+ // CHECK: return %[[EXPANDED]] : tensor<8x32xf32>
7
7
func.func @single_dim_packing (%arg0: tensor <256 xf32 >) -> tensor <8 x32 xf32 > {
8
8
%empty = tensor.empty () : tensor <8 x32 xf32 >
9
9
%0 = tensor.pack %arg0 inner_dims_pos = [0 ] inner_tiles = [32 ] into %empty : tensor <256 xf32 > -> tensor <8 x32 xf32 >
@@ -12,13 +12,47 @@ func.func @single_dim_packing(%arg0: tensor<256xf32>) -> tensor<8x32xf32> {
12
12
13
13
// -----
14
14
15
- // CHECK: func.func @single_dim_packing_with_padding(
16
- // CHECK-SAME: %[[ARG0:.+]]: tensor<255xf32>)
17
- // CHECK-NOT: tensor.expand_shape
18
- // CHECK: tensor.pack
15
+ // CHECK-LABEL : func.func @single_dim_packing_with_padding(
16
+ // CHECK-SAME: %[[ARG0:.+]]: tensor<255xf32>)
17
+ // CHECK-NOT: tensor.expand_shape
18
+ // CHECK: tensor.pack
19
19
func.func @single_dim_packing_with_padding (%arg0: tensor <255 xf32 >) -> tensor <8 x32 xf32 > {
20
20
%empty = tensor.empty () : tensor <8 x32 xf32 >
21
21
%cst = arith.constant 0.000000e+00 : f32
22
22
%0 = tensor.pack %arg0 padding_value (%cst : f32 ) inner_dims_pos = [0 ] inner_tiles = [32 ] into %empty : tensor <255 xf32 > -> tensor <8 x32 xf32 >
23
23
return %0 : tensor <8 x32 xf32 >
24
24
}
25
+
26
+ // -----
27
+
28
+ // CHECK-LABEL: func.func @single_last_inner_dim_packing(
29
+ // CHECK-SAME: %[[ARG0:.+]]: tensor<5x256xf32>)
30
+ // CHECK: %[[EXPANDED:.+]] = tensor.expand_shape %[[ARG0]] {{\[}}[0], [1, 2]] : tensor<5x256xf32> into tensor<5x8x32xf32>
31
+ // CHECK: return %[[EXPANDED]] : tensor<5x8x32xf32>
32
+ func.func @single_last_inner_dim_packing (%arg0: tensor <5 x256 xf32 >) -> tensor <5 x8 x32 xf32 > {
33
+ %empty = tensor.empty () : tensor <5 x8 x32 xf32 >
34
+ %0 = tensor.pack %arg0 inner_dims_pos = [1 ] inner_tiles = [32 ] into %empty : tensor <5 x256 xf32 > -> tensor <5 x8 x32 xf32 >
35
+ return %0 : tensor <5 x8 x32 xf32 >
36
+ }
37
+
38
+ // -----
39
+
40
+ // CHECK-LABEL: func.func @packing_with_outer_dims_perm(
41
+ // CHECK-NOT: tensor.expand_shape
42
+ // CHECK: tensor.pack
43
+ func.func @packing_with_outer_dims_perm (%arg0: tensor <5 x256 xf32 >) -> tensor <8 x5 x32 xf32 > {
44
+ %empty = tensor.empty () : tensor <8 x5 x32 xf32 >
45
+ %0 = tensor.pack %arg0 outer_dims_perm = [1 , 0 ] inner_dims_pos = [1 ] inner_tiles = [32 ] into %empty : tensor <5 x256 xf32 > -> tensor <8 x5 x32 xf32 >
46
+ return %0 : tensor <8 x5 x32 xf32 >
47
+ }
48
+
49
+ // -----
50
+
51
+ // CHECK-LABEL: func.func @single_first_inner_dim_packing(
52
+ // CHECK-NOT: tensor.expand_shape
53
+ // CHECK: tensor.pack
54
+ func.func @single_first_inner_dim_packing (%arg0: tensor <256 x5 xf32 >) -> tensor <8 x5 x32 xf32 > {
55
+ %empty = tensor.empty () : tensor <8 x5 x32 xf32 >
56
+ %0 = tensor.pack %arg0 inner_dims_pos = [0 ] inner_tiles = [32 ] into %empty : tensor <256 x5 xf32 > -> tensor <8 x5 x32 xf32 >
57
+ return %0 : tensor <8 x5 x32 xf32 >
58
+ }
0 commit comments