conv_driver.cpp 25.3 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
16
17
#include "device_convolution_forward_implicit_gemm_v4r1_nchw_kcyx_nkhw.hpp"
#include "device_convolution_forward_implicit_gemm_v4r4_nchw_kcyx_nkhw.hpp"
#include "device_convolution_forward_implicit_gemm_v4r4_nhwc_kyxc_nhwk.hpp"
#include "device_dynamic_convolution_forward_implicit_gemm_v4r4_nchw_kcyx_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
18
#include "device_dynamic_convolution_forward_implicit_gemm_v4r4r2_nchw_kcyx_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
19
20
#include "device_dynamic_convolution_forward_implicit_gemm_v4r4_nhwc_kyxc_nhwk.hpp"
#include "device_dynamic_convolution_forward_implicit_gemm_v5r1_nchw_kcyx_nkhw.hpp"
21

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

Chao Liu's avatar
Chao Liu committed
26
#if 0
Chao Liu's avatar
Chao Liu committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    constexpr index_t N  = 1;
    constexpr index_t C  = 16;
    constexpr index_t HI = 1080;
    constexpr index_t WI = 1920;
    constexpr index_t K  = 16;
    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
    constexpr index_t N  = 1;
    constexpr index_t C  = 16;
    constexpr index_t HI = 540;
    constexpr index_t WI = 960;
    constexpr index_t K  = 16;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

52
53
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
54
55
56
57
58
59
#elif 0
    constexpr index_t N  = 1;
    constexpr index_t C  = 16;
    constexpr index_t HI = 270;
    constexpr index_t WI = 480;
    constexpr index_t K  = 16;
60
61
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
Chao Liu's avatar
Chao Liu committed
62
63

    using ConvStrides   = Sequence<1, 1>;
64
    using ConvDilations = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
65

66
67
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
68
#elif 0
Chao Liu's avatar
Chao Liu committed
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
    constexpr index_t N  = 1;
    constexpr index_t C  = 16;
    constexpr index_t HI = 1080;
    constexpr index_t WI = 1920;
    constexpr index_t K  = 16;
    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
    constexpr index_t N  = 1;
    constexpr index_t C  = 1;
    constexpr index_t HI = 1024;
    constexpr index_t WI = 2048;
    constexpr index_t K  = 4;
    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>;
96
#elif 0
Chao Liu's avatar
Chao Liu committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    constexpr index_t N  = 1;
    constexpr index_t C  = 16;
    constexpr index_t HI = 540;
    constexpr index_t WI = 960;
    constexpr index_t K  = 16;
    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
    constexpr index_t N  = 1;
    constexpr index_t C  = 16;
    constexpr index_t HI = 270;
    constexpr index_t WI = 480;
    constexpr index_t K  = 16;
    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, 36x36, stride 2
    constexpr index_t N  = 128;
    constexpr index_t C  = 192;
    constexpr index_t HI = 37;
    constexpr index_t WI = 37;
    constexpr index_t K  = 384;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

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

    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
#elif 0
    // 3x3, 35x35, stride 2
    constexpr index_t N  = 128;
    constexpr index_t C  = 192;
    constexpr index_t HI = 35;
    constexpr index_t WI = 35;
    constexpr index_t K  = 384;
    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
152
153
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
154
#elif 1
Chao Liu's avatar
Chao Liu committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
    // 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  = 128;
    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 1
Chao Liu's avatar
Chao Liu committed
170
    // 1x1, 8x8
171
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
    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;
Chao Liu's avatar
Chao Liu committed
205
    constexpr index_t K  = 128;
Chao Liu's avatar
Chao Liu committed
206
207
208
209
210
211
212
213
    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
214
#elif 1
Chao Liu's avatar
Chao Liu committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
    // 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>;
Chao Liu's avatar
Chao Liu committed
229
#elif 0
Chao Liu's avatar
Chao Liu committed
230
231
232
    // 7x1, 17x17
    constexpr index_t N  = 128;
    constexpr index_t C  = 128;
233
234
    constexpr index_t HI = 17;
    constexpr index_t WI = 17;
Chao Liu's avatar
Chao Liu committed
235
236
237
238
239
240
241
242
243
    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
244
#elif 0
Chao Liu's avatar
Chao Liu committed
245
246
247
248
249
250
    // 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;
251
252
253
254
255
256
257
258
259
    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
260
261
262
263
264
265
    // 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;
266
267
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
268

Chao Liu's avatar
Chao Liu committed
269
    using ConvStrides   = Sequence<2, 2>;
270
271
    using ConvDilations = Sequence<1, 1>;

