38
38
lvlTypes = [ " compressed" , " dense" , " compressed" , " dense" ]
39
39
}>
40
40
41
+ #DCCD = #sparse_tensor.encoding <{
42
+ lvlTypes = [ " dense" , " compressed" , " compressed" , " dense" ]
43
+ }>
44
+
41
45
// Creates and returns 4-D buffer of size (%s1, %s2, %s3, %s4) filled with the value %f
42
46
func.func @alloc_4d_filled_f32 (%s1 : index , %s2 : index , %s3 : index , %s4 : index , %f : f32 ) -> tensor <?x?x?x?xf32 > {
43
47
%buf = bufferization.alloc_tensor (%s1 , %s2 , %s3 , %s4 ) : tensor <?x?x?x?xf32 >
@@ -77,6 +81,18 @@ func.func @conv_2d_nhwc_hwcf_CDCD(%arg0: tensor<?x?x?x?xf32, #CDCD>, %arg1: tens
77
81
return %ret : tensor <?x?x?x?xf32 , #CDCD >
78
82
}
79
83
84
+ func.func @conv_2d_nhwc_hwcf_DCCD (%arg0: tensor <?x?x?x?xf32 , #DCCD >, %arg1: tensor <?x?x?x?xf32 >) -> tensor <?x?x?x?xf32 , #DCCD > {
85
+ %c1 = arith.constant 1 : index
86
+ %c3 = arith.constant 3 : index
87
+ %c6 = arith.constant 6 : index
88
+ %s = bufferization.alloc_tensor (%c3 , %c6 , %c6 , %c1 ) : tensor <?x?x?x?xf32 , #DCCD >
89
+ %ret = linalg.conv_2d_nhwc_hwcf {dilations = dense <1 > : tensor <2 xi64 >,
90
+ strides = dense <1 > : tensor <2 xi64 >}
91
+ ins (%arg0 , %arg1: tensor <?x?x?x?xf32 , #DCCD >, tensor <?x?x?x?xf32 >)
92
+ outs (%s: tensor <?x?x?x?xf32 , #DCCD >) -> tensor <?x?x?x?xf32 , #DCCD >
93
+ return %ret : tensor <?x?x?x?xf32 , #DCCD >
94
+ }
95
+
80
96
func.func @entry () {
81
97
%c0 = arith.constant 0 : index
82
98
%c1 = arith.constant 1 : index
@@ -96,10 +112,13 @@ func.func @entry() {
96
112
: tensor <?x?x?x?xf32 > to tensor <?x?x?x?xf32 , #CCCC >
97
113
%in2D_nhwc_CDCD = sparse_tensor.convert %in2D_nhwc
98
114
: tensor <?x?x?x?xf32 > to tensor <?x?x?x?xf32 , #CDCD >
115
+ %in2D_nhwc_DCCD = sparse_tensor.convert %in2D_nhwc
116
+ : tensor <?x?x?x?xf32 > to tensor <?x?x?x?xf32 , #DCCD >
99
117
100
118
%dense_ret = call @conv_2d_nhwc_hwcf (%in2D_nhwc , %filter2D_nhwc , %out2D_nhwc ) : (tensor <?x?x?x?xf32 >, tensor <?x?x?x?xf32 >, tensor <?x?x?x?xf32 >) -> (tensor <?x?x?x?xf32 >)
101
119
%CCCC_ret = call @conv_2d_nhwc_hwcf_CCCC (%in2D_nhwc_CCCC , %filter2D_nhwc ) : (tensor <?x?x?x?xf32 , #CCCC >, tensor <?x?x?x?xf32 >) -> (tensor <?x?x?x?xf32 , #CCCC >)
102
120
%CDCD_ret = call @conv_2d_nhwc_hwcf_CDCD (%in2D_nhwc_CDCD , %filter2D_nhwc ) : (tensor <?x?x?x?xf32 , #CDCD >, tensor <?x?x?x?xf32 >) -> (tensor <?x?x?x?xf32 , #CDCD >)
121
+ %DCCD_ret = call @conv_2d_nhwc_hwcf_DCCD (%in2D_nhwc_DCCD , %filter2D_nhwc ) : (tensor <?x?x?x?xf32 , #DCCD >, tensor <?x?x?x?xf32 >) -> (tensor <?x?x?x?xf32 , #DCCD >)
103
122
104
123
// CHECK: ( ( ( ( 108 ), ( 124 ), ( 124 ), ( 124 ), ( 108 ), ( 108 ) ),
105
124
// CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
@@ -171,16 +190,42 @@ func.func @entry() {
171
190
: tensor <?x?x?x?xf32 >, vector <3 x6 x6 x1 xf32 >
172
191
vector.print %v2 : vector <3 x6 x6 x1 xf32 >
173
192
193
+ // CHECK: ( ( ( ( 108 ), ( 124 ), ( 124 ), ( 124 ), ( 108 ), ( 108 ) ),
194
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
195
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
196
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
197
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
198
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ) ),
199
+ // CHECK-SAME: ( ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
200
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
201
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
202
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
203
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
204
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ) ),
205
+ // CHECK-SAME: ( ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
206
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
207
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
208
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
209
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ),
210
+ // CHECK-SAME: ( ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ), ( 108 ) ) ) )
211
+ %3 = sparse_tensor.convert %DCCD_ret
212
+ : tensor <?x?x?x?xf32 , #DCCD > to tensor <?x?x?x?xf32 >
213
+ %v3 = vector.transfer_read %3 [%c0 , %c0 , %c0 , %c0 ], %zero
214
+ : tensor <?x?x?x?xf32 >, vector <3 x6 x6 x1 xf32 >
215
+ vector.print %v3 : vector <3 x6 x6 x1 xf32 >
216
+
174
217
// Free the resources
175
218
bufferization.dealloc_tensor %in2D_nhwc : tensor <?x?x?x?xf32 >
176
219
bufferization.dealloc_tensor %filter2D_nhwc : tensor <?x?x?x?xf32 >
177
220
bufferization.dealloc_tensor %out2D_nhwc : tensor <?x?x?x?xf32 >
178
221
179
222
bufferization.dealloc_tensor %in2D_nhwc_CDCD : tensor <?x?x?x?xf32 , #CDCD >
180
223
bufferization.dealloc_tensor %in2D_nhwc_CCCC : tensor <?x?x?x?xf32 , #CCCC >
224
+ bufferization.dealloc_tensor %in2D_nhwc_DCCD : tensor <?x?x?x?xf32 , #DCCD >
181
225
182
226
bufferization.dealloc_tensor %CCCC_ret : tensor <?x?x?x?xf32 , #CCCC >
183
227
bufferization.dealloc_tensor %CDCD_ret : tensor <?x?x?x?xf32 , #CDCD >
228
+ bufferization.dealloc_tensor %DCCD_ret : tensor <?x?x?x?xf32 , #DCCD >
184
229
185
230
return
186
231
}
0 commit comments