CMakeLists.txt 9.58 KB
Newer Older
1
# ******************************************************************************
2
# Copyright 2017-2019 Intel Corporation
3
#
Robert Kimball's avatar
Robert Kimball committed
4 5 6
# 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
7
#
Robert Kimball's avatar
Robert Kimball committed
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
Robert Kimball's avatar
Robert Kimball committed
10 11 12 13 14
# 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.
15
# ******************************************************************************
Robert Kimball's avatar
Robert Kimball committed
16

17 18 19 20 21 22 23 24 25 26
add_definitions("-DSERIALIZED_ZOO=\"${CMAKE_CURRENT_SOURCE_DIR}/models\"")

if(NOT NGRAPH_UNIT_TEST_ENABLE)
    message(STATUS "unit tests disabled")
    add_subdirectory(util)
    return()
endif()

message(STATUS "unit tests enabled")

27 28 29 30
if(LINUX)
    set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
endif()

31 32 33 34
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
35
        add_compile_options(-Wno-zero-as-null-pointer-constant)
36 37 38
    endif()
endif()

39
set(SRC
40
    algebraic_simplification.cpp
41
    aligned_buffer.cpp
42
    all_close_f.cpp
43
    assertion.cpp
44
    bfloat16.cpp
45
    build_graph.cpp
46
    builder_autobroadcast.cpp
47
    check.cpp
48
    constant_folding.cpp
49
    concat_fusion.cpp
50 51
    control_dependencies.cpp
    coordinate.cpp
52
    copy.cpp
53
    cpio.cpp
54
    cse.cpp
55
    dyn_elimination.cpp
56
    element_type.cpp
57
    file_util.cpp
Scott Cyphers's avatar
Scott Cyphers committed
58
    float16.cpp
59
    includes.cpp
60
    input_output_assign.cpp
Bob Kimball's avatar
Bob Kimball committed
61
    main.cpp
62
    misc.cpp
63
    node_input_output.cpp
64
    nop_elimination.cpp
65
    op.cpp
66
    partial_shape.cpp
67
    pass.cpp
68
    pass_liveness.cpp
Bob Kimball's avatar
Bob Kimball committed
69
    pass_manager.cpp
70
    pass_memory_layout.cpp
71
    pass_shape_relevance.cpp
72
    pattern.cpp
73
    provenance.cpp
74
    reshape_elimination.cpp
75
    reshape_sinking.cpp
76
    shape.cpp
77
    specialize_function.cpp
78
    tensor.cpp
79
    type_prop.cpp
80
    type_prop_layers.cpp
81
    util.cpp
82
    zero_dim_tensor_elimination.cpp
Robert Kimball's avatar
Robert Kimball committed
83 84
)

85 86 87 88
if(NGRAPH_JSON_ENABLE)
    list(APPEND SRC core.cpp event_tracing.cpp serialize.cpp)
endif()

89
if(NOT WIN32 AND NGRAPH_TOOLS_ENABLE)
90 91 92
    list(APPEND SRC tools.cpp)
endif()

93 94 95
set_source_files_properties(includes.cpp PROPERTIES COMPILE_DEFINITIONS
    NGRAPH_INCLUDES="${PROJECT_SOURCE_DIR}/src/ngraph")

96
if (NGRAPH_INTERPRETER_ENABLE)
97 98 99
    list(APPEND SRC
        backend_debug_api.cpp
        builder.cpp
100
        backend_api.cpp)
101
    set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} INTERPRETER)
102 103
endif()

104
if (NGRAPH_CPU_ENABLE)
105
    list(APPEND SRC core_fusion.cpp builder_quantization.cpp)
106
    list(APPEND SRC backend_performance.cpp cpu_fusion.cpp cpu_test.cpp cpu_debugger.cpp)
107 108 109
    if (NOT NGRAPH_DEX_ONLY)
        list(APPEND SRC cpu_codegen.cpp)
    endif()
110 111 112
    if (NGRAPH_HALIDE)
        list(APPEND SRC halide.cpp)
    endif()
113
    set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} CPU)
114 115
endif()

116
if(NGRAPH_GPU_ENABLE)
117
    list(APPEND SRC gpu_test.cpp gpu_fusion.cpp)
118
    set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} GPU)
119 120
endif()

121 122 123
if (NGRAPH_INTELGPU_ENABLE)
    set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} INTELGPU)
endif()
124

125 126
if (NGRAPH_GPUH_ENABLE)
    set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} GPUH)
Sandeep's avatar
Sandeep committed
127 128
endif()

129 130 131 132
if (NGRAPH_PLAIDML_ENABLE)
    set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} PlaidML)
endif()

133 134 135 136
if (NGRAPH_GENERIC_CPU_ENABLE)
    set(ACTIVE_BACKEND_LIST ${ACTIVE_BACKEND_LIST} GCPU)
endif()

137
add_definitions("-DTEST_FILES=\"${CMAKE_CURRENT_SOURCE_DIR}/files\"")
138 139 140 141 142
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
143 144 145
# 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`.
146 147 148 149
# 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
150 151
    backend_all.in.cpp
    backend_any.in.cpp
152
    backend_api.in.cpp
153 154 155 156
    backend_binary_elementwise.in.cpp
    backend_broadcast.in.cpp
    backend_comparison.in.cpp
    backend_dot.in.cpp
157
    backend_embedding_lookup.in.cpp
158
    backend_fused_op.in.cpp
159
    backend_gather.in.cpp
160
    backend_one_hot.in.cpp
161
    backend_pool.in.cpp
162
    backend_reshape.in.cpp
163
    backend_scatter.in.cpp