272
273
274
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
#elif 0
Chao Liu's avatar
Chao Liu committed
275
    // 3x3, 147x147
276
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
277
    constexpr index_t C  = 128;
Chao Liu's avatar
Chao Liu committed
278
279
    constexpr index_t HI = 147;
    constexpr index_t WI = 147;
Chao Liu's avatar
Chao Liu committed
280
    constexpr index_t K  = 128;
281
282
283
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

Chao Liu's avatar
Chao Liu committed
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
    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>;
300
301
    using ConvDilations = Sequence<1, 1>;

302
303
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
304
#elif 0
Chao Liu's avatar
Chao Liu committed
305
306
307
308
309
310
311
312
    // 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
313

Chao Liu's avatar
Chao Liu committed
314
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
315
316
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
317
318
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
319
#elif 0
Chao Liu's avatar
Chao Liu committed
320
    // 1x1, 35x35
Chao Liu's avatar
Chao Liu committed
321
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
322
323
324
325
    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
326
327
328
329
330
331
    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
332
333
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
334
#elif 0
Chao Liu's avatar
Chao Liu committed
335
    // 3x3, 35x35, stride 2
Chao Liu's avatar
Chao Liu committed
336
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
337
338
339
    constexpr index_t C  = 288;
    constexpr index_t HI = 35;
    constexpr index_t WI = 35;
Chao Liu's avatar
Chao Liu committed
340
    constexpr index_t K  = 384;
Chao Liu's avatar
Chao Liu committed
341
342
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
343

Chao Liu's avatar
Chao Liu committed
344
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
345
346
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
347
348
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
349
#elif 0
Chao Liu's avatar
Chao Liu committed
350
    // 1x3, 8x8
Chao Liu's avatar
Chao Liu committed
351
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
352
    constexpr index_t C  = 384;
Chao Liu's avatar
Chao Liu committed
353
354
    constexpr index_t HI = 8;
    constexpr index_t WI = 8;
Chao Liu's avatar
Chao Liu committed
355
    constexpr index_t K  = 448;
Chao Liu's avatar
Chao Liu committed
356
    constexpr index_t Y  = 1;
Chao Liu's avatar
Chao Liu committed
357
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
358
359
360
361

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

Chao Liu's avatar
Chao Liu committed
362
363
    using LeftPads  = Sequence<0, 1>;
    using RightPads = Sequence<0, 1>;
Chao Liu's avatar
Chao Liu committed
364
#elif 0
Chao Liu's avatar
Chao Liu committed
365
    // 3x1, 8x8
Chao Liu's avatar
Chao Liu committed
366
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
367
368
369
370
371
    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
372
373
374
375
376
    constexpr index_t X  = 1;

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

Chao Liu's avatar
Chao Liu committed
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
    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
392
393
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
394
#elif 0
Chao Liu's avatar
Chao Liu committed
395
    // 7x1, 73x73
Chao Liu's avatar
Chao Liu committed
396
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
397
398
399
400
401
    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
402
403
404
405
406
    constexpr index_t X  = 1;

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

Chao Liu's avatar
Chao Liu committed
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
    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
422
423
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
424
#elif 0
Chao Liu's avatar
Chao Liu committed
425
    // 1x1, 14x14, stride 2
Chao Liu's avatar
Chao Liu committed
426
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
427
428
429
430
    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
431
432
433
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
434
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
435
436
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
437
438
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
439
#elif 0
Chao Liu's avatar
Chao Liu committed
440
    // 1x1, 14x14
Chao Liu's avatar
Chao Liu committed
441
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
442
443
444
445
    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
446
447
448
449
450
451
    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
452
453
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
454
#elif 0
Chao Liu's avatar
Chao Liu committed
455
    // 1x1, 14x14, stride 2
Chao Liu's avatar
Chao Liu committed
456
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
457
    constexpr index_t C  = 1024;
Chao Liu's avatar
Chao Liu committed
458
459
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
Chao Liu's avatar
Chao Liu committed
460
    constexpr index_t K  = 512;
Chao Liu's avatar
Chao Liu committed
461
462
463
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
464
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
465
466
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
467
468
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
469
#elif 1
Chao Liu's avatar
Chao Liu committed
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
    // 3x3, 28x28
    constexpr index_t N  = 128;
    constexpr index_t C  = 128;
    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>;
#elif 1
    // 3x3, 14x14
Chao Liu's avatar
Chao Liu committed
486
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
487
    constexpr index_t C  = 256;
Chao Liu's avatar
Chao Liu committed
488
489
490
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
    constexpr index_t K  = 256;
