Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / tests / gtests / test_convolution_eltwise_forward_x8s8f32s32.cpp
1 /*******************************************************************************
2 * Copyright 2018 Intel Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17 #include "mkldnn_test_common.hpp"
18 #include "gtest/gtest.h"
19 #include "math_utils.hpp"
20 #include "mkldnn.hpp"
21 #include "test_convolution_eltwise_forward_common.hpp"
22
23 namespace mkldnn {
24
25 using convolution_test_u8s8s32f32 =
26         convolution_eltwise_test<uint8_t, int8_t, int32_t, float>;
27 using convolution_test_s8s8s32f32 =
28         convolution_eltwise_test<int8_t, int8_t, int32_t, float>;
29
30 #define EXPAND_FORMATS(src, weights, bias, dst) \
31     { mkldnn::memory::format::src, mkldnn::memory::format::weights, \
32     mkldnn::memory::format::bias, mkldnn::memory::format::dst }
33
34 #define CONCAT_WITH_UNDERSCORE_(a,b) a ## _ ## b
35 #define CONCAT_WITH_UNDERSCORE(a,b) CONCAT_WITH_UNDERSCORE_(a,b)
36
37 #define INST_TEST_CASE_(str, test, ...) INSTANTIATE_TEST_CASE_P( \
38         str, test, ::testing::Values(__VA_ARGS__))
39
40 #define INST_TEST_CASE(str, test, ...) INST_TEST_CASE_( \
41         CONCAT_WITH_UNDERSCORE(CONCAT_WITH_UNDERSCORE(Convolution, \
42         str), eltwise), test,  __VA_ARGS__)
43
44 #define EXPAND_ARGS(args) args
45
46 #define PARAMS(...) \
47     EXPAND_ARGS(PARAMS_CONV(eltwise_relu, __VA_ARGS__)), \
48     EXPAND_ARGS(PARAMS_CONV(eltwise_elu, __VA_ARGS__)), \
49     EXPAND_ARGS(PARAMS_CONV(eltwise_tanh, __VA_ARGS__)), \
50     EXPAND_ARGS(PARAMS_CONV(eltwise_square, __VA_ARGS__)), \
51     EXPAND_ARGS(PARAMS_CONV(eltwise_abs, __VA_ARGS__)), \
52     EXPAND_ARGS(PARAMS_CONV(eltwise_sqrt, __VA_ARGS__)), \
53     EXPAND_ARGS(PARAMS_CONV(eltwise_linear, __VA_ARGS__)), \
54     EXPAND_ARGS(PARAMS_CONV(eltwise_bounded_relu, __VA_ARGS__)), \
55     EXPAND_ARGS(PARAMS_CONV(eltwise_soft_relu, __VA_ARGS__)), \
56     EXPAND_ARGS(PARAMS_CONV(eltwise_logistic, __VA_ARGS__)), \
57     EXPAND_ARGS(PARAMS_CONV(eltwise_clamp, __VA_ARGS__)), \
58     EXPAND_ARGS(PARAMS_CONV(eltwise_exp, __VA_ARGS__))
59
60 #define ELTWISE_ALPHA 0.5f
61 #define ELTWISE_BETA 0.f
62
63 #define PARAMS_CONV(alg, src, weights, bias, dst, ...) \
64     test_convolution_eltwise_params_t {alg,  mkldnn::engine::kind::cpu, \
65         mkldnn::convolution_direct, ELTWISE_ALPHA, ELTWISE_BETA, \
66     EXPAND_FORMATS(src, weights, bias, dst), /* empty attributes */ {}, \
67     {__VA_ARGS__} }
68
69 #define INST_TEST_CASE_P_UNSIGNED(test) \
70 TEST_P(test, TestConvolutionEltwise) {} \
71 INST_TEST_CASE(SimpleSmall_Blocked16, test, \
72 PARAMS(nhwc, OIhw4i16o4i, x, nhwc, 2, 1, 32, 13, 13, 32, 13, 13, 1, 1, 0, 0, 1, 1), \
73 PARAMS(nhwc, Goihw16g, x, nhwc, 2, 32, 32, 13, 13, 32, 13, 13, 3, 3, 1, 1, 1, 1), \
74 PARAMS(nhwc, OIhw4i16o4i, x, nhwc, 2, 1, 32, 13, 13, 32, 13, 13, 3, 3, 1, 1, 1, 1) \
75 );\
76 \
77 INST_TEST_CASE(SimpleSmall_Blocked8, test, \
78 PARAMS(nhwc, OhIw8o4i, x, nhwc, 2, 1, 32, 13, 13, 32, 13, 13, 1, 1, 0, 0, 1, 1), \
79 PARAMS(nhwc, Goihw8g, x, nhwc, 2, 32, 32, 13, 13, 32, 13, 13, 3, 3, 1, 1, 1, 1), \
80 PARAMS(nhwc, OhIw8o4i, x, nhwc, 2, 1, 32, 13, 13, 32, 13, 13, 3, 3, 1, 1, 1, 1) \
81 );\
82 \
83 INST_TEST_CASE(SimpleSmall_Blocked8_Tail, test, \
84 PARAMS(nhwc, OhIw8o4i, x, nhwc, 2, 1, 47, 20, 20, 47, 20, 20, 1, 1, 0, 0, 1, 1), \
85 PARAMS(nhwc, Goihw8g, x, nhwc, 2, 47, 47, 20, 20, 47, 20, 20, 3, 3, 1, 1, 1, 1), \
86 PARAMS(nhwc, OhIw8o4i, x, nhwc, 2, 1, 47, 20, 20, 47, 20, 20, 3, 3, 1, 1, 1, 1) \
87 );
88
89 #define INST_TEST_CASE_P_SIGNED(test) \
90 TEST_P(test, TestConvolutionEltwise) {} \
91 INST_TEST_CASE(SimpleSmall_Blocked16, test, \
92 PARAMS(nhwc, OIhw4i16o4i_s8s8, x, nhwc, 2, 1, 32, 13, 13, 32, 12, 12, 3, 3, 0, 0, 1, 1), \
93 PARAMS(nhwc, Goihw16g_s8s8, x, nhwc, 2, 32, 32, 13, 13, 32, 13, 13, 1, 1, 0, 0, 1, 1), \
94 PARAMS(nhwc, OIhw4i16o4i_s8s8, x, nhwc, 2, 1, 32, 13, 13, 32, 13, 13, 3, 3, 1, 1, 1, 1) \
95 );\
96 \
97 INST_TEST_CASE(SimpleSmall_Blocked8, test, \
98 PARAMS(nhwc, OhIw8o4i_s8s8, x, nhwc, 2, 1, 32, 13, 13, 32, 13, 13, 1, 1, 0, 0, 1, 1), \
99 PARAMS(nhwc, OhIw8o4i_s8s8, x, nhwc, 2, 1, 32, 13, 13, 32, 13, 13, 3, 3, 1, 1, 1, 1) \
100 );\
101 \
102 INST_TEST_CASE(SimpleSmall_Blocked8_Tail, test, \
103 PARAMS(nhwc, OhIw8o4i_s8s8, x, nhwc, 2, 1, 47, 20, 20, 47, 20, 20, 1, 1, 0, 0, 1, 1), \
104 PARAMS(nhwc, OhIw8o4i_s8s8, x, nhwc, 2, 1, 47, 20, 20, 47, 20, 20, 3, 3, 1, 1, 1, 1) \
105 );
106
107 //INST_TEST_CASE_P_SIGNED(convolution_test_s8s8s32f32);
108 INST_TEST_CASE_P_UNSIGNED(convolution_test_u8s8s32f32);
109 }