conv_driver.cpp 19.6 KB
Newer Older
Chao Liu's avatar
Chao Liu committed
1
#include <iostream>
Chao Liu's avatar
Chao Liu committed
2
3
#include <numeric>
#include <initializer_list>
Chao Liu's avatar
Chao Liu committed
4
#include <cstdlib>
Chao Liu's avatar
Chao Liu committed
5
#include <stdlib.h>
Chao Liu's avatar
Chao Liu committed
6
#include <half.hpp>
Chao Liu's avatar
Chao Liu committed
7
#include "config.hpp"
Chao Liu's avatar
Chao Liu committed
8
#include "print.hpp"
Chao Liu's avatar
Chao Liu committed
9
#include "device.hpp"
Chao Liu's avatar
Chao Liu committed
10
#include "host_tensor_generator.hpp"
Chao Liu's avatar
Chao Liu committed
11
#include "conv_common.hpp"
12
#include "host_conv.hpp"
Chao Liu's avatar
Chao Liu committed
13
#include "device_tensor.hpp"
Chao Liu's avatar
Chao Liu committed
14
15
#include "device_convolution_implicit_gemm_v4r1_nchw_kcyx_nkhw.hpp"
#include "device_convolution_implicit_gemm_v4r4_nchw_kcyx_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
16
#include "device_dummy_static_transform.hpp"
Chao Liu's avatar
Chao Liu committed
17
18
#include "device_dummy_dynamic_transform_v1.hpp"
#include "device_dummy_dynamic_transform_v2.hpp"
19

