conv_driver.cpp 21.7 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
16
#include "device_convolution_forward_implicit_gemm_v4r1_nchw_kcyx_nkhw.hpp"
#include "device_convolution_forward_implicit_gemm_v4r4_nchw_kcyx_nkhw.hpp"
#include "device_dynamic_convolution_forward_implicit_gemm_v4r4_nchw_kcyx_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
17
#include "device_dummy_static_transform.hpp"
Chao Liu's avatar
Chao Liu committed
18
#include "device_dummy_dynamic_transform_v1.hpp"
Chao Liu's avatar
fix  
Chao Liu committed
19
#include "device_dummy_dynamic_transform.hpp"
20

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#if 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
41
42
43
44
45
46
47
48
    // 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;
49

50
    using ConvStrides   = Sequence<2, 2>;
51
52
53
54
    using ConvDilations = Sequence<1, 1>;

    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
55
#elif 1
Chao Liu's avatar
Chao Liu committed
56
    // 3x3, 71x71
Chao Liu's avatar
Chao Liu committed
57
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
58
59
60
61
62
63
    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
64

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

Chao Liu's avatar
Chao Liu committed
68
69
    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
70
#elif 1
Chao Liu's avatar
Chao Liu committed
71
    // 1x1, 8x8
72
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
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
103
104
105
    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;
106
    constexpr index_t K  = 128;
Chao Liu's avatar
Chao Liu committed
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
    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;
134
135
    constexpr index_t HI = 17;
    constexpr index_t WI = 17;
136
    constexpr index_t K  = 384;
Chao Liu's avatar
Chao Liu committed
137
138
139
140
141
142
143
144
    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>;
145
#elif 0
Chao Liu's avatar
Chao Liu committed
146
147
148
149
150
151
    // 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;
152
153
154
155
156
157
158
159
160
    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
161
162
163
164
165
166
    // 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;
167
168
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
169

Chao Liu's avatar
Chao Liu committed
170
    using ConvStrides   = Sequence<2, 2>;
171
172
    using ConvDilations = Sequence<1, 1>;

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

Chao Liu's avatar
Chao Liu committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
    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>;
201
202
    using ConvDilations = Sequence<1, 1>;

203
204
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
205
#elif 0
Chao Liu's avatar
Chao Liu committed
206
207
208
209
210
211
212
213
    // 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
214

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

Chao Liu's avatar
Chao Liu committed
218
219
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
220
#elif 0
Chao Liu's avatar
Chao Liu committed
221
    // 1x1, 35x35
Chao Liu's avatar
Chao Liu committed
222
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
223
224
225
226
    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
227
228
229
230
231
232
    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
233
234
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
235
#elif 0
Chao Liu's avatar
Chao Liu committed
236
    // 3x3, 35x35, stride 2
Chao Liu's avatar
Chao Liu committed
237
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
238
239
240
    constexpr index_t C  = 288;
    constexpr index_t HI = 35;
    constexpr index_t WI = 35;
Chao Liu's avatar
Chao Liu committed
241
    constexpr index_t K  = 384;
Chao Liu's avatar
Chao Liu committed
242
243
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
244

Chao Liu's avatar
Chao Liu committed
245
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
246
247
    using ConvDilations = Sequence<1, 1>;

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

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

Chao Liu's avatar
Chao Liu committed
263
264
    using LeftPads  = Sequence<0, 1>;
    using RightPads = Sequence<0, 1>;
Chao Liu's avatar
Chao Liu committed
265
#elif 0
Chao Liu's avatar
Chao Liu committed
266
    // 3x1, 8x8
Chao Liu's avatar
Chao Liu committed
267
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
268
269
270
271
272
    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
273
274
275
276
277
    constexpr index_t X  = 1;

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

Chao Liu's avatar
Chao Liu committed
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
    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
293
294
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
295
#elif 0
Chao Liu's avatar
Chao Liu committed
296
    // 7x1, 73x73
Chao Liu's avatar
Chao Liu committed
297
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
298
299
300
301
302
    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
303
304
305
306
307
    constexpr index_t X  = 1;

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

Chao Liu's avatar
Chao Liu committed
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
    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
323
324
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
325
#elif 0
Chao Liu's avatar
Chao Liu committed
326
    // 1x1, 14x14, stride 2
