Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

Fix benchmark app empty device parsing (#38356)

Yug Shah72c577486315
diff --git a/samples/cpp/benchmark_app/utils.cpp b/samples/cpp/benchmark_app/utils.cpp
index 690ba600839..a79fe97f62f 100644
--- a/samples/cpp/benchmark_app/utils.cpp
+++ b/samples/cpp/benchmark_app/utils.cpp
@@ -173,6 +173,9 @@ std::vector<std::string> parse_devices(const std::string& device_string) {
auto devices = split(comma_separated_devices, ',');
for (auto&& device : devices) {
+ device = trim(device);
+ if (device.empty())
+ continue;
// e.g. in AUTO:-CPU,-GPU
if (device.front() == '-')
device.erase(device.begin());
diff --git a/tests/samples_tests/smoke_tests/test_benchmark_app.py b/tests/samples_tests/smoke_tests/test_benchmark_app.py
index c5423df8123..6098de693d1 100755
--- a/tests/samples_tests/smoke_tests/test_benchmark_app.py
+++ b/tests/samples_tests/smoke_tests/test_benchmark_app.py
@@ -21,6 +21,7 @@ import pathlib
import pytest
from common.samples_common_test_class import get_devices, get_cmd_output, prepend
from openvino import opset8 as opset
+from openvino.tools.benchmark.utils.utils import parse_devices
import openvino as ov
def get_executable(sample_language):
@@ -116,6 +117,11 @@ def verify(sample_language, device, api=None, nireq=None, shape=None, data_shape
def test_benchmark_app_help(sample_language):
get_cmd_output(get_executable(sample_language), '-h')
+def test_parse_devices_with_empty_entries():
+ assert parse_devices('MULTI:CPU,,GPU') == ['MULTI', 'CPU', 'GPU']
+ assert parse_devices('MULTI:CPU, ,GPU') == ['MULTI', 'CPU', 'GPU']
+ assert parse_devices('HETERO:CPU,') == ['HETERO', 'CPU']
+
@pytest.mark.parametrize('sample_language', ['C++', 'Python'])
@pytest.mark.parametrize('api', ['sync', 'async'])
diff --git a/tools/benchmark_tool/openvino/tools/benchmark/utils/utils.py b/tools/benchmark_tool/openvino/tools/benchmark/utils/utils.py
index 9ad22632b2d..8565ba095cd 100644
--- a/tools/benchmark_tool/openvino/tools/benchmark/utils/utils.py
+++ b/tools/benchmark_tool/openvino/tools/benchmark/utils/utils.py
@@ -290,6 +290,9 @@ def parse_devices(device_string):
if device_string.find(":") != -1:
hw_devices_str = device_string.partition(":")[-1]
for hw_device in hw_devices_str.split(','):
+ hw_device = hw_device.strip()
+ if not hw_device:
+ continue
if hw_device[0] == '-':
hw_device = hw_device[1:]
result.append(hw_device)