driver.cpp 17.8 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
7
8
#include "config.hpp"
#include "ConstantTensorDescriptor.hpp"
#include "device.hpp"
Chao Liu's avatar
Chao Liu committed
9
#include "conv_common.hpp"
10
#include "host_conv.hpp"
Chao Liu's avatar
Chao Liu committed
11
#include "device_convolution_direct_v2_nchw_kcyx_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
12
#include "device_convolution_implicit_gemm_v1_chwn_cyxk_khwn.hpp"
Chao Liu's avatar
Chao Liu committed
13
#include "device_convolution_implicit_gemm_v1_nchw_cyxk_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
14
#include "device_convolution_implicit_gemm_v2_chwn_cyxk_khwn.hpp"
Chao Liu's avatar
Chao Liu committed
15
#include "device_convolution_implicit_gemm_v3_nchw_cyxk_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
16
#include "device_convolution_implicit_gemm_v4r1_nchw_kcyx_nkhw.hpp"
17
//#include "device_convolution_implicit_gemm_v4r2_nchw_kcyx_nkhw.hpp"
18

Chao Liu's avatar
Chao Liu committed
19
struct GeneratorTensor_1
Chao Liu's avatar
Chao Liu committed
20
21
{
    template <class... Is>
Chao Liu's avatar
Chao Liu committed
22
    double operator()(Is... is)
Chao Liu's avatar
Chao Liu committed
23
    {
Chao Liu's avatar
Chao Liu committed
24
        return 1;
Chao Liu's avatar
Chao Liu committed
25
26
27
    }
};

Chao Liu's avatar
Chao Liu committed
28
29
30
31
32
33
34
35
36
37
38
39
struct GeneratorTensor_2
{
    int min_value = 0;
    int max_value = 1;

    template <class... Is>
    double operator()(Is...)
    {
        return (std::rand() % (max_value - min_value)) + min_value;
    }
};

40
41
42
43
44
45
46
struct GeneratorTensor_3
{
    template <class... Is>
    double operator()(Is... is)
    {
        std::array<index_t, sizeof...(Is)> dims = {{static_cast<index_t>(is)...}};

47
        auto f_acc = [](auto a, auto b) { return 100 * a + b; };
48

49
        return std::accumulate(dims.begin(), dims.end(), index_t(0), f_acc);
50
51
52
    }
};

Chao Liu's avatar
Chao Liu committed
53
54
55
56
57
struct GeneratorTensor_Checkboard
{
    template <class... Ts>
    double operator()(Ts... Xs) const
    {
Chao Liu's avatar
Chao Liu committed
58
        std::array<index_t, sizeof...(Ts)> dims = {{Xs...}};
Chao Liu's avatar
Chao Liu committed
59
60
61
        return std::accumulate(dims.begin(),
                               dims.end(),
                               true,
Chao Liu's avatar
Chao Liu committed
62
                               [](bool init, index_t x) -> int { return init != (x % 2); })
Chao Liu's avatar
Chao Liu committed
63
64
65
66
67
                   ? 1
                   : -1;
    }
};

