24
24
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
25
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
27
- cmake_minimum_required (VERSION 3.5)
28
27
28
+ cmake_minimum_required (VERSION 3.17)
29
+
30
+ project (tritonpythonbackend LANGUAGES C CXX)
31
+
32
+ #
33
+ # Options
34
+ #
35
+ # Must include options required for this project as well as any
36
+ # projects included in this one by FetchContent.
37
+ #
38
+ # GPU support is disabled by default because python backend doesn't
39
+ # because python backend does not need to access CUDA or GPUs
40
+ #
41
+ option (TRITON_ENABLE_GPU "Enable GPU support in backend" OFF )
42
+ option (TRITON_ENABLE_STATS "Include statistics collections in backend" ON )
43
+
44
+ set (TRITON_BACKEND_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/backend repo" )
45
+ set (TRITON_COMMON_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/common repo" )
46
+
47
+ #
48
+ # Dependencies
29
49
#
30
- # libtriton_python.so
50
+ # FetchContent's composibility isn't very good. We must include the
51
+ # transitive closure of all repos so that we can override the tag.
31
52
#
32
- configure_file (libtriton_python.ldscript libtriton_python.ldscript COPYONLY )
53
+ include (FetchContent)
54
+
55
+ FetchContent_Declare(
56
+ repo-common
57
+ GIT_REPOSITORY git@github.com:triton-inference-server/common.git
58
+ GIT_TAG ${TRITON_COMMON_REPO_TAG}
59
+ GIT_SHALLOW ON
60
+ )
61
+ FetchContent_Declare(
62
+ repo-backend
63
+ GIT_REPOSITORY git@github.com:triton-inference-server/backend.git
64
+ GIT_TAG ${TRITON_BACKEND_REPO_TAG}
65
+ GIT_SHALLOW ON
66
+ )
67
+ FetchContent_MakeAvailable(repo-common repo-backend)
33
68
34
- find_package (gRPC CONFIG REQUIRED)
35
- find_package (Protobuf CONFIG REQUIRED)
69
+ FetchContent_Declare(
70
+ googletest
71
+ GIT_REPOSITORY "https://github.com/google/googletest"
72
+ GIT_TAG "release-1.10.0"
73
+ GIT_SHALLOW ON
74
+ )
75
+ FetchContent_Declare(
76
+ grpc
77
+ GIT_REPOSITORY https://github.com/grpc/grpc.git
78
+ GIT_TAG "v1.31.1"
79
+ GIT_SHALLOW ON
80
+ )
81
+ FetchContent_MakeAvailable(googletest grpc)
82
+
83
+ set (_PROTOBUF_LIBPROTOBUF libprotobuf)
84
+ set (_REFLECTION grpc++_reflection)
85
+ set (_PROTOBUF_PROTOC $<TARGET_FILE:protoc>)
86
+ set (_GRPC_GRPCPP grpc++)
87
+ set (_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:grpc_cpp_plugin>)
36
88
37
- set (_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin> )
38
- set (_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc> )
89
+ get_target_property (Protobuf_INCLUDE_DIRS ${_PROTOBUF_LIBPROTOBUF} INTERFACE_INCLUDE_DIRECTORIES )
90
+ get_target_property (gRPC_INCLUDE_DIRS ${_GRPC_GRPCPP} INTERFACE_INCLUDE_DIRECTORIES )
39
91
40
- get_filename_component (python_host_proto_abspath "python_host.proto" ABSOLUTE )
92
+ include_directories (${Protobuf_INCLUDE_DIRS} )
93
+ include_directories (${gRPC_INCLUDE_DIRS} )
94
+ include_directories (${CMAKE_CURRENT_BINARY_DIR} )
95
+
96
+ get_filename_component (python_host_proto_abspath "src/python_host.proto" ABSOLUTE )
41
97
get_filename_component (python_host_proto_dir "${python_host_proto_abspath} " PATH )
42
98
43
99
set (GRPC_SRCS
44
- "${CMAKE_CURRENT_BINARY_DIR} /python_host.grpc.pb.cc" 3
100
+ "${CMAKE_CURRENT_BINARY_DIR} /python_host.grpc.pb.cc"
45
101
"${CMAKE_CURRENT_BINARY_DIR} /python_host.pb.cc" )
46
102
47
103
set (GRPC_HDRS
@@ -60,11 +116,11 @@ add_custom_command(
60
116
--cpp_out "${CMAKE_CURRENT_BINARY_DIR} "
61
117
-I "${python_host_proto_dir} "
62
118
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE} "
63
- "python_host.proto "
64
- DEPENDS "python_host.proto" proto-library
119
+ "${python_host_proto_abspath} "
120
+ DEPENDS "${python_host_proto_abspath} " ${_PROTOBUF_LIBPROTOBUF}
65
121
)
66
122
67
- find_program (PYTHON "python3" REQUIRED)
123
+ find_package (Python REQUIRED COMPONENTS Interpreter)
68
124
add_custom_command (
69
125
OUTPUT ${GRPC_PY}
70
126
COMMAND ${PYTHON}
@@ -73,65 +129,121 @@ add_custom_command(
73
129
-I "${python_host_proto_dir} "
74
130
--grpc_python_out "${CMAKE_CURRENT_BINARY_DIR} "
75
131
--python_out "${CMAKE_CURRENT_BINARY_DIR} "
76
- "python_host.proto "
77
- DEPENDS "python_host.proto" proto-library
132
+ "${python_host_proto_abspath} "
133
+ DEPENDS "${python_host_proto_abspath} " ${_PROTOBUF_LIBPROTOBUF}
78
134
)
79
135
80
136
add_custom_target (python-grpc-py-library ALL
81
137
DEPENDS ${GRPC_PY} )
82
138
83
139
add_library (
84
140
python-grpc-library EXCLUDE_FROM_ALL OBJECT
85
- ${GRPC_SRCS} ${GRPC_HDRS}
141
+ ${GRPC_SRCS} ${GRPC_HDRS}
86
142
)
87
143
88
- include_directories ( ${CMAKE_CURRENT_BINARY_DIR} )
144
+ configure_file (src/libtriton_python.ldscript libtriton_python.ldscript COPYONLY )
89
145
90
146
add_library (
91
- triton_python SHARED
92
- python.cc
93
-
94
- $<TARGET_OBJECTS:backend-library>
95
- $<TARGET_OBJECTS:python-grpc-library>)
96
-
97
- if (${TRITON_ENABLE_GPU} )
98
- target_include_directories (triton_python PRIVATE ${CUDA_INCLUDE_DIRS} )
99
- target_link_libraries (
100
- triton_python
101
- PUBLIC -L/usr/local/cuda/lib64/stubs
102
- PUBLIC -lnvidia-ml
103
- PRIVATE ${CUDA_LIBRARIES}
104
- )
105
- endif () # TRITON_ENABLE_GPU
147
+ triton-python-backend SHARED
148
+ src/python.cc
106
149
107
- set_target_properties (
108
- triton_python
109
- PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /libtriton_python.ldscript
150
+ $<TARGET_OBJECTS:python-grpc-library>
110
151
)
111
152
112
- set_target_properties (
113
- triton_python
114
- PROPERTIES LINK_FLAGS "-Wl,--version-script libtriton_python.ldscript"
153
+
154
+ add_library (
155
+ TritonPythonBackend::triton-python-backend ALIAS triton-python-backend
115
156
)
116
157
117
158
target_include_directories (
118
- triton_python
119
- PRIVATE ${CMAKE_CURRENT_BINARY_DIR} )
159
+ triton-python-backend
160
+ PRIVATE
161
+ ${CMAKE_CURRENT_SOURCE_DIR} /src
162
+ )
163
+
164
+ target_compile_features (triton-python-backend PRIVATE cxx_std_11)
165
+ target_compile_options (
166
+ triton-python-backend PRIVATE
167
+ $<$<OR :$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
168
+ -Wall -Wextra -Wno-unused-parameter -Werror>
169
+ )
120
170
121
171
target_link_libraries (
122
- triton_python
123
- PRIVATE gRPC::grpc++
172
+ triton-python-backend
173
+ PRIVATE
174
+ triton-backend-utils # from repo-backend
175
+ ${_GRPC_GRPCPP}
176
+ )
177
+
178
+ set_target_properties (
179
+ triton-python-backend PROPERTIES
180
+ POSITION_INDEPENDENT_CODE ON
181
+ OUTPUT_NAME triton_python
182
+ LINK_DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /libtriton_python.ldscript
183
+ LINK_FLAGS "-Wl,--version-script libtriton_python.ldscript"
184
+ )
185
+
186
+ #
187
+ # Install
188
+ #
189
+ include (GNUInstallDirs)
190
+ set (INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR} /cmake/TritonPythonBackend)
191
+
192
+ install (
193
+ TARGETS
194
+ triton-python-backend
195
+ EXPORT
196
+ triton-python-backend-targets
197
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
198
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
199
+ )
200
+
201
+ install (
202
+ EXPORT
203
+ triton-python-backend-targets
204
+ FILE
205
+ TritonPythonBackendTargets.cmake
206
+ NAMESPACE
207
+ TritonPythonBackend::
208
+ DESTINATION
209
+ ${INSTALL_CONFIGDIR}
210
+ )
211
+
212
+ install (
213
+ FILES
214
+ ${GRPC_PY}
215
+ src/resources/startup.py
216
+ DESTINATION
217
+ ${INSTALL_CONFIGDIR}
218
+ )
219
+
220
+ install (
221
+ FILES
222
+ src/resources/triton_python_backend_utils.py
223
+ DESTINATION
224
+ ${INSTALL_CONFIGDIR}
225
+ )
226
+
227
+ include (CMakePackageConfigHelpers)
228
+ configure_package_config_file(
229
+ ${CMAKE_CURRENT_LIST_DIR} /cmake/TritonPythonBackendConfig.cmake.in
230
+ ${CMAKE_CURRENT_BINARY_DIR} /TritonPythonBackendConfig.cmake
231
+ INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
124
232
)
125
233
126
234
install (
127
- TARGETS triton_python
128
- LIBRARY DESTINATION backends/python
235
+ FILES
236
+ ${CMAKE_CURRENT_BINARY_DIR} /TritonPythonBackendConfig.cmake
237
+ DESTINATION ${INSTALL_CONFIGDIR}
129
238
)
130
239
131
- install (FILES
132
- ${GRPC_PY}
133
- resources/startup.py
134
- DESTINATION lib/python/runtime)
240
+ #
241
+ # Export from build tree
242
+ #
243
+ export (
244
+ EXPORT triton-python-backend-targets
245
+ FILE ${CMAKE_CURRENT_BINARY_DIR} /TritonPythonBackendTargets.cmake
246
+ NAMESPACE TritonPythonBackend::
247
+ )
135
248
136
- install (FILES ${CMAKE_CURRENT_SOURCE_DIR} /resources/triton_python_backend_utils.py
137
- DESTINATION lib/python/runtime)
249
+ export (PACKAGE TritonPythonBackend)
0 commit comments