Skip to content
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

[PyOV] Fix segfault when constructing std::string and using GPU Plugin #26121

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

from functools import singledispatch
from typing import Any, Dict, Union, Optional
from typing import Any, Dict, Union, Optional, List

import numpy as np

Expand Down Expand Up @@ -41,6 +41,16 @@ def get_request_tensor(
raise TypeError(f"Unsupported key type: {type(key)} for Tensor under key: {key}")


def is_all_ascii(input_array: Union[np.ndarray, List[bytes]]) -> bool:
def isascii(data: Union[str, bytes]) -> bool:
if isinstance(data, bytes):
data = data.decode("utf-8")
return data.isascii()
v_isascii = np.vectorize(isascii)
ascii_flags = v_isascii(input_array)
return ascii_flags.all()


@singledispatch
def value_to_tensor(
value: Union[Tensor, np.ndarray, ScalarTypes, str],
Expand Down Expand Up @@ -321,7 +331,11 @@ def _(
tensor.shape = inputs.shape
# When copying, type should be up/down-casted automatically.
if tensor.element_type == Type.string:
tensor.bytes_data = inputs
# Edge case resolving assignment segfaults on GPU
if is_all_ascii(inputs) and inputs.dtype.char == "U" and inputs.flags["F_CONTIGUOUS"]:
tensor.bytes_data[:] = inputs[:]
else:
tensor.bytes_data = inputs
else:
tensor.data[:] = inputs[:]
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ def create_lookup_table_size_net(self, hash_table_type, keys_type, values_type,
@pytest.mark.nightly
def test_lookup_table_size(self, hash_table_type, params, ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
keys_type = params['keys_type']
if ie_device == 'GPU' and keys_type == str:
pytest.skip("148921: Segmentation fault on GPU")
self._test(*self.create_lookup_table_size_net(hash_table_type=hash_table_type, **params),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)
Loading