Skip to content

Commit 8494c18

Browse files
build: tritonfrontend support for no/partial endpoint builds (#7605)
1 parent d5121e3 commit 8494c18

File tree

8 files changed

+66
-52
lines changed

8 files changed

+66
-52
lines changed

src/CMakeLists.txt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,6 @@ if(${TRITON_ENABLE_TRACING})
249249
main
250250
PRIVATE TRITON_ENABLE_TRACING=1
251251
)
252-
# FIXME: remove, when Windows support is added for Opentelemetry
253-
if (NOT WIN32)
254-
target_include_directories(
255-
main
256-
PRIVATE
257-
${OPENTELEMETRY_CPP_INCLUDE_DIRS}
258-
)
259-
endif()
260252
endif() # TRITON_ENABLE_TRACING
261253

262254
if(${TRITON_ENABLE_NVTX})
@@ -404,9 +396,9 @@ if(${TRITON_ENABLE_HTTP}
404396
# add ${OPENTELEMETRY_CPP_INCLUDE_DIRS} to above target_include_directories
405397
# JIRA DLIS-4786
406398
if (NOT WIN32 AND ${TRITON_ENABLE_TRACING})
407-
target_include_directories(
399+
target_link_libraries(
408400
http-endpoint-library
409-
PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}
401+
PRIVATE tracing-library
410402
)
411403
endif()
412404

@@ -517,19 +509,25 @@ if(${TRITON_ENABLE_TRACING})
517509
)
518510

519511
target_compile_features(tracing-library PRIVATE cxx_std_${TRITON_MIN_CXX_STANDARD})
520-
512+
# FIXME: remove, when Windows support is added for Opentelemetry
521513
if (NOT WIN32)
522514
target_include_directories(
523515
tracing-library
524-
PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}
516+
PUBLIC ${OPENTELEMETRY_CPP_INCLUDE_DIRS}
525517
)
526518

527519
target_link_libraries(
528520
tracing-library
529-
PRIVATE
521+
PUBLIC
530522
${OPENTELEMETRY_CPP_LIBRARIES})
531523
endif()
532524

