driver.hip.cpp 30.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
#include "config.h"
Chao Liu's avatar
Chao Liu committed
7
#include "tensor.hpp"
8
9
#include "ConstantTensorDescriptor.hip.hpp"
#include "conv_common.hip.hpp"
Chao Liu's avatar
Chao Liu committed
10
#include "device_convolution_direct_v2_nchw_kcyx_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
11
//#include "device_direct_convolution_2_vectorized_nchw_kcyx_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
12
#include "device_convolution_implicit_gemm_v1_chwn_cyxk_khwn.hpp"
13
#include "device_convolution_implicit_gemm_v1_nchw_cyxk_khwn.hpp"
Chao Liu's avatar
Chao Liu committed
14
#include "device_convolution_implicit_gemm_v1_nchw_cyxk_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
15
#include "device_convolution_implicit_gemm_v2_chwn_cyxk_khwn.hpp"
Chao Liu's avatar
Chao Liu committed
16
#include "device_convolution_implicit_gemm_v3_nchw_cyxk_nkhw.hpp"
17
#include "device_convolution_implicit_gemm_v4_nchw_kcyx_nkhw.hpp"
Chao Liu's avatar
Chao Liu committed
18

Jing Zhang's avatar
fix  
Jing Zhang committed
19
20
21
22
23
24
25
26
27
28
29
struct GeneratorTensor_0
{
    template <class... Is>
    double operator()(Is... is)
    {
        return 0;
    }
};



Chao Liu's avatar
Chao Liu committed
30
struct GeneratorTensor_1
Chao Liu's avatar
Chao Liu committed
31
32
{
    template <class... Is>
Chao Liu's avatar
Chao Liu committed
33
    double operator()(Is... is)
Chao Liu's avatar
Chao Liu committed
34
    {
Chao Liu's avatar
Chao Liu committed
35
        return 1;
Chao Liu's avatar
Chao Liu committed
36
37
38
    }
};

Chao Liu's avatar
Chao Liu committed
39
40
41
42
43
44
45
46
47
48
49
50
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;
    }
};

51
52
53
54
55
56
57
struct GeneratorTensor_3
{
    template <class... Is>
    double operator()(Is... is)
    {
        std::array<index_t, sizeof...(Is)> dims = {{static_cast<index_t>(is)...}};

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

60
        return std::accumulate(dims.begin(), dims.end(), index_t(0), f_acc);
61
62
63
    }
};

Chao Liu's avatar
Chao Liu committed
64
65
66
67
68
struct GeneratorTensor_Checkboard
{
    template <class... Ts>
    double operator()(Ts... Xs) const
    {
Chao Liu's avatar
Chao Liu committed
69
        std::array<index_t, sizeof...(Ts)> dims = {{Xs...}};
Chao Liu's avatar
Chao Liu committed
70
71
72
        return std::accumulate(dims.begin(),
                               dims.end(),
                               true,
Chao Liu's avatar
Chao Liu committed
73
                               [](bool init, index_t x) -> int { return init != (x % 2); })
Chao Liu's avatar
Chao Liu committed
74
75
76
77
78
                   ? 1
                   : -1;
    }
};

Chao Liu's avatar
Chao Liu committed
79
80
81
82
83
84
// this is ugly, only for 4d
template <class TConstTensorDesc>
void ostream_ConstantTensorDescriptor(TConstTensorDesc, std::ostream& os = std::cout)
{
    static_assert(TConstTensorDesc::nDim == 4, "nDim is not 4");

Chao Liu's avatar
Chao Liu committed
85
86
87
88
    constexpr auto I0   = Number<0>{};
    constexpr auto I1   = Number<1>{};
    constexpr auto I2   = Number<2>{};
    constexpr auto I3   = Number<3>{};
Chao Liu's avatar
Chao Liu committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    constexpr auto desc = TConstTensorDesc{};

    os << "Lengths: {" << desc.GetLength(I0) << ", " << desc.GetLength(I1) << ", "
       << desc.GetLength(I2) << ", " << desc.GetLength(I3) << "}, "
       << "Strides: {" << desc.GetStride(I0) << ", " << desc.GetStride(I1) << ", "
       << desc.GetStride(I2) << ", " << desc.GetStride(I3) << "}" << std::endl;
}

// this is ugly, only for 4d
template <class TConstTensorDesc>
auto make_TensorDescriptor(TConstTensorDesc)
{
    static_assert(TConstTensorDesc::nDim == 4, "nDim is not 4");

Chao Liu's avatar
Chao Liu committed
103
104
105
106
    constexpr auto I0   = Number<0>{};
    constexpr auto I1   = Number<1>{};
    constexpr auto I2   = Number<2>{};
    constexpr auto I3   = Number<3>{};
Chao Liu's avatar
Chao Liu committed
107
108
    constexpr auto desc = TConstTensorDesc{};

Chao Liu's avatar
Chao Liu committed
109
    std::initializer_list<index_t> lengths = {
Chao Liu's avatar
Chao Liu committed
110
        desc.GetLength(I0), desc.GetLength(I1), desc.GetLength(I2), desc.GetLength(I3)};
Chao Liu's avatar
Chao Liu committed
111
    std::initializer_list<index_t> strides = {
Chao Liu's avatar
Chao Liu committed
112
113
114
115
116
        desc.GetStride(I0), desc.GetStride(I1), desc.GetStride(I2), desc.GetStride(I3)};

    return TensorDescriptor(lengths, strides);
}

Jing Zhang's avatar
Jing Zhang committed
117
118
119
120
121
122
123
template <class TIn,
          class TWei,
          class TOut,
          class LowerPads,
          class UpperPads,
          class Strides,
          class Dilations>