Chao Liu's avatar
Chao Liu committed
327
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
328
329
330
331
    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
332
333
334
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

Chao Liu's avatar
Chao Liu committed
338
339
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
340
#elif 0
Chao Liu's avatar
Chao Liu committed
341
    // 1x1, 14x14
Chao Liu's avatar
Chao Liu committed
342
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
343
344
345
346
    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
347
348
349
350
351
352
    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
353
354
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
355
#elif 0
Chao Liu's avatar
Chao Liu committed
356
    // 1x1, 14x14, stride 2
Chao Liu's avatar
Chao Liu committed
357
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
358
    constexpr index_t C  = 1024;
Chao Liu's avatar
Chao Liu committed
359
360
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
Chao Liu's avatar
Chao Liu committed
361
    constexpr index_t K  = 512;
Chao Liu's avatar
Chao Liu committed
362
363
364
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
365
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
366
367
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
368
369
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
370
#elif 1
Chao Liu's avatar
Chao Liu committed
371
372
    // 3x3, 28x28
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
373
    constexpr index_t C  = 128;
Chao Liu's avatar
Chao Liu committed
374
375
376
377
378
379
380
381
382
383
384
    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>;
385
#elif 1
Chao Liu's avatar
Chao Liu committed
386
    // 3x3, 14x14
Chao Liu's avatar
Chao Liu committed
387
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
388
    constexpr index_t C  = 256;
Chao Liu's avatar
Chao Liu committed
389
390
391
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
    constexpr index_t K  = 256;
Chao Liu's avatar
Chao Liu committed
392
393
394
395
396
397
398
399
    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
400
#elif 0
Chao Liu's avatar
Chao Liu committed
401
402
403
404
405
406
    // 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
407
408
409
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

Chao Liu's avatar
Chao Liu committed
413
414
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
415
#elif 0
Chao Liu's avatar
Chao Liu committed
416
    // 7x7, 230x230 stride=2
Chao Liu's avatar
Chao Liu committed
417
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
    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
437
438
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
Chao Liu's avatar
Chao Liu committed
439

Chao Liu's avatar
Chao Liu committed
440
    using ConvStrides   = Sequence<2, 2>;
Chao Liu's avatar
Chao Liu committed
441
442
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
443
444
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
445
#elif 0
Chao Liu's avatar
Chao Liu committed
446
    // 1x1, 28x28, stride 2
Chao Liu's avatar
Chao Liu committed
447
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
448
449
450
451
452
453
    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
454
455
456
457
458
459

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

    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
460
#elif 1
Chao Liu's avatar
Chao Liu committed
461
    // 1x1, 7x7
462
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
463
    constexpr index_t C  = 512;
464
465
    constexpr index_t HI = 7;
    constexpr index_t WI = 7;
Chao Liu's avatar
Chao Liu committed
466
467
468
    constexpr index_t K  = 2048;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
469
470
471
472

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

Chao Liu's avatar
Chao Liu committed
473
474
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
475
#elif 0
Chao Liu's avatar
Chao Liu committed
476
    // 3x3, 7x7
477
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
478
479
480
481
482
483
    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;
484
485
486
487

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

Chao Liu's avatar
Chao Liu committed
488
489
    using LeftPads  = Sequence<1, 1>;
    using RightPads = Sequence<1, 1>;
Chao Liu's avatar
Chao Liu committed
490
#elif 0
Chao Liu's avatar
Chao Liu committed
491
    // 1x1, 56x56
492
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
493
494
495
496
497
    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;
498
    constexpr index_t X  = 1;
499
500
501
502

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

Chao Liu's avatar
Chao Liu committed
503
504
    using LeftPads  = Sequence<0, 0>;
    using RightPads = Sequence<0, 0>;
Chao Liu's avatar
Chao Liu committed
505
#elif 0
Chao Liu's avatar
Chao Liu committed
506
507
508
509
510
511
512
513
514
515
516
517
518
519
    // 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
520
#endif
Chao Liu's avatar
Chao Liu committed
521

Chao Liu's avatar
Chao Liu committed
522
523
524
    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
525
        in_nchw_desc, wei_kcyx_desc, ConvStrides{}, ConvDilations{}, LeftPads{}, RightPads{});
