CMakeLists.txt 6.88 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 18
include_directories(
    SYSTEM
19 20 21
    ${GTEST_INCLUDE_DIR}
    ${EIGEN_INCLUDE_DIR}
    )
Robert Kimball's avatar
Robert Kimball committed
22

Robert Kimball's avatar
Robert Kimball committed
23
set (SRC
24
    backend_api.cpp
25
    algebraic_simplification.cpp
26
    backend_debug_api.cpp
27
    builder.cpp
28
    builder_autobroadcast.cpp
29
    build_graph.cpp
30
    copy.cpp
31
    core_fusion.cpp
32
    cpio.cpp
33
    cse.cpp
34
    element_type.cpp
35
    file_util.cpp
36
    inliner.cpp
37
    input_output_assign.cpp
Bob Kimball's avatar
Bob Kimball committed
38 39
    main.cpp
    op.cpp
40
    graph_partition.cpp
41
    nop_elimination.cpp
42
    pass_liveness.cpp
Bob Kimball's avatar
Bob Kimball committed
43
    pass_manager.cpp
44
    pass_memory_layout.cpp
Robert Kimball's avatar
Robert Kimball committed
45
    serialize.cpp
46
    pattern.cpp
47
    shape.cpp
48
    reshape_elimination.cpp
49
    tensor.cpp
50
    type_prop.cpp
51 52
    util.cpp
    uuid.cpp
53
    zero_dim_tensor_elimination.cpp
Robert Kimball's avatar
Robert Kimball committed
54 55
)

56
add_subdirectory(models)
57
add_subdirectory(files)
58
add_subdirectory(util)
59

60 61 62 63 64 65
#================================================================================================
# To auto generate a suite of unit tests for a backend add a line like this
# set(BACKEND_NAMES ${BACKEND_NAMES} "BACKEND_NAME_GOES_HERE")
# and replace BACKEND_NAME_GOES_HERE with your backend name.
# The code for the unit test suite is in test/backend_test.in.cpp
#================================================================================================
66 67
# TODO add interpreter back to unit tests when it works
set(BACKEND_NAMES ${BACKEND_NAMES} "INTERPRETER")
68

69
if(MKLDNN_INCLUDE_DIR)
70
    include_directories(SYSTEM ${MKLDNN_INCLUDE_DIR})
71 72 73 74
    link_directories(${MKLDNN_LIB_DIR})
    set(SRC ${SRC} mkldnn.cpp)
endif()

75
if(NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR)
76
    include_directories(SYSTEM ${LLVM_INCLUDE_DIR})
77
    link_directories(${LLVM_LIB_DIR})
78
    set(SRC ${SRC} backend_performance.cpp codegen.cpp cpu_fusion.cpp cpu_test.cpp)
79
    set(BACKEND_NAMES ${BACKEND_NAMES} "CPU")
80 81
endif()

82
if(NGRAPH_GPU_ENABLE AND LLVM_INCLUDE_DIR)
83
    include_directories(SYSTEM ${LLVM_INCLUDE_DIR} ${CUDA_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIR})
84
    link_directories(${LLVM_LIB_DIR})
85 86
    link_directories(${CUDA_LIBRARIES})
    link_directories(${CUDA_CUBLAS_LIBRARIES})
87
    link_directories(${CUDNN_LIBRARIES})
Tristan Webb's avatar
Tristan Webb committed
88
    set(SRC
89
        ${SRC}
Tristan Webb's avatar
Tristan Webb committed
90 91
        cudnn.cpp)
    # Disabled for testing
92
    set(BACKEND_NAMES ${BACKEND_NAMES} "GPU")
93 94
endif()

Sandeep's avatar
Sandeep committed
95 96
if(NGRAPH_NNP_ENABLE)
    include_directories(SYSTEM ${NNP_TRANSFORMER_INCLUDE_DIR})
97
    set(BACKEND_NAMES ${BACKEND_NAMES} "NNP_TESTER")
98 99
    set(BACKEND_NAMES ${BACKEND_NAMES} "NNPI")
    set(BACKEND_NAMES ${BACKEND_NAMES} "NNPI_TESTER")