Jing Zhang's avatar
Jing Zhang committed
124
void host_direct_convolution_forw(const Tensor<TIn>& in_nchw,
125
126
127
                             const Tensor<TWei>& wei_kcyx,
                             Tensor<TOut>& out_nkhw,
                             LowerPads,
Jing Zhang's avatar
Jing Zhang committed
128
                             UpperPads,
Jing Zhang's avatar
Jing Zhang committed
129
130
                             Strides,
                             Dilations)
Chao Liu's avatar
Chao Liu committed
131
{
Chao Liu's avatar
Chao Liu committed
132
133
    index_t h_pad_low = LowerPads{}.Get(Number<0>{});
    index_t w_pad_low = LowerPads{}.Get(Number<1>{});
134

Chao Liu's avatar
Chao Liu committed
135
136
    index_t h_pad_up = UpperPads{}.Get(Number<0>{});
    index_t w_pad_up = UpperPads{}.Get(Number<1>{});
137

Jing Zhang's avatar
Jing Zhang committed
138
139
140
    index_t stride_h = Strides{}.Get(Number<0>{});
    index_t stride_w = Strides{}.Get(Number<1>{});

Jing Zhang's avatar
Jing Zhang committed
141
142
143
    index_t dilation_h = Dilations{}.Get(Number<0>{});
    index_t dilation_w = Dilations{}.Get(Number<1>{});

Chao Liu's avatar
Chao Liu committed
144
145
    auto f = [&](auto n, auto k, auto ho, auto wo) {
        double v = 0;
Chao Liu's avatar
Chao Liu committed
146
        for(int c = 0; c < wei_kcyx.mDesc.GetLengths()[1]; ++c)
Chao Liu's avatar
Chao Liu committed
147
        {
Chao Liu's avatar
Chao Liu committed
148
            for(int y = 0; y < wei_kcyx.mDesc.GetLengths()[2]; ++y)
Chao Liu's avatar
Chao Liu committed
149
            {
Jing Zhang's avatar
Jing Zhang committed
150
                int hi = ho * stride_h + y * dilation_h - h_pad_low;
Chao Liu's avatar
Chao Liu committed
151
                for(int x = 0; x < wei_kcyx.mDesc.GetLengths()[3]; ++x)
Chao Liu's avatar
Chao Liu committed
152
                {
Jing Zhang's avatar
Jing Zhang committed
153
                    int wi = wo * stride_w + x * dilation_w - w_pad_low;
154
155
156
                    if(hi >= 0 && hi < in_nchw.mDesc.GetLengths()[2] && wi >= 0 &&
                       wi < in_nchw.mDesc.GetLengths()[3])
                    {
157
                        v += double(in_nchw(n, c, hi, wi)) * double(wei_kcyx(k, c, y, x));
158
                    }
Chao Liu's avatar
Chao Liu committed
159
160
161
                }
            }
        }
162
        out_nkhw(n, k, ho, wo) = v;
Chao Liu's avatar
Chao Liu committed
163
164
165
    };

    auto f_par = make_ParallelTensorFunctor(f,
166
167
168
169
                                            out_nkhw.mDesc.GetLengths()[0],
                                            out_nkhw.mDesc.GetLengths()[1],
                                            out_nkhw.mDesc.GetLengths()[2],
                                            out_nkhw.mDesc.GetLengths()[3]);
Chao Liu's avatar
Chao Liu committed
170

Chao Liu's avatar
Chao Liu committed
171
    f_par(std::thread::hardware_concurrency());
Chao Liu's avatar
Chao Liu committed
172
173
}

Jing Zhang's avatar
Jing Zhang committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
template <class TIn,
          class TWei,
          class TOut,
          class LowerPads,
          class UpperPads,
          class Strides,
          class Dilations>
void host_direct_convolution_back(Tensor<TOut>& in_nchw,
                             const Tensor<TWei>& wei_kcyx,
                             const Tensor<TIn>& out_nkhw,
                             LowerPads,
                             UpperPads,
                             Strides,
                             Dilations
                             )
{
    index_t h_pad_low = LowerPads{}.Get(Number<0>{});
    index_t w_pad_low = LowerPads{}.Get(Number<1>{});

    index_t h_pad_up = UpperPads{}.Get(Number<0>{});
    index_t w_pad_up = UpperPads{}.Get(Number<1>{});

    index_t stride_h = Strides{}.Get(Number<0>{});
    index_t stride_w = Strides{}.Get(Number<1>{});

    index_t dilation_h = Dilations{}.Get(Number<0>{});
    index_t dilation_w = Dilations{}.Get(Number<1>{});

    //loop n,c,hi,wi
    auto f = [&](auto n, auto c, auto hi, auto wi) {
        double v = 0;
        //loop k,y,x
        for(int k = 0; k < wei_kcyx.mDesc.GetLengths()[0]; ++k)
        {
            for(int y = 0; y < wei_kcyx.mDesc.GetLengths()[2]; ++y)
            {
Jing Zhang's avatar
fix  
Jing Zhang committed
210
211
                int ho_ = (hi - y * dilation_h + h_pad_low);
                int ho = ho_ / stride_h; 
Jing Zhang's avatar
Jing Zhang committed
212
213
                for(int x = 0; x < wei_kcyx.mDesc.GetLengths()[3]; ++x)
                {
Jing Zhang's avatar
fix  
Jing Zhang committed
214
215
216
217
                    int wo_ = (wi - x * dilation_w + w_pad_low);
                    int wo = wo_ / stride_w;
                    if(ho >= 0 && ho < out_nkhw.mDesc.GetLengths()[2] && wo >= 0 &&
                       wo < out_nkhw.mDesc.GetLengths()[3] && ho_ % stride_h == 0 && wo_ % stride_w == 0)
Jing Zhang's avatar
Jing Zhang committed
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
                    {
                        v += double(out_nkhw(n, k, ho, wo)) * double(wei_kcyx(k, c, y, x));
                    }
                }
            }
        }
        in_nchw(n, c, hi, wi) = v;
    };

    auto f_par = make_ParallelTensorFunctor(f,
                                            in_nchw.mDesc.GetLengths()[0],
                                            in_nchw.mDesc.GetLengths()[1],
                                            in_nchw.mDesc.GetLengths()[2],
                                            in_nchw.mDesc.GetLengths()[3]);

    f_par(std::thread::hardware_concurrency());
}

