reference_conv_fwd.cpp 23.7 KB
Newer Older
Chao Liu's avatar
Chao Liu committed
1
// SPDX-License-Identifier: MIT
Illia Silin's avatar
Illia Silin committed
2
// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
Chao Liu's avatar
Chao Liu committed
3
4
5
6
7
8
9
10
11
12
13
14

#include <cmath>
#include <cstdlib>
#include <numeric>
#include <type_traits>
#include <vector>
#include <gtest/gtest.h>

#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"

15
#include "ck/library/utility/algorithm.hpp"
Chao Liu's avatar
Chao Liu committed
16
17
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/fill.hpp"
18
19
20
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
Chao Liu's avatar
Chao Liu committed
21
22
23
#include "ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp"

namespace {
24

Chao Liu's avatar
Chao Liu committed
25
26
27
28
using InElementOp  = ck::tensor_operation::element_wise::PassThrough;
using WeiElementOp = ck::tensor_operation::element_wise::PassThrough;
using OutElementOp = ck::tensor_operation::element_wise::PassThrough;

29
template <ck::index_t NDimSpatial,
Chao Liu's avatar
Chao Liu committed
30
31
32
          typename InDataType    = float,
          typename WeiDataType   = float,
          typename OutDataType   = float,
33
34
35
          typename InLayout      = ck::tensor_layout::convolution::GNHWC,
          typename WeiLayout     = ck::tensor_layout::convolution::GKYXC,
          typename OutLayout     = ck::tensor_layout::convolution::GNHWK,
Chao Liu's avatar
Chao Liu committed
36
37
38
          typename FillInputOp   = ck::utils::FillMonotonicSeq<InDataType>,
          typename FillWeightsOp = ck::utils::FillConstant<WeiDataType>>
Tensor<OutDataType>
39
run_reference_convolution_forward(const ck::utils::conv::ConvParam& conv_param,
Chao Liu's avatar
Chao Liu committed
40
41
42
                                  const FillInputOp& fill_input_op     = FillInputOp{},
                                  const FillWeightsOp& fill_weights_op = FillWeightsOp{0.5f})
{
43
44
    const auto in_g_n_c_wis_desc =
        ck::utils::conv::make_input_host_tensor_descriptor_g_n_c_wis_packed<InLayout>(conv_param);
Chao Liu's avatar
Chao Liu committed
45

46
47
    const auto wei_g_k_c_xs_desc =
        ck::utils::conv::make_weight_host_tensor_descriptor_g_k_c_xs_packed<WeiLayout>(conv_param);
Chao Liu's avatar
Chao Liu committed
48

49
50
    const auto out_g_n_k_wos_desc =
        ck::utils::conv::make_output_host_tensor_descriptor_g_n_k_wos_packed<OutLayout>(conv_param);
Chao Liu's avatar
Chao Liu committed
51

52
53
54
    Tensor<InDataType> input(in_g_n_c_wis_desc);
    Tensor<WeiDataType> weights(wei_g_k_c_xs_desc);
    Tensor<OutDataType> host_output(out_g_n_k_wos_desc);
Chao Liu's avatar
Chao Liu committed
55
56
57

    fill_input_op(input.begin(), input.end());
    fill_weights_op(weights.begin(), weights.end());
58
    ck::ranges::fill<OutDataType>(host_output, 0.f);
Chao Liu's avatar
Chao Liu committed
59

60
61
    auto ref_conv     = ck::tensor_operation::host::ReferenceConvFwd<NDimSpatial,
                                                                 InDataType,
Chao Liu's avatar
Chao Liu committed
62
63
64
65
                                                                 WeiDataType,
                                                                 OutDataType,
                                                                 InElementOp,
                                                                 WeiElementOp,
66
                                                                 OutElementOp>();
Chao Liu's avatar
Chao Liu committed
67
68
69
70
    auto ref_invoker  = ref_conv.MakeInvoker();
    auto ref_argument = ref_conv.MakeArgument(input,
                                              weights,
                                              host_output,
71
72
73
74
                                              conv_param.conv_filter_strides_,
                                              conv_param.conv_filter_dilations_,
                                              conv_param.input_left_pads_,
                                              conv_param.input_right_pads_,
Chao Liu's avatar
Chao Liu committed
75
76
77
78
79
80
81
82
83
84
                                              InElementOp{},
                                              WeiElementOp{},
                                              OutElementOp{});

    ref_invoker.Run(ref_argument);
    return host_output;
}

} // anonymous namespace

