Skip to content

refactor: Use safer backend APIs #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/onnxruntime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2238,12 +2238,16 @@ ModelInstanceState::SetInputTensors(
TRITONBACKEND_RequestInput(requests[idx], input_name, &input));
const int64_t* input_shape;
uint32_t input_dims_count;
int64_t element_cnt = 0;
RESPOND_AND_SET_NULL_IF_ERROR(
&((*responses)[idx]), TRITONBACKEND_InputProperties(
input, nullptr, nullptr, &input_shape,
&input_dims_count, nullptr, nullptr));
RESPOND_AND_SET_NULL_IF_ERROR(
&((*responses)[idx]),
GetElementCount(input_shape, input_dims_count, &element_cnt));

batchn_shape[0] += GetElementCount(input_shape, input_dims_count);
batchn_shape[0] += element_cnt;
}
}
// The shape for the entire input batch, [total_batch_size, ...]
Expand Down Expand Up @@ -2402,8 +2406,10 @@ ModelInstanceState::SetStringInputTensor(
expected_byte_sizes.push_back(0);
expected_element_cnts.push_back(0);
} else {
expected_element_cnts.push_back(
GetElementCount(input_shape, input_dims_count));
int64_t element_cnt = 0;
RETURN_IF_ERROR(
GetElementCount(input_shape, input_dims_count, &element_cnt));
expected_element_cnts.push_back(element_cnt);
expected_byte_sizes.push_back(input_byte_size);
}

Expand Down Expand Up @@ -2573,8 +2579,9 @@ ModelInstanceState::ReadOutputTensor(
ONNXTensorElementDataType type;
RETURN_IF_ORT_ERROR(ort_api->GetTensorElementType(type_and_shape, &type));
if (type == ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING) {
const size_t element_count = GetElementCount(batchn_shape);
int64_t element_count = 0;
size_t total_length = 0;
RETURN_IF_ERROR(GetElementCount(batchn_shape, &element_count));
RETURN_IF_ORT_ERROR(
ort_api->GetStringTensorDataLength(output_tensor, &total_length));

Expand Down Expand Up @@ -2776,7 +2783,9 @@ ModelInstanceState::SetStringBuffer(
(*batchn_shape)[0] = shape[0];
}

const size_t expected_element_cnt = GetElementCount(*batchn_shape);
int64_t expected_element_cnt = 0;
RESPOND_AND_SET_NULL_IF_ERROR(
&response, GetElementCount(*batchn_shape, &expected_element_cnt));

// If 'request' requested this output then copy it from
// 'content'. If it did not request this output then just skip it
Expand Down
Loading