236
237
238
239
240
241
template <class TIn, class TWei, class TOut, class LowerPads, class UpperPads>
void host_winograd_3x3_convolution(const Tensor<TIn>& in_nchw,
                                   const Tensor<TWei>& wei_kcyx,
                                   Tensor<TOut>& out_nkhw,
                                   LowerPads,
                                   UpperPads)
Chao Liu's avatar
Chao Liu committed
242
{
Chao Liu's avatar
Chao Liu committed
243
244
    constexpr std::size_t HoPerTile = 2;
    constexpr std::size_t WoPerTile = 2;
Chao Liu's avatar
Chao Liu committed
245

Chao Liu's avatar
Chao Liu committed
246
247
248
249
    std::size_t N  = in_nchw.mDesc.GetLengths()[0];
    std::size_t C  = in_nchw.mDesc.GetLengths()[1];
    std::size_t HI = in_nchw.mDesc.GetLengths()[2];
    std::size_t WI = in_nchw.mDesc.GetLengths()[3];
Chao Liu's avatar
Chao Liu committed
250

Chao Liu's avatar
Chao Liu committed
251
252
253
    std::size_t K = wei_kcyx.mDesc.GetLengths()[0];
    std::size_t Y = wei_kcyx.mDesc.GetLengths()[2];
    std::size_t X = wei_kcyx.mDesc.GetLengths()[3];
Chao Liu's avatar
Chao Liu committed
254

255
256
    std::size_t HO = out_nkhw.mDesc.GetLengths()[2];
    std::size_t WO = out_nkhw.mDesc.GetLengths()[3];
Chao Liu's avatar
Chao Liu committed
257

Chao Liu's avatar
Chao Liu committed
258
259
    index_t h_pad_low = LowerPads{}.Get(Number<0>{});
    index_t w_pad_low = LowerPads{}.Get(Number<1>{});
260

Chao Liu's avatar
Chao Liu committed
261
262
    index_t h_pad_up = UpperPads{}.Get(Number<0>{});
    index_t w_pad_up = UpperPads{}.Get(Number<1>{});
263

Chao Liu's avatar
Chao Liu committed
264
265
    std::size_t HiPerTile = HoPerTile + Y - 1;
    std::size_t WiPerTile = WoPerTile + X - 1;
Chao Liu's avatar
Chao Liu committed
266

Chao Liu's avatar
Chao Liu committed
267
268
    std::size_t HTile = (HO + HoPerTile - 1) / HoPerTile;
    std::size_t WTile = (WO + WoPerTile - 1) / WoPerTile;
Chao Liu's avatar
Chao Liu committed
269

270
271
272
273
274
    Tensor<double> in_hold({N, C, HTile, WTile, HiPerTile, WiPerTile});
    Tensor<double> in_transform({N, C, HTile, WTile, HiPerTile, WiPerTile});
    Tensor<double> wei_transform({K, C, HiPerTile, WiPerTile});
    Tensor<double> out_transform({N, K, HTile, WTile, HiPerTile, HiPerTile});
    Tensor<double> out_hold({N, K, HTile, WTile, HoPerTile, WoPerTile});
Chao Liu's avatar
Chao Liu committed
275

Chao Liu's avatar
Chao Liu committed
276
277
    auto f_in_hold = [&](auto n, auto c, auto htile, auto wtile) {
        for(int j = 0; j < HiPerTile; ++j)
Chao Liu's avatar
Chao Liu committed
278
        {
Chao Liu's avatar
Chao Liu committed
279
280
            int hi = HoPerTile * htile + j - h_pad_low;
            for(int i = 0; i < WiPerTile; ++i)
Chao Liu's avatar
Chao Liu committed
281
            {
Chao Liu's avatar
Chao Liu committed
282
                int wi = WoPerTile * wtile + i - w_pad_low;
283
284
285
286

                if(hi >= 0 && hi < in_nchw.mDesc.GetLengths()[2] && wi >= 0 &&
                   wi < in_nchw.mDesc.GetLengths()[3])
                {
Chao Liu's avatar
Chao Liu committed
287
                    in_hold(n, c, htile, wtile, j, i) = in_nchw(n, c, hi, wi);
288
289
290
                }
                else
                {
291
                    in_hold(n, c, htile, wtile, j, i) = TIn(0);
292
                }
Chao Liu's avatar
Chao Liu committed
293
294
295
296
            }
        }
    };

Chao Liu's avatar
Chao Liu committed
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
    auto f_in_transform = [&](auto n, auto c, auto htile, auto wtile) {
        in_transform(n, c, htile, wtile, 0, 0) =
            in_hold(n, c, htile, wtile, 0, 0) - in_hold(n, c, htile, wtile, 0, 2) -
            in_hold(n, c, htile, wtile, 2, 0) + in_hold(n, c, htile, wtile, 2, 2);
        in_transform(n, c, htile, wtile, 0, 1) =
            in_hold(n, c, htile, wtile, 0, 1) + in_hold(n, c, htile, wtile, 0, 2) -
            in_hold(n, c, htile, wtile, 2, 1) - in_hold(n, c, htile, wtile, 2, 2);
        in_transform(n, c, htile, wtile, 0, 2) =
            -in_hold(n, c, htile, wtile, 0, 1) + in_hold(n, c, htile, wtile, 0, 2) +
            in_hold(n, c, htile, wtile, 2, 1) - in_hold(n, c, htile, wtile, 2, 2);
        in_transform(n, c, htile, wtile, 0, 3) =
            in_hold(n, c, htile, wtile, 0, 1) - in_hold(n, c, htile, wtile, 0, 3) -
            in_hold(n, c, htile, wtile, 2, 1) + in_hold(n, c, htile, wtile, 2, 3);

        in_transform(n, c, htile, wtile, 1, 0) =
            in_hold(n, c, htile, wtile, 1, 0) - in_hold(n, c, htile, wtile, 1, 2) +
            in_hold(n, c, htile, wtile, 2, 0) - in_hold(n, c, htile, wtile, 2, 2);
        in_transform(n, c, htile, wtile, 1, 1) =
            in_hold(n, c, htile, wtile, 1, 1) + in_hold(n, c, htile, wtile, 1, 2) +
            in_hold(n, c, htile, wtile, 2, 1) + in_hold(n, c, htile, wtile, 2, 2);
        in_transform(n, c, htile, wtile, 1, 2) =
            -in_hold(n, c, htile, wtile, 1, 1) + in_hold(n, c, htile, wtile, 1, 2) -
            in_hold(n, c, htile, wtile, 2, 1) + in_hold(n, c, htile, wtile, 2, 2);
        in_transform(n, c, htile, wtile, 1, 3) =
            in_hold(n, c, htile, wtile, 1, 1) - in_hold(n, c, htile, wtile, 1, 3) +
            in_hold(n, c, htile, wtile, 2, 1) - in_hold(n, c, htile, wtile, 2, 3);

        in_transform(n, c, htile, wtile, 2, 0) =
            -in_hold(n, c, htile, wtile, 1, 0) + in_hold(n, c, htile, wtile, 1, 2) +
            in_hold(n, c, htile, wtile, 2, 0) - in_hold(n, c, htile, wtile, 2, 2);
        in_transform(n, c, htile, wtile, 2, 1) =
            -in_hold(n, c, htile, wtile, 1, 1) - in_hold(n, c, htile, wtile, 1, 2) +
            in_hold(n, c, htile, wtile, 2, 1) + in_hold(n, c, htile, wtile, 2, 2);
        in_transform(n, c, htile, wtile, 2, 2) =
            in_hold(n, c, htile, wtile, 1, 1) - in_hold(n, c, htile, wtile, 1, 2) -
            in_hold(n, c, htile, wtile, 2, 1) + in_hold(n, c, htile, wtile, 2, 2);
        in_transform(n, c, htile, wtile, 2, 3) =
            -in_hold(n, c, htile, wtile, 1, 1) + in_hold(n, c, htile, wtile, 1, 3) +
            in_hold(n, c, htile, wtile, 2, 1) - in_hold(n, c, htile, wtile, 2, 3);

        in_transform(n, c, htile, wtile, 3, 0) =
            in_hold(n, c, htile, wtile, 1, 0) - in_hold(n, c, htile, wtile, 1, 2) -
            in_hold(n, c, htile, wtile, 3, 0) + in_hold(n, c, htile, wtile, 3, 2);
        in_transform(n, c, htile, wtile, 3, 1) =
            in_hold(n, c, htile, wtile, 1, 1) + in_hold(n, c, htile, wtile, 1, 2) -
            in_hold(n, c, htile, wtile, 3, 1) - in_hold(n, c, htile, wtile, 3, 2);
        in_transform(n, c, htile, wtile, 3, 2) =
            -in_hold(n, c, htile, wtile, 1, 1) + in_hold(n, c, htile, wtile, 1, 2) +
            in_hold(n, c, htile, wtile, 3, 1) - in_hold(n, c, htile, wtile, 3, 2);
        in_transform(n, c, htile, wtile, 3, 3) =
            in_hold(n, c, htile, wtile, 1, 1) - in_hold(n, c, htile, wtile, 1, 3) -
            in_hold(n, c, htile, wtile, 3, 1) + in_hold(n, c, htile, wtile, 3, 3);
Chao Liu's avatar
Chao Liu committed
349
350
351
    };

    auto f_wei_transform = [&](auto k, auto c) {
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
        wei_transform(k, c, 0, 0) = double(wei_kcyx(k, c, 0, 0));
        wei_transform(k, c, 0, 1) = 0.5 * double(wei_kcyx(k, c, 0, 0)) +
                                    0.5 * double(wei_kcyx(k, c, 0, 1)) +
                                    0.5 * double(wei_kcyx(k, c, 0, 2));
        wei_transform(k, c, 0, 2) = 0.5 * double(wei_kcyx(k, c, 0, 0)) -
                                    0.5 * double(wei_kcyx(k, c, 0, 1)) +
                                    0.5 * double(wei_kcyx(k, c, 0, 2));
        wei_transform(k, c, 0, 3) = double(wei_kcyx(k, c, 0, 2));

        wei_transform(k, c, 1, 0) = 0.5 * double(wei_kcyx(k, c, 0, 0)) +
                                    0.5 * double(wei_kcyx(k, c, 1, 0)) +
                                    0.5 * double(wei_kcyx(k, c, 2, 0));
        wei_transform(k, c, 1, 1) =
            0.25 * double(wei_kcyx(k, c, 0, 0)) + 0.25 * double(wei_kcyx(k, c, 0, 1)) +
            0.25 * double(wei_kcyx(k, c, 0, 2)) + 0.25 * double(wei_kcyx(k, c, 1, 0)) +
            0.25 * double(wei_kcyx(k, c, 1, 1)) + 0.25 * double(wei_kcyx(k, c, 1, 2)) +
            0.25 * double(wei_kcyx(k, c, 2, 0)) + 0.25 * double(wei_kcyx(k, c, 2, 1)) +
            0.25 * double(wei_kcyx(k, c, 2, 2));
        wei_transform(k, c, 1, 2) =
            0.25 * double(wei_kcyx(k, c, 0, 0)) - 0.25 * double(wei_kcyx(k, c, 0, 1)) +
            0.25 * double(wei_kcyx(k, c, 0, 2)) + 0.25 * double(wei_kcyx(k, c, 1, 0)) -
            0.25 * double(wei_kcyx(k, c, 1, 1)) + 0.25 * double(wei_kcyx(k, c, 1, 2)) +
            0.25 * double(wei_kcyx(k, c, 2, 0)) - 0.25 * double(wei_kcyx(k, c, 2, 1)) +
            0.25 * double(wei_kcyx(k, c, 2, 2));
        wei_transform(k, c, 1, 3) = 0.5 * double(wei_kcyx(k, c, 0, 2)) +
                                    0.5 * double(wei_kcyx(k, c, 1, 2)) +
                                    0.5 * double(wei_kcyx(k, c, 2, 2));

        wei_transform(k, c, 2, 0) = 0.5 * double(wei_kcyx(k, c, 0, 0)) -
                                    0.5 * double(wei_kcyx(k, c, 1, 0)) +
                                    0.5 * double(wei_kcyx(k, c, 2, 0));
        wei_transform(k, c, 2, 1) =
            0.25 * double(wei_kcyx(k, c, 0, 0)) + 0.25 * double(wei_kcyx(k, c, 0, 1)) +
            0.25 * double(wei_kcyx(k, c, 0, 2)) - 0.25 * double(wei_kcyx(k, c, 1, 0)) -
            0.25 * double(wei_kcyx(k, c, 1, 1)) - 0.25 * double(wei_kcyx(k, c, 1, 2)) +
            0.25 * double(wei_kcyx(k, c, 2, 0)) + 0.25 * double(wei_kcyx(k, c, 2, 1)) +
            0.25 * double(wei_kcyx(k, c, 2, 2));
        wei_transform(k, c, 2, 2) =
            0.25 * double(wei_kcyx(k, c, 0, 0)) - 0.25 * double(wei_kcyx(k, c, 0, 1)) +
            0.25 * double(wei_kcyx(k, c, 0, 2)) - 0.25 * double(wei_kcyx(k, c, 1, 0)) +
            0.25 * double(wei_kcyx(k, c, 1, 1)) - 0.25 * double(wei_kcyx(k, c, 1, 2)) +
            0.25 * double(wei_kcyx(k, c, 2, 0)) - 0.25 * double(wei_kcyx(k, c, 2, 1)) +
            0.25 * double(wei_kcyx(k, c, 2, 2));
        wei_transform(k, c, 2, 3) = 0.5 * double(wei_kcyx(k, c, 0, 2)) -
                                    0.5 * double(wei_kcyx(k, c, 1, 2)) +
                                    0.5 * double(wei_kcyx(k, c, 2, 2));

        wei_transform(k, c, 3, 0) = double(wei_kcyx(k, c, 2, 0));
        wei_transform(k, c, 3, 1) = 0.5 * double(wei_kcyx(k, c, 2, 0)) +
                                    0.5 * double(wei_kcyx(k, c, 2, 1)) +
                                    0.5 * double(wei_kcyx(k, c, 2, 2));
        wei_transform(k, c, 3, 2) = 0.5 * double(wei_kcyx(k, c, 2, 0)) -
                                    0.5 * double(wei_kcyx(k, c, 2, 1)) +
                                    0.5 * double(wei_kcyx(k, c, 2, 2));
        wei_transform(k, c, 3, 3) = double(wei_kcyx(k, c, 2, 2));
Chao Liu's avatar
Chao Liu committed
407
408
    };

Chao Liu's avatar
Chao Liu committed
409
410
    auto f_out_transform = [&](auto n, auto k, auto htile, auto wtile) {
        for(int j = 0; j < HiPerTile; ++j)
Chao Liu's avatar
Chao Liu committed
411
        {
Chao Liu's avatar
Chao Liu committed
412
            for(int i = 0; i < WiPerTile; ++i)
Chao Liu's avatar
Chao Liu committed
413
414
415
416
            {
                double v = 0;
                for(int c = 0; c < C; ++c)
                {
Chao Liu's avatar
Chao Liu committed
417
                    v += in_transform(n, c, htile, wtile, j, i) * wei_transform(k, c, j, i);
Chao Liu's avatar
Chao Liu committed
418
419
                }

Chao Liu's avatar
Chao Liu committed
420
                out_transform(n, k, htile, wtile, j, i) = v;
Chao Liu's avatar
Chao Liu committed
421
422
423
424
            }
        }
    };

Chao Liu's avatar
Chao Liu committed
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
    auto f_out_hold = [&](auto n, auto k, auto htile, auto wtile) {
        out_hold(n, k, htile, wtile, 0, 0) =
            out_transform(n, k, htile, wtile, 0, 0) + out_transform(n, k, htile, wtile, 0, 1) +
            out_transform(n, k, htile, wtile, 0, 2) + out_transform(n, k, htile, wtile, 1, 0) +
            out_transform(n, k, htile, wtile, 1, 1) + out_transform(n, k, htile, wtile, 1, 2) +
            out_transform(n, k, htile, wtile, 2, 0) + out_transform(n, k, htile, wtile, 2, 1) +
            out_transform(n, k, htile, wtile, 2, 2);
        out_hold(n, k, htile, wtile, 0, 1) =
            out_transform(n, k, htile, wtile, 0, 1) - out_transform(n, k, htile, wtile, 0, 2) -
            out_transform(n, k, htile, wtile, 0, 3) + out_transform(n, k, htile, wtile, 1, 1) -
            out_transform(n, k, htile, wtile, 1, 2) - out_transform(n, k, htile, wtile, 1, 3) +
            out_transform(n, k, htile, wtile, 2, 1) - out_transform(n, k, htile, wtile, 2, 2) -
            out_transform(n, k, htile, wtile, 2, 3);
        out_hold(n, k, htile, wtile, 1, 0) =
            out_transform(n, k, htile, wtile, 1, 0) + out_transform(n, k, htile, wtile, 1, 1) +
            out_transform(n, k, htile, wtile, 1, 2) - out_transform(n, k, htile, wtile, 2, 0) -
            out_transform(n, k, htile, wtile, 2, 1) - out_transform(n, k, htile, wtile, 2, 2) -
            out_transform(n, k, htile, wtile, 3, 0) - out_transform(n, k, htile, wtile, 3, 1) -
            out_transform(n, k, htile, wtile, 3, 2);
        out_hold(n, k, htile, wtile, 1, 1) =
            out_transform(n, k, htile, wtile, 1, 1) - out_transform(n, k, htile, wtile, 1, 2) -
            out_transform(n, k, htile, wtile, 1, 3) - out_transform(n, k, htile, wtile, 2, 1) +
            out_transform(n, k, htile, wtile, 2, 2) + out_transform(n, k, htile, wtile, 2, 3) -
            out_transform(n, k, htile, wtile, 3, 1) + out_transform(n, k, htile, wtile, 3, 2) +
            out_transform(n, k, htile, wtile, 3, 3);
Chao Liu's avatar
Chao Liu committed
450
451
    };

Chao Liu's avatar
Chao Liu committed
452
453
    auto f_out = [&](auto n, auto k, auto htile, auto wtile) {
        for(int j = 0; j < HoPerTile; ++j)
Chao Liu's avatar
Chao Liu committed
454
        {
Chao Liu's avatar
Chao Liu committed
455
456
            std::size_t ho = HoPerTile * htile + j;
            for(int i = 0; i < WoPerTile; ++i)
Chao Liu's avatar
Chao Liu committed
457
            {
458
                std::size_t wo = WoPerTile * wtile + i;
459
                out_nkhw(n, k, ho, wo) = out_hold(n, k, htile, wtile, j, i);
Chao Liu's avatar
Chao Liu committed
460
461
462
463
464
465
            }
        }
    };

    std::size_t num_thread = std::thread::hardware_concurrency();

Chao Liu's avatar
Chao Liu committed
466
467
    make_ParallelTensorFunctor(f_in_hold, N, C, HTile, WTile)(num_thread);
    make_ParallelTensorFunctor(f_in_transform, N, C, HTile, WTile)(num_thread);
Chao Liu's avatar
Chao Liu committed
468
    make_ParallelTensorFunctor(f_wei_transform, K, C)(num_thread);
Chao Liu's avatar
Chao Liu committed
469
470
471
    make_ParallelTensorFunctor(f_out_transform, N, K, HTile, WTile)(num_thread);
    make_ParallelTensorFunctor(f_out_hold, N, K, HTile, WTile)(num_thread);
    make_ParallelTensorFunctor(f_out, N, K, HTile, WTile)(num_thread);
Chao Liu's avatar
Chao Liu committed
472
473
474
475
476
477
}

