conv3d_fwd.cpp 11.2 KB
Newer Older
1
2
3
4
5
6
7
8
#include <half.hpp>
#include <iostream>
#include <stdexcept>
#include <tuple>
#include <vector>

#include "data_type.hpp"
#include "element_wise_operation.hpp"
9
10
#include "conv_fwd_util.hpp"
#include "conv_util.hpp"
11
12
13

namespace {

14
bool test_conv3d_ndhwc()
15
{
16
17
18
19
20
    using namespace std::placeholders;
    using namespace ck::utils;
    namespace ctl = ck::tensor_layout::convolution;

    conv::ConvParams params;
21
22
23
24
25
26
27
28
29
30
31
    params.num_dim_spatial        = 3;
    params.N                      = 2;
    params.K                      = 16;
    params.C                      = 4;
    params.filter_spatial_lengths = std::vector<ck::index_t>{3, 3, 3};
    params.input_spatial_lengths  = std::vector<ck::index_t>{16, 16, 16};
    params.conv_filter_strides    = std::vector<ck::index_t>{1, 1, 1};
    params.conv_filter_dilations  = std::vector<ck::index_t>{1, 1, 1};
    params.input_left_pads        = std::vector<ck::index_t>{1, 1, 1};
    params.input_right_pads       = std::vector<ck::index_t>{1, 1, 1};

32
33
34
35
36
37
38
39
40
41
42
    std::vector<test::conv::DeviceConvFwdNoOpPtr> conv_ptrs;
    test::conv::get_test_convolution_fwd_instance<3>(conv_ptrs);
    conv::ConvFwdOpInstance<float, float, float, ctl::NDHWC, ctl::KZYXC, ctl::NDHWK> conv_instance(
        params);

    auto reference_conv_fwd_fun = std::bind(
        conv::run_reference_convolution_forward<3, float, float, float>, params, _1, _2, _3);
    OpInstanceRunEngine<float, float, float> run_engine(conv_instance, reference_conv_fwd_fun);
    run_engine.SetAtol(1e-5);
    run_engine.SetRtol(1e-4);
    return run_engine.Test(conv_ptrs);
43
44
}

45
bool test_conv3d_ndhwc_2gb_input()
46
{
47
48
49
    using PassThrough = ck::tensor_operation::element_wise::PassThrough;
    using namespace ck::utils;

50
    // >2GB Input
51
    conv::ConvParams params;
52
53
54
55
56
57
58
59
60
61
62
    params.num_dim_spatial        = 3;
    params.N                      = 2;
    params.K                      = 16;
    params.C                      = 32;
    params.filter_spatial_lengths = std::vector<ck::index_t>{3, 3, 3};
    params.input_spatial_lengths  = std::vector<ck::index_t>{32, 1000, 1000};
    params.conv_filter_strides    = std::vector<ck::index_t>{1, 1, 1};
    params.conv_filter_dilations  = std::vector<ck::index_t>{1, 1, 1};
    params.input_left_pads        = std::vector<ck::index_t>{1, 1, 1};
    params.input_right_pads       = std::vector<ck::index_t>{1, 1, 1};

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    std::vector<test::conv::DeviceConvFwdNoOpPtr> conv_ptrs;
    test::conv::get_test_convolution_fwd_instance<3>(conv_ptrs);

    auto arg = conv_ptrs.back()->MakeArgumentPointer(nullptr,
                                                     nullptr,
                                                     nullptr,
                                                     params.N,
                                                     params.K,
                                                     params.C,
                                                     params.input_spatial_lengths,
                                                     params.filter_spatial_lengths,
                                                     params.GetOutputSpatialLengths(),
                                                     params.conv_filter_strides,
                                                     params.conv_filter_dilations,
                                                     params.input_left_pads,
                                                     params.input_right_pads,
                                                     PassThrough{},
                                                     PassThrough{},
                                                     PassThrough{});
    return !(conv_ptrs.back()->IsSupportedArgument(arg.get()));
83
84
}

85
bool test_conv3d_ndhwc_2gb_filters()
86
{
87
88
89
    using PassThrough = ck::tensor_operation::element_wise::PassThrough;
    using namespace ck::utils;

90
    // >2GB Filters
91
    conv::ConvParams params;
92
93
94
95
96
97
98
99
100
101
102
    params.num_dim_spatial        = 3;
    params.N                      = 2;
    params.K                      = 16;
    params.C                      = 32;
    params.filter_spatial_lengths = std::vector<ck::index_t>{4, 1000, 1000};
    params.input_spatial_lengths  = std::vector<ck::index_t>{16, 16, 16};
    params.conv_filter_strides    = std::vector<ck::index_t>{1, 1, 1};
    params.conv_filter_dilations  = std::vector<ck::index_t>{1, 1, 1};
    params.input_left_pads        = std::vector<ck::index_t>{1, 1, 1};
    params.input_right_pads       = std::vector<ck::index_t>{1, 1, 1};

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    std::vector<test::conv::DeviceConvFwdNoOpPtr> conv_ptrs;
    test::conv::get_test_convolution_fwd_instance<3>(conv_ptrs);

    auto arg = conv_ptrs.back()->MakeArgumentPointer(nullptr,
                                                     nullptr,
                                                     nullptr,
                                                     params.N,
                                                     params.K,
                                                     params.C,
                                                     params.input_spatial_lengths,
                                                     params.filter_spatial_lengths,
                                                     params.GetOutputSpatialLengths(),
                                                     params.conv_filter_strides,
                                                     params.conv_filter_dilations,
                                                     params.input_left_pads,
                                                     params.input_right_pads,
                                                     PassThrough{},
                                                     PassThrough{},
                                                     PassThrough{});
    return !(conv_ptrs.back()->IsSupportedArgument(arg.get()));
123
124
}

125
bool test_conv3d_ndhwc_2gb_output()
126
{
127
128
129
    using PassThrough = ck::tensor_operation::element_wise::PassThrough;
    using namespace ck::utils;

130
    // >2GB Output
131
    conv::ConvParams params;
132
133
134
135
136
137
138
139
140
141
142
    params.num_dim_spatial        = 3;
    params.N                      = 2;
    params.K                      = 16;
    params.C                      = 2;
    params.filter_spatial_lengths = std::vector<ck::index_t>{1, 1, 1};
    params.input_spatial_lengths  = std::vector<ck::index_t>{1000, 1000, 30};
    params.conv_filter_strides    = std::vector<ck::index_t>{1, 1, 1};
    params.conv_filter_dilations  = std::vector<ck::index_t>{1, 1, 1};
    params.input_left_pads        = std::vector<ck::index_t>{2, 2, 2};
    params.input_right_pads       = std::vector<ck::index_t>{2, 2, 2};

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    std::vector<test::conv::DeviceConvFwdNoOpPtr> conv_ptrs;
    test::conv::get_test_convolution_fwd_instance<3>(conv_ptrs);
    auto arg = conv_ptrs.back()->MakeArgumentPointer(nullptr,
                                                     nullptr,
                                                     nullptr,
                                                     params.N,
                                                     params.K,
                                                     params.C,
                                                     params.input_spatial_lengths,
                                                     params.filter_spatial_lengths,
                                                     params.GetOutputSpatialLengths(),
                                                     params.conv_filter_strides,
                                                     params.conv_filter_dilations,
                                                     params.input_left_pads,
                                                     params.input_right_pads,
                                                     PassThrough{},
                                                     PassThrough{},
                                                     PassThrough{});
    return !(conv_ptrs.back()->IsSupportedArgument(arg.get()));
162
163
164
}

template <typename T>
165
bool test_conv3d_ndhwc_instances(const std::vector<test::conv::DeviceConvFwdNoOpPtr>& conv_ptrs)
166
{
167
168
169
170
171
    using namespace std::placeholders;
    using namespace ck::utils;
    namespace ctl = ck::tensor_layout::convolution;

    conv::ConvParams params;
172
173
174
175
176
177
178
179
180
    params.N                      = 64;
    params.num_dim_spatial        = 3;
    params.filter_spatial_lengths = std::vector<ck::index_t>{3, 3, 2};
    params.input_spatial_lengths  = std::vector<ck::index_t>{32, 32, 2};
    params.conv_filter_strides    = std::vector<ck::index_t>{2, 2, 2};
    params.conv_filter_dilations  = std::vector<ck::index_t>{1, 1, 1};
    params.input_left_pads        = std::vector<ck::index_t>{1, 1, 1};
    params.input_right_pads       = std::vector<ck::index_t>{1, 1, 1};

181
    conv::ConvFwdOpInstance<T, T, T, ctl::NDHWC, ctl::KZYXC, ctl::NDHWK> conv_instance(params);
182

183
184
185
186
    auto reference_conv_fwd_fun =
        std::bind(conv::run_reference_convolution_forward<3, T, T, T>, params, _1, _2, _3);
    OpInstanceRunEngine<T, T, T> run_engine(conv_instance, reference_conv_fwd_fun);
    return run_engine.Test(conv_ptrs);
187
188
}

189
bool test_conv3d_ndhwc_bf16_instances()
190
{
191
192
    return test_conv3d_ndhwc_instances<ck::bhalf_t>(
        ck::utils::conv::ConvolutionFwdInstances<ck::bhalf_t, ck::bhalf_t, ck::bhalf_t>::Get<3>());
193
194
}

195
bool test_conv3d_ndhwc_f16_instances()
196
{
197
198
    return test_conv3d_ndhwc_instances<ck::half_t>(
        ck::utils::conv::ConvolutionFwdInstances<ck::half_t, ck::half_t, ck::half_t>::Get<3>());
199
200
}

201
bool test_conv3d_ndhwc_f32_instances()
202
{
203
204
    return test_conv3d_ndhwc_instances<float>(
        ck::utils::conv::ConvolutionFwdInstances<float, float, float>::Get<3>());
205
206
}

207
bool test_conv3d_ndhwc_int8_instances()
208
{
209
210
    return test_conv3d_ndhwc_instances<int8_t>(
        ck::utils::conv::ConvolutionFwdInstances<int8_t, int8_t, int8_t>::Get<3>());
211
212
213
214
215
216
217
}

} // anonymous namespace

