2 #===============================================================================
3 # Copyright 2018 Intel Corporation
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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 #===============================================================================
20 import xml.etree.ElementTree as ET
23 year_now = datetime.datetime.now().year
24 banner_year = '2018' if year_now == 2018 else '2018 - %d' % year_now
26 /*******************************************************************************
27 * Copyright %s Intel Corporation
29 * Licensed under the Apache License, Version 2.0 (the "License");
30 * you may not use this file except in compliance with the License.
31 * You may obtain a copy of the License at
33 * http://www.apache.org/licenses/LICENSE-2.0
35 * Unless required by applicable law or agreed to in writing, software
36 * distributed under the License is distributed on an "AS IS" BASIS,
37 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 *******************************************************************************/
42 /* DO NOT EDIT, AUTO-GENERATED */
48 return '%s%s' % (banner(), body)
53 #ifndef MKLDNN_DEBUG_H
54 #define MKLDNN_DEBUG_H
56 #ifndef DOXYGEN_SHOULD_SKIP_THIS
58 /* All symbols shall be internal unless marked as MKLDNN_API */
59 #if defined _WIN32 || defined __CYGWIN__
60 # define MKLDNN_HELPER_DLL_IMPORT __declspec(dllimport)
61 # define MKLDNN_HELPER_DLL_EXPORT __declspec(dllexport)
64 # define MKLDNN_HELPER_DLL_IMPORT __attribute__ ((visibility ("default")))
65 # define MKLDNN_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
67 # define MKLDNN_HELPER_DLL_IMPORT
68 # define MKLDNN_HELPER_DLL_EXPORT
73 # ifdef MKLDNN_DLL_EXPORTS
74 # define MKLDNN_API MKLDNN_HELPER_DLL_EXPORT
76 # define MKLDNN_API MKLDNN_HELPER_DLL_IMPORT
82 #if defined (__GNUC__)
83 # define MKLDNN_DEPRECATED __attribute__((deprecated))
84 #elif defined(_MSC_VER)
85 # define MKLDNN_DEPRECATED __declspec(deprecated)
87 # define MKLDNN_DEPRECATED
90 #include "mkldnn_types.h"
91 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
110 #include "mkldnn_debug.h"
111 #include "mkldnn_types.h"
117 def maybe_skip(enum):
119 'mkldnn_padding_kind_t',
120 'mkldnn_batch_normalization_flag_t',
121 'mkldnn_wino_memory_format_t',
122 'mkldnn_rnn_cell_flags_t',
123 'mkldnn_engine_kind_t',
125 'mkldnn_stream_kind_t',
129 def enum_abbrev(enum):
131 'mkldnn_status_t': 'status',
132 'mkldnn_data_type_t': 'dt',
133 'mkldnn_round_mode_t': 'rmode',
134 'mkldnn_memory_format_t': 'fmt',
135 'mkldnn_prop_kind_t': 'prop_kind',
136 'mkldnn_primitive_kind_t': 'prim_kind',
137 'mkldnn_alg_kind_t': 'alg_kind',
138 'mkldnn_rnn_direction_t': 'rnn_direction',
142 def sanitize_value(v):
145 v = v.split('mkldnn_')[-1]
149 def func_decl(enum, is_header = False):
150 abbrev = enum_abbrev(enum)
151 return 'const char %s*mkldnn_%s2str(%s v)' % \
152 ('MKLDNN_API ' if is_header else '', abbrev, enum)
155 def func_to_str(enum, values):
157 abbrev = enum_abbrev(enum)
159 func += func_decl(enum) + ' {\n'
161 func += '%sif (v == %s) return "%s";\n' \
162 % (indent, v, sanitize_value(v))
163 func += '%sassert(!"unknown %s");\n' % (indent, abbrev)
164 func += '%sreturn "unknown %s";\n}\n' % (indent, abbrev)
171 root = ET.parse(ifile).getroot()
172 for v_enum in root.findall('Enumeration'):
173 enum = v_enum.attrib['name']
176 values = [v_value.attrib['name'] \
177 for v_value in v_enum.findall('EnumValue')]
178 h_body += func_decl(enum, is_header = True) + ';\n'
179 s_body += func_to_str(enum, values) + '\n'
180 return (template(header(h_body)), template(source(s_body)))
185 %s types.xml [output_dir]
187 Generates MKL-DNN debug header and source files with enum to string mapping.
188 Input types.xml file can be obtained with CastXML[1]:
189 $ castxml --castxml-cc-gnu-c clang --castxml-output=1 \\
190 include/mkldnn_types.h -o types.xml
192 [1] https://github.com/CastXML/CastXML''' % sys.argv[0]
200 ifile = sys.argv[1] if len(sys.argv) > 1 else usage()
201 odir = sys.argv[2] if len(sys.argv) > 2 else '.'
202 ofile_h = odir + '/mkldnn_debug.h'
203 ofile_s = odir + '/mkldnn_debug.cpp'
205 (h, s) = generate(ifile)
207 with open(ofile_h, 'w') as fh:
210 with open(ofile_s, 'w') as fs: