Skip to content

Commit

Permalink
[GPU] Initialize string type data with zero-charactor
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsnam-intel committed Oct 29, 2024
1 parent c2e4046 commit a39b4ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/bindings/python/src/pyopenvino/core/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,15 @@ void fill_tensor_from_strings(ov::Tensor& tensor, py::array& array) {
}
py::buffer_info buf = array.request();
auto data = tensor.data<std::string>();
std::cout << "fill_tensor_from_strings()" << std::endl;
for (size_t i = 0; i < tensor.get_size(); ++i) {
char* ptr = reinterpret_cast<char*>(buf.ptr) + (i * buf.itemsize);
// TODO: check other unicode kinds? 2BYTE and 1BYTE?
PyObject* _unicode_obj =
PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, reinterpret_cast<void*>(ptr), buf.itemsize / 4);
PyObject* _utf8_obj = PyUnicode_AsUTF8String(_unicode_obj);
const char* _tmp_str = PyBytes_AsString(_utf8_obj);
std::string d(_tmp_str);
if (!d.empty()) {
data[i] = d;
}
data[i] = std::string(_tmp_str);
Py_XDECREF(_unicode_obj);
Py_XDECREF(_utf8_obj);
}
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/intel_gpu/src/plugin/sync_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,12 @@ void SyncInferRequest::allocate_input(const ov::Output<const ov::Node>& port, si
auto element_type = port.get_element_type();

m_user_inputs[input_idx] = { create_host_tensor(shape, element_type), TensorOwner::PLUGIN };
if (element_type == ov::element::string) {
std::string* data = m_user_inputs.at(input_idx).ptr->data<std::string>();
for (size_t i = 0; i < m_user_inputs.at(input_idx).ptr->get_size(); ++i) {
data[i] = '\0';
}
}
ov::ISyncInferRequest::set_tensor(port, m_user_inputs.at(input_idx).ptr);
}

Expand Down

0 comments on commit a39b4ab

Please sign in to comment.