Chao Liu's avatar
Chao Liu committed
20
int main(int argc, char* argv[])
Chao Liu's avatar
Chao Liu committed
21
{
Chao Liu's avatar
Chao Liu committed
22
23
    using namespace ck;

Chao Liu's avatar
Chao Liu committed
24
#if 0
Chao Liu's avatar
Chao Liu committed
25
    // 3x3, 71x71
Chao Liu's avatar
Chao Liu committed
26
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
27
28
29
30
31
32
    constexpr index_t C  = 192;
    constexpr index_t HI = 71;
    constexpr index_t WI = 71;
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
33

Chao Liu's avatar
Chao Liu committed
34
    using ConvStrides   = Sequence<2, 2>;
35
    using ConvDilations = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
36

Chao Liu's avatar
Chao Liu committed
37
38
    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
39
#elif 0
Chao Liu's avatar
Chao Liu committed
40
    // 1x1, 8x8
41
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    constexpr index_t C  = 1536;
    constexpr index_t HI = 8;
    constexpr index_t WI = 8;
    constexpr index_t K  = 256;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
#elif 0
    // 1x1, 73x73
    constexpr index_t N  = 128;
    constexpr index_t C  = 160;
    constexpr index_t HI = 73;
    constexpr index_t WI = 73;
    constexpr index_t K  = 64;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
#elif 0
    // 3x3, 35x35
    constexpr index_t N  = 128;
    constexpr index_t C  = 96;
    constexpr index_t HI = 35;
    constexpr index_t WI = 35;
    constexpr index_t K  = 96;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
#elif 0
    // 3x3, 71x71
    constexpr index_t N  = 128;
    constexpr index_t C  = 192;
    constexpr index_t HI = 71;
    constexpr index_t WI = 71;
    constexpr index_t K  = 192;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    using ConvStrides   = Sequence<2, 2>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
#elif 0
    // 7x1, 17x17
    constexpr index_t N  = 128;
    constexpr index_t C  = 128;
103
104
    constexpr index_t HI = 17;
    constexpr index_t WI = 17;
Chao Liu's avatar
Chao Liu committed
105
106
107
108
109
110
111
112
113
    constexpr index_t K  = 128;
    constexpr index_t Y  = 7;
    constexpr index_t X  = 1;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<3, 0>;
    using RightPads = Sequence<3, 0>;
Chao Liu's avatar
Chao Liu committed
114
#elif 0
Chao Liu's avatar
Chao Liu committed
115
116
117
118
119
120
    // 1x7, 17x17
    constexpr index_t N  = 128;
    constexpr index_t C  = 128;
    constexpr index_t HI = 17;
    constexpr index_t WI = 17;
    constexpr index_t K  = 128;
121
122
123
124
125
126
127
128
129
    constexpr index_t Y  = 1;
    constexpr index_t X  = 7;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<0, 3>;
    using RightPads = Sequence<0, 3>;
#elif 0
Chao Liu's avatar
Chao Liu committed
130
131
132
133
134
135
    // 3x3, 299x299 stride=2
    constexpr index_t N  = 128;
    constexpr index_t C  = 3;
    constexpr index_t HI = 299;
    constexpr index_t WI = 299;
    constexpr index_t K  = 32;
136
137
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
138

Chao Liu's avatar
Chao Liu committed
139
    using ConvStrides   = Sequence<2, 2>;
140
141
    using ConvDilations = Sequence<1, 1>;

142
143
144
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
#elif 0
Chao Liu's avatar
Chao Liu committed
145
    // 3x3, 147x147
146
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
147
148
149
150
    constexpr index_t C  = 32;
    constexpr index_t HI = 147;
    constexpr index_t WI = 147;
    constexpr index_t K  = 64;
151
152
153
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

Chao Liu's avatar
Chao Liu committed
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
#elif 0
    // 3x3, 149x149
    constexpr index_t N  = 128;
    constexpr index_t C  = 32;
    constexpr index_t HI = 149;
    constexpr index_t WI = 149;
    constexpr index_t K  = 32;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    using ConvStrides   = Sequence<1, 1>;
170
171
    using ConvDilations = Sequence<1, 1>;

172
173
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
174
#elif 0
Chao Liu's avatar
Chao Liu committed
175
176
177
178
179
180
181
182
    // 3x3, 17x17, stride 2
    constexpr index_t N  = 128;
    constexpr index_t C  = 192;
    constexpr index_t HI = 17;
    constexpr index_t WI = 17;
    constexpr index_t K  = 192;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
183

Chao Liu's avatar
Chao Liu committed
184
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
185
186
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
187
188
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
189
#elif 0
Chao Liu's avatar
Chao Liu committed
190
    // 1x1, 35x35
Chao Liu's avatar
Chao Liu committed
191
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
192
193
194
195
    constexpr index_t C  = 384;
    constexpr index_t HI = 35;
    constexpr index_t WI = 35;
    constexpr index_t K  = 96;
Chao Liu's avatar
Chao Liu committed
196
197
198
199
200
201
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
202
203
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
204
#elif 1
Chao Liu's avatar
Chao Liu committed
205
    // 3x3, 35x35, stride 2
Chao Liu's avatar
Chao Liu committed
206
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
207
208
209
    constexpr index_t C  = 288;
    constexpr index_t HI = 35;
    constexpr index_t WI = 35;
Chao Liu's avatar
Chao Liu committed
210
    constexpr index_t K  = 384;
Chao Liu's avatar
Chao Liu committed
211
212
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
213

Chao Liu's avatar
Chao Liu committed
214
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
215
216
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
217
218
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
219
#elif 0
Chao Liu's avatar
Chao Liu committed
220
    // 1x3, 8x8
Chao Liu's avatar
Chao Liu committed
221
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
222
    constexpr index_t C  = 384;
Chao Liu's avatar
Chao Liu committed
223
224
    constexpr index_t HI = 8;
    constexpr index_t WI = 8;
Chao Liu's avatar
Chao Liu committed
225
    constexpr index_t K  = 448;
Chao Liu's avatar
Chao Liu committed
226
    constexpr index_t Y  = 1;
Chao Liu's avatar
Chao Liu committed
227
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
228
229
230
231

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
232
233
    using LeftPads  = Sequence<0, 1>;
    using RightPads = Sequence<0, 1>;
Chao Liu's avatar
Chao Liu committed
234
#elif 0
Chao Liu's avatar
Chao Liu committed
235
    // 3x1, 8x8
Chao Liu's avatar
Chao Liu committed
236
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
237
238
239
240
241
    constexpr index_t C  = 448;
    constexpr index_t HI = 8;
    constexpr index_t WI = 8;
    constexpr index_t K  = 512;
    constexpr index_t Y  = 3;
Chao Liu's avatar
Chao Liu committed
242
243
244
245
246
    constexpr index_t X  = 1;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
    using LeftPads  = Sequence<1, 0>;
    using RightPads = Sequence<1, 0>;
#elif 0
    // 3x3, 147x147
    constexpr index_t N  = 128;
    constexpr index_t C  = 64;
    constexpr index_t HI = 147;
    constexpr index_t WI = 147;
    constexpr index_t K  = 96;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    using ConvStrides   = Sequence<2, 2>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
262
263
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
264
#elif 0
Chao Liu's avatar
Chao Liu committed
265
    // 7x1, 73x73
Chao Liu's avatar
Chao Liu committed
266
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
267
268
269
270
271
    constexpr index_t C  = 64;
    constexpr index_t HI = 73;
    constexpr index_t WI = 73;
    constexpr index_t K  = 64;
    constexpr index_t Y  = 7;
Chao Liu's avatar
Chao Liu committed
272
273
274
275
276
    constexpr index_t X  = 1;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
    using LeftPads  = Sequence<3, 0>;
    using RightPads = Sequence<3, 0>;
#elif 0
    // 3x3, 73x73
    constexpr index_t N  = 128;
    constexpr index_t C  = 64;
    constexpr index_t HI = 73;
    constexpr index_t WI = 73;
    constexpr index_t K  = 96;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
292
293
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
294
#elif 0
Chao Liu's avatar
Chao Liu committed
295
    // 1x1, 14x14, stride 2
Chao Liu's avatar
Chao Liu committed
296
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
297
298
299
300
    constexpr index_t C  = 1024;
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
    constexpr index_t K  = 2048;
Chao Liu's avatar
Chao Liu committed
301
302
303
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
304
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
305
306
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
307
308
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
309
#elif 0
Chao Liu's avatar
Chao Liu committed
310
    // 1x1, 14x14
Chao Liu's avatar
Chao Liu committed
311
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
312
313
314
315
    constexpr index_t C  = 1024;
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
    constexpr index_t K  = 256;
Chao Liu's avatar
Chao Liu committed
316
317
318
319
320
321
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
322
323
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
324
#elif 0
Chao Liu's avatar
Chao Liu committed
325
    // 1x1, 14x14, stride 2
Chao Liu's avatar
Chao Liu committed
326
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
327
    constexpr index_t C  = 1024;
Chao Liu's avatar
Chao Liu committed
328
329
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
Chao Liu's avatar
Chao Liu committed
330
    constexpr index_t K  = 512;
Chao Liu's avatar
Chao Liu committed
331
332
333
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
334
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
335
336
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
337
338
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
339
#elif 1
Chao Liu's avatar
Chao Liu committed
340
341
    // 3x3, 28x28
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
342
    constexpr index_t C  = 192;
Chao Liu's avatar
Chao Liu committed
343
344
345
346
347
348
349
350
351
352
353
    constexpr index_t HI = 28;
    constexpr index_t WI = 28;
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
354
#elif 0
Chao Liu's avatar
Chao Liu committed
355
    // 3x3, 14x14
Chao Liu's avatar
Chao Liu committed
356
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
357
    constexpr index_t C  = 256;
Chao Liu's avatar
Chao Liu committed
358
359
360
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
    constexpr index_t K  = 256;
Chao Liu's avatar
Chao Liu committed
361
362
363
364
365
366
367
368
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
369
#elif 0
Chao Liu's avatar
Chao Liu committed
370
371
372
373
374
375
    // 1x1, 56x56, stride 2
    constexpr index_t N  = 128;
    constexpr index_t C  = 256;
    constexpr index_t HI = 56;
    constexpr index_t WI = 56;
    constexpr index_t K  = 128;
Chao Liu's avatar
Chao Liu committed
376
377
378
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
379
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
380
381
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
382
383
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
384
#elif 0
Chao Liu's avatar
Chao Liu committed
385
    // 7x7, 230x230 stride=2
Chao Liu's avatar
Chao Liu committed
386
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
    constexpr index_t C  = 3;
    constexpr index_t HI = 230;
    constexpr index_t WI = 230;
    constexpr index_t K  = 64;
    constexpr index_t Y  = 7;
    constexpr index_t X  = 7;

    using ConvStrides   = Sequence<2, 2>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
#elif 0
    // 1x1, 28x28, stride = 2
    constexpr index_t N  = 128;
    constexpr index_t C  = 512;
    constexpr index_t HI = 28;
    constexpr index_t WI = 28;
    constexpr index_t K  = 1024;
Chao Liu's avatar
Chao Liu committed
406
407
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
Chao Liu's avatar
Chao Liu committed
408

Chao Liu's avatar
Chao Liu committed
409
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
410
411
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
412
413
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
414
#elif 0
Chao Liu's avatar
Chao Liu committed
415
    // 1x1, 28x28, stride 2
Chao Liu's avatar
Chao Liu committed
416
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
417
418
419
420
421
422
    constexpr index_t C  = 512;
    constexpr index_t HI = 28;
    constexpr index_t WI = 28;
    constexpr index_t K  = 256;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
Chao Liu's avatar
Chao Liu committed
423
424
425
426
427
428

    using ConvStrides   = Sequence<2, 2>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
429
#elif 0
Chao Liu's avatar
Chao Liu committed
430
    // 1x1, 7x7
431
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
432
    constexpr index_t C  = 512;
433
434
    constexpr index_t HI = 7;
    constexpr index_t WI = 7;
Chao Liu's avatar
Chao Liu committed
435
436
437
    constexpr index_t K  = 2048;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
438
439
440
441

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
442
443
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
444
#elif 0
Chao Liu's avatar
Chao Liu committed
445
    // 3x3, 7x7
446
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
447
448
449
450
451
452
    constexpr index_t C  = 512;
    constexpr index_t HI = 7;
    constexpr index_t WI = 7;
    constexpr index_t K  = 512;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
453
454
455
456

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
457
458
    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
459
#elif 0
Chao Liu's avatar
Chao Liu committed
460
    // 1x1, 56x56
461
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
462
463
464
465
466
    constexpr index_t C  = 64;
    constexpr index_t HI = 56;
    constexpr index_t WI = 56;
    constexpr index_t K  = 64;
    constexpr index_t Y  = 1;
467
    constexpr index_t X  = 1;
468
469
470
471

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
472
473
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
474
#elif 0
Chao Liu's avatar
Chao Liu committed
475
476
477
478
479
480
481
482
483
484
485
486
487
488
    // 3x3, 56x56
    constexpr index_t N  = 128;
    constexpr index_t C  = 64;
    constexpr index_t HI = 56;
    constexpr index_t WI = 56;
    constexpr index_t K  = 64;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
489
#endif
Chao Liu's avatar
Chao Liu committed
490

Chao Liu's avatar
Chao Liu committed
491
492
493
    auto in_nchw_desc  = make_native_tensor_descriptor_packed(Sequence<N, C, HI, WI>{});
    auto wei_kcyx_desc = make_native_tensor_descriptor_packed(Sequence<K, C, Y, X>{});
    auto out_nkhw_desc = get_convolution_output_default_4d_tensor_descriptor(
Chao Liu's avatar
Chao Liu committed
494
        in_nchw_desc, wei_kcyx_desc, ConvStrides{}, ConvDilations{}, LeftPads{}, RightPads{});
Chao Liu's avatar
Chao Liu committed
495

Chao Liu's avatar
Chao Liu committed
496
497
498
    ostream_tensor_descriptor(in_nchw_desc, std::cout << "in_nchw_desc: ");
    ostream_tensor_descriptor(wei_kcyx_desc, std::cout << "wei_kcyx_desc: ");
    ostream_tensor_descriptor(out_nkhw_desc, std::cout << "out_nkhw_desc: ");
Chao Liu's avatar
Chao Liu committed
499
500
501
502
    print_array("LeftPads", LeftPads{});
    print_array("RightPads", RightPads{});
    print_array("ConvStrides", ConvStrides{});
    print_array("ConvDilations", ConvDilations{});
Chao Liu's avatar
Chao Liu committed
503

Chao Liu's avatar
Chao Liu committed
504
#if 1
Chao Liu's avatar
Chao Liu committed
505
506
    using in_data_t  = float;
    using out_data_t = float;
Chao Liu's avatar
Chao Liu committed
507
508
509
510
511
512
513
514
515
#else
    using in_data_t  = half_float::half;
    using out_data_t = half_float::half;
#endif

    Tensor<in_data_t> in_nchw(make_HostTensorDescriptor(in_nchw_desc));
    Tensor<in_data_t> wei_kcyx(make_HostTensorDescriptor(wei_kcyx_desc));
    Tensor<out_data_t> out_nkhw_host(make_HostTensorDescriptor(out_nkhw_desc));
    Tensor<out_data_t> out_nkhw_device(make_HostTensorDescriptor(out_nkhw_desc));
Chao Liu's avatar
Chao Liu committed
516

Chao Liu's avatar
Chao Liu committed
517
    std::size_t num_thread = std::thread::hardware_concurrency();
Chao Liu's avatar
Chao Liu committed
518

Chao Liu's avatar
Chao Liu committed
519
520
521
522
523
524
525
    if(argc != 3)
    {
        printf("arg1: do_verification, arg2: nrepeat\n");
        exit(1);
    }

    bool do_verification = atoi(argv[1]);
Chao Liu's avatar
Chao Liu committed
526
    index_t nrepeat      = atoi(argv[2]);
527
528
529

    if(do_verification)
    {
Chao Liu's avatar
Chao Liu committed
530
#if 0
531
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
532
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
533
534
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
bug fix  
Chao Liu committed
535
        wei_kcyx.GenerateTensorValue(GeneratorTensor_3{}, num_thread);
536
537
538
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_3{}, num_thread);
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
539
#elif 1
540
        in_nchw.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
Chao Liu's avatar
Chao Liu committed
541
        wei_kcyx.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
Chao Liu's avatar
Chao Liu committed
542
#elif 0
543
544
545
546
547
548
        in_nchw.GenerateTensorValue(GeneratorTensor_2{1, 5}, num_thread);

        auto gen_wei = [](auto... is) {
            return GeneratorTensor_2{1, 5}(is...) * GeneratorTensor_Checkboard{}(is...);
        };
        wei_kcyx.GenerateTensorValue(gen_wei, num_thread);
Chao Liu's avatar
Chao Liu committed
549
#endif
550
    }
