forked from triton-inference-server/python_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
390 lines (347 loc) · 10.7 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# Copyright 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required(VERSION 3.17)
project(tritonpythonbackend LANGUAGES C CXX)
# Use C++17 standard as Triton's minimum required.
set(TRITON_MIN_CXX_STANDARD 17 CACHE STRING "The minimum C++ standard which features are requested to build this target.")
#
# Options
#
# Must include options required for this project as well as any
# projects included in this one by FetchContent.
#
option(TRITON_ENABLE_GPU "Enable GPU support in backend" ON)
option(TRITON_ENABLE_STATS "Include statistics collections in backend" ON)
option(TRITON_ENABLE_NVTX "Include nvtx markers collection in backend." OFF)
# FIXME: CI needs to enable the GPU flag. Python for window currently does not
# support GPU tensors. For simplicity, we will override this option here.
if(WIN32)
set(TRITON_ENABLE_GPU OFF CACHE BOOL "GPU disabled" FORCE)
endif()
set(TRITON_BACKEND_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/backend repo")
set(TRITON_COMMON_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/common repo")
set(TRITON_CORE_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/core repo")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
#
# Dependencies
#
# FetchContent's composability isn't very good. We must include the
# transitive closure of all repos so that we can override the tag.
#
include(FetchContent)
# We need to use ExternalProject because we want to use Boost 1.76 which is not
# available in Ubuntu 20.04
include(ExternalProject)
FetchContent_Declare(
repo-common
GIT_REPOSITORY https://github.com/triton-inference-server/common.git
GIT_TAG ${TRITON_COMMON_REPO_TAG}
)
FetchContent_Declare(
repo-core
GIT_REPOSITORY https://github.com/triton-inference-server/core.git
GIT_TAG ${TRITON_CORE_REPO_TAG}
)
FetchContent_Declare(
repo-backend
GIT_REPOSITORY https://github.com/triton-inference-server/backend.git
GIT_TAG ${TRITON_BACKEND_REPO_TAG}
)
FetchContent_MakeAvailable(repo-common repo-core repo-backend)
FetchContent_Declare(
pybind11
GIT_REPOSITORY "https://github.com/pybind/pybind11"
# COMMIT ID for v2.10.0
GIT_TAG "aa304c9c7d725ffb9d10af08a3b34cb372307020"
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(pybind11)
#
# DLPack
#
FetchContent_Declare(
dlpack
GIT_REPOSITORY "https://github.com/dmlc/dlpack"
GIT_TAG "v0.8"
GIT_SHALLOW ON
)
# Option must be set off so WIN32 build does not break
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(BUILD_MOCK OFF)
FetchContent_MakeAvailable(dlpack)
#
# Boost
#
ExternalProject_Add(
boostorg
URL https://archives.boost.io/release/1.79.0/source/boost_1_79_0.tar.gz
URL_HASH SHA256=273f1be93238a068aba4f9735a4a2b003019af067b9c183ed227780b8f36062c
PREFIX "boost-src"
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E copy_directory
<SOURCE_DIR>/boost/ ${CMAKE_BINARY_DIR}/boost
INSTALL_COMMAND ""
BUILD_COMMAND ""
)
set(boostorg_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/boost/")
#
# CUDA
#
if(${TRITON_ENABLE_GPU})
find_package(CUDAToolkit REQUIRED)
message(STATUS "Using CUDA ${CUDA_VERSION}")
set(CUDA_NVCC_FLAGS -std=c++${TRITON_MIN_CXX_STANDARD})
elseif()
message(WARNING "TRITON_ENABLE_GPU is OFF, GPU Tensor support will be disabled")
endif() # TRITON_ENABLE_GPU
if(${TRITON_ENABLE_NVTX})
add_definitions(-DTRITON_ENABLE_NVTX=1)
endif() # TRITON_ENABLE_NVTX
find_package(ZLIB REQUIRED)
if(NOT WIN32)
find_package(Threads REQUIRED)
endif()
include_directories(${CMAKE_BINARY_DIR})
configure_file(src/libtriton_python.ldscript libtriton_python.ldscript COPYONLY)
set(
COMMON_SRCS
src/infer_response.cc
src/infer_response.h
src/infer_request.cc
src/infer_request.h
src/message_queue.h
src/ipc_message.cc
src/ipc_message.h
src/pb_string.cc
src/pb_string.h
src/pb_map.cc
src/pb_map.h
src/scoped_defer.cc
src/scoped_defer.h
src/pb_error.cc
src/pb_error.h
src/pb_log.cc
src/pb_log.h
src/pb_memory.cc
src/pb_memory.h
src/pb_tensor.cc
src/pb_tensor.h
src/pb_utils.cc
src/pb_utils.h
src/shm_manager.cc
src/shm_manager.h
src/pb_exception.h
src/pb_preferred_memory.h
src/metric.h
src/metric.cc
src/metric_family.h
src/metric_family.cc
src/gpu_buffers.cc
src/gpu_buffers.h
src/model_loader.h
src/model_loader.cc
)
set(
PYTHON_BACKEND_SRCS
src/python_be.cc
src/python_be.h
src/pb_env.cc
src/pb_env.h
src/pb_metric_reporter.cc
src/pb_metric_reporter.h
src/memory_manager.cc
src/memory_manager.h
src/request_executor.cc
src/request_executor.h
src/stub_launcher.h
src/stub_launcher.cc
src/infer_payload.h
src/infer_payload.cc
)
list(APPEND
PYTHON_BACKEND_SRCS
${COMMON_SRCS}
)
add_library(
triton-python-backend SHARED
${PYTHON_BACKEND_SRCS}
)
set(
PYTHON_BACKEND_STUB_SRCS
src/pb_stub_utils.h
src/pb_stub_utils.cc
src/response_sender.cc
src/response_sender.h
src/pb_stub.h
src/pb_stub.cc
src/pb_response_iterator.h
src/pb_response_iterator.cc
src/pb_cancel.cc
src/pb_cancel.h
)
list(APPEND
PYTHON_BACKEND_STUB_SRCS
${COMMON_SRCS}
)
add_executable(
triton-python-backend-stub
${PYTHON_BACKEND_STUB_SRCS}
)
add_dependencies(triton-python-backend boostorg)
add_dependencies(triton-python-backend-stub boostorg)
set_property(TARGET triton-python-backend-stub PROPERTY OUTPUT_NAME triton_python_backend_stub)
add_library(
TritonPythonBackend::triton-python-backend ALIAS triton-python-backend
)
target_compile_features(triton-python-backend PRIVATE cxx_std_${TRITON_MIN_CXX_STANDARD})
target_compile_options(
triton-python-backend PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Werror>
$<$<CXX_COMPILER_ID:MSVC>:/Wall /D_WIN32_WINNT=0x0A00 /EHsc /Zc:preprocessor>
)
target_compile_features(triton-python-backend-stub PRIVATE cxx_std_${TRITON_MIN_CXX_STANDARD})
target_compile_options(
triton-python-backend-stub PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-fvisibility=hidden -Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Werror>
$<$<CXX_COMPILER_ID:MSVC>:/Wall /D_WIN32_WINNT=0x0A00 /EHsc /Zc:preprocessor>
)
target_compile_definitions(triton-python-backend-stub PRIVATE TRITON_PB_STUB)
# For WIN32 do not link Threads and DL_LIBS
if(WIN32)
target_link_libraries(
triton-python-backend
PRIVATE
dlpack
triton-backend-utils # from repo-backend
-lrt # shared memory
triton-core-serverstub # from repo-core
ZLIB::ZLIB
-larchive
)
target_link_libraries(
triton-python-backend-stub
PRIVATE
dlpack
triton-backend-utils # from repo-backend
pybind11::embed
-lrt # shared memory
-larchive # libarchive
)
else()
target_link_libraries(
triton-python-backend
PRIVATE
dlpack
Threads::Threads
triton-backend-utils # from repo-backend
${CMAKE_DL_LIBS} # dlopen and dlclose
-lrt # shared memory
triton-core-serverstub # from repo-core
ZLIB::ZLIB
-larchive
)
target_link_libraries(
triton-python-backend-stub
PRIVATE
dlpack
Threads::Threads
triton-backend-utils # from repo-backend
${CMAKE_DL_LIBS} # dlopen and dlclose
pybind11::embed
-lrt # shared memory
-larchive # libarchive
)
endif()
if(WIN32)
set_target_properties(
triton-python-backend PROPERTIES
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME triton_python
)
else()
set_target_properties(
triton-python-backend PROPERTIES
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME triton_python
LINK_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libtriton_python.ldscript
LINK_FLAGS "-Wl,--version-script libtriton_python.ldscript"
)
endif()
add_subdirectory(./src/shm_monitor)
#
# Install
#
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/TritonPythonBackend)
install(
TARGETS
triton-python-backend
triton-python-backend-stub
EXPORT
triton-python-backend-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/backends/python
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/backends/python
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/backends/python
)
install(
EXPORT
triton-python-backend-targets
FILE
TritonPythonBackendTargets.cmake
NAMESPACE
TritonPythonBackend::
DESTINATION
${INSTALL_CONFIGDIR}
)
install(
FILES
src/resources/triton_python_backend_utils.py
DESTINATION
${CMAKE_INSTALL_PREFIX}/backends/python
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/TritonPythonBackendConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/TritonPythonBackendConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/TritonPythonBackendConfig.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
#
# Export from build tree
#
export(
EXPORT triton-python-backend-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/TritonPythonBackendTargets.cmake
NAMESPACE TritonPythonBackend::
)
export(PACKAGE TritonPythonBackend)