Skip to content

Commit 96f19f8

Browse files
authoredSep 11, 2020
Add the new build (triton-inference-server#1)
* Add the new build * Add installation of python files * Review edits * Move resources -> src/ * Remove debug message
1 parent 98132a8 commit 96f19f8

7 files changed

+249
-104
lines changed
 

‎CMakeLists.txt

+161-49
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,80 @@
2424
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2525
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

27-
cmake_minimum_required (VERSION 3.5)
2827

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
2949
#
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.
3152
#
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)
3368

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>)
3688

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)
3991

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)
4197
get_filename_component(python_host_proto_dir "${python_host_proto_abspath}" PATH)
4298

4399
set(GRPC_SRCS
44-
"${CMAKE_CURRENT_BINARY_DIR}/python_host.grpc.pb.cc"3
100+
"${CMAKE_CURRENT_BINARY_DIR}/python_host.grpc.pb.cc"
45101
"${CMAKE_CURRENT_BINARY_DIR}/python_host.pb.cc")
46102

47103
set(GRPC_HDRS
@@ -60,11 +116,11 @@ add_custom_command(
60116
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
61117
-I "${python_host_proto_dir}"
62118
--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}
65121
)
66122

67-
find_program(PYTHON "python3" REQUIRED)
123+
find_package(Python REQUIRED COMPONENTS Interpreter)
68124
add_custom_command(
69125
OUTPUT ${GRPC_PY}
70126
COMMAND ${PYTHON}
@@ -73,65 +129,121 @@ add_custom_command(
73129
-I "${python_host_proto_dir}"
74130
--grpc_python_out "${CMAKE_CURRENT_BINARY_DIR}"
75131
--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}
78134
)
79135

80136
add_custom_target(python-grpc-py-library ALL
81137
DEPENDS ${GRPC_PY})
82138

83139
add_library(
84140
python-grpc-library EXCLUDE_FROM_ALL OBJECT
85-
${GRPC_SRCS} ${GRPC_HDRS}
141+
${GRPC_SRCS} ${GRPC_HDRS}
86142
)
87143

88-
include_directories(${CMAKE_CURRENT_BINARY_DIR})
144+
configure_file(src/libtriton_python.ldscript libtriton_python.ldscript COPYONLY)
89145

90146
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
106149

107-
set_target_properties(
108-
triton_python
109-
PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libtriton_python.ldscript
150+
$<TARGET_OBJECTS:python-grpc-library>
110151
)
111152

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
115156
)
116157

117158
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+
)
120170

121171
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}
124232
)
125233

126234
install(
127-
TARGETS triton_python
128-
LIBRARY DESTINATION backends/python
235+
FILES
236+
${CMAKE_CURRENT_BINARY_DIR}/TritonPythonBackendConfig.cmake
237+
DESTINATION ${INSTALL_CONFIGDIR}
129238
)
130239

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+
)
135248

136-
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/triton_python_backend_utils.py
137-
DESTINATION lib/python/runtime)
249+
export(PACKAGE TritonPythonBackend)
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions
6+
# are met:
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# * Neither the name of NVIDIA CORPORATION nor the names of its
13+
# contributors may be used to endorse or promote products derived
14+
# from this software without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17+
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24+
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
include(CMakeFindDependencyMacro)
29+
30+
get_filename_component(
31+
TRITONPYTHONBACKEND_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH
32+
)
33+
34+
list(APPEND CMAKE_MODULE_PATH ${TRITONPYTHONBACKEND_CMAKE_DIR})
35+
36+
if(NOT TARGET TritonPythonBackend::triton-python-backend)
37+
include("${TRITONPYTHONBACKEND_CMAKE_DIR}/TritonPythonBackendTargets.cmake")
38+
endif()
39+
40+
set(TRITONPYTHONBACKEND_LIBRARIES TritonPythonBackend::triton-python-backend)
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.