Chao Liu's avatar
Chao Liu committed
68
int main(int argc, char* argv[])
Chao Liu's avatar
Chao Liu committed
69
{
Chao Liu's avatar
Chao Liu committed
70
71
    using namespace ck;

Chao Liu's avatar
Chao Liu committed
72
73
#if 0
    constexpr index_t N  = 8;
Chao Liu's avatar
Chao Liu committed
74
    constexpr index_t C  = 16;
Chao Liu's avatar
Chao Liu committed
75
76
77
78
79
80
81
82
    constexpr index_t HI = 3;
    constexpr index_t WI = 18;
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
83
#elif 0
84
    // 3x3, 34x34
85
    constexpr index_t N  = 128;
86
    constexpr index_t C  = 256;
87
88
    constexpr index_t HI = 34;
    constexpr index_t WI = 34;
89
90
91
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
92

93
94
95
    using ConvStrides   = Sequence<2, 2>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
96
97
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
98
#elif 0
99
    // 3x3, 56x56
Chao Liu's avatar
Chao Liu committed
100
101
    constexpr index_t N  = 64;
    constexpr index_t C  = 64;
102
103
    constexpr index_t HI = 56;
    constexpr index_t WI = 56;
Chao Liu's avatar
Chao Liu committed
104
105
106
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
107
108
109

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
110
#elif 0
Chao Liu's avatar
Chao Liu committed
111
112
113
114
115
    // 3x3 filter, 28x28 image
    constexpr index_t N  = 128;
    constexpr index_t C  = 256;
    constexpr index_t HI = 28;
    constexpr index_t WI = 28;
116
    constexpr index_t K  = 128;
Chao Liu's avatar
Chao Liu committed
117
118
119
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

Chao Liu's avatar
Chao Liu committed
120
    using ConvStrides   = Sequence<1, 1>;
121
122
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
123
124
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
125
#elif 0
Chao Liu's avatar
Chao Liu committed
126
    // 1x1 filter, 28x28 image
127
128
    constexpr index_t N  = 128;
    constexpr index_t C  = 512;
Chao Liu's avatar
Chao Liu committed
129
130
131
132
133
134
    constexpr index_t HI = 28;
    constexpr index_t WI = 28;
    constexpr index_t K  = 512;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
135
136
137
    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
138
139
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
140
141
#elif 0
    // 3x3 filter, 20x84 image, 1x1 padding
Chao Liu's avatar
Chao Liu committed
142
143
144
145
146
147
148
149
150
151
    constexpr index_t N  = 16;
    constexpr index_t C  = 256;
    constexpr index_t HI = 20;
    constexpr index_t WI = 84;
    constexpr index_t K  = 256;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    constexpr index_t HPad = 1;
    constexpr index_t WPad = 1;
Chao Liu's avatar
Chao Liu committed
152
153
#elif 0
    // 3x3 filter, 112x112 image, 1x1 padding
Chao Liu's avatar
Chao Liu committed
154
155
156
157
158
159
160
161
162
163
    constexpr index_t N  = 16;
    constexpr index_t C  = 64;
    constexpr index_t HI = 112;
    constexpr index_t WI = 112;
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    constexpr index_t HPad = 1;
    constexpr index_t WPad = 1;
164
#elif 0
165
166
167
168
169
170
171
172
173
174
175
    // 5x5 filter, 20x86 image
    constexpr index_t N  = 16;
    constexpr index_t C  = 256;
    constexpr index_t HI = 20;
    constexpr index_t WI = 86;
    constexpr index_t K  = 512;
    constexpr index_t Y  = 5;
    constexpr index_t X  = 5;

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
176
177
#elif 0
    // 5x5 filter, 20x86 image, 1x1 padding
Chao Liu's avatar
Chao Liu committed
178
179
180
181
182
183
184
185
186
187
    constexpr index_t N  = 16;
    constexpr index_t C  = 256;
    constexpr index_t HI = 20;
    constexpr index_t WI = 86;
    constexpr index_t K  = 512;
    constexpr index_t Y  = 5;
    constexpr index_t X  = 5;

    constexpr index_t HPad = 1;
    constexpr index_t WPad = 1;
Chao Liu's avatar
Chao Liu committed
188
189
#elif 0
    // 5x5 filter, 28x28 image, 2x2 padding
Chao Liu's avatar
Chao Liu committed
190
191
192
193
194
195
196
197
198
199
    constexpr index_t N  = 16;
    constexpr index_t C  = 192;
    constexpr index_t HI = 28;
    constexpr index_t WI = 28;
    constexpr index_t K  = 32;
    constexpr index_t Y  = 5;
    constexpr index_t X  = 5;

    constexpr index_t HPad = 2;
    constexpr index_t WPad = 2;
Chao Liu's avatar
Chao Liu committed
200
#elif 0
201
    // 3x3 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
202
    constexpr index_t N  = 128;
203
    constexpr index_t C  = 256;
Chao Liu's avatar
Chao Liu committed
204
205
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
206
207
208
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
209
210
211

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
212
#elif 0
213
    // 1x1 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
214
215
216
217
218
219
220
221
    constexpr index_t N  = 128;
    constexpr index_t C  = 512;
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
    constexpr index_t K  = 512;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

222
223
224
    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
225
226
227
228
229
230
231
232
233
234
235
236
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
#elif 0
    // 1x1 filter, 7x7 image
    constexpr index_t N  = 128;
    constexpr index_t C  = 512;
    constexpr index_t HI = 7;
    constexpr index_t WI = 7;
    constexpr index_t K  = 2048;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

237
238
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
239
#elif 0
240
241
    // 1x1 filter, 73x73 image
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
242
    constexpr index_t C  = 512;
243
244
245
246
247
248
    constexpr index_t HI = 73;
    constexpr index_t WI = 73;
    constexpr index_t K  = 128;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

Chao Liu's avatar
Chao Liu committed
249
250
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
251
#elif 0
Chao Liu's avatar
Chao Liu committed
252
    // 1x1 filter, 8x8 image
Chao Liu's avatar
Chao Liu committed
253
    // cudnn@V100 68%, ck@V100 72%, ck@P100 52%, ck@VII 42%
Chao Liu's avatar
Chao Liu committed
254
255
256
257
258
259
260
261
262
263
264
265
266
    constexpr index_t N  = 64;
    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>;

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
267
#elif 1
Chao Liu's avatar
Chao Liu committed
268
    // 1x1 filter, 8x8 image
Chao Liu's avatar
Chao Liu committed
269
    // cudnn@V100 77%, ck@V100 76%, ck@P100 79%, ck@VII 51%
Chao Liu's avatar
Chao Liu committed
270
271
272
273
274
275
276
277
278
279
280
281
282
    constexpr index_t N  = 128;
    constexpr index_t C  = 2048;
    constexpr index_t HI = 8;
    constexpr index_t WI = 8;
    constexpr index_t K  = 384;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
283
#elif 0
Chao Liu's avatar
Chao Liu committed
284
    // 1x1 filter, 7x7 image
Chao Liu's avatar
Chao Liu committed
285
    // cudnn@V100 82%, ck@V100 76%, ck@P100 67%, ck@VII 64%
Chao Liu's avatar
Chao Liu committed
286
287
288
289
290
291
292
293
294
295
296
297
298
    constexpr index_t N  = 128;
    constexpr index_t C  = 832;
    constexpr index_t HI = 7;
    constexpr index_t WI = 7;
    constexpr index_t K  = 384;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
299
#elif 0
Chao Liu's avatar
Chao Liu committed
300
    // 1x1 filter, 8x8 image
Chao Liu's avatar
Chao Liu committed
301
    // cudnn@V100 83%, ck@V100 75%, ck@P100 78%, ck@VII 65%
Chao Liu's avatar
Chao Liu committed
302
303
304
305
306
307
308
309
310
311
312
313
314
    constexpr index_t N  = 128;
    constexpr index_t C  = 1280;
    constexpr index_t HI = 8;
    constexpr index_t WI = 8;
    constexpr index_t K  = 384;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
315
#elif 0
Chao Liu's avatar
Chao Liu committed
316
    // 1x1 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
317
    // cudnn@V100 62%, ck@V100 68%, ck@P100 70%, ck@VII 50%
Chao Liu's avatar
Chao Liu committed
318
319
320
321
322
323
324
325
326
327
328
329
330
    constexpr index_t N  = 128;
    constexpr index_t C  = 512;
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
    constexpr index_t K  = 128;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
331
#elif 0
Chao Liu's avatar
Chao Liu committed
332
    // 1x1 filter, 8x8 image
Chao Liu's avatar
Chao Liu committed
333
    // cudnn@V100 74%, ck@V100 57%, ck@P100 78%, ck@VII 61%
Chao Liu's avatar
Chao Liu committed
334
335
336
337
338
339
340
341
342
343
344
345
346
    constexpr index_t N  = 64;
    constexpr index_t C  = 1536;
    constexpr index_t HI = 8;
    constexpr index_t WI = 8;
    constexpr index_t K  = 384;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
347
#elif 0
Chao Liu's avatar
Chao Liu committed
348
    // 1x1 filter, 28x28 image
Chao Liu's avatar
Chao Liu committed
349
    // cudnn@V100 86%, ck@V100 84%, ck@P100 80%, ck@VII 69%
Chao Liu's avatar
Chao Liu committed
350
351
352
353
354
355
356
357
358
359
360
361
362
    constexpr index_t N  = 128;
    constexpr index_t C  = 256;
    constexpr index_t HI = 28;
    constexpr index_t WI = 28;
    constexpr index_t K  = 128;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
363
#elif 0
Chao Liu's avatar
Chao Liu committed
364
    // 1x1 filter, 7x7 image
Chao Liu's avatar
Chao Liu committed
365
    // cudnn@V100 71%, ck@V100 55%, ck@P100 70%, ck@VII 62%
Chao Liu's avatar
Chao Liu committed
366
367
368
369
370
371
372
373
374
375
376
377
378
    constexpr index_t N  = 128;
    constexpr index_t C  = 832;
    constexpr index_t HI = 7;
    constexpr index_t WI = 7;
    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>;

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
379
#elif 0
Chao Liu's avatar
Chao Liu committed
380
    // 3x3 filter, 2x2 stride, 35x35 input, 17x17 output
Chao Liu's avatar
Chao Liu committed
381
    // cudnn@V100 90%, ck@V100 93%, ck@P100 83%, ck@VII 81%
Chao Liu's avatar
Chao Liu committed
382
383
384
385
386
387
388
389
390
391
392
393
394
    constexpr index_t N  = 128;
    constexpr index_t C  = 288;
    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>;

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
395
#elif 0
Chao Liu's avatar
Chao Liu committed
396
    // 1x1 filter, 17x17 input
Chao Liu's avatar
Chao Liu committed
397
    // cudnn@V100 81%, ck@V100 76%, ck@P100 70%, ck@VII 76%
Chao Liu's avatar
Chao Liu committed
398
399
400
401
402
403
404
405
406
407
408
409
410
    constexpr index_t N  = 128;
    constexpr index_t C  = 768;
    constexpr index_t HI = 17;
    constexpr index_t WI = 17;
    constexpr index_t K  = 128;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
411
#elif 0
Chao Liu's avatar
Chao Liu committed
412
    // 1x1 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
413
    // cudnn@V100 73%, ck@V100 71%, ck@P100 70%, ck@VII 64%
Chao Liu's avatar
Chao Liu committed
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
    constexpr index_t N  = 128;
    constexpr index_t C  = 528;
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
    constexpr index_t K  = 128;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;

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

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
#elif 0
    // 1x1 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
429
    // cudnn@V100 73%, ck@V100 72%, ck@P100 79%, ck@VII 75%
Chao Liu's avatar
Chao Liu committed
430
431
432
433
434
435
436
437
438
439
440
441
442
    constexpr index_t N  = 128;
    constexpr index_t C  = 528;
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
    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>;

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
443
#elif 0
Chao Liu's avatar
Chao Liu committed
444
    // 1x1 filter, 7x7 image
Chao Liu's avatar
Chao Liu committed
445
    // cudnn@V100 49%, ck@V100 50%, ck@P100 61%, ck@VII 52%
Chao Liu's avatar
Chao Liu committed
446
447
448
449
    constexpr index_t N  = 128;
    constexpr index_t C  = 832;
    constexpr index_t HI = 7;
    constexpr index_t WI = 7;
Chao Liu's avatar
Chao Liu committed
450
451
452
    constexpr index_t K  = 128;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
Chao Liu's avatar
Chao Liu committed
453
454
455
456

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

Chao Liu's avatar
Chao Liu committed
457
458
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
459
#endif
Chao Liu's avatar
Chao Liu committed
460

461
462
463
    auto lower_pads = Sequence<HPad, WPad>{};
    auto upper_pads = Sequence<HPad, WPad>{};

Chao Liu's avatar
Chao Liu committed
464
465
    auto in_nchw_desc  = make_ConstantTensorDescriptor_packed(Sequence<N, C, HI, WI>{});
    auto wei_kcyx_desc = make_ConstantTensorDescriptor_packed(Sequence<K, C, Y, X>{});
466
    auto out_nkhw_desc = get_convolution_with_padding_output_default_4d_tensor_descriptor(
467
        in_nchw_desc, wei_kcyx_desc, ConvStrides{}, ConvDilations{}, lower_pads, upper_pads);
Chao Liu's avatar
Chao Liu committed
468

Chao Liu's avatar
Chao Liu committed
469
    ostream_ConstantTensorDescriptor(in_nchw_desc, std::cout << "in_nchw_desc: ");
Chao Liu's avatar
Chao Liu committed
470
    ostream_ConstantTensorDescriptor(wei_kcyx_desc, std::cout << "wei_kcyx_desc: ");
Chao Liu's avatar
Chao Liu committed
471
    ostream_ConstantTensorDescriptor(out_nkhw_desc, std::cout << "out_nkhw_desc: ");
Chao Liu's avatar
Chao Liu committed
472

Chao Liu's avatar
Chao Liu committed
473
474
    using in_data_t  = float;
    using out_data_t = float;
475
476
477
478
    Tensor<in_data_t> in_nchw(make_TensorDescriptor(in_nchw_desc));
    Tensor<in_data_t> wei_kcyx(make_TensorDescriptor(wei_kcyx_desc));
    Tensor<out_data_t> out_nkhw_host(make_TensorDescriptor(out_nkhw_desc));
    Tensor<out_data_t> out_nkhw_device(make_TensorDescriptor(out_nkhw_desc));
Chao Liu's avatar
Chao Liu committed
479

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

Chao Liu's avatar
Chao Liu committed
482
483
484
485
486
487
488
    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
489
    index_t nrepeat      = atoi(argv[2]);
490
491
492

    if(do_verification)
    {
Chao Liu's avatar
Chao Liu committed
493
#if 0
494
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
495
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
496
497
498
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
        wei_kcyx.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
499
500
501
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_3{}, num_thread);
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
502
#elif 1
503
        in_nchw.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
Chao Liu's avatar
Chao Liu committed
504
        wei_kcyx.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
Chao Liu's avatar
Chao Liu committed
505
#elif 0
506
507
508
509
510
511
        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
512
#endif
513
    }
