a4d5cdb2b456558220c0a1f191205954645dc5c9
[platform/upstream/dldt.git] / ngraph / test / CMakeLists.txt
1 # ******************************************************************************
2 # Copyright 2017-2020 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 add_definitions("-DSERIALIZED_ZOO=\"${CMAKE_CURRENT_SOURCE_DIR}/models\"")
18 set(NGRAPH_ONNX_NAMESPACE ngraph_onnx)
19
20 set(ONNX_LIBRARIES onnx onnx_proto)
21
22 add_subdirectory(runtime)
23
24 if(NOT NGRAPH_UNIT_TEST_ENABLE)
25     message(STATUS "unit tests disabled")
26     add_subdirectory(util)
27     return()
28 endif()
29
30 message(STATUS "unit tests enabled")
31
32 if(LINUX)
33     set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
34 endif()
35
36 if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
37     if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.0.0")
38         # gtest has issues with this with v1.8.x
39         # gtest issue is supposed to be addressed after v1.8.x
40         add_compile_options(-Wno-zero-as-null-pointer-constant)
41     endif()
42 endif()
43
44 set(SRC
45     aligned_buffer.cpp
46     all_close_f.cpp
47     attributes.cpp
48     bfloat16.cpp
49     build_graph.cpp
50     builder_autobroadcast.cpp
51     check.cpp
52     constant.cpp
53     constant_folding.cpp
54     control_dependencies.cpp
55     convert_u1_to_string.cpp
56     coordinate.cpp
57     copy.cpp
58     element_type.cpp
59     eval.cpp
60     file_util.cpp
61     float16.cpp
62     graph_rewrite.cpp
63     includes.cpp
64     input_output_assign.cpp
65     intervals.cpp
66     main.cpp
67     matcher_pass.cpp
68     misc.cpp
69     ngraph_api.cpp
70     node_input_output.cpp
71     op.cpp
72     op_eval/floor_mod.cpp
73     op_eval/hsigmoid.cpp
74     op_eval/hswish.cpp
75     op_eval/interpolate.cpp
76     op_eval/matmul.cpp
77     op_eval/mish.cpp
78     op_eval/non_zero.cpp
79     op_eval/reduce_l1.cpp
80     op_eval/reduce_l2.cpp
81     op_eval/roi_align.cpp
82     op_eval/round.cpp
83     op_eval/softplus.cpp
84     op_eval/split.cpp
85     op_eval/swish.cpp
86     op_eval/strided_slice.cpp
87     op_eval/variadic_split.cpp
88     op_is.cpp
89     opset1.cpp
90     partial_shape.cpp
91     pass_liveness.cpp
92     pass_manager.cpp
93     pass_shape_relevance.cpp
94     pattern.cpp
95     provenance.cpp
96     replace_node.cpp
97     shape.cpp
98     specialize_function.cpp
99     tensor.cpp
100     type_prop/assign.cpp
101     type_prop/avg_pool.cpp
102     type_prop/batch_norm.cpp
103     type_prop/batch_to_space.cpp
104     type_prop/binary_convolution.cpp
105     type_prop/binary_elementwise.cpp
106     type_prop/broadcast.cpp
107     type_prop/bucketize.cpp
108     type_prop/clamp.cpp
109     type_prop/concat.cpp
110     type_prop/constant.cpp
111     type_prop/convert.cpp
112     type_prop/convolution.cpp
113     type_prop/ctc_loss.cpp
114     type_prop/deformable_convolution.cpp
115     type_prop/deformable_psroi_pooling.cpp
116     type_prop/depth_to_space.cpp
117     type_prop/dot.cpp
118     type_prop/dyn_reshape.cpp
119     type_prop/strided_slice.cpp
120     type_prop/elu.cpp
121     type_prop/embeddingbag_offsetssum.cpp
122     type_prop/extractimagepatches.cpp
123     type_prop/embeddingbag_packedsum.cpp
124     type_prop/embedding_segments_sum.cpp
125     type_prop/fake_quantize.cpp
126     type_prop/gather.cpp
127     type_prop/gather_nd.cpp
128     type_prop/gather_tree.cpp
129     type_prop/grn.cpp
130     type_prop/group_convolution.cpp
131     type_prop/group_convolution_backprop_data.cpp
132     type_prop/gru_cell.cpp
133     type_prop/gru_sequence.cpp
134     type_prop/hard_sigmoid.cpp
135     type_prop/hsigmoid.cpp
136     type_prop/hswish.cpp
137     type_prop/interpolate.cpp
138     type_prop/lrn.cpp
139     type_prop/lstm_cell.cpp
140     type_prop/lstm_sequence.cpp
141     type_prop/loop.cpp
142     type_prop/matmul.cpp
143     type_prop/max_pool.cpp
144     type_prop/mish.cpp
145     type_prop/mvn.cpp
146     type_prop/non_max_suppression.cpp
147     type_prop/non_zero.cpp
148     type_prop/normalize.cpp
149     type_prop/one_hot.cpp
150     type_prop/pad.cpp
151     type_prop/parameter.cpp
152     type_prop/prelu.cpp
153     type_prop/proposal.cpp
154     type_prop/quantize.cpp
155     type_prop/quantized_convolution.cpp
156     type_prop/quantized_dot.cpp
157     type_prop/range.cpp
158     type_prop/read_value.cpp
159     type_prop/reduce_l1.cpp
160     type_prop/reduce_l2.cpp
161     type_prop/reorg_yolo.cpp
162     type_prop/replace_slice.cpp
163     type_prop/reshape.cpp
164     type_prop/reverse.cpp
165     type_prop/reverse_sequence.cpp
166     type_prop/roi_align.cpp
167     type_prop/round.cpp
168     type_prop/rnn_cell.cpp
169     type_prop/rnn_sequence.cpp
170     type_prop/round.cpp
171     type_prop/scatter_elements_update.cpp
172     type_prop/scatter_nd_update.cpp
173     type_prop/scatter_update.cpp
174     type_prop/select.cpp
175     type_prop/shape_of.cpp
176     type_prop/shuffle_channels.cpp
177     type_prop/slice.cpp
178     type_prop/softplus.cpp
179     type_prop/space_to_batch.cpp
180     type_prop/space_to_depth.cpp
181     type_prop/split.cpp
182     type_prop/squared_difference.cpp
183     type_prop/squeeze.cpp
184     type_prop/sum.cpp
185     type_prop/swish.cpp
186     type_prop/reduce_prod.cpp
187     type_prop/reduce_sum.cpp
188     type_prop/ti.cpp
189     type_prop/tile.cpp
190     type_prop/top_k.cpp
191     type_prop/transpose.cpp
192     type_prop/unary_elementwise.cpp
193     type_prop/unsqueeze.cpp
194     type_prop/variadic_split.cpp
195     type_prop_layers.cpp
196     util.cpp
197 )
198
199 # This code generates one source file per header file under ngraph/src where the source file
200 # has just a single #include statement. This checks that each header in the source tree is
201 # complete and self-contained so it can be included without requiring any other includes.
202 set(DIRECTORIES_IGNORED runtime frontend)
203 set(NGRAPH_MAIN_SRC_DIR "${CMAKE_SOURCE_DIR}/src/ngraph")
204 file(GLOB_RECURSE LIST_RECURSE
205     "${NGRAPH_MAIN_SRC_DIR}/builder/*.hpp"
206     "${NGRAPH_MAIN_SRC_DIR}/codegen/*.hpp"
207     "${NGRAPH_MAIN_SRC_DIR}/descriptor/*.hpp"
208     "${NGRAPH_MAIN_SRC_DIR}/distributed/*.hpp"
209     "${NGRAPH_MAIN_SRC_DIR}/op/*.hpp"
210     "${NGRAPH_MAIN_SRC_DIR}/pass/*.hpp"
211     "${NGRAPH_MAIN_SRC_DIR}/state*.hpp")
212 file(GLOB LIST
213     "${NGRAPH_MAIN_SRC_DIR}/*.hpp"
214     "${CMAKE_CURRENT_SOURCE_DIR}/runtime/*.hpp")
215 set(NGRAPH_HEADER_LIST ${LIST_RECURSE} ${LIST})
216 list(APPEND NGRAPH_HEADER_LIST ${LIST})
217 foreach(HEADER ${NGRAPH_HEADER_LIST})
218     file(RELATIVE_PATH OUT_PATH ${NGRAPH_MAIN_SRC_DIR} ${HEADER})
219     string(REGEX REPLACE "hpp$" "cpp" OUT_PATH ${OUT_PATH})
220     set(OUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/include_test/${OUT_PATH}")
221     configure_file("header_standalone.in.cpp" ${OUT_FILE})
222     list(APPEND SRC ${OUT_FILE})
223 endforeach()
224
225 set_source_files_properties(includes.cpp PROPERTIES COMPILE_DEFINITIONS
226     NGRAPH_INCLUDES="${PROJECT_SOURCE_DIR}/src/ngraph")
227
228 if (ENABLE_MKL_DNN)
229     message(STATUS "NGRAPH_TESTS: IE:CPU enabled")
230     set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} "IE:CPU")
231 endif()
232 if (ENABLE_CLDNN)
233     message(STATUS "NGRAPH_TESTS: IE:GPU enabled")
234     set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} "IE:GPU")
235 endif()
236
237 if (NGRAPH_INTERPRETER_ENABLE)
238     list(APPEND SRC
239         backend_debug_api.cpp
240         builder.cpp
241         backend_api.cpp)
242     set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} INTERPRETER)
243 endif()
244
245 add_definitions("-DTEST_FILES=\"${CMAKE_CURRENT_SOURCE_DIR}/files\"")
246 add_subdirectory(util)
247
248 # backend specific test files must meet the following requirements:
249 # 1) The must be named <name>.in.cpp
250 # 2) They must be in the `test/backend` directory
251 # 3) Include "util/test_control.hpp" in your cpp file
252 # 4) add the line `static string s_manifest = "${MANIFEST}";` to your cpp file
253 # 5) Use the `NGRAPH_TEST` macro in place of `TEST`.
254 # All such files are configured via cmake which replaces all instances of cmake variables
255 # such as ${BACKEND_NAME} with their values, such as CPU, GPU, or INTERPRETER.
256
257 set(MULTI_TEST_SRC
258     backend/abc.in.cpp
259     backend/abs.in.cpp
260     backend/acos.in.cpp
261     backend/acosh.in.cpp
262     backend/add.in.cpp
263     backend/aliased_output.in.cpp
264     backend/api.in.cpp
265     backend/asin.in.cpp
266     backend/asinh.in.cpp
267     backend/atan.in.cpp
268     backend/atanh.in.cpp
269     backend/auto_broadcast.in.cpp
270     backend/batch_norm.in.cpp
271     backend/broadcast.in.cpp
272     backend/builder_reduce_ops_opset1.in.cpp
273     backend/ceiling.in.cpp
274     backend/comparison.in.cpp
275     backend/concat.in.cpp
276     backend/constant.in.cpp
277     backend/convert.in.cpp
278     backend/convolution.in.cpp
279     backend/cos.in.cpp
280     backend/cosh.in.cpp
281     backend/ctc_greedy_decoder.in.cpp
282     backend/cum_sum.in.cpp
283     backend/divide.in.cpp
284     backend/dot.in.cpp
285     backend/dyn_reshape.in.cpp
286     backend/strided_slice.in.cpp
287     backend/dynamic.in.cpp
288     backend/erf.in.cpp
289     backend/exp.in.cpp
290     backend/floor.in.cpp
291     backend/function_name.in.cpp
292     backend/fused_op.in.cpp
293     backend/gather.in.cpp
294     backend/gather_nd.in.cpp
295     backend/gelu.in.cpp
296     backend/group_convolution.in.cpp
297     backend/interpolate.in.cpp
298     backend/log.in.cpp
299     backend/log_softmax.in.cpp
300     backend/logical_or.in.cpp
301     backend/logical_xor.in.cpp
302     backend/lrn.in.cpp
303     backend/matmul.in.cpp
304     backend/max.in.cpp
305     backend/maximum.in.cpp
306     backend/min.in.cpp
307     backend/minimum.in.cpp
308     backend/multiple_backends.in.cpp
309     backend/multiple_result.in.cpp
310     backend/multiply.in.cpp
311     backend/negative.in.cpp
312     backend/node_name.in.cpp
313     backend/normalize_l2.in.cpp
314     backend/not.in.cpp
315     backend/non_zero.in.cpp
316     backend/numeric.in.cpp
317     backend/one_hot.in.cpp
318     backend/pad.in.cpp
319     backend/parameter_as_output.in.cpp
320     backend/power.in.cpp
321     backend/quantize_dequantize.in.cpp
322     backend/quantized_convolution.in.cpp
323     backend/quantized_dot.in.cpp
324     backend/range.in.cpp
325     backend/reduce_max.in.cpp
326     backend/reduce_mean.in.cpp
327     backend/reduce_min.in.cpp
328     backend/reduce_prod.in.cpp
329     backend/reduce_sum.in.cpp
330     backend/region_yolo.in.cpp
331     backend/relu.in.cpp
332     backend/reorg_yolo.in.cpp
333     backend/replace_slice.in.cpp
334     backend/reshape.in.cpp
335     backend/reverse_sequence.in.cpp
336     backend/reverse.in.cpp
337     backend/round.in.cpp
338     backend/select.in.cpp
339     backend/shape_of.in.cpp
340     backend/sigmoid.in.cpp
341     backend/sign.in.cpp
342     backend/sin.in.cpp
343     backend/sinh.in.cpp
344     backend/slice.in.cpp
345     backend/softmax.in.cpp
346     backend/sqrt.in.cpp
347     backend/subtract.in.cpp
348     backend/sum.in.cpp
349     backend/tan.in.cpp
350     backend/tanh.in.cpp
351     backend/tile.in.cpp
352     backend/topk.in.cpp
353     backend/transpose.in.cpp
354     backend/unhandled_op.in.cpp
355     backend/validate_call.in.cpp
356     backend/zero_sized.in.cpp
357 )
358
359 if (NGRAPH_ONNX_IMPORT_ENABLE AND NOT NGRAPH_USE_PROTOBUF_LITE)
360     list(APPEND MULTI_TEST_SRC
361             onnx/onnx_import.in.cpp
362             onnx/onnx_import_controlflow.in.cpp
363             onnx/onnx_import_const_folding.in.cpp
364             onnx/onnx_import_convpool.in.cpp
365             onnx/onnx_import_dyn_shapes.in.cpp
366             onnx/onnx_import_external_data.in.cpp
367             onnx/onnx_import_provenance.in.cpp
368             onnx/onnx_import_reshape.in.cpp
369             onnx/onnx_import_rnn.in.cpp
370             onnx/onnx_import_quant.in.cpp)
371     list(APPEND SRC
372             onnx/onnx_import_exceptions.cpp
373             onnx/onnx_import_library.cpp)
374 endif()
375
376 foreach(BACKEND_NAME ${ACTIVE_BACKEND_LIST})
377     if(${BACKEND_NAME} MATCHES ^INTERPRETER$)
378         set(TEST_LOOPS 100)
379     else()
380         set(TEST_LOOPS 2)
381     endif()
382
383     string(TOLOWER ${BACKEND_NAME} BACKEND_DIR)
384     string(REGEX REPLACE "([a-z0-9]+):(.*)" "\\1" BACKEND_DIR ${BACKEND_DIR})
385     set(MANIFEST ${CMAKE_CURRENT_SOURCE_DIR}/runtime/${BACKEND_DIR}/unit_test.manifest)
386
387     foreach(TEST_SRC ${MULTI_TEST_SRC})
388         string(REPLACE ":" "_" BACKEND_NAME ${BACKEND_NAME})
389         string(REPLACE ".in." "_${BACKEND_NAME}." TARGET_NAME ${TEST_SRC})
390         configure_file(${TEST_SRC} ${TARGET_NAME})
391         set(SRC ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} ${SRC})
392     endforeach()
393
394     message(STATUS "Adding unit test for backend ${BACKEND_NAME}")
395 endforeach()
396
397 add_executable(unit-test ${SRC})
398
399 target_include_directories(unit-test PRIVATE ".")
400 target_include_directories(unit-test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/runtime)
401
402 add_definitions("-DCURDIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"")
403 add_definitions("-DJSON_INCLUDES=\"${JSON_INCLUDE_DIR}\"")
404
405 if(NGRAPH_ADDRESS_SANITIZER)
406     add_compile_options(-g -fsanitize=address -fno-omit-frame-pointer)
407 endif()
408
409 target_link_libraries(unit-test PRIVATE ngraph_test_util
410                                         ngraph
411                                         ngraph::builder
412                                         ngraph_backend
413                                         libgtest)
414
415 # Protobuf-lite does not support parsing files from prototxt format
416 # Since most of the onnx models are stored in this format it have to be disabled
417 if (NGRAPH_ONNX_IMPORT_ENABLE AND NOT NGRAPH_USE_PROTOBUF_LITE)
418     target_include_directories(unit-test
419         SYSTEM PRIVATE ${ONNX_INCLUDE_DIR} ${ONNX_PROTO_INCLUDE_DIR} ${Protobuf_INCLUDE_DIRS})
420     target_link_libraries(unit-test PRIVATE ${Protobuf_LIBRARIES} ${ONNX_LIBRARIES})
421 endif()
422
423 target_compile_definitions(unit-test PRIVATE NGRAPH_VERSION_LABEL="${NGRAPH_VERSION_LABEL}")
424 if(NOT WIN32)
425     target_link_libraries(unit-test PRIVATE pthread)
426 endif()
427 target_link_libraries(unit-test PRIVATE ${CMAKE_DL_LIBS})
428
429 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")
430     target_compile_options(unit-test PRIVATE -Wno-undef -Wno-reserved-id-macro)
431 endif()
432
433 # So many type_prop tests these days that we need to set /bigobj flag for MSVC.
434 # We should probably split up type_prop.cpp.
435 if (MSVC)
436     target_compile_options(unit-test PRIVATE "/bigobj")
437 endif()
438
439 if (TARGET inference_engine)
440     target_link_libraries(unit-test PRIVATE inference_engine)
441 endif()
442
443 if (NGRAPH_ONNX_IMPORT_ENABLE)
444     target_link_libraries(unit-test PRIVATE onnx_importer)
445 endif()
446
447 target_link_libraries(unit-test PRIVATE ie_backend)
448
449 if (NGRAPH_INTERPRETER_ENABLE)
450     target_compile_definitions(unit-test PRIVATE NGRAPH_INTERPRETER_ENABLE)
451     target_link_libraries(unit-test PRIVATE interpreter_backend)
452 endif()