driver.cpp 21.1 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"
Chao Liu's avatar
Chao Liu committed
17
#include "device_convolution_implicit_gemm_v4r2_nchw_kcyx_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
18
#include "device_convolution_implicit_gemm_v4r3_nchw_kcyx_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
19
#include "device_convolution_implicit_gemm_v4r4_nchw_kcyx_nkhw.hpp"
20

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

Chao Liu's avatar
Chao Liu committed
30
31
32
33
34
35
36
37
38
39
40
41
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;
    }
};

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

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

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

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

Jehandad Khan's avatar
Jehandad Khan committed
70

Chao Liu's avatar
Chao Liu committed
71
int main(int argc, char* argv[])
Chao Liu's avatar
Chao Liu committed
72
{
Chao Liu's avatar
Chao Liu committed
73
    using namespace ck;
Jehandad Khan's avatar
Jehandad Khan committed
74
    ConvolutionDir dir = Forward;
Chao Liu's avatar
Chao Liu committed
75

76
#if 1
Jehandad Khan's avatar
Jehandad Khan committed
77
    constexpr index_t N  = 64;
Chao Liu's avatar
Chao Liu committed
78
    constexpr index_t C  = 1536;
Chao Liu's avatar
Chao Liu committed
79
80
    constexpr index_t HI = 8;
    constexpr index_t WI = 8;
Chao Liu's avatar
Chao Liu committed
81
    constexpr index_t K  = 256;
Chao Liu's avatar
Chao Liu committed
82
83
84
85
86
    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
87
88
89

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Jehandad Khan's avatar
Jehandad Khan committed
90
    dir = BackwardWeights;
91
#elif 0
92
    // 3x3, 34x34
93
    constexpr index_t N  = 128;
94
    constexpr index_t C  = 256;
95
96
    constexpr index_t HI = 34;
    constexpr index_t WI = 34;
97
98
99
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
100

Chao Liu's avatar
Chao Liu committed
101
    using ConvStrides   = Sequence<1, 1>;
102
103
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
104
105
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
106
#elif 0
107
    // 3x3, 56x56
Chao Liu's avatar
Chao Liu committed
108
109
    constexpr index_t N  = 64;
    constexpr index_t C  = 64;
110
111
    constexpr index_t HI = 56;
    constexpr index_t WI = 56;
Chao Liu's avatar
Chao Liu committed
112
113
114
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
115
116
117

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
118
#elif 0
Chao Liu's avatar
Chao Liu committed
119
120
121
122
123
    // 3x3 filter, 28x28 image
    constexpr index_t N  = 128;
    constexpr index_t C  = 256;
    constexpr index_t HI = 28;
    constexpr index_t WI = 28;
124
    constexpr index_t K  = 128;
Chao Liu's avatar
Chao Liu committed
125
126
127
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

Chao Liu's avatar
Chao Liu committed
128
    using ConvStrides   = Sequence<1, 1>;
129
130
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
131
132
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
133
#elif 0
Chao Liu's avatar
Chao Liu committed
134
    // 1x1 filter, 28x28 image
135
136
    constexpr index_t N  = 128;
    constexpr index_t C  = 512;
Chao Liu's avatar
Chao Liu committed
137
138
139
140
141
142
    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
143
144
145
    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
146
147
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
148
149
#elif 0
    // 3x3 filter, 20x84 image, 1x1 padding
Chao Liu's avatar
Chao Liu committed
150
151
152
153
154
155
156
157
158
159
    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
160
161
#elif 0
    // 3x3 filter, 112x112 image, 1x1 padding
Chao Liu's avatar
Chao Liu committed
162
163
164
165
166
167
168
169
170
171
    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;
172
#elif 0
173
174
175
176
177
178
179
180
181
182
183
    // 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
184
185
#elif 0
    // 5x5 filter, 20x86 image, 1x1 padding
Chao Liu's avatar
Chao Liu committed
186
187
188
189
190
191
192
193
194
195
    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
196
197
#elif 0
    // 5x5 filter, 28x28 image, 2x2 padding
Chao Liu's avatar
Chao Liu committed
198
199
200
201
202
203
204
205
206
207
    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
208
#elif 0
209
    // 3x3 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
210
    constexpr index_t N  = 128;
211
    constexpr index_t C  = 256;
Chao Liu's avatar
Chao Liu committed
212
213
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
214
215
216
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
217
218
219

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
220
#elif 0
221
    // 1x1 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
222
223
224
225
226
227
228
229
    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;

230
231
232
    using ConvStrides   = Sequence<1, 1>;
    using ConvDilations = Sequence<1, 1>;

Chao Liu's avatar
Chao Liu committed
233
234
235
236
237
238
239
240
241
242
243
244
    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;

245
246
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
247
#elif 0
248
249
    // 1x1 filter, 73x73 image
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
250
    constexpr index_t C  = 512;
251
252
253
254
255
256
    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
257
258
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
259
#elif 1
Chao Liu's avatar
Chao Liu committed
260
    // 1x1 filter, 8x8 image
Chao Liu's avatar
Chao Liu committed
261
    // cudnn@V100 68%, ck@V100 72%, ck@P100 52%, ck@VII 42%
Chao Liu's avatar
Chao Liu committed
262
263
264
265
266
267
268
269
270
271
272
273
274
    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
275
#elif 0
Chao Liu's avatar
Chao Liu committed
276
    // 1x1 filter, 8x8 image
Chao Liu's avatar
Chao Liu committed
277
    // cudnn@V100 77%, ck@V100 76%, ck@P100 79%, ck@VII 51%
Chao Liu's avatar
Chao Liu committed
278
279
280
281
282
283
284
285
286
287
288
289
290
    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
291
#elif 0
Chao Liu's avatar
Chao Liu committed
292
    // 1x1 filter, 7x7 image
Chao Liu's avatar
Chao Liu committed
293
    // cudnn@V100 82%, ck@V100 76%, ck@P100 67%, ck@VII 64%
Chao Liu's avatar
Chao Liu committed
294
295
296
297
298
299
300
301
302
303
304
305
306
    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
307
#elif 0
Chao Liu's avatar
Chao Liu committed
308
    // 1x1 filter, 8x8 image
Chao Liu's avatar
Chao Liu committed
309
    // cudnn@V100 83%, ck@V100 75%, ck@P100 78%, ck@VII 65%
Chao Liu's avatar
Chao Liu committed
310
311
312
313
314
315
316
317
318
319
320
321
322
    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
323
#elif 0
Chao Liu's avatar
Chao Liu committed
324
    // 1x1 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
325
    // cudnn@V100 62%, ck@V100 68%, ck@P100 70%, ck@VII 50%
Chao Liu's avatar
Chao Liu committed
326
327
328
329
330
331
332
333
334
335
336
337
338
    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
339
#elif 0
Chao Liu's avatar
Chao Liu committed
340
    // 1x1 filter, 8x8 image
Chao Liu's avatar
Chao Liu committed
341
    // cudnn@V100 74%, ck@V100 57%, ck@P100 78%, ck@VII 61%
Chao Liu's avatar
Chao Liu committed
342
343
344
345
346
347
348
349
350
351
352
353
354
    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
355
#elif 0
Chao Liu's avatar
Chao Liu committed
356
    // 1x1 filter, 28x28 image
Chao Liu's avatar
Chao Liu committed
357
    // cudnn@V100 86%, ck@V100 84%, ck@P100 80%, ck@VII 69%
Chao Liu's avatar
Chao Liu committed
358
359
360
361
362
363
364
365
366
367
368
369
370
    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
371
#elif 0
Chao Liu's avatar
Chao Liu committed
372
    // 1x1 filter, 7x7 image
Chao Liu's avatar
Chao Liu committed
373
    // cudnn@V100 71%, ck@V100 55%, ck@P100 70%, ck@VII 62%
Chao Liu's avatar
Chao Liu committed
374
375
376
377
378
379
380
381
382
383
384
385
386
    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
387
#elif 0
Chao Liu's avatar
Chao Liu committed
388
    // 3x3 filter, 2x2 stride, 35x35 input, 17x17 output
Chao Liu's avatar
Chao Liu committed
389
    // cudnn@V100 90%, ck@V100 93%, ck@P100 83%, ck@VII 81%
Chao Liu's avatar
Chao Liu committed
390
391
392
393
394
395
396
397
398
399
400
401
402
    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
403
#elif 0
Chao Liu's avatar
Chao Liu committed
404
    // 1x1 filter, 17x17 input
Chao Liu's avatar
Chao Liu committed
405
    // cudnn@V100 81%, ck@V100 76%, ck@P100 70%, ck@VII 76%
Chao Liu's avatar
Chao Liu committed
406
407
408
409
410
411
412
413
414
415
416
417
418
    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
419
#elif 0
Chao Liu's avatar
Chao Liu committed
420
    // 1x1 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
421
    // cudnn@V100 73%, ck@V100 71%, ck@P100 70%, ck@VII 64%
Chao Liu's avatar
Chao Liu committed
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
    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
437
    // cudnn@V100 73%, ck@V100 72%, ck@P100 79%, ck@VII 75%
Chao Liu's avatar
Chao Liu committed
438
439
440
441
442
443
444
445
446
447
448
449
450
    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
451
#elif 0
Chao Liu's avatar
Chao Liu committed
452
    // 1x1 filter, 7x7 image
Chao Liu's avatar
Chao Liu committed
453
    // cudnn@V100 49%, ck@V100 50%, ck@P100 61%, ck@VII 52%
Chao Liu's avatar
Chao Liu committed
454
455
456
457
    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
458
459
460
    constexpr index_t K  = 128;
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
Chao Liu's avatar
Chao Liu committed
461
462
463
464

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

Chao Liu's avatar
Chao Liu committed
465
466
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
467
#endif
Chao Liu's avatar
Chao Liu committed
468

469
470
471
    auto lower_pads = Sequence<HPad, WPad>{};
    auto upper_pads = Sequence<HPad, WPad>{};

Chao Liu's avatar
Chao Liu committed
472
473
    auto in_nchw_desc  = make_ConstantTensorDescriptor_packed(Sequence<N, C, HI, WI>{});
    auto wei_kcyx_desc = make_ConstantTensorDescriptor_packed(Sequence<K, C, Y, X>{});
474
    auto out_nkhw_desc = get_convolution_with_padding_output_default_4d_tensor_descriptor(
475
        in_nchw_desc, wei_kcyx_desc, ConvStrides{}, ConvDilations{}, lower_pads, upper_pads);
Chao Liu's avatar
Chao Liu committed
476

Chao Liu's avatar
Chao Liu committed
477
    ostream_ConstantTensorDescriptor(in_nchw_desc, std::cout << "in_nchw_desc: ");
Chao Liu's avatar
Chao Liu committed
478
    ostream_ConstantTensorDescriptor(wei_kcyx_desc, std::cout << "wei_kcyx_desc: ");
Chao Liu's avatar
Chao Liu committed
479
    ostream_ConstantTensorDescriptor(out_nkhw_desc, std::cout << "out_nkhw_desc: ");
Chao Liu's avatar
Chao Liu committed
480

Chao Liu's avatar
Chao Liu committed
481
482
    using in_data_t  = float;
    using out_data_t = float;
Jehandad Khan's avatar
Jehandad Khan committed
483
484
485
486
    Tensor<in_data_t> in_nchw_device(make_TensorDescriptor(in_nchw_desc));
    Tensor<in_data_t> wei_kcyx_device(make_TensorDescriptor(wei_kcyx_desc));
    Tensor<in_data_t> in_nchw_host(make_TensorDescriptor(in_nchw_desc));
    Tensor<in_data_t> wei_kcyx_host(make_TensorDescriptor(wei_kcyx_desc));
487
488
    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
489

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

Chao Liu's avatar
Chao Liu committed
492
493
494
495
496
497
498
    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
499
    index_t nrepeat      = atoi(argv[2]);
500
501
502

    if(do_verification)
    {
Chao Liu's avatar
Chao Liu committed
503
#if 0
504
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
505
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
506
507
508
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
        wei_kcyx.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
509
510
511
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_3{}, num_thread);
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
512
#elif 1
Jehandad Khan's avatar
Jehandad Khan committed
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
        in_nchw_device.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
        assert(in_nchw_device.mData.size() == in_nchw_host.mData.size());
        for(auto i = 0; i < in_nchw_device.mData.size(); ++i)
        {
            in_nchw_host.mData[i] = in_nchw_device.mData[i];
        }
        wei_kcyx_device.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
        assert(wei_kcyx_device.mData.size() == wei_kcyx_host.mData.size());
        for(auto i =0; i < wei_kcyx_device.mData.size(); ++i)
        {
            wei_kcyx_host.mData[i] = wei_kcyx_device.mData[i];
        }
        out_nkhw_device.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
        assert(out_nkhw_device.mData.size() == out_nkhw_host.mData.size());
        for(auto i = 0; i < out_nkhw_device.mData.size(); ++i)
        {
            out_nkhw_host.mData[i] = out_nkhw_device.mData[i];
        }
Chao Liu's avatar
Chao Liu committed
531
#elif 0
532
533
534
535
536
537
        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
538
#endif
539
    }