Chao Liu's avatar
Chao Liu committed
551

Chao Liu's avatar
Chao Liu committed
552
#if 0
Chao Liu's avatar
Chao Liu committed
553
554
555
556
557
558
559
560
    device_convolution_implicit_gemm_v4r1_nchw_kcyx_nkhw(in_nchw_desc,
                                                         in_nchw,
                                                         wei_kcyx_desc,
                                                         wei_kcyx,
                                                         out_nkhw_desc,
                                                         out_nkhw_device,
                                                         ConvStrides{},
                                                         ConvDilations{},
561
562
                                                         LeftPads{},
                                                         RightPads{},
Chao Liu's avatar
Chao Liu committed
563
                                                         nrepeat);
Chao Liu's avatar
Chao Liu committed
564
#elif 0
Chao Liu's avatar
Chao Liu committed
565
566
567
568
569
570
    device_convolution_implicit_gemm_v4r4_nchw_kcyx_nkhw(in_nchw_desc,
                                                         in_nchw,
                                                         wei_kcyx_desc,
                                                         wei_kcyx,
                                                         out_nkhw_desc,
                                                         out_nkhw_device,
Chao Liu's avatar
Chao Liu committed
571
572
                                                         ConvStrides{},
                                                         ConvDilations{},
573
574
                                                         LeftPads{},
                                                         RightPads{},
Chao Liu's avatar
Chao Liu committed
575
                                                         nrepeat);
