@@ -2477,58 +2477,33 @@ ModelInstanceState::SetStringInputBuffer(
2477
2477
std::vector<TRITONBACKEND_Response*>* responses, char * input_buffer,
2478
2478
std::vector<const char *>* string_ptrs)
2479
2479
{
2480
+ std::vector<std::pair<const char *, const uint32_t >> str_list;
2480
2481
// offset for each response
2481
2482
size_t buffer_copy_offset = 0 ;
2482
2483
for (size_t idx = 0 ; idx < expected_byte_sizes.size (); idx++) {
2483
2484
const size_t expected_byte_size = expected_byte_sizes[idx];
2484
2485
const size_t expected_element_cnt = expected_element_cnts[idx];
2485
2486
2486
- size_t element_cnt = 0 ;
2487
2487
if ((*responses)[idx] != nullptr ) {
2488
- size_t remaining_bytes = expected_byte_size;
2489
2488
char * data_content = input_buffer + buffer_copy_offset;
2490
- // Continue if the remaining bytes may still contain size info
2491
- while (remaining_bytes >= sizeof (uint32_t )) {
2492
- if (element_cnt >= expected_element_cnt) {
2493
- RESPOND_AND_SET_NULL_IF_ERROR (
2494
- &((*responses)[idx]),
2495
- TRITONSERVER_ErrorNew (
2496
- TRITONSERVER_ERROR_INVALID_ARG,
2497
- (std::string (" unexpected number of string elements " ) +
2498
- std::to_string (element_cnt + 1 ) + " for inference input '" +
2499
- input_name + " ', expecting " +
2500
- std::to_string (expected_element_cnt))
2501
- .c_str ()));
2502
- break ;
2503
- }
2504
-
2505
- const uint32_t len = *(reinterpret_cast <const uint32_t *>(data_content));
2506
- remaining_bytes -= sizeof (uint32_t );
2489
+ TRITONSERVER_Error* err = ValidateStringBuffer (
2490
+ data_content, expected_byte_size, expected_element_cnt,
2491
+ input_name.c_str (), &str_list);
2492
+ // Set string values.
2493
+ for (const auto & [addr, len] : str_list) {
2507
2494
// Make first byte of size info 0, so that if there is string data
2508
2495
// in front of it, the data becomes valid C string.
2509
- *data_content = 0 ;
2510
- data_content = data_content + sizeof (uint32_t );
2511
- if (len > remaining_bytes) {
2512
- RESPOND_AND_SET_NULL_IF_ERROR (
2513
- &((*responses)[idx]),
2514
- TRITONSERVER_ErrorNew (
2515
- TRITONSERVER_ERROR_INVALID_ARG,
2516
- (std::string (" incomplete string data for inference input '" ) +
2517
- input_name + " ', expecting string of length " +
2518
- std::to_string (len) + " but only " +
2519
- std::to_string (remaining_bytes) + " bytes available" )
2520
- .c_str ()));
2521
- break ;
2522
- } else {
2523
- string_ptrs->push_back (data_content);
2524
- element_cnt++;
2525
- data_content = data_content + len;
2526
- remaining_bytes -= len;
2527
- }
2496
+ *const_cast <char *>(addr - sizeof (uint32_t )) = 0 ;
2497
+ string_ptrs->push_back (addr);
2528
2498
}
2529
- }
2530
2499
2531
- FillStringData (string_ptrs, expected_element_cnt - element_cnt);
2500
+ size_t element_cnt = str_list.size ();
2501
+ if (err != nullptr ) {
2502
+ RESPOND_AND_SET_NULL_IF_ERROR (&((*responses)[idx]), err);
2503
+ FillStringData (string_ptrs, expected_element_cnt - element_cnt);
2504
+ }
2505
+ str_list.clear ();
2506
+ }
2532
2507
buffer_copy_offset += expected_byte_size;
2533
2508
}
2534
2509
}
0 commit comments