Chao Liu's avatar
Chao Liu committed
514

Chao Liu's avatar
Chao Liu committed
515
#if 0
Chao Liu's avatar
Chao Liu committed
516
    device_convolution_direct_v2_nchw_kcyx_nkhw
Chao Liu's avatar
Chao Liu committed
517
        in_nchw_desc, in_nchw, wei_kcyx_desc, wei_kcyx, out_nkhw_desc, out_nkhw_device, nrepeat);
Chao Liu's avatar
Chao Liu committed
518
#elif 0
519
    device_convolution_implicit_gemm_v1_chwn_cyxk_khwn
Chao Liu's avatar
Chao Liu committed
520
        in_nchw_desc, in_nchw, wei_kcyx_desc, wei_kcyx, out_nkhw_desc, out_nkhw_device, nrepeat);
Chao Liu's avatar
Chao Liu committed
521
#elif 0
Chao Liu's avatar
Chao Liu committed
522
    device_convolution_implicit_gemm_v1_nchw_cyxk_nkhw
Chao Liu's avatar
Chao Liu committed
523
        in_nchw_desc, in_nchw, wei_kcyx_desc, wei_kcyx, out_nkhw_desc, out_nkhw_device, nrepeat);
524
#elif 0
Chao Liu's avatar
Chao Liu committed
525
    device_convolution_implicit_gemm_v2_chwn_cyxk_khwn
