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

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

25
#if 0
Chao Liu's avatar
Chao Liu committed
26
27
    constexpr index_t N  = 1;
    constexpr index_t C  = 16;
Chao Liu's avatar
Chao Liu committed
28
29
30
31
32
33
34
35
36
    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>;

Chao Liu's avatar
Chao Liu committed
37
38
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Jing Zhang's avatar
Jing Zhang committed
39
#elif 0
Chao Liu's avatar
Chao Liu committed
40
    constexpr index_t N  = 1;
Chao Liu's avatar
Chao Liu committed
41
    constexpr index_t C  = 16;
Jing Zhang's avatar
Jing Zhang committed
42
    constexpr index_t HI = 540;
Chao Liu's avatar
Chao Liu committed
43
    constexpr index_t WI = 960;
Chao Liu's avatar
Chao Liu committed
44
45
46
47
48
49
50
    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>;

Jing Zhang's avatar
Jing Zhang committed
51
52
    using LeftPads                   = Sequence<0, 0>;
    using RightPads                  = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
53
#elif 0
Chao Liu's avatar
Chao Liu committed
54
    constexpr index_t N  = 1;
Chao Liu's avatar
Chao Liu committed
55
    constexpr index_t C  = 16;
Chao Liu's avatar
Chao Liu committed
56
57
58
59
60
61
62
63
64
    constexpr index_t HI = 270;
    constexpr index_t WI = 480;
    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>;

Jing Zhang's avatar
Jing Zhang committed
65
66
    using LeftPads                   = Sequence<0, 0>;
    using RightPads                  = Sequence<0, 0>;
Jing Zhang's avatar
Jing Zhang committed
67
#elif 0
Chao Liu's avatar
Chao Liu committed
68
    constexpr index_t N  = 1;
root's avatar
root committed
69
    constexpr index_t C  = 16;
Chao Liu's avatar
Chao Liu committed
70
71
    constexpr index_t HI = 1080;
    constexpr index_t WI = 1920;
Jing Zhang's avatar
Jing Zhang committed
72
    constexpr index_t K  = 16;
Chao Liu's avatar
Chao Liu committed
73
74
75
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

Jing Zhang's avatar
Jing Zhang committed
76
    using ConvStrides   = Sequence<1, 1>;
Jing Zhang's avatar
Jing Zhang committed
77
    using ConvDilations = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
78

Jing Zhang's avatar
Jing Zhang committed
79
80
    using LeftPads                   = Sequence<1, 1>;
    using RightPads                  = Sequence<1, 1>;
Jing Zhang's avatar
int8  
Jing Zhang committed
81
#elif 0
Chao Liu's avatar
Chao Liu committed
82
    constexpr index_t N  = 1;
Jing Zhang's avatar
Jing Zhang committed
83
84
85
    constexpr index_t C  = 4;
    constexpr index_t HI = 64;
    constexpr index_t WI = 64;
Jing Zhang's avatar
mock up  
Jing Zhang committed
86
    constexpr index_t K  = 4;
Chao Liu's avatar
Chao Liu committed
87
88
89
90
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    using ConvStrides   = Sequence<1, 1>;
Jing Zhang's avatar
fixed  
Jing Zhang committed
91
    using ConvDilations = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
92

Chao Liu's avatar
Chao Liu committed
93
94
    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
Jing Zhang's avatar
Jing Zhang committed
95
#elif 1
Chao Liu's avatar
Chao Liu committed
96
    constexpr index_t N  = 1;
Chao Liu's avatar
Chao Liu committed
97
    constexpr index_t C  = 16;
Jing Zhang's avatar
Jing Zhang committed
98
    constexpr index_t HI = 544;
Chao Liu's avatar
Chao Liu committed
99
100
101
102
103
104
105
106
107
108
    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>;
Chao Liu's avatar
test  
Chao Liu committed
109
#elif 0
Chao Liu's avatar
Chao Liu committed
110
    constexpr index_t N  = 1;
Chao Liu's avatar
Chao Liu committed
111
    constexpr index_t C  = 16;
Chao Liu's avatar
Chao Liu committed
112
113
114
    constexpr index_t HI = 270;
    constexpr index_t WI = 480;
    constexpr index_t K  = 16;