Chao Liu's avatar
Chao Liu committed
491
492
493
494
495
496
497
498
    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
499
#elif 0
Chao Liu's avatar
Chao Liu committed
500
501
502
503
504
505
    // 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
506
507
508
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
509
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
510
511
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
512
513
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
514
#elif 0
Chao Liu's avatar
Chao Liu committed
515
    // 7x7, 230x230 stride=2
Chao Liu's avatar
Chao Liu committed
516
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
    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
536
537
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
Chao Liu's avatar
Chao Liu committed
538

Chao Liu's avatar
Chao Liu committed
539
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
540
541
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
542
543
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
544
#elif 0
Chao Liu's avatar
Chao Liu committed
545
    // 1x1, 28x28, stride 2
Chao Liu's avatar
Chao Liu committed
546
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
547
548
549
550
551
552
    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
553
554
555
556
557
558

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

    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
559
#elif 1
Chao Liu's avatar
Chao Liu committed
560
    // 1x1, 7x7
561
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
562
    constexpr index_t C  = 512;
563
564
    constexpr index_t HI = 7;
    constexpr index_t WI = 7;
Chao Liu's avatar
Chao Liu committed
565
566
567
    constexpr index_t K  = 2048;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
568
569
570
571

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

Chao Liu's avatar
Chao Liu committed
572
573
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
574
#elif 0
Chao Liu's avatar
Chao Liu committed
575
    // 3x3, 7x7
576
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
577
578
579
580
581
582
    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;
583
584
585
586

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

Chao Liu's avatar
Chao Liu committed
587
588
    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
589
#elif 0
Chao Liu's avatar
Chao Liu committed
590
    // 1x1, 56x56
591
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
592
593
594
595
596
    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;
597
    constexpr index_t X  = 1;
598
599
600
601

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

Chao Liu's avatar
Chao Liu committed
602
603
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
604
#elif 0
Chao Liu's avatar
Chao Liu committed
605
606
607
608
609
610
611
612
613
614
615
616
617
618
    // 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
619
#endif
Chao Liu's avatar
Chao Liu committed
620

Chao Liu's avatar
Chao Liu committed
621
622
623
    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
624
        in_nchw_desc, wei_kcyx_desc, ConvStrides{}, ConvDilations{}, LeftPads{}, RightPads{});
Chao Liu's avatar
Chao Liu committed
625

Chao Liu's avatar
Chao Liu committed
626
627
628
    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
629
630
631
632
633
    print_array("LeftPads", to_multi_index(LeftPads{}));
    print_array("RightPads", to_multi_index(RightPads{}));
    print_array("ConvStrides", to_multi_index(ConvStrides{}));
    print_array("ConvDilations", to_multi_index(ConvDilations{}));

634
#if 1
Chao Liu's avatar
Chao Liu committed
635
636
637
638
639
640
641
642
643
644
645
    using in_data_t                  = float;
    constexpr index_t in_vector_size = 1;
    using acc_data_t                 = float;
    using out_data_t                 = float;
#elif 0
    using in_data_t                  = float;
    constexpr index_t in_vector_size = 1;
    using acc_data_t                 = float;
    using out_data_t                 = int8_t;
#elif 1
    using in_data_t                  = int8_t;
646
    constexpr index_t in_vector_size = 16;
Chao Liu's avatar
Chao Liu committed
647
648
    using acc_data_t                 = int32_t;
    using out_data_t                 = int8_t;
Chao Liu's avatar
Chao Liu committed
649
650
651
652
653
654
#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
655

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

Chao Liu's avatar
Chao Liu committed
658
    if(argc != 4)
Chao Liu's avatar
Chao Liu committed
659
    {
Chao Liu's avatar
Chao Liu committed
660
        printf("arg1: do_verification, arg2: do_log, arg3: nrepeat\n");
Chao Liu's avatar
Chao Liu committed
661
662
663
664
        exit(1);
    }

    bool do_verification = atoi(argv[1]);
Chao Liu's avatar
Chao Liu committed
665
666
    bool do_log          = atoi(argv[2]);
    index_t nrepeat      = atoi(argv[3]);
667
668
669

    if(do_verification)
    {
Chao Liu's avatar
Chao Liu committed
670
#if 0
671
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
672
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
673
674
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
675
        wei_kcyx.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
676
#elif 0
Chao Liu's avatar
Chao Liu committed
677
        in_nchw.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
678
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
679
#elif 1
680
        in_nchw.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
Chao Liu's avatar
Chao Liu committed
681
        wei_kcyx.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
Chao Liu's avatar
Chao Liu committed
682
#elif 0
683
684
685
686
687
688
        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
689
#endif
690
    }