Chao Liu's avatar
Chao Liu committed
526
        in_nchw_desc, in_nchw, wei_kcyx_desc, wei_kcyx, out_nkhw_desc, out_nkhw_device, nrepeat);
Chao Liu's avatar
Chao Liu committed
527
#elif 1
Chao Liu's avatar
Chao Liu committed
528
529
    device_convolution_implicit_gemm_v3_nchw_cyxk_nkhw(
        in_nchw_desc, in_nchw, wei_kcyx_desc, wei_kcyx, out_nkhw_desc, out_nkhw_device, nrepeat);
530
#elif 0
Chao Liu's avatar
Chao Liu committed
531
532
533
534
535
536
537
538
539
    device_convolution_implicit_gemm_v4_nchw_kcyx_nkhw(in_nchw_desc,
                                                       in_nchw,
                                                       wei_kcyx_desc,
                                                       wei_kcyx,
                                                       out_nkhw_desc,
                                                       out_nkhw_device,
                                                       ConvStrides{},
                                                       ConvDilations{},
                                                       nrepeat);
540
#elif 0
Chao Liu's avatar
Chao Liu committed
541
    device_implicit_gemm_convolution_1_chwn_cyxk_khwn_padded(in_nchw_desc,
Chao Liu's avatar
Chao Liu committed
542
                                                             in_nchw,
Chao Liu's avatar
Chao Liu committed
543
544
                                                             wei_kcyx_desc,
                                                             wei_kcyx,
Chao Liu's avatar
Chao Liu committed
545
546
547
548
549
                                                             out_nkhw_desc,
                                                             out_nkhw_device,
                                                             lower_pads,
                                                             upper_pads,
                                                             nrepeat);