85
86
87
88
89
90
91
92
// Eeference convolution assume dimensions of tensor descriptors are in GNCDHW/GKCZYX/GNKDHW order,
// regardless of physical tensor layouts in  memory.
// Some tests below assume dimensions of tensor descriptors can be in other order, and therefore
// are disabled
// TODO: add more tests, which comply with assumption about dimension order of reference convolution
// and add tests for more physical layout
#if 0
TEST(ReferenceConvolutionFWD, Conv2DGNHWC)
Chao Liu's avatar
Chao Liu committed
93
{
94
95
96
97
98
99
100
101
102
103
104
    ck::utils::conv::ConvParam conv_param(2,
                                          1,
                                          1,
                                          1,
                                          2,
                                          std::vector<ck::index_t>{3, 3},
                                          std::vector<ck::index_t>{6, 6},
                                          std::vector<ck::index_t>{1, 1},
                                          std::vector<ck::index_t>{1, 1},
                                          std::vector<ck::index_t>{0, 0},
                                          std::vector<ck::index_t>{0, 0});
Chao Liu's avatar
Chao Liu committed
105

106
107
    auto out_tensor = run_reference_convolution_forward<2>(conv_param);
    std::vector<std::size_t> ref_dims{1, 1, 4, 4, 1};
Chao Liu's avatar
Chao Liu committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    std::vector<float> ref_data{130.5,
                                148.5,
                                166.5,
                                184.5,
                                238.5,
                                256.5,
                                274.5,
                                292.5,
                                346.5,
                                364.5,
                                382.5,
                                400.5,
                                454.5,
                                472.5,
                                490.5,
                                508.5};
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
124
125
ck::utils::CorrectnessValidator validator;
    EXPECT_TRUE(validator.check_err(
Chao Liu's avatar
Chao Liu committed
126
        out_tensor.mDesc.GetLengths(), ref_dims, "Error: wrong output tensor dimensions!"));
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
127
    EXPECT_TRUE(validator.check_err(out_tensor, ref_data, "Error: incorrect results!"));
Chao Liu's avatar
Chao Liu committed
128
129
}

130
TEST(ReferenceConvolutionFWD, Conv2DGNHWCStridesDilationsPadding)
Chao Liu's avatar
Chao Liu committed
131
{
132
133
134
135
136
137
138
139
140
141
142
    ck::utils::conv::ConvParam conv_param(2,
                                          1,
                                          1,
                                          2,
                                          2,
                                          std::vector<ck::index_t>{3, 3},
                                          std::vector<ck::index_t>{12, 12},
                                          std::vector<ck::index_t>{2, 2},
                                          std::vector<ck::index_t>{2, 2},
                                          std::vector<ck::index_t>{1, 1},
                                          std::vector<ck::index_t>{1, 1});
Chao Liu's avatar
Chao Liu committed
143

144
145
    auto out_tensor                   = run_reference_convolution_forward<2>(conv_param);
    std::vector<std::size_t> ref_dims = std::vector<std::size_t>{1, 5, 5, 2};
Chao Liu's avatar
Chao Liu committed
146
147
148
149
150
151
    std::vector<float> ref_data{
        210.,  210.,  327.,   327.,   351.,   351.,   375.,   375.,   399.,   399.,
        459.,  459.,  706.5,  706.5,  742.5,  742.5,  778.5,  778.5,  814.5,  814.5,
        747.,  747.,  1138.5, 1138.5, 1174.5, 1174.5, 1210.5, 1210.5, 1246.5, 1246.5,
        1035., 1035., 1570.5, 1570.5, 1606.5, 1606.5, 1642.5, 1642.5, 1678.5, 1678.5,
        1323., 1323., 2002.5, 2002.5, 2038.5, 2038.5, 2074.5, 2074.5, 2110.5, 2110.5};
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
152
153
ck::utils::CorrectnessValidator validator;
    EXPECT_TRUE(validator.check_err(
Chao Liu's avatar
Chao Liu committed
154
        out_tensor.mDesc.GetLengths(), ref_dims, "Error: wrong output tensor dimensions!"));
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
155
    EXPECT_TRUE(validator.check_err(out_tensor, ref_data, "Error: incorrect results!"));
Chao Liu's avatar
Chao Liu committed
156
157
}