164
    backend_sum.in.cpp
165 166
    backend_topk.in.cpp
    backend_arg_reduce.in.cpp
167
    backend_test.in.cpp
168
    backend_unary_elementwise.in.cpp
169
    convolution_test.in.cpp
170
    dyn_replace_slice_test.in.cpp
171
    dyn_slice_test.in.cpp
172
    dynamic.in.cpp
173
)
174

175
if(NGRAPH_DISTRIBUTED_ENABLE)
Robert Kimball's avatar
Robert Kimball committed
176
    list(APPEND MULTI_TEST_SRC distributed.in.cpp)
177
endif()
178

179 180 181
if (NGRAPH_CPU_ENABLE)
    list(APPEND MULTI_TEST_SRC backend_graph_comparison.in.cpp)
endif()
182

183
if (NGRAPH_ONNX_IMPORT_ENABLE)
184 185 186 187 188 189
    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)
190
    if (NGRAPH_ONNXIFI_ENABLE)
191
        list(APPEND SRC onnx/onnxifi.cpp onnx/onnxifi_span.cpp)
192 193 194
    endif()
endif()

195
foreach(BACKEND_NAME ${ACTIVE_BACKEND_LIST})
196 197 198 199 200 201 202 203 204 205 206
    # 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()

207 208 209 210 211 212 213 214
    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()
215

216 217
    message(STATUS "Adding unit test for backend ${BACKEND_NAME}")
endforeach()
218

Robert Kimball's avatar
Robert Kimball committed
219 220 221
add_executable(unit-test ${SRC})

target_include_directories(unit-test PRIVATE ".")
222

223 224
add_definitions("-DCURDIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"")
add_definitions("-DJSON_INCLUDES=\"${JSON_INCLUDE_DIR}\"")
225

226
if(NGRAPH_ADDRESS_SANITIZER)
227
    add_compile_options(-g -fsanitize=address -fno-omit-frame-pointer)
228
endif()
Robert Kimball's avatar
Robert Kimball committed
229

Robert Kimball's avatar
Robert Kimball committed
230
target_link_libraries(unit-test PRIVATE ngraph_test_util)
231 232 233 234
target_link_libraries(unit-test PRIVATE ngraph libgtest)
if (NGRAPH_JSON_ENABLE)
    target_link_libraries(unit-test PRIVATE libjson)
endif()
235 236 237
if(NOT WIN32)
    target_link_libraries(unit-test PRIVATE pthread)
endif()
Robert Kimball's avatar
Robert Kimball committed
238
target_link_libraries(unit-test PRIVATE ${CMAKE_DL_LIBS})
239

240 241 242 243
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")
    target_compile_options(unit-test PRIVATE -Wno-undef -Wno-reserved-id-macro)
endif()

244 245 246 247 248 249
# So many type_prop tests these days that we need to set /bigobj flag for MSVS.
# We should probably split up type_prop.cpp.
if (MSVS)
    target_compile_options(unit-test PRIVATE "/bigobj")
endif()

250
if (NGRAPH_CPU_ENABLE)
251
    # The INTERPRETER backend is required for convolution, and backwards unit tests
Robert Kimball's avatar
Robert Kimball committed
252 253
    target_link_libraries(unit-test PRIVATE cpu_backend interpreter_backend)
    target_link_libraries(unit-test PRIVATE libmkldnn)
254 255
endif()

256 257 258 259 260 261 262
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()

263 264
if (NGRAPH_PLAIDML_ENABLE)
    target_link_libraries(unit-test PRIVATE plaidml_backend)
265 266
    # Some PlaidML devices aren't so precise, so we increase the allowable tolerance.
    target_compile_definitions(unit-test PRIVATE "PlaidML_FLOAT_TOLERANCE_BITS=12")
267 268
endif()

269
if (NGRAPH_TBB_ENABLE)
Robert Kimball's avatar
Robert Kimball committed
270
    target_compile_definitions(unit-test PRIVATE NGRAPH_TBB_ENABLE)
271 272
endif()

Jayaram Bobba's avatar
Jayaram Bobba committed
273 274 275 276
if (NGRAPH_HALIDE)
    target_compile_definitions(unit-test PRIVATE "NGRAPH_HALIDE")
endif()

277
if (NGRAPH_INTERPRETER_ENABLE)
Robert Kimball's avatar
Robert Kimball committed
278
    target_compile_definitions(unit-test PRIVATE NGRAPH_INTERPRETER_ENABLE)
279
    target_link_libraries(unit-test PRIVATE interpreter_backend)
280 281
endif()

282
if (NGRAPH_GPU_ENABLE)
Robert Kimball's avatar
Robert Kimball committed
283
    target_link_libraries(unit-test PRIVATE gpu_backend)
284 285
endif()

Robert Kimball's avatar
Robert Kimball committed
286 287 288 289
if (NGRAPH_NOP_ENABLE)
    target_link_libraries(unit-test PRIVATE nop_backend)
endif()

290 291 292 293
if (NGRAPH_GPUH_ENABLE)
    target_link_libraries(unit-test PRIVATE gpuh_backend)
endif()

294 295
if (NGRAPH_ONNXIFI_ENABLE)
    target_include_directories(unit-test SYSTEM PUBLIC ${ONNX_INCLUDE_DIR})
Robert Kimball's avatar
Robert Kimball committed
296
    target_link_libraries(unit-test PRIVATE onnxifi-ngraph)
297 298
endif()

299 300 301 302 303 304 305 306 307 308 309 310 311
# 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()
312 313

add_custom_target(check
314 315 316 317
    DEPENDS
    style-check
    unit-test-check
)