525+
set_target_properties(
526+
tracing-library
527+
PROPERTIES
528+
POSITION_INDEPENDENT_CODE ON
529+
)
530+
533531
target_link_libraries(
534532
tracing-library
535533
PUBLIC

src/grpc/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ target_include_directories(
8383
# add ${OPENTELEMETRY_CPP_INCLUDE_DIRS} to above target_include_directories
8484
# JIRA DLIS-4786
8585
if (NOT WIN32 AND ${TRITON_ENABLE_TRACING})
86-
target_include_directories(
86+
target_link_libraries(
8787
grpc-endpoint-library
88-
PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}
88+
PRIVATE
89+
tracing-library
8990
)
9091
endif()
9192

src/python/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@
2626

2727
cmake_minimum_required(VERSION 3.18)
2828

29-
message("tritonfrontend python package build skipped when relevant frontends are disabled.")
30-
message("In order to build tritonfrontend, the following flags are needed: -DTRITON_ENABLE_HTTP=ON -DTRITON_ENABLE_GRPC=ON")
31-
32-
# [DLIS-7232] tritonfrontend package expects all supported packages to be
33-
# built, without any check/verification for respective frontend enable flags.
34-
# Support for partial builds(ex: HTTP but not gRPC) will be addressed later.
35-
if(NOT (${TRITON_ENABLE_HTTP} AND ${TRITON_ENABLE_GRPC}))
36-
return()
37-
endif()
38-
3929
add_subdirectory(tritonfrontend)
4030

4131
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/TRITON_VERSION ${TRITON_VERSION})

src/python/tritonfrontend/CMakeLists.txt

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,10 @@ set(
6262
../../common.h
6363
../../common.cc
6464
../../restricted_features.h
65-
../../tracer.h
66-
$<$<BOOL:${TRITON_ENABLE_TRACING}>:../../tracer.cc>
6765
../../classification.cc
6866
)
6967

70-
set(PY_BINDING_DEPENDENCY_LIBS
71-
triton-common-json
72-
triton-common-logging
73-
triton-core-serverapi
74-
triton-core-serverstub
75-
)
68+
set(PY_BINDING_DEPENDENCY_LIBS)
7669

7770
# Conditional Linking Based on Flags
7871
if(${TRITON_ENABLE_HTTP})
@@ -96,18 +89,14 @@ endif()
9689

9790
if(${TRITON_ENABLE_TRACING})
9891
message("TRACING/STATS IS CURRENTLY NOT SUPPORTED.")
99-
find_package(absl CONFIG REQUIRED)
100-
find_package(CURL CONFIG REQUIRED)
101-
find_package(nlohmann_json CONFIG REQUIRED)
102-
find_package(opentelemetry-cpp CONFIG REQUIRED)
103-
list(APPEND PY_BINDING_DEPENDENCY_LIBS
104-
tracing-library
92+
list(
93+
APPEND PY_BINDING_DEPENDENCY_LIBS
94+
tracing-library
10595
)
10696
endif()
10797

10898
# ===================== End of Collection ===================================
10999

110-
111100
# ================== Create Python Frontend Bindings ========================
112101
set(
113102
PYTHON_FRONTEND_BINDING_SRCS
@@ -122,12 +111,10 @@ pybind11_add_module(
122111
${PYTHON_FRONTEND_BINDING_SRCS}
123112
)
124113

125-
target_include_directories(py-bindings PRIVATE ${CMAKE_SOURCE_DIR}/src)
126-
127114
target_link_libraries(
128115
py-bindings
129116
PRIVATE
130-
${PY_BINDING_DEPENDENCY_LIBS}
117+
${PY_BINDING_DEPENDENCY_LIBS}
131118
)
132119

133120
if(${TRITON_ENABLE_HTTP})
@@ -153,14 +140,10 @@ if(${TRITON_ENABLE_GPU})
153140
endif()
154141

155142
if(${TRITON_ENABLE_TRACING})
156-
target_include_directories(
143+
target_compile_definitions(
157144
py-bindings
158-
PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}
145+
PRIVATE TRITON_ENABLE_TRACING=1
159146
)
160-
target_compile_definitions(
161-
py-bindings
162-
PRIVATE TRITON_ENABLE_TRACING=1
163-
)
164147
endif()
165148

166149
if(${TRITON_ENABLE_STATS})
@@ -170,12 +153,19 @@ if(${TRITON_ENABLE_STATS})
170153
)
171154
endif()
172155

156+
if(${TRITON_ENABLE_METRICS})
157+
target_compile_definitions(
158+
py-bindings
159+
PRIVATE TRITON_ENABLE_METRICS=1
160+
)
161+
endif()
173162

174163
set_property(TARGET py-bindings PROPERTY OUTPUT_NAME tritonfrontend_bindings)
175164

176165
set_target_properties(
177166
py-bindings
178167
PROPERTIES
179168
BUILD_RPATH "$ORIGIN:/opt/tritonserver/lib"
169+
POSITION_INDEPENDENT_CODE ON
180170
)
181171
# ===================== End of Python Bindings ==============================

src/python/tritonfrontend/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,14 @@
2929
import builtins
3030
from importlib.metadata import PackageNotFoundError, version
3131

32-
from tritonfrontend._api._kservegrpc import KServeGrpc
33-
from tritonfrontend._api._kservehttp import KServeHttp
32+
try:
33+
from tritonfrontend._api._kservehttp import KServeHttp
34+
except ImportError:
35+
# TRITON_ENABLE_HTTP=OFF
36+
pass
37+
38+
try:
39+
from tritonfrontend._api._kservegrpc import KServeGrpc
40+
except ImportError:
41+
# TRITON_ENABLE_GRPC=OFF
42+
pass

src/python/tritonfrontend/_api/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@
2323
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
26+
27+
try:
28+
from ._kservehttp import KServeHttp
29+
except ImportError:
30+
# TRITON_ENABLE_HTTP=OFF
31+
# TritonFrontendHttp Package was not present
32+
pass
33+
34+
try:
35+
from ._kservegrpc import KServeGrpc
36+
except ImportError:
37+
# TRITON_ENABLE_GRPC=OFF
38+
# TritonFrontendGrpc Package was not present
39+
pass

src/python/tritonfrontend/_api/_error_mapping.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
UnsupportedError,
3737
)
3838

39+
# ERROR_MAPPING takes in tritonfrontend Error and maps to respective tritonserver Error
3940
ERROR_MAPPING = {
4041
TritonError: tritonserver.TritonError,
4142
NotFoundError: tritonserver.NotFoundError,

src/python/tritonfrontend/_c/tritonfrontend_pybind.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@
2727
#include <pybind11/pybind11.h>
2828
#include <pybind11/stl.h>
2929

30+
#ifdef TRITON_ENABLE_GRPC
3031
#include "../../../grpc/grpc_server.h"
32+
#endif
33+
34+
35+
#ifdef TRITON_ENABLE_HTTP
3136
#include "../../../http_server.h"
37+
#endif
38+
39+
3240
#include "triton/core/tritonserver.h"
3341
#include "tritonfrontend.h"
3442

@@ -53,12 +61,14 @@ PYBIND11_MODULE(tritonfrontend_bindings, m)
5361
py::register_exception<AlreadyExistsError>(
5462
m, "AlreadyExistsError", tfe.ptr());
5563

56-
64+
#ifdef TRITON_ENABLE_HTTP
5765
py::class_<TritonFrontend<HTTPServer, HTTPAPIServer>>(m, "TritonFrontendHttp")
5866
.def(py::init<uintptr_t, UnorderedMapType>())
5967
.def("start", &TritonFrontend<HTTPServer, HTTPAPIServer>::StartService)
6068
.def("stop", &TritonFrontend<HTTPServer, HTTPAPIServer>::StopService);
69+
#endif // TRITON_ENABLE_HTTP
6170

71+
#ifdef TRITON_ENABLE_GRPC
6272
py::class_<TritonFrontend<
6373
triton::server::grpc::Server, triton::server::grpc::Server>>(
6474
m, "TritonFrontendGrpc")
@@ -71,6 +81,7 @@ PYBIND11_MODULE(tritonfrontend_bindings, m)
7181
"stop", &TritonFrontend<
7282
triton::server::grpc::Server,
7383
triton::server::grpc::Server>::StopService);
84+
#endif // TRITON_ENABLE_GRPC
7485
}
7586

7687
}}} // namespace triton::server::python

0 commit comments

Comments
 (0)