158
TEST(ReferenceConvolutionFWD, Conv1DGNWC)
Chao Liu's avatar
Chao Liu committed
159
{
160
161
162
163
164
165
166
167
168
169
170
    ck::utils::conv::ConvParam conv_param(1,
                                          1,
                                          1,
                                          1,
                                          2,
                                          std::vector<ck::index_t>{3},
                                          std::vector<ck::index_t>{6},
                                          std::vector<ck::index_t>{1},
                                          std::vector<ck::index_t>{1},
                                          std::vector<ck::index_t>{0},
                                          std::vector<ck::index_t>{0});
Chao Liu's avatar
Chao Liu committed
171
172
173
174
175
176

    auto out_tensor =
        run_reference_convolution_forward<1,
                                          float,
                                          float,
                                          float,
177
178
179
180
                                          ck::tensor_layout::convolution::GNWC,
                                          ck::tensor_layout::convolution::GKXC,
                                          ck::tensor_layout::convolution::GNWK>(conv_param);
    std::vector<std::size_t> ref_dims{1, 1, 4, 1};
Chao Liu's avatar
Chao Liu committed
181
    std::vector<float> ref_data{7.5, 13.5, 19.5, 25.5};
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
182
183
ck::utils::CorrectnessValidator validator;
    EXPECT_TRUE(validator.check_err(
Chao Liu's avatar
Chao Liu committed
184
        out_tensor.mDesc.GetLengths(), ref_dims, "Error: wrong output tensor dimensions!"));
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
185
    EXPECT_TRUE(validator.check_err(out_tensor, ref_data, "Error: incorrect results!"));
Chao Liu's avatar
Chao Liu committed
186
187
}

188
TEST(ReferenceConvolutionFWD, Conv1DGNWCStridesDilationsPadding)
Chao Liu's avatar
Chao Liu committed
189
{
190
191
192
193
194
195
196
197
198
199
200
    ck::utils::conv::ConvParam conv_param(1,
                                          1,
                                          1,
                                          2,
                                          2,
                                          std::vector<ck::index_t>{3},
                                          std::vector<ck::index_t>{12},
                                          std::vector<ck::index_t>{2},
                                          std::vector<ck::index_t>{2},
                                          std::vector<ck::index_t>{1},
                                          std::vector<ck::index_t>{1});
Chao Liu's avatar
Chao Liu committed
201
202
203
204
205
206

    auto out_tensor =
        run_reference_convolution_forward<1,
                                          float,
                                          float,
                                          float,
207
208
209
210
                                          ck::tensor_layout::convolution::GNWC,
                                          ck::tensor_layout::convolution::GKXC,
                                          ck::tensor_layout::convolution::GNWK>(conv_param);
    std::vector<std::size_t> ref_dims{1, 1, 5, 2};
Chao Liu's avatar
Chao Liu committed
211
    std::vector<float> ref_data{9., 9., 19.5, 19.5, 31.5, 31.5, 43.5, 43.5, 55.5, 55.5};
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
212
213
ck::utils::CorrectnessValidator validator;
    EXPECT_TRUE(validator.check_err(
Chao Liu's avatar
Chao Liu committed
214
        out_tensor.mDesc.GetLengths(), ref_dims, "Error: wrong output tensor dimensions!"));
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
215
    EXPECT_TRUE(validator.check_err(out_tensor, ref_data, "Error: incorrect results!"));
Chao Liu's avatar
Chao Liu committed
216
217
}