Chao Liu's avatar
Chao Liu committed
576
577
578
579
580
581
582
583
584
585
586
587
#elif 0
    device_dummy_static_transform(in_nchw_desc,
                                  in_nchw,
                                  wei_kcyx_desc,
                                  wei_kcyx,
                                  out_nkhw_desc,
                                  out_nkhw_device,
                                  ConvStrides{},
                                  ConvDilations{},
                                  LeftPads{},
                                  RightPads{},
                                  nrepeat);
Chao Liu's avatar
Chao Liu committed
588
#elif 0
Chao Liu's avatar
Chao Liu committed
589
590
591
592
593
594
595
596
597
598
599
    device_dummy_dynamic_transform_v1(in_nchw_desc,
                                      in_nchw,
                                      wei_kcyx_desc,
                                      wei_kcyx,
                                      out_nkhw_desc,
                                      out_nkhw_device,
                                      ConvStrides{},
                                      ConvDilations{},
                                      LeftPads{},
                                      RightPads{},
                                      nrepeat);
Chao Liu's avatar
Chao Liu committed
600
#elif 1
Chao Liu's avatar
Chao Liu committed
601
602
603
604
605
606
607
608
609
610
611
    device_dummy_dynamic_transform_v2(in_nchw_desc,
                                      in_nchw,
                                      wei_kcyx_desc,
                                      wei_kcyx,
                                      out_nkhw_desc,
                                      out_nkhw_device,
                                      ConvStrides{},
                                      ConvDilations{},
                                      LeftPads{},
                                      RightPads{},
                                      nrepeat);
