1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# ******************************************************************************
# Copyright 2017-2019 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
if(LINUX)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.0.0")
# gtest has issues with this with v1.8.x
# gtest issue is supposed to be addressed after v1.8.x
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-zero-as-null-pointer-constant")
endif()
endif()
set(SRC
algebraic_simplification.cpp
aligned_buffer.cpp
all_close_f.cpp
assertion.cpp
bfloat16.cpp
build_graph.cpp
builder_autobroadcast.cpp
check.cpp
constant_folding.cpp
concat_fusion.cpp
control_dependencies.cpp
coordinate.cpp
copy.cpp
cpio.cpp
cse.cpp
dyn_elimination.cpp
element_type.cpp
file_util.cpp
float16.cpp
includes.cpp
input_output_assign.cpp
main.cpp
misc.cpp
node_input_output.cpp
nop_elimination.cpp
op.cpp
partial_shape.cpp
pass.cpp
pass_liveness.cpp
pass_manager.cpp
pass_memory_layout.cpp
pass_shape_relevance.cpp
pattern.cpp
provenance.cpp
reshape_elimination.cpp
reshape_sinking.cpp
shape.cpp
specialize_function.cpp
tensor.cpp
type_prop.cpp
type_prop_layers.cpp
util.cpp
zero_dim_tensor_elimination.cpp
)
if(NGRAPH_JSON_ENABLE)
list(APPEND SRC core.cpp event_tracing.cpp serialize.cpp)
endif()
if(NOT WIN32 AND NGRAPH_TOOLS_ENABLE)
list(APPEND SRC tools.cpp)
endif()
set_source_files_properties(includes.cpp PROPERTIES COMPILE_DEFINITIONS
NGRAPH_INCLUDES="${PROJECT_SOURCE_DIR}/src/ngraph")
if (NGRAPH_INTERPRETER_ENABLE)
list(APPEND SRC
async.cpp
backend_debug_api.cpp
builder.cpp
backend_api.cpp)
if (NGRAPH_CPU_ENABLE)
list(APPEND SRC hybrid_backend.cpp)
endif()
set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} INTERPRETER)
endif()
if (NGRAPH_CPU_ENABLE)
list(APPEND SRC core_fusion.cpp builder_quantization.cpp)
list(APPEND SRC backend_performance.cpp cpu_fusion.cpp cpu_test.cpp cpu_debugger.cpp)
if (NOT NGRAPH_DEX_ONLY)
list(APPEND SRC cpu_codegen.cpp)
endif()
if (NGRAPH_HALIDE)
list(APPEND SRC halide.cpp)
endif()
set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} CPU)
endif()
if(NGRAPH_GPU_ENABLE)
list(APPEND SRC gpu_test.cpp gpu_fusion.cpp)
set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} GPU)
endif()
if (NGRAPH_INTELGPU_ENABLE)
set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} INTELGPU)
endif()
if (NGRAPH_GPUH_ENABLE)
set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} GPUH)
endif()
if (NGRAPH_PLAIDML_ENABLE)
set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} PlaidML)
endif()
if (NGRAPH_GENERIC_CPU_ENABLE)
set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} GCPU)
endif()
add_subdirectory(models)
add_subdirectory(files)
add_subdirectory(util)
# backend specific test files must meet the following requirements:
# 1) The must be named <name>.in.cpp
# 2) They must be in the test directory
# 3) Include "util/test_control.hpp" in your cpp file
# 4) add the line `static string s_manifest = "${MANIFEST}";` to your cpp file
# 5) Use the `NGRAPH_TEST` macro in place of `TEST`.
# All such files are configured via cmake which replaces all instances of cmake variables
# such as ${BACKEND_NAME} with their values, such as CPU, GPU, or INTERPRETER.
set(MULTI_TEST_SRC
autodiff.in.cpp
backend_all.in.cpp
backend_any.in.cpp
backend_api.in.cpp
backend_binary_elementwise.in.cpp
backend_broadcast.in.cpp
backend_comparison.in.cpp
backend_dot.in.cpp
backend_embedding_lookup.in.cpp
backend_fused_op.in.cpp
backend_gather.in.cpp
backend_one_hot.in.cpp
backend_pool.in.cpp
backend_reshape.in.cpp
backend_scatter.in.cpp
backend_sum.in.cpp
backend_topk.in.cpp
backend_arg_reduce.in.cpp
backend_test.in.cpp
backend_unary_elementwise.in.cpp
convolution_test.in.cpp
dynamic.in.cpp
)
if(NGRAPH_DISTRIBUTED_ENABLE)
list(APPEND MULTI_TEST_SRC distributed.in.cpp)
endif()
if (NGRAPH_CPU_ENABLE)
list(APPEND MULTI_TEST_SRC backend_graph_comparison.in.cpp)
endif()
if (NGRAPH_ONNX_IMPORT_ENABLE)
list(APPEND MULTI_TEST_SRC
onnx/onnx_import.in.cpp
onnx/onnx_import_convpool.in.cpp
onnx/onnx_import_reshape.in.cpp
onnx/onnx_import_rnn.in.cpp
onnx/onnx_import_quant.in.cpp)
if (NGRAPH_ONNXIFI_ENABLE)
list(APPEND SRC onnx/onnxifi.cpp onnx/onnxifi_span.cpp)
endif()
endif()
foreach(BACKEND_NAME ${ACTIVE_BACKEND_LIST})
# Some---but not all---autodiff tests go through multiple iterations with
# different random seeds. On the CPU backend this is currently very slow
# because the autodiff tests recompile with each iteration. That behavior
# can be changed, but it's a bit involved, so for the time being we just
# reduce the number of test iterations on non-INTERPRETER backends.
if(${BACKEND_NAME} MATCHES ^INTERPRETER$)
set(TEST_LOOPS 100)
else()
set(TEST_LOOPS 2)
endif()
string(TOLOWER ${BACKEND_NAME} BACKEND_DIR)
set(MANIFEST ${PROJECT_SOURCE_DIR}/src/ngraph/runtime/${BACKEND_DIR}/unit_test.manifest)
foreach(TEST_SRC ${MULTI_TEST_SRC})
string(REPLACE ".in." "_${BACKEND_NAME}." TARGET_NAME ${TEST_SRC})
configure_file(${TEST_SRC} ${TARGET_NAME})
set(SRC ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} ${SRC})
endforeach()
message(STATUS "Adding unit test for backend ${BACKEND_NAME}")
endforeach()
add_executable(unit-test ${SRC})
target_include_directories(unit-test PRIVATE ".")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCURDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJSON_INCLUDES=\\\"${JSON_INCLUDE_DIR}\\\"")
if(NGRAPH_ADDRESS_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
endif()
target_link_libraries(unit-test PRIVATE ngraph_test_util)
target_link_libraries(unit-test PRIVATE ngraph libgtest)
if (NGRAPH_JSON_ENABLE)
target_link_libraries(unit-test PRIVATE libjson)
endif()
if(NOT WIN32)
target_link_libraries(unit-test PRIVATE pthread)
endif()
target_link_libraries(unit-test PRIVATE ${CMAKE_DL_LIBS})
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")
target_compile_options(unit-test PRIVATE -Wno-undef -Wno-reserved-id-macro)
endif()
if (NGRAPH_CPU_ENABLE)
# The INTERPRETER backend is required for convolution, and backwards unit tests
target_link_libraries(unit-test PRIVATE cpu_backend interpreter_backend)
target_link_libraries(unit-test PRIVATE libmkldnn)
endif()
if (NGRAPH_TOOLS_ENABLE)
get_property(NBENCH_PATH TARGET nbench PROPERTY BINARY_DIR)
set(NBENCH "${NBENCH_PATH}/nbench")
target_compile_definitions(unit-test PRIVATE NBENCH_PATH="${NBENCH}")
add_dependencies(unit-test nbench)
endif()
if (NGRAPH_PLAIDML_ENABLE)
target_link_libraries(unit-test PRIVATE plaidml_backend)
endif()
if (NGRAPH_TBB_ENABLE)
target_compile_definitions(unit-test PRIVATE NGRAPH_TBB_ENABLE)
endif()
if (NGRAPH_HALIDE)
target_compile_definitions(unit-test PRIVATE "NGRAPH_HALIDE")
endif()
if (NGRAPH_INTERPRETER_ENABLE)
target_compile_definitions(unit-test PRIVATE NGRAPH_INTERPRETER_ENABLE)
target_link_libraries(unit-test PRIVATE interpreter_backend)
endif()
if (NGRAPH_GPU_ENABLE)
target_link_libraries(unit-test PRIVATE gpu_backend)
endif()
if (NGRAPH_NOP_ENABLE)
target_link_libraries(unit-test PRIVATE nop_backend)
endif()
if (NGRAPH_GPUH_ENABLE)
target_link_libraries(unit-test PRIVATE gpuh_backend)
endif()
if (NGRAPH_ONNXIFI_ENABLE)
target_include_directories(unit-test SYSTEM PUBLIC ${ONNX_INCLUDE_DIR})
target_link_libraries(unit-test PRIVATE onnxifi-ngraph)
endif()
# If all the runtime libraries are installed into one location, that will make life easier.
if (MSVS)
add_custom_target(unit-test-check
COMMAND set "PATH=${EXTERNAL_PROJECTS_ROOT}/src/ngraph/Release;${EXTERNAL_PROJECTS_ROOT}/mkldnn/lib/;${EXTERNAL_PROJECTS_ROOT}/mkl/src/ext_mkl/lib/;${EXTERNAL_PROJECTS_ROOT}/ext_tbb-prefix/src/ext_tbb/tbb2019_20181203oss/bin/intel64/vc14;%PATH%"
COMMAND ${PROJECT_BINARY_DIR}/test/unit-test \${ARGS}
DEPENDS unit-test
)
else()
add_custom_target(unit-test-check
COMMAND ${PROJECT_BINARY_DIR}/test/unit-test \${ARGS}
DEPENDS unit-test
)
endif()
add_custom_target(check
DEPENDS
style-check
unit-test-check
)