218
TEST(ReferenceConvolutionFWD, Conv1DGNWCSameOutputSize)
Chao Liu's avatar
Chao Liu committed
219
{
220
221
222
223
224
225
226
227
228
229
230
    ck::utils::conv::ConvParam conv_param(1,
                                          1,
                                          2,
                                          16,
                                          4,
                                          std::vector<ck::index_t>{3},
                                          std::vector<ck::index_t>{16},
                                          std::vector<ck::index_t>{1},
                                          std::vector<ck::index_t>{1},
                                          std::vector<ck::index_t>{1},
                                          std::vector<ck::index_t>{1});
Chao Liu's avatar
Chao Liu committed
231
232
233
234
235

    auto out_tensor2 = run_reference_convolution_forward<1,
                                                         float,
                                                         float,
                                                         float,
236
237
238
239
                                                         ck::tensor_layout::convolution::GNWC,
                                                         ck::tensor_layout::convolution::GKXC,
                                                         ck::tensor_layout::convolution::GNWK>(
        conv_param, ck::utils::FillMonotonicSeq<float>{0.f, 0.1f});
Chao Liu's avatar
Chao Liu committed
240

241
    std::vector<std::size_t> ref_dims{1, 2, 16, 16};
Chao Liu's avatar
Chao Liu committed
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
    std::vector<float> ref_data{
        1.4,       1.4,       1.4,       1.4,       1.4,       1.4,       1.4,       1.4,
        1.4,       1.4,       1.4,       1.4,       1.4,       1.4,       1.4,       1.4,
        3.3,       3.3,       3.3,       3.3,       3.3,       3.3,       3.3,       3.3,
        3.3,       3.3,       3.3,       3.3,       3.3,       3.3,       3.3,       3.3,
        5.7,       5.7,       5.7,       5.7,       5.7,       5.7,       5.7,       5.7,
        5.7,       5.7,       5.7,       5.7,       5.7,       5.7,       5.7,       5.7,
        8.1,       8.1,       8.1,       8.1,       8.1,       8.1,       8.1,       8.1,
        8.1,       8.1,       8.1,       8.1,       8.1,       8.1,       8.1,       8.1,
        10.5,      10.5,      10.5,      10.5,      10.5,      10.5,      10.5,      10.5,
        10.5,      10.5,      10.5,      10.5,      10.5,      10.5,      10.5,      10.5,
        12.900001, 12.900001, 12.900001, 12.900001, 12.900001, 12.900001, 12.900001, 12.900001,
        12.900001, 12.900001, 12.900001, 12.900001, 12.900001, 12.900001, 12.900001, 12.900001,
        15.3,      15.3,      15.3,      15.3,      15.3,      15.3,      15.3,      15.3,
        15.3,      15.3,      15.3,      15.3,      15.3,      15.3,      15.3,      15.3,
        17.7,      17.7,      17.7,      17.7,      17.7,      17.7,      17.7,      17.7,
        17.7,      17.7,      17.7,      17.7,      17.7,      17.7,      17.7,      17.7,
        20.1,      20.1,      20.1,      20.1,      20.1,      20.1,      20.1,      20.1,
        20.1,      20.1,      20.1,      20.1,      20.1,      20.1,      20.1,      20.1,
        22.5,      22.5,      22.5,      22.5,      22.5,      22.5,      22.5,      22.5,
        22.5,      22.5,      22.5,      22.5,      22.5,      22.5,      22.5,      22.5,
        24.900002, 24.900002, 24.900002, 24.900002, 24.900002, 24.900002, 24.900002, 24.900002,
        24.900002, 24.900002, 24.900002, 24.900002, 24.900002, 24.900002, 24.900002, 24.900002,
        27.300001, 27.300001, 27.300001, 27.300001, 27.300001, 27.300001, 27.300001, 27.300001,
        27.300001, 27.300001, 27.300001, 27.300001, 27.300001, 27.300001, 27.300001, 27.300001,
        29.7,      29.7,      29.7,      29.7,      29.7,      29.7,      29.7,      29.7,
        29.7,      29.7,      29.7,      29.7,      29.7,      29.7,      29.7,      29.7,
        32.100002, 32.100002, 32.100002, 32.100002, 32.100002, 32.100002, 32.100002, 32.100002,
        32.100002, 32.100002, 32.100002, 32.100002, 32.100002, 32.100002, 32.100002, 32.100002,
        34.5,      34.5,      34.5,      34.5,      34.5,      34.5,      34.5,      34.5,
        34.5,      34.5,      34.5,      34.5,      34.5,      34.5,      34.5,      34.5,
        23.8,      23.8,      23.8,      23.8,      23.8,      23.8,      23.8,      23.8,
        23.8,      23.8,      23.8,      23.8,      23.8,      23.8,      23.8,      23.8,
        27.,       27.,       27.,       27.,       27.,       27.,       27.,       27.,
        27.,       27.,       27.,       27.,       27.,       27.,       27.,       27.,
        41.7,      41.7,      41.7,      41.7,      41.7,      41.7,      41.7,      41.7,
        41.7,      41.7,      41.7,      41.7,      41.7,      41.7,      41.7,      41.7,
        44.100002, 44.100002, 44.100002, 44.100002, 44.100002, 44.100002, 44.100002, 44.100002,
        44.100002, 44.100002, 44.100002, 44.100002, 44.100002, 44.100002, 44.100002, 44.100002,
        46.5,      46.5,      46.5,      46.5,      46.5,      46.5,      46.5,      46.5,
        46.5,      46.5,      46.5,      46.5,      46.5,      46.5,      46.5,      46.5,
        48.899998, 48.899998, 48.899998, 48.899998, 48.899998, 48.899998, 48.899998, 48.899998,
        48.899998, 48.899998, 48.899998, 48.899998, 48.899998, 48.899998, 48.899998, 48.899998,
        51.3,      51.3,      51.3,      51.3,      51.3,      51.3,      51.3,      51.3,
        51.3,      51.3,      51.3,      51.3,      51.3,      51.3,      51.3,      51.3,
        53.7,      53.7,      53.7,      53.7,      53.7,      53.7,      53.7,      53.7,
        53.7,      53.7,      53.7,      53.7,      53.7,      53.7,      53.7,      53.7,
        56.100002, 56.100002, 56.100002, 56.100002, 56.100002, 56.100002, 56.100002, 56.100002,
        56.100002, 56.100002, 56.100002, 56.100002, 56.100002, 56.100002, 56.100002, 56.100002,
        58.5,      58.5,      58.5,      58.5,      58.5,      58.5,      58.5,      58.5,
        58.5,      58.5,      58.5,      58.5,      58.5,      58.5,      58.5,      58.5,
        60.899998, 60.899998, 60.899998, 60.899998, 60.899998, 60.899998, 60.899998, 60.899998,
        60.899998, 60.899998, 60.899998, 60.899998, 60.899998, 60.899998, 60.899998, 60.899998,
        63.3,      63.3,      63.3,      63.3,      63.3,      63.3,      63.3,      63.3,
        63.3,      63.3,      63.3,      63.3,      63.3,      63.3,      63.3,      63.3,
        65.7,      65.7,      65.7,      65.7,      65.7,      65.7,      65.7,      65.7,
        65.7,      65.7,      65.7,      65.7,      65.7,      65.7,      65.7,      65.7,
        68.1,      68.1,      68.1,      68.1,      68.1,      68.1,      68.1,      68.1,
        68.1,      68.1,      68.1,      68.1,      68.1,      68.1,      68.1,      68.1,
        70.5,      70.5,      70.5,      70.5,      70.5,      70.5,      70.5,      70.5,
        70.5,      70.5,      70.5,      70.5,      70.5,      70.5,      70.5,      70.5,
        72.9,      72.9,      72.9,      72.9,      72.9,      72.9,      72.9,      72.9,
        72.9,      72.9,      72.9,      72.9,      72.9,      72.9,      72.9,      72.9,
        49.4,      49.4,      49.4,      49.4,      49.4,      49.4,      49.4,      49.4,
        49.4,      49.4,      49.4,      49.4,      49.4,      49.4,      49.4,      49.4};
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
307
308
ck::utils::CorrectnessValidator validator;
    EXPECT_TRUE(validator.check_err(
Chao Liu's avatar
Chao Liu committed
309
        out_tensor2.mDesc.GetLengths(), ref_dims, "Error: wrong output tensor dimensions!"));
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
310
    EXPECT_TRUE(validator.check_err(out_tensor2, ref_data, "Error: incorrect results!"));
Chao Liu's avatar
Chao Liu committed
311
}
312
#endif
Chao Liu's avatar
Chao Liu committed
313