int main()
{
    bool res{true};
218
219
    res = test_conv3d_ndhwc();
    std::cout << "test_conv3d_ndhwc ..... " << (res ? "SUCCESS" : "FAILURE") << std::endl;
220

221
222
223
224
225
226
227
228
229
    res = test_conv3d_ndhwc_2gb_input();
    std::cout << "\ntest_conv3d_ndhwc_2gb_input ..... " << (res ? "SUCCESS" : "FAILURE")
              << std::endl;
    res = test_conv3d_ndhwc_2gb_filters();
    std::cout << "\ntest_conv3d_ndhwc_2gb_filters ..... " << (res ? "SUCCESS" : "FAILURE")
              << std::endl;
    res = test_conv3d_ndhwc_2gb_output();
    std::cout << "\ntest_conv3d_ndhwc_2gb_output ..... " << (res ? "SUCCESS" : "FAILURE")
              << std::endl;
230

231
232
    res = test_conv3d_ndhwc_bf16_instances();
    std::cout << "\ntest_conv3d_ndhwc_bf16_instances ..... " << (res ? "SUCCESS" : "FAILURE")
233
              << std::endl;
234
235
    res = test_conv3d_ndhwc_f16_instances();
    std::cout << "\ntest_conv3d_ndhwc_f16_instances ..... " << (res ? "SUCCESS" : "FAILURE")
236
              << std::endl;
237
238
    res = test_conv3d_ndhwc_f32_instances();
    std::cout << "\ntest_conv3d_ndhwc_f32_instances ..... " << (res ? "SUCCESS" : "FAILURE")
239
              << std::endl;
240
    res = test_conv3d_ndhwc_int8_instances();
241
    std::cout << "\ntest_conv3d_ndhwc_int8_instances ..... " << (res ? "SUCCESS" : "FAILURE")
242
243
              << std::endl;

244
    return res ? 0 : 1;
245
}