Chao Liu's avatar
Chao Liu committed
526

Chao Liu's avatar
Chao Liu committed
527
528
529
    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
530
531
532
533
    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
534

Chao Liu's avatar
Chao Liu committed
535
#if 1
Chao Liu's avatar
Chao Liu committed
536
537
    using in_data_t  = float;
    using out_data_t = float;
Chao Liu's avatar
Chao Liu committed
538
539
540
541
542
543
544
545
546
#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
547

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

Chao Liu's avatar
Chao Liu committed
550
551
552
553
554
555
556
    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
557
    index_t nrepeat      = atoi(argv[2]);
558
559
560

    if(do_verification)
    {
Chao Liu's avatar
Chao Liu committed
561
#if 0
562
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
563
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
564
565
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
bug fix  
Chao Liu committed
566
        wei_kcyx.GenerateTensorValue(GeneratorTensor_3{}, num_thread);
567
#elif 0
568
        in_nchw.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
569
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
570
#elif 1
571
        in_nchw.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
Chao Liu's avatar
Chao Liu committed
572
        wei_kcyx.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
Chao Liu's avatar
Chao Liu committed
573
#elif 0
574
575
576
577
578
579
        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
580
#endif
581
    }
Chao Liu's avatar
Chao Liu committed
582

Chao Liu's avatar
Chao Liu committed
583
#if 0
584
    device_convolution_forward_implicit_gemm_v4r1_nchw_kcyx_nkhw(in_nchw_desc,
585
586
587
588
589
590
591
592
593
594
                                                                 in_nchw,
                                                                 wei_kcyx_desc,
                                                                 wei_kcyx,
                                                                 out_nkhw_desc,
                                                                 out_nkhw_device,
                                                                 ConvStrides{},
                                                                 ConvDilations{},
                                                                 LeftPads{},
                                                                 RightPads{},
                                                                 nrepeat);
595
#elif 0
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
    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 1
    device_dynamic_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);
619
#elif 0
Chao Liu's avatar
Chao Liu committed
620
621
622
623
624
625
626
627
628
629
630
    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
631
#elif 0
Chao Liu's avatar
Chao Liu committed
632
633
634
635
636
637
638
639
640
641
642
    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
643
#elif 1
Chao Liu's avatar
Chao Liu committed
644
645
646
647
648
649
650
651
652
653
654
    device_dummy_dynamic_transform(in_nchw_desc,
                                   in_nchw,
                                   wei_kcyx_desc,
                                   wei_kcyx,
                                   out_nkhw_desc,
                                   out_nkhw_device,
                                   ConvStrides{},
                                   ConvDilations{},
                                   LeftPads{},
                                   RightPads{},
                                   nrepeat);
655
#endif
Chao Liu's avatar
Chao Liu committed
656

657
    if(do_verification)
658
    {
Chao Liu's avatar
Chao Liu committed
659
#if 0
660
661
        if(Y == 3 && X == 3 && ConvStrides{}[0] == 1 && ConvStrides{}[1] == 1 &&
           ConvDilations{}[0] == 1 && ConvDilations{}[1] == 1)
662
        {
Chao Liu's avatar
Chao Liu committed
663
664
            host_winograd_3x3_convolution(
                in_nchw, wei_kcyx, out_nkhw_host, LeftPads{}, RightPads{});
665
666
        }
        else
Chao Liu's avatar
Chao Liu committed
667
#endif
668
        {
669
670
671
672
673
            host_direct_convolution(in_nchw,
                                    wei_kcyx,
                                    out_nkhw_host,
                                    ConvStrides{},
                                    ConvDilations{},
Chao Liu's avatar
Chao Liu committed
674
675
                                    LeftPads{},
                                    RightPads{});
676
677
        }
        check_error(out_nkhw_host, out_nkhw_device);
Chao Liu's avatar
Chao Liu committed
678

Chao Liu's avatar
Chao Liu committed
679
#if 0
680
        LogRange(std::cout << "in_nchw : ", in_nchw.mData, ",") << std::endl;
Chao Liu's avatar
Chao Liu committed
681
        LogRange(std::cout << "wei_kcyx: ", wei_kcyx.mData, ",") << std::endl;
682
683
        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
684
#endif
685
    }
686
}