314
TEST(ReferenceConvolutionFWD, Conv3DGNCDHW)
Chao Liu's avatar
Chao Liu committed
315
{
316
317
318
319
320
321
322
323
324
325
326
    ck::utils::conv::ConvParam conv_param(3,
                                          1,
                                          1,
                                          1,
                                          2,
                                          std::vector<ck::index_t>{3, 3, 3},
                                          std::vector<ck::index_t>{6, 6, 6},
                                          std::vector<ck::index_t>{1, 1, 1},
                                          std::vector<ck::index_t>{1, 1, 1},
                                          std::vector<ck::index_t>{0, 0, 0},
                                          std::vector<ck::index_t>{0, 0, 0});
Chao Liu's avatar
Chao Liu committed
327
328
329
330
331

    auto out_tensor = run_reference_convolution_forward<3,
                                                        float,
                                                        float,
                                                        float,
332
333
334
335
336
                                                        ck::tensor_layout::convolution::GNCDHW,
                                                        ck::tensor_layout::convolution::GKCZYX,
                                                        ck::tensor_layout::convolution::GNKDHW>(
        conv_param, ck::utils::FillMonotonicSeq<float>{0.f, 0.1f});
    std::vector<std::size_t> ref_dims{1, 1, 1, 4, 4, 4};
Chao Liu's avatar
Chao Liu committed
337
338
339
340
341
342
343
344
345
    std::vector<float> ref_data{
        407.7,     410.40002, 413.09998, 415.80002, 423.90002, 426.6,     429.30002, 432.,
        440.1,     442.80002, 445.5,     448.2,     456.30002, 459.,      461.7,     464.40002,
        504.90002, 507.6,     510.30002, 513.,      521.1,     523.8,     526.5,     529.2001,
        537.3,     540.,      542.7001,  545.4,     553.5,     556.2001,  558.9,     561.6,
        602.10004, 604.8,     607.5,     610.2,     618.3,     621.,      623.7,     626.4,
        634.5,     637.2,     639.9,     642.60004, 650.7,     653.4,     656.10004, 658.8,
        699.3,     702.,      704.7,     707.4,     715.5,     718.2,     720.9,     723.60004,
        731.7,     734.4001,  737.10004, 739.8,     747.9001,  750.60004, 753.3,     756.};
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
346
347
ck::utils::CorrectnessValidator validator;
    EXPECT_TRUE(validator.check_err(out_tensor.mDesc.GetLengths(),
Chao Liu's avatar
Chao Liu committed
348
349
                                     ref_dims,
                                     "Error [case 1]: wrong output tensor dimensions!"));
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
350
    EXPECT_TRUE(validator.check_err(out_tensor, ref_data, "Error [case 1]: incorrect results!"));
Chao Liu's avatar
Chao Liu committed
351
352
}