Chao Liu's avatar
Chao Liu committed
115
116
117
118
119
120
121
    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>;
Jing Zhang's avatar
Jing Zhang committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    using RightPads = Sequence<1, 1>;
#elif 0
    constexpr index_t N  = 1;
    constexpr index_t C  = 16;
    constexpr index_t HI = 135;
    constexpr index_t WI = 240;
    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>;
Chao Liu's avatar
Chao Liu committed
136
137
    using RightPads = Sequence<1, 1>;
#elif 0
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    // 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>;
152
#elif 0
153
154
155
156
157
158
159
160
    // 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;
161

162
    using ConvStrides   = Sequence<2, 2>;
163
164
165
166
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
167
#elif 1
Chao Liu's avatar
Chao Liu committed
168
    // 3x3, 71x71
Chao Liu's avatar
Chao Liu committed
169
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
170
171
172
173
174
175
    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
176

Chao Liu's avatar
Chao Liu committed
177
    using ConvStrides   = Sequence<2, 2>;
178
    using ConvDilations = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
179

Chao Liu's avatar
Chao Liu committed
180
181
    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
182
#elif 1
Chao Liu's avatar
Chao Liu committed
183
    // 1x1, 8x8
184
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
    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;
218
    constexpr index_t K  = 128;
Chao Liu's avatar
Chao Liu committed
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
    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>;
242
#elif 1
Chao Liu's avatar
Chao Liu committed
243
244
245
    // 7x1, 17x17
    constexpr index_t N  = 128;
    constexpr index_t C  = 128;
246
247
    constexpr index_t HI = 17;
    constexpr index_t WI = 17;
248
    constexpr index_t K  = 128;
Chao Liu's avatar
Chao Liu committed
249
250
251
252
253
254
255
256
    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>;
257
#elif 0
Chao Liu's avatar
Chao Liu committed
258
259
260
261
262
263
    // 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;
264
265
266
267
268
269
270
271
272
    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
273
274
275
276
277
278
    // 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;
279
280
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
281

Chao Liu's avatar
Chao Liu committed
282
    using ConvStrides   = Sequence<2, 2>;
283
284
    using ConvDilations = Sequence<1, 1>;

285
286
287
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
#elif 0
Chao Liu's avatar
Chao Liu committed
288
    // 3x3, 147x147
289
    constexpr index_t N  = 128;
290
    constexpr index_t C  = 128;
Chao Liu's avatar
Chao Liu committed
291
292
    constexpr index_t HI = 147;
    constexpr index_t WI = 147;
293
    constexpr index_t K  = 128;
294
295
296
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

Chao Liu's avatar
Chao Liu committed
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
    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>;
313
314
    using ConvDilations = Sequence<1, 1>;

315
316
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
317
#elif 0
Chao Liu's avatar
Chao Liu committed
318
319
320
321
322
323
324
325
    // 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
326

Chao Liu's avatar
Chao Liu committed
327
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
328
329
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
330
331
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
332
#elif 0
Chao Liu's avatar
Chao Liu committed
333
    // 1x1, 35x35
Chao Liu's avatar
Chao Liu committed
334
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
335
336
337
338
    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
339
340
341
342
343
344
    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
345
346
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
347
#elif 0
Chao Liu's avatar
Chao Liu committed
348
    // 3x3, 35x35, stride 2
Chao Liu's avatar
Chao Liu committed
349
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
350
351
352
    constexpr index_t C  = 288;
    constexpr index_t HI = 35;
    constexpr index_t WI = 35;
Chao Liu's avatar
Chao Liu committed
353
    constexpr index_t K  = 384;
Chao Liu's avatar
Chao Liu committed
354
355
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
356

Chao Liu's avatar
Chao Liu committed
357
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
358
359
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
360
361
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
362
#elif 0
Chao Liu's avatar
Chao Liu committed
363
    // 1x3, 8x8
Chao Liu's avatar
Chao Liu committed
364
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
365
    constexpr index_t C  = 384;
Chao Liu's avatar
Chao Liu committed
366
367
    constexpr index_t HI = 8;
    constexpr index_t WI = 8;
Chao Liu's avatar
Chao Liu committed
368
    constexpr index_t K  = 448;