550
#endif
Chao Liu's avatar
Chao Liu committed
551

552
    if(do_verification)
553
    {
Chao Liu's avatar
Chao Liu committed
554
#if 1
555
556
        if(Y == 3 && X == 3 && ConvStrides{}[0] == 1 && ConvStrides{}[1] == 1 &&
           ConvDilations{}[0] == 1 && ConvDilations{}[1] == 1)
557
        {
Chao Liu's avatar
Chao Liu committed
558
            host_winograd_3x3_convolution(in_nchw, wei_kcyx, out_nkhw_host, lower_pads, upper_pads);
559
560
        }
        else
Chao Liu's avatar
Chao Liu committed
561
#endif
562
        {
563
564
565
566
567
568
569
            host_direct_convolution(in_nchw,
                                    wei_kcyx,
                                    out_nkhw_host,
                                    ConvStrides{},
                                    ConvDilations{},
                                    lower_pads,
                                    upper_pads);
570
571
        }
        check_error(out_nkhw_host, out_nkhw_device);
Chao Liu's avatar
Chao Liu committed
572

Chao Liu's avatar
Chao Liu committed
573
#if 0
574
        LogRange(std::cout << "in_nchw : ", in_nchw.mData, ",") << std::endl;
Chao Liu's avatar
Chao Liu committed
575
        LogRange(std::cout << "wei_kcyx: ", wei_kcyx.mData, ",") << std::endl;
576
577
        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
578
#endif
579
    }
580
}