forked from Xilinx/inference-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
242 lines (221 loc) · 7.5 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
# Copyright 2021 Xilinx, Inc.
# Copyright 2022 Advanced Micro Devices, Inc.
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
cmake_minimum_required(VERSION 3.21)
# parse version
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" ver)
string(REPLACE "\n" "" ver ${ver})
string(REGEX MATCHALL "([0-9]+)|-(.*)\\+" result ${ver})
list(GET result 0 ver_major)
list(GET result 1 ver_minor)
list(GET result 2 ver_patch)
list(LENGTH result result_len)
if(result_len EQUAL "4")
list(GET result 3 ver_label)
string(LENGTH ${ver_label} ver_label_len)
string(SUBSTRING ${ver_label} 1 ${ver_label_len} ver_label)
message(
STATUS
"Building version ${ver_major}.${ver_minor}.${ver_patch}-${ver_label}"
)
else()
set(ver_label "")
message(STATUS "Building version ${ver_major}.${ver_minor}.${ver_patch}")
endif()
# set the project name
project(
amdinfer
VERSION ${ver_major}.${ver_minor}.${ver_patch}
LANGUAGES C CXX
DESCRIPTION "AMDinfer inference library and server"
)
# Only do these if this is the main project, and not if it is included through
# add_subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_LINKER_WRAPPER_FLAG "-Wl,")
add_link_options("LINKER:--as-needed")
# cannot use linker options like --no-undefined and --no-allow-shlib-undefined
# because for manylinux builds, the Python extension is intentionally not
# linked against Python at compile time so we need to allow undefined symbols.
# The workers are also not fully linked either.
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Coverage"
CACHE STRING "Available build-types: Debug, Release and Coverage"
)
# set standard options
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -Wpedantic -pedantic-errors")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(AMDINFER_BUILD_TESTING_DEFAULT ON)
else()
set(AMDINFER_BUILD_TESTING_DEFAULT OFF)
endif()
if(CMAKE_BUILD_TYPE MATCHES Coverage)
include(CodeCoverage)
endif()
include(CMakeDependentOption)
include(CTest)
include(EnableIPO)
include(AddOption)
# check requirements
find_package(Drogon CONFIG)
find_package(OpenCV)
find_package(opentelemetry-cpp CONFIG)
find_package(spdlog)
find_package(Threads REQUIRED)
# rocm, the toolkit used by migraphx
list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm)
find_package(migraphx QUIET)
find_package(tfzendnn)
find_package(ptzendnn)
find_package(protobuf CONFIG)
find_package(absl CONFIG)
find_package(gRPC CONFIG)
find_package(Doxygen)
find_package(Sphinx)
find_package(efsw)
find_package(json-c QUIET)
find_package(prometheus-cpp)
find_package(sockpp QUIET)
check_include_file_cxx(half/half.hpp HALF_INCLUDE)
if(NOT HALF_INCLUDE)
message(FATAL_ERROR "half could not be included, required for FP16 support")
endif()
find_package(xir QUIET)
find_package(vart CONFIG COMPONENTS runner util QUIET)
find_package(rt-engine QUIET)
find_package(unilog QUIET)
find_package(target-factory QUIET)
find_package(aks QUIET)
if(${xir_FOUND}
AND ${vart_FOUND}
AND ${rt-engine_FOUND}
AND ${unilog_FOUND}
AND ${target-factory_FOUND}
)
set(AMDINFER_VITIS_FOUND ON)
set(AMDINFER_AKS_FOUND ${aks_FOUND})
message(STATUS "Enabling Vitis dependencies")
if(aks_FOUND)
message(STATUS "Enabling AKS dependencies")
else()
message(STATUS "AKS not found, disabling AKS dependencies")
endif()
else()
set(AMDINFER_VITIS_FOUND OFF)
set(AMDINFER_AKS_FOUND OFF)
message(STATUS "One or more Vitis dependencies not found. Disabling Vitis")
endif()
configure_file(
${PROJECT_SOURCE_DIR}/src/amdinfer/version.hpp.in
${PROJECT_SOURCE_DIR}/src/amdinfer/version.hpp
)
message(STATUS "Build Options:")
add_option("ENABLE_REST" "Enable the REST server" ON)
add_option("ENABLE_GRPC" "Enable the gRPC server" ${gRPC_FOUND})
add_option("ENABLE_METRICS" "Enable Prometheus metrics" ON)
add_option("ENABLE_LOGGING" "Enable logging" ${spdlog_FOUND})
add_option("ENABLE_TRACING" "Enable Jaeger tracing" ${opentelemetry-cpp_FOUND})
add_option("ENABLE_AKS" "Enable AKS dependencies" ${AMDINFER_AKS_FOUND})
add_option("ENABLE_VITIS" "Enable Vitis dependencies" ${AMDINFER_VITIS_FOUND})
add_option("BUILD_EXAMPLES" "Build examples" ON)
add_option("BUILD_SHARED" "Build AMDinfer as a shared library" ON)
add_option("BUILD_TESTING" "Build C++ tests" ${AMDINFER_BUILD_TESTING_DEFAULT})
add_option("ENABLE_IPO" "Enable interprocedural optimizations" OFF)
add_option("ENABLE_LINTING" "Enable build-time linting" OFF)
add_option("ENABLE_TFZENDNN" "Enable TF+ZenDNN worker" ${tfzendnn_FOUND})
add_option("ENABLE_PTZENDNN" "Enable PT+ZenDNN worker" ${ptzendnn_FOUND})
add_option("ENABLE_MIGRAPHX" "Enable migraphx worker" ${migraphx_FOUND})
add_option("ENABLE_PYTHON_BINDINGS" "Build Python bindings" ON)
message(STATUS "Derived Options:")
if(${AMDINFER_ENABLE_REST} OR ${AMDINFER_ENABLE_METRICS})
add_derived_option("ENABLE_HTTP" ON)
else()
add_derived_option("ENABLE_HTTP" OFF)
endif()
# override tracing option and disable it if building Python bindings
if(SKBUILD)
set(AMDINFER_ENABLE_TRACING OFF)
endif()
configure_file(
src/amdinfer/build_options.hpp.in
${PROJECT_SOURCE_DIR}/include/amdinfer/build_options.hpp
)
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/tools/benchmark.yml)
configure_file(
tools/benchmark.yml.in ${PROJECT_SOURCE_DIR}/tools/benchmark.yml
)
endif()
# include this after configuring all files due to the GLOB expression
include(ClangTools)
if(CMAKE_BUILD_TYPE MATCHES Coverage)
append_coverage_compiler_flags()
setup_target_for_coverage_fastcov(
NAME
coverage # New target name
EXECUTABLE
python3
EXECUTABLE_ARGS
${PROJECT_SOURCE_DIR}/tests/test.py
--mode
tests
--build
Coverage
--load-before
DEPENDENCIES
amdinfer-server
FASTCOV_ARGS
"--include"
${PROJECT_SOURCE_DIR}
"--exceptional-branch-coverage"
BASE_DIRECTORY
${PROJECT_SOURCE_DIR}
EXCLUDE
${PROJECT_SOURCE_DIR}/build
${PROJECT_SOURCE_DIR}/tests
${PROJECT_SOURCE_DIR}/external
${PROJECT_SOURCE_DIR}/examples
${PROJECT_SOURCE_DIR}/src/amdinfer/bindings
)
else()
message(STATUS "Not a coverage build, not configuring coverage measurement")
endif()
set(AMDINFER_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/include
)
set(AMDINFER_PUBLIC_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include)
set(AMDINFER_TEST_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/tests/src)
if(${AMDINFER_ENABLE_LINTING})
enable_cxx_linting()
endif()
if(${Doxygen_FOUND} AND ${Sphinx_FOUND})
message(STATUS "Doxygen and Sphinx found. Building documentation")
add_subdirectory(docs)
else()
message(STATUS "Doxygen or Sphinx not found. Skipping building documentation")
endif()
add_subdirectory(external)
add_subdirectory(src/amdinfer)
if(${AMDINFER_BUILD_EXAMPLES})
add_subdirectory(examples)
endif()
if(${AMDINFER_BUILD_TESTING})
include(GTest)
include(GoogleTest)
add_subdirectory(tests)
endif()