Chao Liu's avatar
Chao Liu committed
369
    constexpr index_t Y  = 1;
Chao Liu's avatar
Chao Liu committed
370
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
371
372
373
374

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

Chao Liu's avatar
Chao Liu committed
375
376
    using LeftPads  = Sequence<0, 1>;
    using RightPads = Sequence<0, 1>;
Chao Liu's avatar
Chao Liu committed
377
#elif 0
Chao Liu's avatar
Chao Liu committed
378
    // 3x1, 8x8
Chao Liu's avatar
Chao Liu committed
379
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
380
381
382
383
384
    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
385
386
387
388
389
    constexpr index_t X  = 1;

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

Chao Liu's avatar
Chao Liu committed
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
    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
405
406
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
407
#elif 0
Chao Liu's avatar
Chao Liu committed
408
    // 7x1, 73x73
Chao Liu's avatar
Chao Liu committed
409
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
410
411
412
413
414
    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
415
416
417
418
419
    constexpr index_t X  = 1;

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

Chao Liu's avatar
Chao Liu committed
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
    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
435
436
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
437
#elif 0
Chao Liu's avatar
Chao Liu committed
438
    // 1x1, 14x14, stride 2
Chao Liu's avatar
Chao Liu committed
439
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
440
441
442
443
    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
444
445
446
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
447
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
448
449
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
450
451
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
452
#elif 0
Chao Liu's avatar
Chao Liu committed
453
    // 1x1, 14x14
Chao Liu's avatar
Chao Liu committed
454
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
455
456
457
458
    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
459
460
461
462
463
464
    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
465
466
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
467
#elif 0
Chao Liu's avatar
Chao Liu committed
468
    // 1x1, 14x14, stride 2
Chao Liu's avatar
Chao Liu committed
469
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
470
    constexpr index_t C  = 1024;
Chao Liu's avatar
Chao Liu committed
471
472
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
Chao Liu's avatar
Chao Liu committed
473
    constexpr index_t K  = 512;
Chao Liu's avatar
Chao Liu committed
474
475
476
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
477
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
478
479
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
480
481
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
482
#elif 1
Chao Liu's avatar
Chao Liu committed
483
484
    // 3x3, 28x28
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
485
    constexpr index_t C  = 128;
Chao Liu's avatar
Chao Liu committed
486
487
488
489
490
491
492
493
494
495
496
    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>;
497
#elif 1
Chao Liu's avatar
Chao Liu committed
498
    // 3x3, 14x14
Chao Liu's avatar
Chao Liu committed
499
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
500
    constexpr index_t C  = 256;
Chao Liu's avatar
Chao Liu committed
501
502
503
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
    constexpr index_t K  = 256;
Chao Liu's avatar
Chao Liu committed
504
505
506
507
508
509
510
511
    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
512
#elif 0
Chao Liu's avatar
Chao Liu committed
513
514
515
516
517
518
    // 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
519
520
521
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
522
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
523
524
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
525
526
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
527
#elif 0
Chao Liu's avatar
Chao Liu committed
528
    // 7x7, 230x230 stride=2
Chao Liu's avatar
Chao Liu committed
529
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    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
549
550
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
Chao Liu's avatar
Chao Liu committed
551

Chao Liu's avatar
Chao Liu committed
552
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
553
554
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
555
556
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
557
#elif 0
Chao Liu's avatar
Chao Liu committed
558
    // 1x1, 28x28, stride 2
Chao Liu's avatar
Chao Liu committed
559
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
560
561
562
563
564
565
    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
566
567
568
569
570
571

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

    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
572
#elif 1
Chao Liu's avatar
Chao Liu committed
573
    // 1x1, 7x7
574
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
575
    constexpr index_t C  = 512;
576
577
    constexpr index_t HI = 7;
    constexpr index_t WI = 7;
Chao Liu's avatar
Chao Liu committed
578
579
580
    constexpr index_t K  = 2048;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
581
582
583
584

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

Chao Liu's avatar
Chao Liu committed
585
586
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
587
#elif 0
Chao Liu's avatar
Chao Liu committed
588
    // 3x3, 7x7
589
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
590
591
592
593
594
595
    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;
596
597
598
599

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