template <class T>
void check_error(const Tensor<T>& ref, const Tensor<T>& result)
{
    float error     = 0;
Chao Liu's avatar
Chao Liu committed
478
    float max_diff  = -1;
Chao Liu's avatar
Chao Liu committed
479
480
481
    float ref_value = 0, result_value = 0;
    for(int i = 0; i < ref.mData.size(); ++i)
    {
482
483
        error += std::abs(double(ref.mData[i]) - double(result.mData[i]));
        float diff = std::abs(double(ref.mData[i]) - double(result.mData[i]));
Chao Liu's avatar
Chao Liu committed
484
485
486
487
488
489
490
491
492
493
494
495
        if(max_diff < diff)
        {
            max_diff     = diff;
            ref_value    = ref.mData[i];
            result_value = result.mData[i];
        }
    }

    std::cout << "error: " << error << std::endl;
    std::cout << "max_diff: " << max_diff << ", " << ref_value << ", " << result_value << std::endl;
}

Chao Liu's avatar
Chao Liu committed
496
int main(int argc, char* argv[])
Chao Liu's avatar
Chao Liu committed
497
{
Jing Zhang's avatar
Jing Zhang committed
498
499
    constexpr index_t HStride = 2;
    constexpr index_t WStride = 2;
Jing Zhang's avatar
Jing Zhang committed
500

Jing Zhang's avatar
Jing Zhang committed
501
502
503
504
    constexpr index_t HDilation = 1;
    constexpr index_t WDilation = 1;

    constexpr index_t Direction = 2; //1: Forward; 2:Backward
Jing Zhang's avatar
fix  
Jing Zhang committed
505
#if 0
Chao Liu's avatar
Chao Liu committed
506
    constexpr index_t N  = 8;
Jing Zhang's avatar
Jing Zhang committed
507
    constexpr index_t C  = 128;
Jing Zhang's avatar
fix  
Jing Zhang committed
508
509
510
    constexpr index_t HI = 2;
    constexpr index_t WI = 32;
    constexpr index_t K  = 16;
Jing Zhang's avatar
Jing Zhang committed
511
512
    constexpr index_t Y  = 1;
    constexpr index_t X  = 1;
Chao Liu's avatar
Chao Liu committed
513
514
515

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
516
#elif 0
517
    // 3x3, 34x34
518
519
    constexpr index_t N  = 64;
    constexpr index_t C  = 256;
520
521
    constexpr index_t HI = 34;
    constexpr index_t WI = 34;
522
523
524
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
525
526
527

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
528
#elif 0
529
    // 3x3, 56x56
Chao Liu's avatar
Chao Liu committed
530
531
    constexpr index_t N  = 64;
    constexpr index_t C  = 64;
532
533
    constexpr index_t HI = 56;
    constexpr index_t WI = 56;
Chao Liu's avatar
Chao Liu committed
534
535
536
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
537
538
539

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Jing Zhang's avatar
Jing Zhang committed
540
#elif 0
Chao Liu's avatar
Chao Liu committed
541
542
543
544
545
    // 3x3 filter, 28x28 image
    constexpr index_t N  = 128;
    constexpr index_t C  = 256;
    constexpr index_t HI = 28;
    constexpr index_t WI = 28;
546
    constexpr index_t K  = 128;
Chao Liu's avatar
Chao Liu committed
547
548
549
550
551
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Jing Zhang's avatar
Jing Zhang committed
552
#elif 1
Chao Liu's avatar
Chao Liu committed
553
    // 1x1 filter, 28x28 image
554
555
    constexpr index_t N  = 128;
    constexpr index_t C  = 512;
Chao Liu's avatar
Chao Liu committed
556
557
558
559
560
561
562
563
    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;

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
564
565
#elif 0
    // 3x3 filter, 20x84 image, 1x1 padding
Chao Liu's avatar
Chao Liu committed
566
567
568
569
570
571
572
573
574
575
    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
576
577
#elif 0
    // 3x3 filter, 112x112 image, 1x1 padding
Chao Liu's avatar
Chao Liu committed
578
579
580
581
582
583
584
585
586
587
    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;
588
#elif 0
589
590
591
592
593
594
595
596
597
598
599
    // 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
600
601
#elif 0
    // 5x5 filter, 20x86 image, 1x1 padding
Chao Liu's avatar
Chao Liu committed
602
603
604
605
606
607
608
609
610
611
    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
612
613
#elif 0
    // 5x5 filter, 28x28 image, 2x2 padding
Chao Liu's avatar
Chao Liu committed
614
615
616
617
618
619
620
621
622
623
    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
624
#elif 0
625
    // 3x3 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
626
    constexpr index_t N  = 128;
627
    constexpr index_t C  = 256;
Chao Liu's avatar
Chao Liu committed
628
629
    constexpr index_t HI = 14;
    constexpr index_t WI = 14;
630
631
632
    constexpr index_t K  = 128;
    constexpr index_t Y  = 3;
    constexpr index_t X  = 3;
Chao Liu's avatar
Chao Liu committed
633
634
635

    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
636
#elif 0
637
    // 1x1 filter, 14x14 image
Chao Liu's avatar
Chao Liu committed
638
639
640
641
642
643
644
645
    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;

Chao Liu's avatar
Chao Liu committed
646
647
648
649
650
651
652
653
654
655
656
657
    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;

658
659
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
660
#elif 0
661
662
    // 1x1 filter, 73x73 image
    constexpr index_t N  = 128;
Chao Liu's avatar
Chao Liu committed
663
    constexpr index_t C  = 512;
664
665
666
667
668
669
    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
670
671
    constexpr index_t HPad = 0;
    constexpr index_t WPad = 0;
Chao Liu's avatar
Chao Liu committed
672
#endif
Chao Liu's avatar
Chao Liu committed
673

674
675
676
    auto lower_pads = Sequence<HPad, WPad>{};
    auto upper_pads = Sequence<HPad, WPad>{};

Jing Zhang's avatar
Jing Zhang committed
677
678
    auto strides   = Sequence<HStride, WStride>{};
    auto dilations = Sequence<HDilation, WDilation>{};
Jing Zhang's avatar
Jing Zhang committed
679

Chao Liu's avatar
Chao Liu committed
680
681
    auto in_nchw_desc  = make_ConstantTensorDescriptor_packed(Sequence<N, C, HI, WI>{});
    auto wei_kcyx_desc = make_ConstantTensorDescriptor_packed(Sequence<K, C, Y, X>{});
Jing Zhang's avatar
Jing Zhang committed
682
683
    auto out_nkhw_desc = get_convolution_output_default_4d_tensor_descriptor(
        in_nchw_desc, wei_kcyx_desc, strides, dilations);
Chao Liu's avatar
Chao Liu committed
684

Jing Zhang's avatar
Jing Zhang committed
685
686
    auto wei_ckyx_back_desc = wei_kcyx_desc.ReorderGivenNew2Old(Sequence<1, 0, 2, 3>{});

Chao Liu's avatar
Chao Liu committed
687
    ostream_ConstantTensorDescriptor(in_nchw_desc, std::cout << "in_nchw_desc: ");
Chao Liu's avatar
Chao Liu committed
688
    ostream_ConstantTensorDescriptor(wei_kcyx_desc, std::cout << "wei_kcyx_desc: ");
Chao Liu's avatar
Chao Liu committed
689
    ostream_ConstantTensorDescriptor(out_nkhw_desc, std::cout << "out_nkhw_desc: ");
Chao Liu's avatar
Chao Liu committed
690

Chao Liu's avatar
Chao Liu committed
691
692
    using in_data_t  = float;
    using out_data_t = float;
693
    Tensor<in_data_t> in_nchw(make_TensorDescriptor(in_nchw_desc));
Jing Zhang's avatar
Jing Zhang committed
694
695
    Tensor<in_data_t> out_nkhw(make_TensorDescriptor(out_nkhw_desc));
    Tensor<in_data_t> in_nchw_device(make_TensorDescriptor(in_nchw_desc));
696
    Tensor<out_data_t> out_nkhw_device(make_TensorDescriptor(out_nkhw_desc));
Jing Zhang's avatar
Jing Zhang committed
697
    Tensor<in_data_t> wei_kcyx(make_TensorDescriptor(wei_kcyx_desc));
Chao Liu's avatar
Chao Liu committed
698

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

Chao Liu's avatar
Chao Liu committed
701
702
703
704
705
706
707
    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
708
    index_t nrepeat      = atoi(argv[2]);
709
710
711

    if(do_verification)
    {
Chao Liu's avatar
Chao Liu committed
712
#if 0
713
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
714
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
715
716
717
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
        wei_kcyx.GenerateTensorValue(GeneratorTensor_2{-5, 5}, num_thread);
718
719
720
#elif 0
        in_nchw.GenerateTensorValue(GeneratorTensor_3{}, num_thread);
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
721
#elif 1
Jing Zhang's avatar
fix  
Jing Zhang committed
722
723
724
        in_nchw.GenerateTensorValue(GeneratorTensor_0{}, num_thread);
        out_nkhw.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
        wei_kcyx.GenerateTensorValue(GeneratorTensor_1{}, num_thread);
Chao Liu's avatar
Chao Liu committed
725
#elif 0
726
727
728
729
730
731
        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
732
#endif
733
    }
Chao Liu's avatar
Chao Liu committed
734

Chao Liu's avatar
Chao Liu committed
735
#if 1
Chao Liu's avatar
Chao Liu committed
736
#if 0
Chao Liu's avatar
Chao Liu committed
737
    device_direct_convolution_1
Chao Liu's avatar
Chao Liu committed
738
#elif 0
Chao Liu's avatar
Chao Liu committed
739
    device_convolution_direct_v2_nchw_kcyx_nkhw
Chao Liu's avatar
Chao Liu committed
740
#elif 0
Chao Liu's avatar
Chao Liu committed
741
    device_direct_convolution_2_vectorized_nchw_kcyx_nkhw
Chao Liu's avatar
Chao Liu committed
742
#elif 0
743
    device_convolution_implicit_gemm_v1_chwn_cyxk_khwn
Chao Liu's avatar
Chao Liu committed
744
#elif 0
745
    device_convolution_implicit_gemm_v1_nchw_cyxk_khwn
Chao Liu's avatar
Chao Liu committed
746
#elif 0
Chao Liu's avatar
Chao Liu committed
747
    device_convolution_implicit_gemm_v1_nchw_cyxk_nkhw
748
#elif 0
Chao Liu's avatar
Chao Liu committed
749
    device_convolution_implicit_gemm_v2_chwn_cyxk_khwn
Chao Liu's avatar
Chao Liu committed
750
#elif 0
Chao Liu's avatar
Chao Liu committed
751
    device_convolution_implicit_gemm_v3_nchw_cyxk_nkhw
752
753
#elif 1
    device_convolution_implicit_gemm_v4_nchw_kcyx_nkhw
754
#endif
Jing Zhang's avatar
Jing Zhang committed
755
756
757
    (out_nkhw_desc,
     out_nkhw,
     wei_ckyx_back_desc,
Jing Zhang's avatar
Jing Zhang committed
758
     wei_kcyx,
Jing Zhang's avatar
Jing Zhang committed
759
     in_nchw_desc,
Jing Zhang's avatar
Jing Zhang committed
760
     strides,
Jing Zhang's avatar
Jing Zhang committed
761
     dilations,
Jing Zhang's avatar
Jing Zhang committed
762
763
764
     in_nchw_device,
     nrepeat
     );
765

Chao Liu's avatar
Chao Liu committed
766
#elif 1
Chao Liu's avatar
Chao Liu committed
767
    device_implicit_gemm_convolution_1_chwn_cyxk_khwn_padded(in_nchw_desc,
Chao Liu's avatar
Chao Liu committed
768
                                                             in_nchw,
Chao Liu's avatar
Chao Liu committed
769
770
                                                             wei_kcyx_desc,
                                                             wei_kcyx,
Chao Liu's avatar
Chao Liu committed
771
772
773
774
775
                                                             out_nkhw_desc,
                                                             out_nkhw_device,
                                                             lower_pads,
                                                             upper_pads,
                                                             nrepeat);
776
#endif
Chao Liu's avatar
Chao Liu committed
777

778
    if(do_verification)
779
    {
Jing Zhang's avatar
Jing Zhang committed
780
#if 0
Chao Liu's avatar
Chao Liu committed
781
        if(Y == 3 && X == 3)
782
        {
Chao Liu's avatar
Chao Liu committed
783
            host_winograd_3x3_convolution(in_nchw, wei_kcyx, out_nkhw_host, lower_pads, upper_pads);
784
785
        }
        else
Chao Liu's avatar
Chao Liu committed
786
#endif
Jing Zhang's avatar
Jing Zhang committed
787
788
789
790
791
792
793
        if(Direction == 1)
        {
            host_direct_convolution_forw(
                in_nchw, wei_kcyx, out_nkhw, lower_pads, upper_pads, strides, dilations);
            check_error(out_nkhw, out_nkhw_device);
        }
        else
794
        {
Jing Zhang's avatar
Jing Zhang committed
795
796
797
            host_direct_convolution_back(
                in_nchw, wei_kcyx, out_nkhw, lower_pads, upper_pads, strides, dilations);
            check_error(in_nchw, in_nchw_device);
798
        }
Chao Liu's avatar
Chao Liu committed
799

Chao Liu's avatar
Chao Liu committed
800
#if 0
Jing Zhang's avatar
fix  
Jing Zhang committed
801
        //LogRange(std::cout << "in_nchw : ", in_nchw.mData, ",") << std::endl;
Chao Liu's avatar
Chao Liu committed
802
        LogRange(std::cout << "wei_kcyx: ", wei_kcyx.mData, ",") << std::endl;
Jing Zhang's avatar
fix  
Jing Zhang committed
803
804
        LogRange(std::cout << "in_nchw_host  : ", in_nchw.mData, ",") << std::endl;
        LogRange(std::cout << "in_nchw_device: ", in_nchw_device.mData, ",") << std::endl;
Chao Liu's avatar
Chao Liu committed
805
#endif
806
    }
807
}