Chao Liu's avatar
Chao Liu committed
691

Chao Liu's avatar
Chao Liu committed
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
#if 0
    device_convolution_forward_implicit_gemm_v4r1_nchw_kcyx_nkhw(in_nchw_desc,
                                                                 in_nchw,
                                                                 wei_kcyx_desc,
                                                                 wei_kcyx,
                                                                 out_nkhw_desc,
                                                                 out_nkhw_device,
                                                                 ConvStrides{},
                                                                 ConvDilations{},
                                                                 LeftPads{},
                                                                 RightPads{},
                                                                 nrepeat);
#elif 0
    device_convolution_forward_implicit_gemm_v4r4_nchw_kcyx_nkhw(in_nchw_desc,
                                                                 in_nchw,
                                                                 wei_kcyx_desc,
                                                                 wei_kcyx,
                                                                 out_nkhw_desc,
                                                                 out_nkhw_device,
                                                                 ConvStrides{},
                                                                 ConvDilations{},
                                                                 LeftPads{},
                                                                 RightPads{},
                                                                 nrepeat);
#elif 0
    device_convolution_forward_implicit_gemm_v4r4_nhwc_kyxc_nhwk(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
728
#elif 0
Chao Liu's avatar
Chao Liu committed
729
730
731
    device_dynamic_convolution_forward_implicit_gemm_v4r4_nchw_kcyx_nkhw<in_data_t,
                                                                         in_vector_size,
                                                                         acc_data_t,
732
733
734
735
736
737
738
739
740
741
                                                                         out_data_t>(
        in_nchw_desc,
        in_nchw,
        wei_kcyx_desc,
        wei_kcyx,
        out_nkhw_desc,
        out_nkhw_device,
        ConvStrides{},
        ConvDilations{},
        LeftPads{},
Chao Liu's avatar
Chao Liu committed
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
        RightPads{},
        nrepeat);
#elif 1
    device_dynamic_convolution_forward_implicit_gemm_v4r4r2_nchw_kcyx_nkhw<in_data_t,
                                                                           in_vector_size,
                                                                           acc_data_t,
                                                                           out_data_t>(
        in_nchw_desc,
        in_nchw,
        wei_kcyx_desc,
        wei_kcyx,
        out_nkhw_desc,
        out_nkhw_device,
        ConvStrides{},
        ConvDilations{},
        LeftPads{},
758
759
        RightPads{},
        nrepeat);
760
#elif 1
Chao Liu's avatar
Chao Liu committed
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
    device_dynamic_convolution_forward_implicit_gemm_v4r4_nhwc_kyxc_nhwk<in_data_t,
                                                                         in_vector_size,
                                                                         acc_data_t,
                                                                         out_data_t>

        (in_nchw_desc,
         in_nchw,
         wei_kcyx_desc,
         wei_kcyx,
         out_nkhw_desc,
         out_nkhw_device,
         ConvStrides{},
         ConvDilations{},
         LeftPads{},
         RightPads{},
         nrepeat);
#elif 1
    device_dynamic_convolution_forward_implicit_gemm_v5r1_nchw_kcyx_nkhw<in_data_t,
                                                                         in_vector_size,
                                                                         acc_data_t,
                                                                         out_data_t>(
        in_nchw_desc,
        in_nchw,
        wei_kcyx_desc,
        wei_kcyx,
        out_nkhw_desc,
        out_nkhw_device,
        ConvStrides{},
        ConvDilations{},
        LeftPads{},
        RightPads{},
        nrepeat);
793
#endif
Chao Liu's avatar
Chao Liu committed
794

795
    if(do_verification)
796
    {
Chao Liu's avatar
Chao Liu committed
797
798
799
800
801
802
803
804
        host_direct_convolution(in_nchw,
                                wei_kcyx,
                                out_nkhw_host,
                                ConvStrides{},
                                ConvDilations{},
                                LeftPads{},
                                RightPads{});

805
        check_error(out_nkhw_host, out_nkhw_device);
Chao Liu's avatar
Chao Liu committed
806

Chao Liu's avatar
Chao Liu committed
807
808
809
810
811
812
813
        if(do_log)
        {
            LogRange(std::cout << "in_nchw : ", in_nchw.mData, ",") << std::endl;
            LogRange(std::cout << "wei_kcyx: ", wei_kcyx.mData, ",") << std::endl;
            LogRange(std::cout << "out_nkhw_host  : ", out_nkhw_host.mData, ",") << std::endl;
            LogRange(std::cout << "out_nkhw_device: ", out_nkhw_device.mData, ",") << std::endl;
        }
814
    }
815
}