1/*******************************************************************************
2* Copyright 2018-2022 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 "dnnl_test_common.hpp"
18#include "math_utils.hpp"
19#include "oneapi/dnnl/dnnl.hpp"
20#include "test_convolution_eltwise_forward_common.hpp"
21#include "gtest/gtest.h"
22
23namespace dnnl {
24
25using convolution_test_u8s8s32f32
26 = convolution_eltwise_test<uint8_t, int8_t, int32_t, float>;
27using convolution_test_s8s8s32f32
28 = convolution_eltwise_test<int8_t, int8_t, int32_t, float>;
29
30#define EXPAND_FORMATS(src, weights, bias, dst) \
31 { \
32 dnnl::memory::format_tag::src, dnnl::memory::format_tag::weights, \
33 dnnl::memory::format_tag::bias, dnnl::memory::format_tag::dst \
34 }
35
36#define CONCAT_WITH_UNDERSCORE_(a, b) a##_##b
37#define CONCAT_WITH_UNDERSCORE(a, b) CONCAT_WITH_UNDERSCORE_(a, b)
38
39#define CPU_INST_TEST_CASE_(str, test, ...) \
40 CPU_INSTANTIATE_TEST_SUITE_P(str, test, ::testing::Values(__VA_ARGS__))
41
42#define CPU_INST_TEST_CASE(str, test, ...) \
43 CPU_INST_TEST_CASE_( \
44 CONCAT_WITH_UNDERSCORE( \
45 CONCAT_WITH_UNDERSCORE(Convolution, str), eltwise), \
46 test, __VA_ARGS__)
47
48#define GPU_INST_TEST_CASE_(str, test, ...) \
49 GPU_INSTANTIATE_TEST_SUITE_P(str, test, ::testing::Values(__VA_ARGS__))
50
51#define GPU_INST_TEST_CASE(str, test, ...) \
52 GPU_INST_TEST_CASE_( \
53 CONCAT_WITH_UNDERSCORE( \
54 CONCAT_WITH_UNDERSCORE(Convolution, str), eltwise), \
55 test, __VA_ARGS__)
56
57#define EXPAND_ARGS(args) args
58
59#define PARAMS(...) \
60 EXPAND_ARGS(PARAMS_CONV(algorithm::eltwise_relu, __VA_ARGS__)), \
61 EXPAND_ARGS(PARAMS_CONV(algorithm::eltwise_elu, __VA_ARGS__)), \
62 EXPAND_ARGS(PARAMS_CONV(algorithm::eltwise_tanh, __VA_ARGS__)), \
63 EXPAND_ARGS(PARAMS_CONV(algorithm::eltwise_square, __VA_ARGS__)), \
64 EXPAND_ARGS(PARAMS_CONV(algorithm::eltwise_abs, __VA_ARGS__)), \
65 EXPAND_ARGS(PARAMS_CONV(algorithm::eltwise_linear, __VA_ARGS__)), \
66 EXPAND_ARGS(PARAMS_CONV(algorithm::eltwise_clip, __VA_ARGS__)), \
67 EXPAND_ARGS( \
68 PARAMS_CONV(algorithm::eltwise_soft_relu, __VA_ARGS__)), \
69 EXPAND_ARGS( \
70 PARAMS_CONV(algorithm::eltwise_logistic, __VA_ARGS__)), \
71 EXPAND_ARGS(PARAMS_CONV(algorithm::eltwise_swish, __VA_ARGS__))
72// Not testing due to not scaled output
73// EXPAND_ARGS(PARAMS_CONV(algorithm::eltwise_exp, __VA_ARGS__))
74
75#define ELTWISE_ALPHA 0.5f
76#define ELTWISE_BETA 2.f
77
78#define PARAMS_CONV(alg, src, weights, bias, dst, ...) \
79 test_convolution_eltwise_params_t { \
80 alg, dnnl::algorithm::convolution_direct, ELTWISE_ALPHA, ELTWISE_BETA, \
81 EXPAND_FORMATS(src, weights, bias, dst), \
82 /* empty attributes */ {}, { \
83 __VA_ARGS__ \
84 } \
85 }
86
87#define CPU_INST_TEST_CASE_P(test) \
88 TEST_P(test, TestConvolutionEltwise) {} \
89 CPU_INST_TEST_CASE(SimpleSmall_Blocked16, test, \
90 PARAMS(nhwc, OIhw4i16o4i, x, nhwc, 2, 1, 32, 13, 13, 32, 12, 12, \
91 3, 3, 0, 0, 1, 1), \
92 PARAMS(nhwc, Goihw16g, x, nhwc, 2, 32, 32, 13, 13, 32, 13, 13, 1, \
93 1, 0, 0, 1, 1), \
94 PARAMS(nhwc, OIhw4i16o4i, x, nhwc, 2, 1, 32, 13, 13, 32, 13, 13, \
95 3, 3, 1, 1, 1, 1));
96
97CPU_INST_TEST_CASE_P(convolution_test_s8s8s32f32);
98CPU_INST_TEST_CASE_P(convolution_test_u8s8s32f32);
99
100#define GPU_INST_TEST_CASE_P(test) \
101 TEST_P(test, GPU_TestConvolutionEltwise) {} \
102 GPU_INST_TEST_CASE(SimpleSmall_Blocked16, test, \
103 PARAMS(nhwc, oihw, x, nhwc, 2, 1, 32, 13, 13, 32, 12, 12, 3, 3, 0, \
104 0, 1, 1), \
105 PARAMS(nhwc, Goihw16g, x, nhwc, 2, 32, 32, 13, 13, 32, 13, 13, 1, \
106 1, 0, 0, 1, 1), \
107 PARAMS(nhwc, iohw, x, nhwc, 2, 1, 32, 13, 13, 32, 13, 13, 3, 3, 1, \
108 1, 1, 1));
109
110GPU_INST_TEST_CASE_P(convolution_test_s8s8s32f32);
111GPU_INST_TEST_CASE_P(convolution_test_u8s8s32f32);
112
113} // namespace dnnl
114