Chao Liu's avatar
Chao Liu committed
540

Chao Liu's avatar
Chao Liu committed
541
#if 0
Chao Liu's avatar
Chao Liu committed
542
    device_convolution_direct_v2_nchw_kcyx_nkhw
Chao Liu's avatar
Chao Liu committed
543
        (in_nchw_desc, in_nchw, wei_kcyx_desc, wei_kcyx, out_nkhw_desc, out_nkhw_device, nrepeat);
544
#elif 0
Chao Liu's avatar
Chao Liu committed
545
    device_convolution_implicit_gemm_v1_chwn_cyxk_khwn(
Chao Liu's avatar
Chao Liu committed
546
        in_nchw_desc, in_nchw, wei_kcyx_desc, wei_kcyx, out_nkhw_desc, out_nkhw_device, nrepeat);
Chao Liu's avatar
Chao Liu committed
547
#elif 0
Chao Liu's avatar
Chao Liu committed
548
    device_convolution_implicit_gemm_v1_nchw_cyxk_nkhw(
Chao Liu's avatar
Chao Liu committed
549
        in_nchw_desc, in_nchw, wei_kcyx_desc, wei_kcyx, out_nkhw_desc, out_nkhw_device, nrepeat);
550
#elif 0
Chao Liu's avatar
Chao Liu committed
551
    device_convolution_implicit_gemm_v2_chwn_cyxk_khwn(
Chao Liu's avatar
Chao Liu committed
552
        in_nchw_desc, in_nchw, wei_kcyx_desc, wei_kcyx, out_nkhw_desc, out_nkhw_device, nrepeat);
