CMakeLists.txt 5 KB
Newer Older
1
# ******************************************************************************
2 3
# Copyright 2017-2018 Intel Corporation
#
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
set(SRC
18
    algebraic_simplification.cpp
19
    assertion.cpp
20
    builder_autobroadcast.cpp
21
    build_graph.cpp
22
    constant_folding.cpp
23
    copy.cpp
24
    cpio.cpp
25
    cse.cpp
26
    element_type.cpp
27
    file_util.cpp
28
    all_close_f.cpp
29
    inliner.cpp
30
    input_output_assign.cpp
Bob Kimball's avatar
Bob Kimball committed
31 32
    main.cpp
    op.cpp
33
    graph_partition.cpp
34
    nop_elimination.cpp
35
    pass_liveness.cpp
Bob Kimball's avatar
Bob Kimball committed
36
    pass_manager.cpp
37
    pass_memory_layout.cpp
Robert Kimball's avatar
Robert Kimball committed
38
    serialize.cpp
39
    pattern.cpp
40
    shape.cpp
41
    reshape_elimination.cpp
42
    tensor.cpp
43
    type_prop.cpp
44 45
    util.cpp
    uuid.cpp
46
    zero_dim_tensor_elimination.cpp
Robert Kimball's avatar
Robert Kimball committed
47 48
)

49 50 51 52
if (NGRAPH_ONNX_IMPORT_ENABLE)
    list(APPEND SRC onnx_import.cpp)
endif()

53 54 55 56
if (NGRAPH_INTERPRETER_ENABLE)
    set(SRC ${SRC} backend_debug_api.cpp builder.cpp backend_api.cpp)
endif()

57 58 59 60
if (NGRAPH_CPU_ENABLE)
    set(SRC ${SRC} core_fusion.cpp)
endif()

61
add_subdirectory(models)
62
add_subdirectory(files)
63
add_subdirectory(util)
64

65
if(NGRAPH_CPU_ENABLE)
66
    set(SRC ${SRC} backend_performance.cpp codegen.cpp cpu_fusion.cpp cpu_test.cpp)
67 68
endif()

69
if(NGRAPH_GPU_ENABLE)
70
    set(SRC ${SRC} cudnn.cpp gpu_test.cpp)
71 72
endif()

73 74 75 76 77 78
foreach(TEST_CONFIG ${UNIT_TEST_CONFIG_LIST})
    string(FIND ${TEST_CONFIG} "@" OFFSET)
    string(SUBSTRING ${TEST_CONFIG} 0 ${OFFSET} BACKEND_NAME)
    math(EXPR OFFSET ${OFFSET}+1)
    string(SUBSTRING ${TEST_CONFIG} ${OFFSET} -1 MANIFEST)

79
    configure_file(backend_test.in.cpp backend_test_${BACKEND_NAME}.cpp)
80
    configure_file(convolution_test.in.cpp convolution_test_${BACKEND_NAME}.cpp)
81 82
    set(SRC ${CMAKE_CURRENT_BINARY_DIR}/backend_test_${BACKEND_NAME}.cpp ${SRC})
    set(SRC ${CMAKE_CURRENT_BINARY_DIR}/convolution_test_${BACKEND_NAME}.cpp ${SRC})
83 84
    if(NGRAPH_DISTRIBUTED_ENABLE)
        configure_file(distributed.cpp distributed_${BACKEND_NAME}.cpp)
85
        set(SRC ${CMAKE_CURRENT_BINARY_DIR}/distributed_${BACKEND_NAME}.cpp  ${SRC})
86
    endif()
87

88 89 90 91 92 93 94 95 96 97 98 99
    # 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()

    configure_file(autodiff.in.cpp autodiff_${BACKEND_NAME}.cpp)
100
    set(SRC ${CMAKE_CURRENT_BINARY_DIR}/autodiff_${BACKEND_NAME}.cpp ${SRC})
101

102 103
    message(STATUS "Adding unit test for backend ${BACKEND_NAME}")
endforeach()
104

105
include_directories(".")
106

107
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Robert Kimball's avatar
Robert Kimball committed
108
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCURDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"")
109 110
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJSON_INCLUDES=\\\"${JSON_INCLUDE_DIR}\\\"")

111 112 113
if(NGRAPH_ADDRESS_SANITIZER)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
endif()
Robert Kimball's avatar
Robert Kimball committed
114

115 116 117 118 119 120 121 122
if(NGRAPH_DISTRIBUTED_ENABLE)
    find_package(MPI REQUIRED)
    add_definitions(-DNGRAPH_DISTRIBUTED)
    include_directories(SYSTEM ${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
    link_directories(${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
    link_libraries(${MPI_CXX_LIBRARIES})
endif()

123
add_executable(unit-test ${SRC})
124
target_link_libraries(unit-test ngraph_test_util)
125 126
target_link_libraries(unit-test ngraph libgtest libjson pthread)
target_link_libraries(unit-test ${CMAKE_DL_LIBS})
127

128 129 130 131
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")
    target_compile_options(unit-test PRIVATE -Wno-undef -Wno-reserved-id-macro)
endif()

132 133 134
if (NGRAPH_CPU_ENABLE)
    # The INTERPRETER backend is required for graph_partition, convolution, and backwards unit tests
    target_link_libraries(unit-test cpu_backend interpreter_backend)
Robert Kimball's avatar
Robert Kimball committed
135
    target_link_libraries(unit-test libmkldnn)
136 137
endif()

138 139
if (NGRAPH_TBB_ENABLE)
    add_definitions(-DNGRAPH_TBB_ENABLE)
140 141
endif()

142 143 144
if (NGRAPH_INTERPRETER_ENABLE)
    add_definitions(-DNGRAPH_INTERPRETER_ENABLE)
    target_link_libraries(unit-test interpreter_backend)
145 146
endif()

147 148
if (NGRAPH_GPU_ENABLE)
    target_link_libraries(unit-test gpu_backend)
149 150
endif()

151
add_custom_target(unit-test-check
152 153
    COMMAND ${PROJECT_BINARY_DIR}/test/unit-test \${ARGS}
    DEPENDS unit-test
154
)
155 156

add_custom_target(check
157 158 159 160
    DEPENDS
    style-check
    unit-test-check
)