Chao Liu's avatar
Chao Liu committed
600
601
    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
602
#elif 0
Chao Liu's avatar
Chao Liu committed
603
    // 1x1, 56x56
604
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
605
606
607
608
609
    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;
610
    constexpr index_t X  = 1;
611
612
613
614

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

Chao Liu's avatar
Chao Liu committed
615
616
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
617
#elif 0
Chao Liu's avatar
Chao Liu committed
618
619
620
621
622
623
624
625
626
627
628
629
630
631
    // 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
632
#endif
Chao Liu's avatar
Chao Liu committed
633

Chao Liu's avatar
Chao Liu committed
634
635
636
    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
637
        in_nchw_desc, wei_kcyx_desc, ConvStrides{}, ConvDilations{}, LeftPads{}, RightPads{});
Chao Liu's avatar
Chao Liu committed
638

Jing Zhang's avatar
Jing Zhang committed
639
640
641
642
643
    constexpr auto Ho = out_nkhw_desc.GetLength(Number<2>{});
    constexpr auto Wo = out_nkhw_desc.GetLength(Number<3>{});

    auto add_nkhw_desc = make_native_tensor_descriptor_packed(Sequence<N, K, Ho * 2, Wo * 2>{});

Chao Liu's avatar
Chao Liu committed
644
645
646
    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: ");
Jing Zhang's avatar
Jing Zhang committed
647
648
    ostream_tensor_descriptor(add_nkhw_desc, std::cout << "add_nkhw_desc: ");

Chao Liu's avatar
Chao Liu committed
649
650
651
652
    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{}));
Chao Liu's avatar
Chao Liu committed
653

Jing Zhang's avatar
int8  
Jing Zhang committed
654
#if 0
root's avatar
root committed
655
    using in_data_t                  = float;
Chao Liu's avatar
Chao Liu committed
656
    constexpr index_t in_vector_size = 1;
root's avatar
root committed
657
    using acc_data_t                 = float;
Chao Liu's avatar
Chao Liu committed
658
    using out_data_t                 = float;
Jing Zhang's avatar
Jing Zhang committed
659
660
#elif 0
    using in_data_t                  = half_t;
Jing Zhang's avatar
tweak  
Jing Zhang committed
661
    constexpr index_t in_vector_size = 4;
Jing Zhang's avatar
Jing Zhang committed
662
663
    using acc_data_t                 = float;
    using out_data_t                 = half_t;
root's avatar
root committed
664
#elif 0
Chao Liu's avatar
tweak  
Chao Liu committed
665
666
667
668
    using in_data_t                  = float;
    constexpr index_t in_vector_size = 1;
    using acc_data_t                 = float;
    using out_data_t                 = int8_t;
Chao Liu's avatar
Chao Liu committed
669
#elif 1
Chao Liu's avatar
Chao Liu committed
670
    using in_data_t                  = int8_t;
Jing Zhang's avatar
int8  
Jing Zhang committed
671
    constexpr index_t in_vector_size = 16;
Chao Liu's avatar
Chao Liu committed
672
673
    using acc_data_t                 = int32_t;
    using out_data_t                 = int8_t;
Chao Liu's avatar
Chao Liu committed
674
675
676
677
#endif

    Tensor<in_data_t> in_nchw(make_HostTensorDescriptor(in_nchw_desc));
    Tensor<in_data_t> wei_kcyx(make_HostTensorDescriptor(wei_kcyx_desc));
Jing Zhang's avatar
Jing Zhang committed
678
    Tensor<out_data_t> add_nkhw(make_HostTensorDescriptor(add_nkhw_desc));
Jing Zhang's avatar
Jing Zhang committed
679

Jing Zhang's avatar
Jing Zhang committed
680
681
    Tensor<out_data_t> out_nkhw_host(make_HostTensorDescriptor(add_nkhw_desc));
    Tensor<out_data_t> out_nkhw_device(make_HostTensorDescriptor(add_nkhw_desc));
Chao Liu's avatar
Chao Liu committed
682

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

Chao Liu's avatar
Chao Liu committed
685
    if(argc != 4)
