@@ -56,3 +56,75 @@ func.func @single_first_inner_dim_packing(%arg0: tensor<256x5xf32>) -> tensor<8x
56
56
%0 = tensor.pack %arg0 inner_dims_pos = [0 ] inner_tiles = [32 ] into %empty : tensor <256 x5 xf32 > -> tensor <8 x5 x32 xf32 >
57
57
return %0 : tensor <8 x5 x32 xf32 >
58
58
}
59
+
60
+ // -----
61
+
62
+ // CHECK-LABEL: func.func @unpack_1d_to_collapse
63
+ // CHECK-SAME: %[[ARG0:.+]]: tensor<8x32xf32>)
64
+ // CHECK: %[[COLLAPSED:.+]] = tensor.collapse_shape %[[ARG0]] {{\[}}[0, 1]] : tensor<8x32xf32> into tensor<256xf32>
65
+ // CHECK: return %[[COLLAPSED]]
66
+ func.func @unpack_1d_to_collapse (%arg0: tensor <8 x32 xf32 >) -> tensor <256 xf32 > {
67
+ %empty = tensor.empty () : tensor <256 xf32 >
68
+ %0 = tensor.unpack %arg0 inner_dims_pos = [0 ] inner_tiles = [32 ] into %empty : tensor <8 x32 xf32 > -> tensor <256 xf32 >
69
+ return %0 : tensor <256 xf32 >
70
+ }
71
+
72
+ // -----
73
+
74
+ // CHECK-LABEL: func.func @unpack_to_partial_slice
75
+ // CHECK-NOT: tensor.collapse
76
+ // CHECK: tensor.unpack
77
+ func.func @unpack_to_partial_slice (%arg0: tensor <8 x32 xf32 >) -> tensor <255 xf32 > {
78
+ %empty = tensor.empty () : tensor <255 xf32 >
79
+ %0 = tensor.unpack %arg0 inner_dims_pos = [0 ] inner_tiles = [32 ] into %empty : tensor <8 x32 xf32 > -> tensor <255 xf32 >
80
+ return %0 : tensor <255 xf32 >
81
+ }
82
+
83
+ // -----
84
+
85
+ // CHECK-LABEL: func.func @unpack_dynamic
86
+ // CHECK-NOT: tensor.collapse
87
+ // CHECK: tensor.unpack
88
+ func.func @unpack_dynamic (%arg0: tensor <?x32 xf32 >) -> tensor <?xf32 > {
89
+ %c32 = arith.constant 32 : index
90
+ %c0 = arith.constant 0 : index
91
+ %d0 = tensor.dim %arg0 , %c0 : tensor <?x32 xf32 >
92
+ %size = arith.muli %d0 , %c32 : index
93
+ %empty = tensor.empty (%size ) : tensor <?xf32 >
94
+ %0 = tensor.unpack %arg0 inner_dims_pos = [0 ] inner_tiles = [32 ] into %empty : tensor <?x32 xf32 > -> tensor <?xf32 >
95
+ return %0 : tensor <?xf32 >
96
+ }
97
+
98
+ // -----
99
+
100
+ // CHECK-LABEL: func.func @single_last_inner_dim_unpacking(
101
+ // CHECK-SAME: %[[ARG0:.+]]: tensor<5x8x32xf32>)
102
+ // CHECK: %[[COLLAPSED:.+]] = tensor.collapse_shape %[[ARG0]] {{\[}}[0], [1, 2]] : tensor<5x8x32xf32> into tensor<5x256xf32>
103
+ // CHECK: return %[[COLLAPSED]] : tensor<5x256xf32>
104
+ func.func @single_last_inner_dim_unpacking (%arg0: tensor <5 x8 x32 xf32 >) -> tensor <5 x256 xf32 > {
105
+ %empty = tensor.empty () : tensor <5 x256 xf32 >
106
+ %0 = tensor.unpack %arg0 inner_dims_pos = [1 ] inner_tiles = [32 ] into %empty : tensor <5 x8 x32 xf32 > -> tensor <5 x256 xf32 >
107
+ return %0 : tensor <5 x256 xf32 >
108
+ }
109
+
110
+ // -----
111
+
112
+ // CHECK-LABEL: func.func @unpacking_with_outer_dims_perm(
113
+ // CHECK-NOT: tensor.collpase_shape
114
+ // CHECK: tensor.unpack
115
+ func.func @unpacking_with_outer_dims_perm (%arg0: tensor <8 x5 x32 xf32 >) -> tensor <5 x256 xf32 > {
116
+ %empty = tensor.empty () : tensor <5 x256 xf32 >
117
+ %0 = tensor.unpack %arg0 outer_dims_perm = [1 , 0 ] inner_dims_pos = [1 ] inner_tiles = [32 ] into %empty : tensor <8 x5 x32 xf32 > -> tensor <5 x256 xf32 >
118
+ return %0 : tensor <5 x256 xf32 >
119
+ }
120
+
121
+ // -----
122
+
123
+ // CHECK-LABEL: func.func @single_first_inner_dim_unpacking(
124
+ // CHECK-NOT: tensor.collapse_shape
125
+ // CHECK: tensor.unpack
126
+ func.func @single_first_inner_dim_unpacking (%arg0: tensor <8 x5 x32 xf32 >) -> tensor <256 x5 xf32 > {
127
+ %empty = tensor.empty () : tensor <256 x5 xf32 >
128
+ %0 = tensor.unpack %arg0 inner_dims_pos = [0 ] inner_tiles = [32 ] into %empty : tensor <8 x5 x32 xf32 > -> tensor <256 x5 xf32 >
129
+ return %0 : tensor <256 x5 xf32 >
130
+ }
0 commit comments