612
#endif
Chao Liu's avatar
Chao Liu committed
613

614
    if(do_verification)
615
    {
Chao Liu's avatar
Chao Liu committed
616
#if 0
617
618
        if(Y == 3 && X == 3 && ConvStrides{}[0] == 1 && ConvStrides{}[1] == 1 &&
           ConvDilations{}[0] == 1 && ConvDilations{}[1] == 1)
619
        {
Chao Liu's avatar
Chao Liu committed
620
621
            host_winograd_3x3_convolution(
                in_nchw, wei_kcyx, out_nkhw_host, LeftPads{}, RightPads{});
622
623
        }
        else
Chao Liu's avatar
Chao Liu committed
624
#endif
625
        {
626
627
628
629
630
            host_direct_convolution(in_nchw,
                                    wei_kcyx,
                                    out_nkhw_host,
                                    ConvStrides{},
                                    ConvDilations{},
Chao Liu's avatar
Chao Liu committed
631
632
                                    LeftPads{},
                                    RightPads{});
633
634
        }
        check_error(out_nkhw_host, out_nkhw_device);
Chao Liu's avatar
Chao Liu committed
635

Chao Liu's avatar
Chao Liu committed
636
#if 0
637
        LogRange(std::cout << "in_nchw : ", in_nchw.mData, ",") << std::endl;
Chao Liu's avatar
Chao Liu committed
638
        LogRange(std::cout << "wei_kcyx: ", wei_kcyx.mData, ",") << std::endl;
639
640
        LogRange(std::cout << "out_nkhw_host  : ", out_nkhw_host.mData, ",") << std::endl;
        LogRange(std::cout << "out_nkhw_device: ", out_nkhw_device.mData, ",") << std::endl;
Chao Liu's avatar
Chao Liu committed
641
#endif
642
    }
643
}