Chao Liu's avatar
Chao Liu committed
686
    {
Chao Liu's avatar
Chao Liu committed
687
        printf("arg1: do_verification, arg2: do_log, arg3: nrepeat\n");
Chao Liu's avatar
Chao Liu committed
688
689
690
691
        exit(1);
    }

    bool do_verification = atoi(argv[1]);
Chao Liu's avatar
Chao Liu committed
692
693
    bool do_log          = atoi(argv[2]);
    index_t nrepeat      = atoi(argv[3]);
694
695
696

    if(do_verification)
    {
root's avatar
root committed
697
#if 0
698
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
699
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
700
701
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
702
        wei_kcyx.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
703
#elif 0
704
        in_nchw.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
705
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
706
#elif 1
707
        in_nchw.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
Chao Liu's avatar
Chao Liu committed
708
        wei_kcyx.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
Chao Liu's avatar
Chao Liu committed
709
#elif 0
710
711
712
713
714
715
        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
716
#endif
Jing Zhang's avatar
fixed  
Jing Zhang committed
717
718
        // add_nkhw.GenerateTensorValue(GeneratorTensor_2{-1, 1}, num_thread);
        add_nkhw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
719
    }
Chao Liu's avatar
Chao Liu committed
720

Chao Liu's avatar
Chao Liu committed
721
#if 0
722
    device_convolution_forward_implicit_gemm_v4r1_nchw_kcyx_nkhw(in_nchw_desc,
723
724
725
726
727
728
729
730
731
732
                                                                 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
733
#elif 0
734
735
736
737
738
739
740
741
742
743
744
    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);
Chao Liu's avatar
Chao Liu committed
745
#elif 0
Chao Liu's avatar
Chao Liu committed
746
747
748
749
750
751
752
753
754
755
756
    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);
root's avatar
tweak  
root committed
757
#elif 0
Chao Liu's avatar
Chao Liu committed
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
    device_dynamic_convolution_forward_implicit_gemm_v4r4_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);
Jing Zhang's avatar
Jing Zhang committed
774
#elif 0
Chao Liu's avatar
Chao Liu committed
775
776
777
    device_dynamic_convolution_forward_implicit_gemm_v4r4_nhwc_kyxc_nhwk<in_data_t,
                                                                         in_vector_size,
                                                                         acc_data_t,
778
                                                                         out_data_t>
Chao Liu's avatar
Chao Liu committed
779
780
781
782
783
784
785
786
787
788
789
790

        (in_nchw_desc,
         in_nchw,
         wei_kcyx_desc,
         wei_kcyx,
         out_nkhw_desc,
         out_nkhw_device,
         ConvStrides{},
         ConvDilations{},
         LeftPads{},
         RightPads{},
         nrepeat);
root's avatar
root committed
791
#elif 1
Jing Zhang's avatar
mock up  
Jing Zhang committed
792
793
794
795
796
797
798
799
    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,
Jing Zhang's avatar
Jing Zhang committed
800
        add_nkhw_desc,
Jing Zhang's avatar
Jing Zhang committed
801
        add_nkhw,
Jing Zhang's avatar
Jing Zhang committed
802
        out_nkhw_desc,
Jing Zhang's avatar
mock up  
Jing Zhang committed
803
804
805
806
807
808
        out_nkhw_device,
        ConvStrides{},
        ConvDilations{},
        LeftPads{},
        RightPads{},
        nrepeat);
809
#endif
Chao Liu's avatar
Chao Liu committed
810

811
    if(do_verification)
812
    {
Chao Liu's avatar
Chao Liu committed
813
814
        host_direct_convolution(in_nchw,
                                wei_kcyx,
Jing Zhang's avatar
Jing Zhang committed
815
                                add_nkhw,
Chao Liu's avatar
Chao Liu committed
816
817
818
819
820
821
                                out_nkhw_host,
                                ConvStrides{},
                                ConvDilations{},
                                LeftPads{},
                                RightPads{});

822
        check_error(out_nkhw_host, out_nkhw_device);
Chao Liu's avatar
Chao Liu committed
823

Jing Zhang's avatar
fixed  
Jing Zhang committed
824
#if 1
Chao Liu's avatar
Chao Liu committed
825
826
827
828
829
830
831
        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;
        }
Jing Zhang's avatar
Jing Zhang committed
832
#endif
833
    }
834
}