353
TEST(ReferenceConvolutionFWD, Conv3DGNCDHWStridesDilations)
Chao Liu's avatar
Chao Liu committed
354
{
355
356
357
358
359
360
361
362
363
364
365
    ck::utils::conv::ConvParam conv_param(3,
                                          1,
                                          1,
                                          2,
                                          2,
                                          std::vector<ck::index_t>{3, 3, 3},
                                          std::vector<ck::index_t>{12, 12, 12},
                                          std::vector<ck::index_t>{3, 3, 3},
                                          std::vector<ck::index_t>{1, 1, 1},
                                          std::vector<ck::index_t>{0, 0, 0},
                                          std::vector<ck::index_t>{0, 0, 0});
Chao Liu's avatar
Chao Liu committed
366
367
368
369
370

    auto out_tensor = run_reference_convolution_forward<3,
                                                        float,
                                                        float,
                                                        float,
371
372
373
374
375
                                                        ck::tensor_layout::convolution::GNCDHW,
                                                        ck::tensor_layout::convolution::GKCZYX,
                                                        ck::tensor_layout::convolution::GNKDHW>(
        conv_param, ck::utils::FillMonotonicSeq<float>{0.f, 0.1f});
    std::vector<std::size_t> ref_dims{1, 1, 2, 4, 4, 4};
Chao Liu's avatar
Chao Liu committed
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
    std::vector<float> ref_data{
        2756.7002, 2764.7998, 2772.9001, 2781.,     2853.9001, 2862.,     2870.1,    2878.2002,
        2951.1,    2959.2002, 2967.2998, 2975.4001, 3048.2998, 3056.4001, 3064.5,    3072.6,
        3923.1,    3931.2,    3939.2998, 3947.4,    4020.2998, 4028.4001, 4036.5002, 4044.5999,
        4117.5,    4125.6,    4133.7,    4141.8,    4214.7,    4222.8,    4230.9004, 4239.,
        5089.5,    5097.5996, 5105.7,    5113.8,    5186.7,    5194.8,    5202.9,    5211.,
        5283.9004, 5292.,     5300.0996, 5308.2,    5381.0996, 5389.2,    5397.3,    5405.4004,
        6255.9004, 6264.0005, 6272.1,    6280.2,    6353.1,    6361.2,    6369.301,  6377.4,
        6450.301,  6458.4,    6466.5,    6474.6,    6547.5,    6555.6,    6563.699,  6571.801,
        2756.7002, 2764.7998, 2772.9001, 2781.,     2853.9001, 2862.,     2870.1,    2878.2002,
        2951.1,    2959.2002, 2967.2998, 2975.4001, 3048.2998, 3056.4001, 3064.5,    3072.6,
        3923.1,    3931.2,    3939.2998, 3947.4,    4020.2998, 4028.4001, 4036.5002, 4044.5999,
        4117.5,    4125.6,    4133.7,    4141.8,    4214.7,    4222.8,    4230.9004, 4239.,
        5089.5,    5097.5996, 5105.7,    5113.8,    5186.7,    5194.8,    5202.9,    5211.,
        5283.9004, 5292.,     5300.0996, 5308.2,    5381.0996, 5389.2,    5397.3,    5405.4004,
        6255.9004, 6264.0005, 6272.1,    6280.2,    6353.1,    6361.2,    6369.301,  6377.4,
        6450.301,  6458.4,    6466.5,    6474.6,    6547.5,    6555.6,    6563.699,  6571.801};
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
393
394
ck::utils::CorrectnessValidator validator;
    EXPECT_TRUE(validator.check_err(out_tensor.mDesc.GetLengths(),
Chao Liu's avatar
Chao Liu committed
395
396
                                     ref_dims,
                                     "Error [case 2]: wrong output tensor dimensions!"));
Bartlomiej Kocot's avatar
tmp  
Bartlomiej Kocot committed
397
    EXPECT_TRUE(validator.check_err(
398
        out_tensor, ref_data, "Error [case 2]: incorrect results!", 1e-4f, 1e-6f));
Chao Liu's avatar
Chao Liu committed
399
}