Skip to content

Commit 47d5217

Browse files
authored
Update python.cc from original repo (triton-inference-server#5)
1 parent f4fda36 commit 47d5217

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

src/python.cc

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
#include <thread>
5151
#include <unordered_map>
5252
#include <vector>
53-
5453
#include "python_host.grpc.pb.h"
55-
5654
#include "triton/backend/backend_common.h"
5755
#include "triton/common/triton_json.h"
5856
#include "triton/common/tritonbackend.h"
@@ -268,6 +266,7 @@ ModelInstanceState::CreatePythonInterpreter()
268266
TRITONSERVER_Error*
269267
ModelInstanceState::ConnectPythonInterpreter()
270268
{
269+
grpc_init();
271270
auto grpc_channel =
272271
grpc::CreateChannel(domain_socket_, grpc::InsecureChannelCredentials());
273272

@@ -437,11 +436,10 @@ ModelInstanceState::GetInputTensor(
437436
uint32_t input_dims_count;
438437
uint64_t input_byte_size;
439438
uint32_t input_buffer_count;
440-
GUARDED_RESPOND_IF_ERROR(
441-
responses, r,
442-
TRITONBACKEND_InputProperties(
443-
in, &input_name, &input_dtype, &input_shape, &input_dims_count,
444-
&input_byte_size, &input_buffer_count));
439+
440+
RETURN_IF_ERROR(TRITONBACKEND_InputProperties(
441+
in, &input_name, &input_dtype, &input_shape, &input_dims_count,
442+
&input_byte_size, &input_buffer_count));
445443

446444
// Update input_tensor
447445
input_tensor->set_name(input_name);
@@ -458,18 +456,14 @@ ModelInstanceState::GetInputTensor(
458456
TRITONSERVER_MemoryType input_memory_type = TRITONSERVER_MEMORY_CPU;
459457
int64_t input_memory_type_id = 0;
460458
for (size_t j = 0; j < input_buffer_count; ++j) {
461-
GUARDED_RESPOND_IF_ERROR(
462-
responses, r,
463-
TRITONBACKEND_InputBuffer(
464-
in, j, &input_buffer, &buffer_byte_size, &input_memory_type,
465-
&input_memory_type_id));
466-
if ((responses[iidx] == nullptr) ||
467-
(input_memory_type == TRITONSERVER_MEMORY_GPU)) {
468-
GUARDED_RESPOND_IF_ERROR(
469-
responses, r,
470-
TRITONSERVER_ErrorNew(
471-
TRITONSERVER_ERROR_UNSUPPORTED,
472-
"failed to get input buffer in CPU memory"));
459+
RETURN_IF_ERROR(TRITONBACKEND_InputBuffer(
460+
in, j, &input_buffer, &buffer_byte_size, &input_memory_type,
461+
&input_memory_type_id));
462+
463+
if (input_memory_type == TRITONSERVER_MEMORY_GPU) {
464+
RETURN_IF_ERROR(TRITONSERVER_ErrorNew(
465+
TRITONSERVER_ERROR_UNSUPPORTED,
466+
"failed to get input buffer in CPU memory"));
473467
}
474468
data_buffer->append((const char*)input_buffer, buffer_byte_size);
475469
}
@@ -890,9 +884,17 @@ TRITONBACKEND_ModelInstanceExecute(
890884
response, &triton_output, python_output_result.name().c_str(),
891885
triton_dt, python_output_dims.data(), dims_count));
892886

893-
std::vector<int64_t> output_dims(
894-
python_output_dims.begin(), python_output_dims.end());
895-
int64_t output_byte_size = GetByteSize(triton_dt, output_dims);
887+
int64_t output_byte_size;
888+
889+
// Custom handling for TRITONSERVER_TYPE_BYTES
890+
if (triton_dt == TRITONSERVER_TYPE_BYTES) {
891+
output_byte_size = python_output_result.raw_data().size();
892+
} else {
893+
std::vector<int64_t> output_dims(
894+
python_output_dims.begin(), python_output_dims.end());
895+
output_byte_size = GetByteSize(triton_dt, output_dims);
896+
}
897+
896898
void* output_buffer;
897899

898900
TRITONSERVER_MemoryType output_memory_type = TRITONSERVER_MEMORY_CPU;

0 commit comments

Comments
 (0)