100 101
    set(ADDITIONAL_NNP_TEST ${NNP_TRANSFORMER_SOURCE_DIR}/test/test_nnp_backend.cpp)
    # Ensures ADDITIONAL_NNP_TEST are a dependency on nnp transformer
Sandeep's avatar
Sandeep committed
102 103
    add_custom_command(OUTPUT ${ADDITIONAL_NNP_TEST} DEPENDS ext_nnp_transformer COMMAND "")
    set(SRC ${SRC} ${ADDITIONAL_NNP_TEST})
104 105
endif()

106 107 108 109 110 111
if(NGRAPH_DISTRIBUTED_ENABLE AND MPI_C_INCLUDE_PATH)
    include_directories(SYSTEM ${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
    link_directories(${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
    foreach(BACKEND_NAME ${BACKEND_NAMES})
        configure_file(distributed.cpp distributed_${BACKEND_NAME}.cpp)
        set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/distributed_${BACKEND_NAME}.cpp)
112
    endforeach()
113 114
endif()

115 116 117 118 119 120 121

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)

122
    configure_file(backend_test.in.cpp backend_test_${BACKEND_NAME}.cpp)
123
    configure_file(convolution_test.in.cpp convolution_test_${BACKEND_NAME}.cpp)
124
    set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/backend_test_${BACKEND_NAME}.cpp)
125
    set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/convolution_test_${BACKEND_NAME}.cpp)
126

127 128 129 130 131 132 133 134 135 136 137 138 139 140
    # 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)
    set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/autodiff_${BACKEND_NAME}.cpp)

141 142
    message(STATUS "Adding unit test for backend ${BACKEND_NAME}")
endforeach()
143

144
include_directories(".")
145

146
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Robert Kimball's avatar
Robert Kimball committed
147
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCURDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"")
148 149
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJSON_INCLUDES=\\\"${JSON_INCLUDE_DIR}\\\"")

150 151 152
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
153

154
add_executable(unit-test ${SRC})
155 156
target_link_libraries(unit-test ngraph_test_util)
add_dependencies(unit-test ngraph_test_util)
157

158 159 160 161
if(MPI_C_INCLUDE_PATH)
    target_link_libraries(unit-test ${MPI_CXX_LIBRARIES})
endif()

162 163 164 165 166
if(MKLDNN_INCLUDE_DIR)
    target_link_libraries(unit-test mkldnn)
    add_dependencies(unit-test ext_mkldnn)
endif()

167 168 169 170 171
if(LLVM_INCLUDE_DIR)
    target_link_libraries(unit-test ${LLVM_LINK_LIBS})
    add_dependencies(unit-test ext_llvm)
endif()

Tristan Webb's avatar
Tristan Webb committed
172
if(CUDA_INCLUDE_DIRS)
173 174
    find_library(CUDA_NVRTC_LIBRARY nvrtc /usr/local/cuda/lib64)
    target_link_libraries(unit-test ${CUDA_NVRTC_LIBRARY} ${CUDA_LIBRARIES} ${CUDNN_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES})
175 176
endif()

177
target_link_libraries(unit-test ngraph libgtest pthread)
178 179
target_link_libraries(unit-test ${CMAKE_DL_LIBS})

180 181 182 183 184 185
if(NGRAPH_NNP_ENABLE)
    # A framework like TF shall not need to link `libnnp.so`, but shall call via libngraph.so.
    # Since we're testing non-public APIs in libnnp.so, we link it directly here.
    target_link_libraries(unit-test ${NNP_TRANSFORMER_LIB_DIR}/libnnp.so)
endif()

186
add_dependencies(unit-test ngraph libgtest ext_json)
187
include_directories(SYSTEM ${JSON_INCLUDE_DIR})
188

189
add_custom_target(style-check
190 191
    COMMAND ${PROJECT_SOURCE_DIR}/maint/check-code-format.sh
)
192 193

add_custom_target(unit-test-check
Bob Kimball's avatar
Bob Kimball committed
194
	COMMAND ${PROJECT_BINARY_DIR}/test/unit-test \${ARGS}
195
	DEPENDS unit-test
196
)
197 198

add_custom_target(check
199 200 201 202
    DEPENDS
    style-check
    unit-test-check
)