From 7b9f6c47b15e9adb17bb7773ecf03b0263865d2c Mon Sep 17 00:00:00 2001 From: "Wang, Yang" Date: Thu, 13 Jul 2023 01:09:25 +0000 Subject: [PATCH] [AUTO] AUTO can't fall back if target device throws the exception before compiling model via AUTO (#18311) * 1. Update AUTO candidate device filtering logic. 2. Add AUTO handling the exception logic when generating the target device infomation. Signed-off-by: Wang, Yang * Update. * Update. * Update. * Update. --------- Signed-off-by: Wang, Yang Co-authored-by: Chen Peter --- src/plugins/auto/src/plugin.cpp | 15 ++- .../auto/tests/unit/get_device_list.cpp | 3 + .../tests/unit/parse_meta_device_test.cpp | 105 +++++++++++------- 3 files changed, 79 insertions(+), 44 deletions(-) diff --git a/src/plugins/auto/src/plugin.cpp b/src/plugins/auto/src/plugin.cpp index 442bd57abf8..deec5477ecf 100644 --- a/src/plugins/auto/src/plugin.cpp +++ b/src/plugins/auto/src/plugin.cpp @@ -261,8 +261,19 @@ std::vector Plugin::parse_meta_devices(const std::string& pri LOG_DEBUG_TAG("deviceNameWithID:%s, defaultDeviceID:%s, uniqueName:%s", device_name_with_id.c_str(), default_device_id.c_str(), unique_name.c_str()); // create meta device - meta_devices.push_back({device_name_with_id, get_device_config(device_name_with_id), - num_requests, default_device_id, unique_name, device_priority}); + try { + meta_devices.push_back({device_name_with_id, + get_device_config(device_name_with_id), + num_requests, + default_device_id, + unique_name, + device_priority}); + } catch (const ov::Exception&) { + LOG_DEBUG_TAG("Failed to create meta device for deviceNameWithID:%s, defaultDeviceID:%s, uniqueName:%s", + device_name_with_id.c_str(), + default_device_id.c_str(), + unique_name.c_str()); + } } if (enable_device_priority) { device_priority++; diff --git a/src/plugins/auto/tests/unit/get_device_list.cpp b/src/plugins/auto/tests/unit/get_device_list.cpp index 26a316a1aae..c7eb8fa8e81 100644 --- a/src/plugins/auto/tests/unit/get_device_list.cpp +++ b/src/plugins/auto/tests/unit/get_device_list.cpp @@ -133,7 +133,10 @@ const std::vector testConfigs = {Params{" ", " "}, Params{"CPU,GPU.1,GPU", "CPU,GPU.1,GPU"}, Params{"CPU,VPUX", "CPU,VPUX"}, Params{"CPU,-VPUX", "CPU"}, + Params{"INVALID_DEVICE", "INVALID_DEVICE"}, Params{"CPU,-INVALID_DEVICE", "CPU"}, + Params{"CPU,INVALID_DEVICE", "CPU,INVALID_DEVICE"}, + Params{"-CPU,INVALID_DEVICE", "INVALID_DEVICE"}, Params{"CPU,GPU,VPUX", "CPU,GPU,VPUX"}}; const std::vector testConfigsWithIdNotInteldGPU = {Params{" ", " "}, diff --git a/src/plugins/auto/tests/unit/parse_meta_device_test.cpp b/src/plugins/auto/tests/unit/parse_meta_device_test.cpp index f6df697f30f..f79a1695ec0 100644 --- a/src/plugins/auto/tests/unit/parse_meta_device_test.cpp +++ b/src/plugins/auto/tests/unit/parse_meta_device_test.cpp @@ -6,22 +6,24 @@ using namespace ov::mock_auto_plugin; using Config = std::map; +using testing::Throw; const char igpuFullDeviceName[] = "Intel(R) Gen9 HD Graphics (iGPU)"; const char dgpuFullDeviceName[] = "Intel(R) Iris(R) Xe MAX Graphics (dGPU)"; const std::vector availableDevsNoID = {"CPU", "GPU", "VPUX"}; -using ConfigParams = std::tuple< - std::string, // Priority devices - std::vector, // expect metaDevices - bool // if throw exception - >; +using ConfigParams = std::tuple, // expect metaDevices + bool, // if throw exception + int // expected times of calling get_supported_property() + >; class ParseMetaDeviceTest : public tests::AutoTest, public ::testing::TestWithParam { public: static std::string getTestCaseName(testing::TestParamInfo obj) { std::string priorityDevices; std::vector metaDevices; bool throwException; - std::tie(priorityDevices, metaDevices, throwException) = obj.param; + int expectedTimes; + std::tie(priorityDevices, metaDevices, throwException, expectedTimes) = obj.param; std::ostringstream result; result << "priorityDevices_" << priorityDevices; if (throwException) { @@ -29,16 +31,17 @@ public: } else { result << "_throwException_false"; } + result << "_expectedGetSupportedProperty_" << expectedTimes; return result.str(); } void SetUp() override { + ON_CALL(*core, get_supported_property(StrEq("INVALID_DEVICE"), _)).WillByDefault(Throw(ov::Exception(""))); ON_CALL(*plugin, parse_meta_devices).WillByDefault([this](const std::string& priorityDevices, const ov::AnyMap& config) { return plugin->Plugin::parse_meta_devices(priorityDevices, config); }); - std::tie(priorityDevices, metaDevices, throwException) = GetParam(); - sizeOfMetaDevices = static_cast(metaDevices.size()); + std::tie(priorityDevices, metaDevices, throwException, expectedTimes) = GetParam(); } void compare(std::vector& result, std::vector& expect) { @@ -67,7 +70,7 @@ protected: std::string priorityDevices; std::vector metaDevices; bool throwException; - int sizeOfMetaDevices; + int expectedTimes; }; using ParseMetaDeviceNoIDTest = ParseMetaDeviceTest; @@ -75,7 +78,7 @@ TEST_P(ParseMetaDeviceTest, ParseMetaDevicesWithPriority) { EXPECT_CALL(*plugin, parse_meta_devices(_, _)).Times(1); EXPECT_CALL(*core, get_property(_, _, _)).Times(AnyNumber()); EXPECT_CALL(*core, get_available_devices()).Times(1); - EXPECT_CALL(*core, get_supported_property(_, _)).Times(sizeOfMetaDevices); + EXPECT_CALL(*core, get_supported_property(_, _)).Times(expectedTimes); if (throwException) { ASSERT_ANY_THROW(plugin->parse_meta_devices(priorityDevices, {})); } else { @@ -110,7 +113,7 @@ TEST_P(ParseMetaDeviceNoIDTest, ParseMetaDevices) { EXPECT_CALL(*plugin, parse_meta_devices(_, _)).Times(1); EXPECT_CALL(*core, get_property(_, _, _)).Times(AnyNumber()); EXPECT_CALL(*core, get_available_devices()).Times(1); - EXPECT_CALL(*core, get_supported_property(_, _)).Times(sizeOfMetaDevices); + EXPECT_CALL(*core, get_supported_property(_, _)).Times(expectedTimes); if (throwException) { ASSERT_ANY_THROW(plugin->parse_meta_devices(priorityDevices, {})); } else { @@ -124,43 +127,61 @@ TEST_P(ParseMetaDeviceNoIDTest, ParseMetaDevices) { // ConfigParams {devicePriority, expect metaDevices, ifThrowException} const std::vector testConfigs = { - ConfigParams {"CPU,GPU,VPUX", - {{"CPU", {}, -1, "", "CPU_", 0}, - {"GPU.0", {}, -1, "", std::string(igpuFullDeviceName) + "_0", 1}, - {"GPU.1", {}, -1, "", std::string(dgpuFullDeviceName) + "_1", 1}, - {"VPUX", {}, -1, "", "VPUX_", 2}}, false}, - ConfigParams {"VPUX,GPU,CPU", - {{"VPUX", {}, -1, "", "VPUX_", 0}, - {"GPU.0", {}, -1, "", std::string(igpuFullDeviceName) + "_0", 1}, - {"GPU.1", {}, -1, "", std::string(dgpuFullDeviceName) + "_1", 1}, - {"CPU", {}, -1, "", "CPU_", 2}}, false}, - ConfigParams {"CPU(1),GPU(2),VPUX(4)", - {{"CPU", {}, 1, "", "CPU_", 0}, - {"GPU.0", {}, 2, "", std::string(igpuFullDeviceName) + "_0", 1}, - {"GPU.1", {}, 2, "", std::string(dgpuFullDeviceName) + "_1", 1}, - {"VPUX", {}, 4, "", "VPUX_", 2}}, false}, + ConfigParams{"CPU,GPU,VPUX", + {{"CPU", {}, -1, "", "CPU_", 0}, + {"GPU.0", {}, -1, "", std::string(igpuFullDeviceName) + "_0", 1}, + {"GPU.1", {}, -1, "", std::string(dgpuFullDeviceName) + "_1", 1}, + {"VPUX", {}, -1, "", "VPUX_", 2}}, + false, + 4}, + ConfigParams{"VPUX,GPU,CPU", + {{"VPUX", {}, -1, "", "VPUX_", 0}, + {"GPU.0", {}, -1, "", std::string(igpuFullDeviceName) + "_0", 1}, + {"GPU.1", {}, -1, "", std::string(dgpuFullDeviceName) + "_1", 1}, + {"CPU", {}, -1, "", "CPU_", 2}}, + false, + 4}, + ConfigParams{"VPUX,GPU,INVALID_DEVICE", + {{"VPUX", {}, -1, "", "VPUX_", 0}, + {"GPU.0", {}, -1, "", std::string(igpuFullDeviceName) + "_0", 1}, + {"GPU.1", {}, -1, "", std::string(dgpuFullDeviceName) + "_1", 1}}, + false, + 3}, + ConfigParams{"CPU(1),GPU(2),VPUX(4)", + {{"CPU", {}, 1, "", "CPU_", 0}, + {"GPU.0", {}, 2, "", std::string(igpuFullDeviceName) + "_0", 1}, + {"GPU.1", {}, 2, "", std::string(dgpuFullDeviceName) + "_1", 1}, + {"VPUX", {}, 4, "", "VPUX_", 2}}, + false, + 4}, - ConfigParams {"CPU(-1),GPU,VPUX", {}, true}, - ConfigParams {"CPU(NA),GPU,VPUX", {}, true}, + ConfigParams{"CPU(-1),GPU,VPUX", {}, true, 0}, + ConfigParams{"CPU(NA),GPU,VPUX", {}, true, 0}, + ConfigParams{"INVALID_DEVICE", {}, false, 0}, + ConfigParams{"INVALID_DEVICE,CPU", {{"CPU", {}, -1, "", "CPU_", 1}}, false, 2}, - ConfigParams {"CPU(3),GPU.1,VPUX", - {{"CPU", {}, 3, "", "CPU_", 0}, - {"GPU.1", {}, -1, "", std::string(dgpuFullDeviceName) + "_1", 1}, - {"VPUX", {}, -1, "", "VPUX_", 2}}, false}, - ConfigParams {"VPUX,GPU.1,CPU(3)", - {{"VPUX", {}, -1, "", "VPUX_", 0}, - {"GPU.1", {}, -1, "", std::string(dgpuFullDeviceName) + "_1", 1}, - {"CPU", {}, 3, "", "CPU_", 2}}, false} -}; + ConfigParams{"CPU(3),GPU.1,VPUX", + {{"CPU", {}, 3, "", "CPU_", 0}, + {"GPU.1", {}, -1, "", std::string(dgpuFullDeviceName) + "_1", 1}, + {"VPUX", {}, -1, "", "VPUX_", 2}}, + false, + 3}, + ConfigParams{"VPUX,GPU.1,CPU(3)", + {{"VPUX", {}, -1, "", "VPUX_", 0}, + {"GPU.1", {}, -1, "", std::string(dgpuFullDeviceName) + "_1", 1}, + {"CPU", {}, 3, "", "CPU_", 2}}, + false, + 3}}; const std::vector testConfigsNoID = { - ConfigParams {"CPU,GPU,VPUX", - {{"CPU", {}, -1, "", "CPU_", 0}, - {"GPU", {}, -1, "0", std::string(igpuFullDeviceName) + "_0", 1}, - {"VPUX", {}, -1, "", "VPUX_", 2}}, false}, + ConfigParams{"CPU,GPU,VPUX", + {{"CPU", {}, -1, "", "CPU_", 0}, + {"GPU", {}, -1, "0", std::string(igpuFullDeviceName) + "_0", 1}, + {"VPUX", {}, -1, "", "VPUX_", 2}}, + false, + 3}, }; - INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, ParseMetaDeviceTest, ::testing::ValuesIn(testConfigs), ParseMetaDeviceTest::getTestCaseName);