Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

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

Lines changed: 161 additions & 49 deletions
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)
Lines changed: 40 additions & 0 deletions
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.

‎python.cc renamed to ‎src/python.cc

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <stdio.h>
3434
#include <sys/wait.h>
3535
#include <unistd.h>
36-
3736
#include <algorithm>
3837
#include <chrono>
3938
#include <condition_variable>
@@ -53,15 +52,13 @@
5352
#include <vector>
5453

5554
#include "python_host.grpc.pb.h"
56-
#include "src/backends/backend/examples/backend_utils.h"
57-
#include "src/backends/backend/tritonbackend.h"
58-
#include "src/core/json.h"
59-
#include "src/core/tritonserver.h"
6055

61-
namespace ni = nvidia::inferenceserver;
62-
namespace nib = nvidia::inferenceserver::backend;
56+
#include "triton/backend/backend_common.h"
57+
#include "triton/common/triton_json.h"
58+
#include "triton/common/tritonbackend.h"
59+
#include "triton/common/tritonserver.h"
6360

64-
namespace nvidia { namespace inferenceserver { namespace backend {
61+
namespace triton { namespace backend { namespace python {
6562

6663
#define RESPOND_AND_RETURN_IF_ERROR(REQUEST, X) \
6764
do { \
@@ -82,10 +79,6 @@ namespace nvidia { namespace inferenceserver { namespace backend {
8279
} \
8380
} while (false)
8481

85-
}}} // namespace nvidia::inferenceserver::backend
86-
87-
namespace {
88-
8982
#define GUARDED_RESPOND_IF_ERROR(RESPONSES, IDX, X) \
9083
do { \
9184
if ((RESPONSES)[IDX] != nullptr) { \
@@ -130,18 +123,18 @@ class ModelInstanceState {
130123

131124
/// Load Triton inputs to the appropriate Protobufs
132125
TRITONSERVER_Error* GetInputTensor(
133-
const uint32_t iidx, TRITONBACKEND_Request* request,
134-
ni::Tensor* input_tensor, std::vector<TRITONBACKEND_Response*>& responses,
135-
size_t r, uint32_t& batch_size);
126+
const uint32_t iidx, TRITONBACKEND_Request* request, Tensor* input_tensor,
127+
std::vector<TRITONBACKEND_Response*>& responses, size_t r,
128+
uint32_t& batch_size);
136129

137130
// TODO: Create getter and setters
138-
std::unique_ptr<ni::PythonInterpreter::Stub> stub;
131+
std::unique_ptr<PythonInterpreter::Stub> stub;
139132

140133
private:
141134
ModelInstanceState(
142135
ModelState* model_state, TRITONBACKEND_ModelInstance* model_instance,
143136
const char* name, const TRITONSERVER_InstanceGroupKind kind,
144-
const int32_t device_id, ni::TritonJson::Value&& model_config,
137+
const int32_t device_id, triton::common::TritonJson::Value&& model_config,
145138
TRITONBACKEND_Model* trition_model);
146139

147140
TRITONSERVER_Error* ConnectPythonInterpreter();
@@ -156,7 +149,7 @@ class ModelInstanceState {
156149
bool connected_ = false;
157150

158151
public:
159-
ni::TritonJson::Value model_config;
152+
triton::common::TritonJson::Value model_config;
160153

161154
private:
162155
TRITONBACKEND_Model* triton_model_;
@@ -176,7 +169,7 @@ class ModelState {
176169
uint64_t ModelVersion() const { return model_version_; }
177170

178171
// Get backend state
179-
::BackendState* BackendState() { return backend_state_; }
172+
BackendState* StateForBackend() { return backend_state_; }
180173

181174
// Get Model Path
182175
const char* ModelPath() { return model_path_; }
@@ -185,15 +178,15 @@ class ModelState {
185178
ModelState(
186179
TRITONSERVER_Server* triton_server, TRITONBACKEND_Model* triton_model,
187180
const char* model_name, const uint64_t model_version,
188-
ni::TritonJson::Value&& model_config, ::BackendState* backend_state,
189-
const char* model_path);
181+
triton::common::TritonJson::Value&& model_config,
182+
BackendState* backend_state, const char* model_path);
190183

191184
TRITONSERVER_Server* triton_server_;
192185
TRITONBACKEND_Model* triton_model_;
193186
const std::string model_name_;
194187
const uint64_t model_version_;
195-
ni::TritonJson::Value model_config_;
196-
::BackendState* backend_state_;
188+
triton::common::TritonJson::Value model_config_;
189+
BackendState* backend_state_;
197190
const char* model_path_;
198191
};
199192

@@ -238,10 +231,10 @@ ModelInstanceState::CreatePythonInterpreter()
238231
if (interpreter_pid_ == 0) {
239232
// Use the python available in $PATH
240233
std::string python_interpreter_path =
241-
model_state_->BackendState()->python_runtime;
234+
model_state_->StateForBackend()->python_runtime;
242235

243236
std::stringstream ss;
244-
ss << model_state_->BackendState()->python_lib << "/startup.py";
237+
ss << model_state_->StateForBackend()->python_lib << "/startup.py";
245238
std::string python_interpreter_startup = ss.str();
246239

247240
subinterpreter_commandline[0] = python_interpreter_path.c_str();
@@ -278,10 +271,10 @@ ModelInstanceState::ConnectPythonInterpreter()
278271
auto grpc_channel =
279272
grpc::CreateChannel(domain_socket_, grpc::InsecureChannelCredentials());
280273

281-
stub = ni::PythonInterpreter::NewStub(grpc_channel);
274+
stub = PythonInterpreter::NewStub(grpc_channel);
282275

283-
std::shared_ptr<ni::InitializationCommand> initialization_params(
284-
new ni::InitializationCommand());
276+
std::shared_ptr<InitializationCommand> initialization_params(
277+
new InitializationCommand());
285278

286279
std::vector<std::string> keys;
287280
LOG_IF_ERROR(model_config.Members(&keys), "can't get key names");
@@ -294,7 +287,7 @@ ModelInstanceState::ConnectPythonInterpreter()
294287
value_pair->set_value(val);
295288
};
296289

297-
ni::TritonJson::WriteBuffer buffer;
290+
triton::common::TritonJson::WriteBuffer buffer;
298291
model_config.Write(&buffer);
299292

300293
insert_model_param("model_config", std::move(buffer.MutableContents()));
@@ -312,7 +305,7 @@ ModelInstanceState::ConnectPythonInterpreter()
312305
constexpr uint8_t conn_attempts = 5;
313306
for (int i = 0; i < conn_attempts; ++i) {
314307
grpc::ClientContext context;
315-
ni::Empty null_msg;
308+
Empty null_msg;
316309
status = stub->Init(&context, *initialization_params, &null_msg);
317310
if (status.ok()) {
318311
LOG_MESSAGE(
@@ -334,7 +327,7 @@ ModelInstanceState::ConnectPythonInterpreter()
334327
ModelInstanceState::ModelInstanceState(
335328
ModelState* model_state, TRITONBACKEND_ModelInstance* triton_model_instance,
336329
const char* name, const TRITONSERVER_InstanceGroupKind kind,
337-
const int32_t device_id, ni::TritonJson::Value&& model_config,
330+
const int32_t device_id, triton::common::TritonJson::Value&& model_config,
338331
TRITONBACKEND_Model* triton_model)
339332
: model_state_(model_state), triton_model_instance_(triton_model_instance),
340333
name_(name), kind_(kind), device_id_(device_id),
@@ -372,7 +365,7 @@ ModelInstanceState::Create(
372365
RETURN_IF_ERROR(
373366
TRITONSERVER_MessageSerializeToJson(config_message, &buffer, &byte_size));
374367

375-
ni::TritonJson::Value model_config;
368+
triton::common::TritonJson::Value model_config;
376369

377370
TRITONSERVER_Error* err = model_config.Parse(buffer, byte_size);
378371
RETURN_IF_ERROR(TRITONSERVER_MessageDelete(config_message));
@@ -392,7 +385,7 @@ ModelInstanceState::~ModelInstanceState()
392385
{
393386
// Close python interpreter.
394387
grpc::ClientContext context;
395-
ni::Empty null_msg;
388+
Empty null_msg;
396389

397390
if (connected_) {
398391
auto err = stub->Fini(&context, null_msg, &null_msg);
@@ -424,9 +417,9 @@ ModelInstanceState::~ModelInstanceState()
424417

425418
TRITONSERVER_Error*
426419
ModelInstanceState::GetInputTensor(
427-
const uint32_t iidx, TRITONBACKEND_Request* request,
428-
ni::Tensor* input_tensor, std::vector<TRITONBACKEND_Response*>& responses,
429-
size_t r, uint32_t& batch_size)
420+
const uint32_t iidx, TRITONBACKEND_Request* request, Tensor* input_tensor,
421+
std::vector<TRITONBACKEND_Response*>& responses, size_t r,
422+
uint32_t& batch_size)
430423
{
431424
const char* input_name;
432425
// Load iidx'th input name
@@ -495,7 +488,7 @@ ModelState::Create(TRITONBACKEND_Model* triton_model, ModelState** state)
495488
RETURN_IF_ERROR(
496489
TRITONSERVER_MessageSerializeToJson(config_message, &buffer, &byte_size));
497490

498-
ni::TritonJson::Value model_config;
491+
triton::common::TritonJson::Value model_config;
499492
TRITONSERVER_Error* err = model_config.Parse(buffer, byte_size);
500493
RETURN_IF_ERROR(TRITONSERVER_MessageDelete(config_message));
501494
RETURN_IF_ERROR(err);
@@ -514,7 +507,7 @@ ModelState::Create(TRITONBACKEND_Model* triton_model, ModelState** state)
514507

515508
void* bstate;
516509
RETURN_IF_ERROR(TRITONBACKEND_BackendState(backend, &bstate));
517-
::BackendState* backend_state = reinterpret_cast<::BackendState*>(bstate);
510+
BackendState* backend_state = reinterpret_cast<BackendState*>(bstate);
518511

519512
const char* path = nullptr;
520513
TRITONBACKEND_ModelArtifactType artifact_type;
@@ -539,17 +532,15 @@ ModelState::Create(TRITONBACKEND_Model* triton_model, ModelState** state)
539532
ModelState::ModelState(
540533
TRITONSERVER_Server* triton_server, TRITONBACKEND_Model* triton_model,
541534
const char* model_name, const uint64_t model_version,
542-
ni::TritonJson::Value&& model_config, ::BackendState* backend_state,
543-
const char* model_path)
535+
triton::common::TritonJson::Value&& model_config,
536+
BackendState* backend_state, const char* model_path)
544537
: triton_server_(triton_server), triton_model_(triton_model),
545538
model_name_(model_name), model_version_(model_version),
546539
model_config_(std::move(model_config)), backend_state_(backend_state),
547540
model_path_(model_path)
548541
{
549542
}
550543

551-
} // namespace
552-
553544
extern "C" {
554545

555546
TRITONSERVER_Error*
@@ -590,24 +581,24 @@ TRITONBACKEND_Initialize(TRITONBACKEND_Backend* backend)
590581
TRITONSERVER_LOG_VERBOSE,
591582
(std::string("backend configuration:\n") + buffer).c_str());
592583

593-
ni::TritonJson::Value backend_config;
584+
triton::common::TritonJson::Value backend_config;
594585
if (byte_size != 0) {
595586
RETURN_IF_ERROR(backend_config.Parse(buffer, byte_size));
596587
}
597588

598589
std::unique_ptr<BackendState> backend_state(new BackendState());
599-
ni::TritonJson::Value cmdline;
590+
triton::common::TritonJson::Value cmdline;
600591
bool found_py_lib_config = false;
601592
bool found_py_runtime_config = false;
602593

603594
if (backend_config.Find("cmdline", &cmdline)) {
604-
ni::TritonJson::Value python_lib;
595+
triton::common::TritonJson::Value python_lib;
605596
if (cmdline.Find("python-lib", &python_lib)) {
606597
RETURN_IF_ERROR(python_lib.AsString(&backend_state->python_lib));
607598
found_py_lib_config = true;
608599
}
609600

610-
ni::TritonJson::Value python_runtime;
601+
triton::common::TritonJson::Value python_runtime;
611602
if (cmdline.Find("python-runtime", &python_runtime)) {
612603
RETURN_IF_ERROR(python_runtime.AsString(&backend_state->python_runtime));
613604
found_py_runtime_config = true;
@@ -756,11 +747,11 @@ TRITONBACKEND_ModelInstanceExecute(
756747
}
757748

758749
// Create ExecuteRequest
759-
ni::ExecuteRequest execute_request;
750+
ExecuteRequest execute_request;
760751
for (uint32_t r = 0; r < request_count; ++r) {
761752
TRITONBACKEND_Request* request = requests[r];
762753

763-
ni::InferenceRequest* inference_request = execute_request.add_requests();
754+
InferenceRequest* inference_request = execute_request.add_requests();
764755

765756
uint32_t requested_input_count = 0;
766757
GUARDED_RESPOND_IF_ERROR(
@@ -774,7 +765,7 @@ TRITONBACKEND_ModelInstanceExecute(
774765

775766
uint32_t batch_size = 0;
776767
for (size_t iidx = 0; iidx < requested_input_count; ++iidx) {
777-
ni::Tensor* input_tensor = inference_request->add_inputs();
768+
Tensor* input_tensor = inference_request->add_inputs();
778769
GUARDED_RESPOND_IF_ERROR(
779770
responses, r,
780771
instance_state->GetInputTensor(
@@ -806,7 +797,7 @@ TRITONBACKEND_ModelInstanceExecute(
806797

807798
// ExecuteResponse
808799
grpc::ClientContext context;
809-
ni::ExecuteResponse execute_response;
800+
ExecuteResponse execute_response;
810801

811802
uint64_t compute_start_ns = 0;
812803
SET_TIMESTAMP(compute_start_ns);
@@ -860,7 +851,7 @@ TRITONBACKEND_ModelInstanceExecute(
860851
uint32_t requested_output_count = 0;
861852

862853
// Get response r
863-
ni::InferenceResponse inference_response = execute_response.responses(r);
854+
InferenceResponse inference_response = execute_response.responses(r);
864855

865856
if (inference_response.failed()) {
866857
TRITONSERVER_Error* err = TRITONSERVER_ErrorNew(
@@ -883,7 +874,7 @@ TRITONBACKEND_ModelInstanceExecute(
883874
TRITONBACKEND_RequestOutputCount(request, &requested_output_count));
884875
for (size_t j = 0; j < requested_output_count; ++j) {
885876
// Prepare output buffers.
886-
const ni::Tensor python_output_result = inference_response.outputs(j);
877+
const Tensor python_output_result = inference_response.outputs(j);
887878
TRITONBACKEND_Output* triton_output;
888879
TRITONSERVER_DataType triton_dt =
889880
static_cast<TRITONSERVER_DataType>(python_output_result.dtype());
@@ -901,7 +892,7 @@ TRITONBACKEND_ModelInstanceExecute(
901892

902893
std::vector<int64_t> output_dims(
903894
python_output_dims.begin(), python_output_dims.end());
904-
int64_t output_byte_size = nib::GetByteSize(triton_dt, output_dims);
895+
int64_t output_byte_size = GetByteSize(triton_dt, output_dims);
905896
void* output_buffer;
906897

907898
TRITONSERVER_MemoryType output_memory_type = TRITONSERVER_MEMORY_CPU;
@@ -932,7 +923,7 @@ TRITONBACKEND_ModelInstanceExecute(
932923
auto output_response_tensor = std::find_if(
933924
inference_response.outputs().begin(),
934925
inference_response.outputs().end(),
935-
[&output_tensor_name](const ni::Tensor& itr) {
926+
[&output_tensor_name](const Tensor& itr) {
936927
return itr.name() == output_tensor_name;
937928
});
938929

@@ -1028,3 +1019,5 @@ TRITONBACKEND_ModelInstanceFinalize(TRITONBACKEND_ModelInstance* instance)
10281019
}
10291020

10301021
} // extern "C"
1022+
1023+
}}} // namespace triton::backend::python

‎python_host.proto renamed to ‎src/python_host.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
syntax = "proto3";
2828

29-
package nvidia.inferenceserver;
29+
package triton.backend.python;
3030

3131
message InitializationCommand
3232
{
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.