Chao Liu's avatar
Chao Liu committed
553
#elif 0
Chao Liu's avatar
Chao Liu committed
554
    device_convolution_implicit_gemm_v3_nchw_cyxk_nkhw(
Chao Liu's avatar
Chao Liu committed
555
        (in_nchw_desc, in_nchw, wei_kcyx_desc, wei_kcyx, out_nkhw_desc, out_nkhw_device, nrepeat);
Chao Liu's avatar
Chao Liu committed
556
#elif 1
557
558
// this is the same as MIOpen
// I should modify this one 
Chao Liu's avatar
Chao Liu committed
559
    device_convolution_implicit_gemm_v4r1_nchw_kcyx_nkhw(in_nchw_desc,
Jehandad Khan's avatar
Jehandad Khan committed
560
                                                         in_nchw_device,
Chao Liu's avatar
Chao Liu committed
561
                                                         wei_kcyx_desc,
Jehandad Khan's avatar
Jehandad Khan committed
562
                                                         wei_kcyx_device,
Chao Liu's avatar
Chao Liu committed
563
564
565
566
567
                                                         out_nkhw_desc,
                                                         out_nkhw_device,
                                                         ConvStrides{},
                                                         ConvDilations{},
                                                         nrepeat);
Chao Liu's avatar
Chao Liu committed
568
#elif 0
Chao Liu's avatar
Chao Liu committed
569
570
571
572
573
574
    device_convolution_implicit_gemm_v4r2_nchw_kcyx_nkhw(in_nchw_desc,
                                                         in_nchw,
                                                         wei_kcyx_desc,
                                                         wei_kcyx,
                                                         out_nkhw_desc,
                                                         out_nkhw_device,
Chao Liu's avatar
Chao Liu committed
575
576
577
                                                         ConvStrides{},
                                                         ConvDilations{},
                                                         nrepeat);
Chao Liu's avatar
Chao Liu committed
578
#elif 0
Chao Liu's avatar
Chao Liu committed
579
580
581
582
583
584
    device_convolution_implicit_gemm_v4r3_nchw_kcyx_nkhw(in_nchw_desc,
                                                         in_nchw,
                                                         wei_kcyx_desc,
                                                         wei_kcyx,
                                                         out_nkhw_desc,
                                                         out_nkhw_device,
Chao Liu's avatar
Chao Liu committed
585
586
587
                                                         ConvStrides{},
                                                         ConvDilations{},
                                                         nrepeat);
588
#elif 0
Chao Liu's avatar
Chao Liu committed
589
590
591
592
593
594
    device_convolution_implicit_gemm_v4r4_nchw_kcyx_nkhw(in_nchw_desc,
                                                         in_nchw,
                                                         wei_kcyx_desc,
                                                         wei_kcyx,
                                                         out_nkhw_desc,
                                                         out_nkhw_device,
Chao Liu's avatar
Chao Liu committed
595
596
597
                                                         ConvStrides{},
                                                         ConvDilations{},
                                                         nrepeat);
598
#elif 0
Chao Liu's avatar
Chao Liu committed
599
    device_implicit_gemm_convolution_1_chwn_cyxk_khwn_padded(in_nchw_desc,
Chao Liu's avatar
Chao Liu committed
600
                                                             in_nchw,
Chao Liu's avatar
Chao Liu committed
601
602
                                                             wei_kcyx_desc,
                                                             wei_kcyx,
Chao Liu's avatar
Chao Liu committed
603
604
605
606
607
                                                             out_nkhw_desc,
                                                             out_nkhw_device,
                                                             lower_pads,
                                                             upper_pads,
                                                             nrepeat);
608
#endif
Chao Liu's avatar
Chao Liu committed
609

610
    if(do_verification)
611
    {
Jehandad Khan's avatar
Jehandad Khan committed
612
#if 0
613
614
        if(Y == 3 && X == 3 && ConvStrides{}[0] == 1 && ConvStrides{}[1] == 1 &&
           ConvDilations{}[0] == 1 && ConvDilations{}[1] == 1)
615
        {
Chao Liu's avatar
Chao Liu committed
616
            host_winograd_3x3_convolution(in_nchw, wei_kcyx, out_nkhw_host, lower_pads, upper_pads);
617
618
        }
        else
Chao Liu's avatar
Chao Liu committed
619
#endif
620
        {
Jehandad Khan's avatar
Jehandad Khan committed
621
            host_direct_convolution(in_nchw_host,
622
                                    out_nkhw_host,
Jehandad Khan's avatar
Jehandad Khan committed
623
                                    wei_kcyx_host,
624
                                    ConvDilations{},
Jehandad Khan's avatar
Jehandad Khan committed
625
                                    ConvStrides{},
626
                                    lower_pads,
Jehandad Khan's avatar
Jehandad Khan committed
627
                                    upper_pads, dir);
628
        }
Jehandad Khan's avatar
Jehandad Khan committed
629
630
631
632
        if(dir == Forward)
            check_error(out_nkhw_host, out_nkhw_device);
        else
            check_error(wei_kcyx_host, wei_kcyx_device);
Chao Liu's avatar
Chao Liu committed
633

Chao Liu's avatar
Chao Liu committed
634
#if 0
635
        LogRange(std::cout << "in_nchw : ", in_nchw.mData, ",") << std::endl;
Chao Liu's avatar
Chao Liu committed
636
        LogRange(std::cout << "wei_kcyx: ", wei_kcyx.mData, ",") << std::endl;
637
638
        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
639
#endif
640
    }
641
}