forked from openvinotoolkit/openvino_tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
269 lines (231 loc) · 8.95 KB
/
CMakeLists.txt
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
# Copyright (C) 2021-2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.14)
project (openvino_tensorflow CXX)
# set directory where the custom finders live
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
# set(CMAKE_CXX_COMPILER "clang++")
include(ExternalProject)
include(CMakeDependentOption)
include(cmake/sdl.cmake)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wno-comment -Wno-sign-compare -Wno-backslash-newline-escape")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wno-comment -Wno-sign-compare")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14 /wd4308 /wd4146 /wd4703 /wd4244 /wd4819 /EHsc")
endif()
# In order to compile ngraph-tf with memory leak detection, run `cmake` with `-DCMAKE_BUILD_TYPE=Sanitize`.
# N.B.: This *will* crash python unit tests because ngraph-tf will be loaded "too late" via `dlopen`,
# so only use this with C++ tests.
# (In theory using `LD_PRELOAD` should address the python issue, but it doesn't appear to work on OS X, at least.)
# If there are any memory leaks, then upon running the binary a report will be automatically generated.
SET(CMAKE_CXX_FLAGS_SANITIZE
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -D_LIBCPP_HAS_NO_ASAN -fsanitize-address-use-after-scope"
CACHE STRING "Flags used by the C++ compiler during sanitized builds."
FORCE )
SET(CMAKE_C_FLAGS_SANITIZE
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -D_LIBCPP_HAS_NO_ASAN -fsanitize-address-use-after-scope"
CACHE STRING "Flags used by the C compiler during sanitized builds."
FORCE )
SET(CMAKE_EXE_LINKER_FLAGS_SANITIZE
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address -D_LIBCPP_HAS_NO_ASAN -fsanitize-address-use-after-scope"
CACHE STRING "Flags used for linking binaries during sanitized builds."
FORCE )
SET(CMAKE_SHARED_LINKER_FLAGS_SANITIZE
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address -D_LIBCPP_HAS_NO_ASAN -fsanitize-address-use-after-scope"
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
FORCE )
MARK_AS_ADVANCED(
CMAKE_CXX_FLAGS_SANITIZE
CMAKE_C_FLAGS_SANITIZE
CMAKE_EXE_LINKER_FLAGS_SANITIZE
CMAKE_SHARED_LINKER_FLAGS_SANITIZE)
# These variables are undocumented but useful.
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
# Invoke a command to determine how many CPU cores we have, and set
# NUM_MAKE_PROCESSES accordingly so we know what number to pass to make -j.
if(APPLE)
set (PROCESSOR_COUNT_COMMAND sysctl -n hw.physicalcpu)
else()
set (PROCESSOR_COUNT_COMMAND nproc)
endif()
execute_process(
COMMAND ${PROCESSOR_COUNT_COMMAND}
RESULT_VARIABLE NPROC_RESULT
OUTPUT_VARIABLE NUM_MAKE_PROCESSES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT APPLE)
# FIXME: Doesn't work for Ubuntu
execute_process(COMMAND cat /etc/os-release
OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCH "ID=\"([a-z])+\"" OS_VERSION "${LSB_RELEASE_ID_SHORT}")
string(REGEX MATCH "\"([a-z])+\"" OS_VERSION "${OS_VERSION}")
message("OS version is ${OS_VERSION}")
else()
# Handle the case for MacOS
# TBD
endif()
# Default to four jobs if the command fails.
if(NPROC_RESULT)
message (WARNING "Unable to detect number of processors. Building nGraph with make -j4.")
set(NUM_MAKE_PROCESSES 4)
endif()
# Need to setup the RPATH here - else it won't work.
# During installation, a Python pip package is created which when
# installed is located in the same level as the tensorflow directory
# site-packages/
# /ngraph
# libopenvino_tensorflow.so
# ...
# /tensorflow
# libtensorflow_framework.so.1
# python/
# _pywrap....so
# Therefore we are setting two entries in the RPATH:
# 1. $ORIGIN/.
# 2. $ORIGIN/../tensorflow/
#
set(CMAKE_BUILD_RPATH_USE_ORIGIN true)
if(APPLE)
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_INSTALL_RPATH "@loader_path/;@loader_path/../tensorflow;")
elseif(DEFINED OPENVINO_TF_RPATH)
set(CMAKE_INSTALL_RPATH "\$ORIGIN:\$ORIGIN/../tensorflow:${OPENVINO_TF_RPATH}")
else()
set(CMAKE_INSTALL_RPATH "\$ORIGIN:\$ORIGIN/../tensorflow")
endif()
# Find TensorFlow
find_package(TensorFlow REQUIRED)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(OPENVINO_TF_CXX11_ABI "${TensorFlow_CXX_ABI}")
message( STATUS "OpenVINO™ integration with TensorFlow using CXX11 ABI: ${OPENVINO_TF_CXX11_ABI}" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=${OPENVINO_TF_CXX11_ABI}")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(OPENVINO_TF_CXX11_ABI "${TensorFlow_CXX_ABI}")
message( STATUS "OpenVINO™ integration with TensorFlow using CXX11 ABI: ${OPENVINO_TF_CXX11_ABI}" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=${OPENVINO_TF_CXX11_ABI}")
endif()
if(APPLE)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(LIBNGRAPH "libngraphd.dylib")
else()
set(LIBNGRAPH "libngraph.dylib")
endif()
elseif(WIN32)
set(LIBNGRAPH "ngraph.lib")
else()
set(LIBNGRAPH "libngraph.so")
endif(APPLE)
if(WIN32)
add_definitions(-DNOMINMAX)
endif()
# Build options
option(UNIT_TEST_ENABLE "Control the building of unit tests" FALSE)
option(UNIT_TEST_TF_CC_DIR "Location where TensorFlow CC library is located" FALSE)
option(USE_OPENVINO_FROM_LOCATION "Use OpenVINO located in OPENVINO_ARTIFACTS_DIR" FALSE)
option(OPENVINO_ARTIFACTS_DIR "Where would OpenVINO be installed after build" FALSE)
set(InferenceEngine_DIR ${OPENVINO_ARTIFACTS_DIR}/runtime/cmake)
find_package(InferenceEngine REQUIRED)
set(ngraph_DIR ${OPENVINO_ARTIFACTS_DIR}/runtime/cmake)
find_package(ngraph QUIET)
include_directories(${InferenceEngine_INCLUDE_DIRS})
if (THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO")
set(TBB_DIR ${OPENVINO_ARTIFACTS_DIR}/runtime/3rdparty/tbb/cmake)
find_package(TBB COMPONENTS tbb tbbmalloc)
endif()
message(STATUS "UNIT_TEST_TF_CC_DIR: ${TF_PRE_BUILT_LOCATION}")
if(UNIT_TEST_TF_CC_DIR)
# Check if the path specified is ABSOLUTE or RELATVE
if (NOT IS_ABSOLUTE ${UNIT_TEST_TF_CC_DIR})
set(UNIT_TEST_TF_CC_DIR ${CMAKE_CURRENT_BINARY_DIR}/${UNIT_TEST_TF_CC_DIR})
endif()
# Create absolute path for the directory
get_filename_component(
TF_PRE_BUILT_LOCATION
"${UNIT_TEST_TF_CC_DIR}"
ABSOLUTE
)
if (NOT EXISTS ${TF_PRE_BUILT_LOCATION})
message(FATAL_ERROR
"TensorFlow pre-built directory doesn't exist: " ${TF_PRE_BUILT_LOCATION} )
endif()
endif()
message(STATUS "UNIT_TEST_ENABLE: ${UNIT_TEST_ENABLE}")
message(STATUS "OPENVINO_ARTIFACTS_DIR: ${OPENVINO_ARTIFACTS_DIR}")
message(STATUS "USE_PRE_BUILT_OPENVINO: ${USE_PRE_BUILT_OPENVINO}")
message(STATUS "OPENVINO_VERSION: ${OPENVINO_VERSION}")
if (${OPENVINO_VERSION} MATCHES "master")
# master works with checks of latest release
add_definitions(-DOPENVINO_2022_1=1)
elseif (${OPENVINO_VERSION} MATCHES "2022.1.0")
add_definitions(-DOPENVINO_2022_1=1)
else()
message(FATAL_ERROR "Unsupported OpenVINO version: ${OPENVINO_VERSION")
endif()
if(WIN32)
add_definitions(-DBUILD_API=1)
endif()
if(OS_VERSION STREQUAL "\"centos\"")
set(LIB "lib64")
else()
set(LIB "lib/intel64")
endif()
if(ngraph_FOUND)
set(NGRAPH_INSTALL_DIR ${OPENVINO_ARTIFACTS_DIR}/runtime)
else()
set(NGRAPH_INSTALL_DIR ${OPENVINO_ARTIFACTS_DIR})
endif()
SET(BASEPATH "${CMAKE_SOURCE_DIR}")
INCLUDE_DIRECTORIES("${BASEPATH}")
# Add the directories to be built
add_subdirectory(third-party)
add_subdirectory(logging)
add_subdirectory(openvino_tensorflow)
add_subdirectory(tools)
add_subdirectory(ocm/OCM)
# The following targets depend on the Tensorflow source code directory
# Get the absolute file name for the source
get_filename_component(
TensorFlow_SRC_DIR
"${TF_SRC_DIR}"
ABSOLUTE
)
add_subdirectory(examples)
if (DEFINED TF_SRC_DIR)
message(STATUS "TensorFlow_SRC_DIR: ${TensorFlow_SRC_DIR}")
add_subdirectory(examples/classification_sample)
else()
message(
STATUS
"TensorFlow source directory not provided. "
"C++ Examples won't be built"
)
endif()
if (UNIT_TEST_ENABLE)
if (NOT DEFINED TF_SRC_DIR)
message(
STATUS
"TensorFlow source directory not provided. "
"C++ unit tests won't be built"
)
else()
if (NOT EXISTS ${TensorFlow_SRC_DIR})
message(
STATUS
"TensorFlow source directory doesn't exist"
)
endif()
# Check if the path specified is ABSOLUTE or RELATVE
if (NOT IS_ABSOLUTE ${TF_SRC_DIR})
set(TF_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/${TF_SRC_DIR})
endif()
endif()
add_subdirectory(test)
message(STATUS "unit tests enabled")
endif()