1#if 0
2/*******************************************************************************
3* Copyright 2017-2020 Intel Corporation
4*
5* Licensed under the Apache License, Version 2.0 (the "License");
6* you may not use this file except in compliance with the License.
7* You may obtain a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14* See the License for the specific language governing permissions and
15* limitations under the License.
16*******************************************************************************/
17#endif
18
19#include "oneapi/dnnl/dnnl.hpp"
20
21#define EXPAND_FORMATS(src, weights, bias, dst) \
22 { \
23 dnnl::memory::format_tag::src, dnnl::memory::format_tag::weights, \
24 dnnl::memory::format_tag::bias, dnnl::memory::format_tag::dst \
25 }
26
27#define ALGORITHM dnnl::algorithm::convolution_direct
28
29#ifdef DIRECTION_FORWARD
30#define FMT_WEIGHTS_BLOCKED OIhw8i8o
31#define FMT_WEIGHTS_BLOCKED_G gOIhw8i8o
32#define FMT_WEIGHTS_GPU_BLOCKED16x16 IOhw16i16o
33#define FMT_WEIGHTS_GPU_BLOCKED16 OIhw16i16o
34#if defined(FP32)
35#define FMT_WEIGHTS_BLOCKED16 OIhw16i16o
36#define FMT_WEIGHTS_BLOCKED16_G gOIhw16i16o
37#elif defined(S16S16S32)
38#define FMT_WEIGHTS_BLOCKED16 OIhw8i16o2i
39#define FMT_WEIGHTS_BLOCKED16_G gOIhw8i16o2i
40#elif defined(U8S8)
41#define FMT_WEIGHTS_BLOCKED16 OIhw4i16o4i
42#define FMT_WEIGHTS_BLOCKED16_G gOIhw4i16o4i
43#endif
44#define FMT_WEIGHTS_BLOCKED16_IOhw16o16i FMT_WEIGHTS_BLOCKED16
45#define TEST_CASE_NAME_PREFIX Forward
46#elif defined DIRECTION_BACKWARD_DATA
47#define FMT_WEIGHTS_BLOCKED OIhw8o8i
48#define FMT_WEIGHTS_BLOCKED_G gOIhw8o8i
49#define FMT_WEIGHTS_GPU_BLOCKED16x16 OIhw16o16i
50#define FMT_WEIGHTS_GPU_BLOCKED16 OIhw16o16i
51#if defined(FP32)
52#define FMT_WEIGHTS_BLOCKED16 OIhw16o16i
53#define FMT_WEIGHTS_BLOCKED16_G gOIhw16o16i
54#define FMT_WEIGHTS_BLOCKED16_IOhw16o16i IOhw16o16i
55#define FMT_WEIGHTS_BLOCKED16_G_IOhw16o16i gIOhw16o16i
56#elif defined(S16S16S32)
57#define FMT_WEIGHTS_BLOCKED16 OIhw8o16i2o
58#define FMT_WEIGHTS_BLOCKED16_G gOIhw8o16i2o
59#define FMT_WEIGHTS_BLOCKED16_IOhw16o16i FMT_WEIGHTS_BLOCKED16
60#define FMT_WEIGHTS_BLOCKED16_G_IOhw16o16i FMT_WEIGHTS_BLOCKED16_G
61#endif
62#define TEST_CASE_NAME_PREFIX BackwardData
63#elif defined DIRECTION_BACKWARD_WEIGHTS
64#define FMT_WEIGHTS_BLOCKED OIhw8i8o
65#define FMT_WEIGHTS_BLOCKED_G gOIhw8i8o
66#define FMT_WEIGHTS_BLOCKED16 OIhw16i16o
67#define FMT_WEIGHTS_BLOCKED16_G gOIhw16i16o
68#define FMT_WEIGHTS_BLOCKED16_IOhw16o16i FMT_WEIGHTS_BLOCKED16
69#define FMT_WEIGHTS_BLOCKED16_G_IOhw16o16i FMT_WEIGHTS_BLOCKED16_G
70#define FMT_WEIGHTS_GPU_BLOCKED16x16 IOhw16i16o
71#define FMT_WEIGHTS_GPU_BLOCKED16 IOhw16i16o
72#define TEST_CASE_NAME_PREFIX BackwardWeights
73#endif
74
75#define FMT_BIAS x
76#define FMT_NO_BIAS undef
77#define FMT_DATA_BLOCKED nChw8c
78#define FMT_DATA_BLOCKED16 nChw16c
79
80#define CONCAT_WITH_UNDERSCORE_(a, b) a##_##b
81#define CONCAT_WITH_UNDERSCORE(a, b) CONCAT_WITH_UNDERSCORE_(a, b)
82
83#define CPU_INST_TEST_CASE_(str, ...) \
84 CPU_INSTANTIATE_TEST_SUITE_P( \
85 str, convolution_test, ::testing::Values(__VA_ARGS__))
86#define CPU_INST_TEST_CASE(str, ...) \
87 CPU_INST_TEST_CASE_( \
88 CONCAT_WITH_UNDERSCORE(TEST_CASE_NAME_PREFIX, str), __VA_ARGS__)
89
90#define GPU_INST_TEST_CASE_(str, ...) \
91 GPU_INSTANTIATE_TEST_SUITE_P( \
92 str, convolution_test, ::testing::Values(__VA_ARGS__))
93#define GPU_INST_TEST_CASE(str, ...) \
94 GPU_INST_TEST_CASE_( \
95 CONCAT_WITH_UNDERSCORE(TEST_CASE_NAME_PREFIX, str), __VA_ARGS__)
96
97#define INST_TEST_CASE(str, ...) \
98 CPU_INST_TEST_CASE(str, __VA_ARGS__); \
99 GPU_INST_TEST_CASE(str, __VA_ARGS__)
100
101#define PARAMS(src, weights, bias, dst, ...) \
102 test_convolution_params_t { \
103 ALGORITHM, EXPAND_FORMATS(src, weights, bias, dst), \
104 /* empty attributes */ {}, { \
105 __VA_ARGS__ \
106 } \
107 }
108
109#define PARAMS_EXPECT_FAIL(src, weights, bias, dst, code, ...) \
110 test_convolution_params_t { \
111 ALGORITHM, EXPAND_FORMATS(src, weights, bias, dst), \
112 /* empty attributes */ {}, {__VA_ARGS__}, true, code \
113 }
114
115#define PARAMS_ATTR(src, weights, bias, dst, scale, policy, ...) \
116 test_convolution_params_t { \
117 ALGORITHM, EXPAND_FORMATS(src, weights, bias, dst), \
118 {scale, test_convolution_attr_t::scale_t::policy}, { \
119 __VA_ARGS__ \
120 } \
121 }
122
123#ifdef TEST_PARAM_ATTR
124#include "convolution_attr.h"
125#else
126#include "convolution_simple.h"
127#endif
128