Skip to content

Commit d7f47aa

Browse files
WeldonWangwangpeterchen-intelriverlijunjie
authored
Provide ENABLE_STARTUP_FALLBACK property to enable/disable CPU as acc… (#14503)
* Provide ENABLE_STARTUP_FALLBACK property to enable/disable CPU as acceleration * Add more test cases to ENABLE_STARTUP_FALLBACK property * Remove unnecessary config * Remove plugin.hpp * Update test case by PR#14754 * Update copyright Co-authored-by: River Li <[email protected]> * Simplify using namespace --------- Co-authored-by: Chen Peter <[email protected]> Co-authored-by: River Li <[email protected]>
1 parent 8292575 commit d7f47aa

File tree

8 files changed

+181
-5
lines changed

8 files changed

+181
-5
lines changed

src/inference/include/openvino/runtime/auto/properties.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@ namespace intel_auto {
1818
*/
1919
static constexpr Property<bool> device_bind_buffer{"DEVICE_BIND_BUFFER"};
2020

21+
/**
22+
* @brief auto/multi device setting that enable/disable CPU as acceleration (or helper device) at the beginning
23+
*/
24+
static constexpr Property<bool> enable_startup_fallback{"ENABLE_STARTUP_FALLBACK"};
25+
2126
} // namespace intel_auto
2227
} // namespace ov

src/plugins/auto/auto_schedule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void AutoSchedule::init(const ScheduleContext::Ptr& sContext) {
160160
bool isActualDevCPU =
161161
_loadContext[ACTUALDEVICE].deviceInfo.deviceName.find("CPU") !=std::string::npos && !isCumulative;
162162
// if Actual device is CPU or perf_hint is cumulative, disabled _loadContext[CPU], only use _loadContext[ACTUALDEVICE]
163-
if (isActualDevCPU || isCumulative) {
163+
if (isActualDevCPU || isCumulative || !_autoSContext->_startupfallback) {
164164
_loadContext[CPU].isEnabled = false;
165165
} else {
166166
const auto CPUIter = std::find_if(_autoSContext->_devicePriorities.begin(), _autoSContext->_devicePriorities.end(),

src/plugins/auto/common.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class MultiScheduleContext : public ScheduleContext {
123123
bool _needPerfCounters;
124124
bool _batchingDisabled = {false};
125125
bool _bindBuffer = false;
126+
bool _startupfallback = true;
126127
virtual ~MultiScheduleContext() = default;
127128
};
128129

src/plugins/auto/plugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ InferenceEngine::Parameter MultiDeviceInferencePlugin::GetConfig(const std::stri
246246
return ov::util::from_string(val, ov::log::level);
247247
} else if (name == ov::device::priorities) {
248248
return ov::util::from_string(val, ov::device::priorities);
249+
} else if (name == ov::intel_auto::enable_startup_fallback) {
250+
return val == PluginConfigParams::YES ? true : false;
249251
} else {
250252
return val;
251253
}
@@ -453,6 +455,9 @@ IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadNetworkImpl(cons
453455
auto tmpiter = fullConfig.find(ov::intel_auto::device_bind_buffer.name());
454456
if (tmpiter != fullConfig.end() && tmpiter->second == PluginConfigParams::YES)
455457
autoSContext->_bindBuffer = true;
458+
auto tmpiter_enableStartupFallback = fullConfig.find(ov::intel_auto::enable_startup_fallback.name());
459+
if (tmpiter_enableStartupFallback != fullConfig.end() && tmpiter_enableStartupFallback->second == PluginConfigParams::NO)
460+
autoSContext->_startupfallback = false;
456461
return std::make_shared<AutoExecutableNetwork>(autoSContext, std::make_shared<AutoSchedule>());
457462
}
458463
OV_ITT_SCOPED_TASK(itt::domains::MULTIPlugin, "MultiDeviceInferencePlugin::LoadNetworkImpl:MultiMode");

src/plugins/auto/utils/config.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct PluginConfig {
2424
_devicePriority(""),
2525
_modelPriority(1),
2626
_deviceBindBuffer(false),
27+
_enableStartupFallback(true),
2728
_logLevel("LOG_NONE") {
2829
adjustKeyMapValues();
2930
}
@@ -38,6 +39,7 @@ struct PluginConfig {
3839
res.push_back(ov::log::level.name());
3940
res.push_back(ov::intel_auto::device_bind_buffer.name());
4041
res.push_back(ov::auto_batch_timeout.name());
42+
res.push_back(ov::intel_auto::enable_startup_fallback.name());
4143
return res;
4244
}();
4345
auto multi_supported_configKeys = supported_configKeys;
@@ -65,7 +67,8 @@ struct PluginConfig {
6567
RW_property(ov::hint::performance_mode.name()),
6668
RW_property(ov::hint::num_requests.name()),
6769
RW_property(ov::intel_auto::device_bind_buffer.name()),
68-
RW_property(ov::cache_dir.name())};
70+
RW_property(ov::cache_dir.name()),
71+
RW_property(ov::intel_auto::enable_startup_fallback.name())};
6972
std::vector<ov::PropertyName> supportedProperties;
7073
supportedProperties.reserve(roProperties.size() + rwProperties.size());
7174
supportedProperties.insert(supportedProperties.end(), roProperties.begin(), roProperties.end());
@@ -178,6 +181,12 @@ struct PluginConfig {
178181
} else if (kvp.first == ov::cache_dir.name()) {
179182
_cacheDir = kvp.second;
180183
_isSetCacheDir = true;
184+
} else if (kvp.first == ov::intel_auto::enable_startup_fallback.name()) {
185+
if (kvp.second == PluginConfigParams::YES) _enableStartupFallback = true;
186+
else if (kvp.second == PluginConfigParams::NO) _enableStartupFallback = false;
187+
else
188+
IE_THROW() << "Unsupported config value: " << kvp.second
189+
<< " for key: " << kvp.first;
181190
} else {
182191
if (pluginName.find("AUTO") != std::string::npos || !supportHWProprety)
183192
// AUTO and MULTI just only accept its own properites and secondary property when calling
@@ -261,7 +270,10 @@ struct PluginConfig {
261270
_keyConfigMap[ov::intel_auto::device_bind_buffer.name()] = PluginConfigParams::YES;
262271
else
263272
_keyConfigMap[ov::intel_auto::device_bind_buffer.name()] = PluginConfigParams::NO;
264-
273+
if (_enableStartupFallback)
274+
_keyConfigMap[ov::intel_auto::enable_startup_fallback.name()] = PluginConfigParams::YES;
275+
else
276+
_keyConfigMap[ov::intel_auto::enable_startup_fallback.name()] = PluginConfigParams::NO;
265277
_keyConfigMap[ov::auto_batch_timeout.name()] = _batchTimeout;
266278

267279
_keyConfigMap[ov::log::level.name()] = _logLevel;
@@ -281,6 +293,7 @@ struct PluginConfig {
281293
std::string _devicePriority;
282294
int _modelPriority;
283295
bool _deviceBindBuffer;
296+
bool _enableStartupFallback;
284297
std::string _logLevel;
285298
PerfHintsConfig _perfHintsConfig;
286299
// Add this flag to check if user app sets hint with none value that is equal to the default value of hint.

src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ const std::vector<ov::AnyMap> multi_Auto_properties = {
2828
{ov::device::priorities(CommonTestUtils::DEVICE_CPU), ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY)},
2929
{ov::device::priorities(CommonTestUtils::DEVICE_CPU), ov::hint::performance_mode(ov::hint::PerformanceMode::CUMULATIVE_THROUGHPUT)},
3030
{ov::device::priorities(CommonTestUtils::DEVICE_CPU), ov::intel_auto::device_bind_buffer("YES")},
31-
{ov::device::priorities(CommonTestUtils::DEVICE_CPU), ov::intel_auto::device_bind_buffer("NO")}
31+
{ov::device::priorities(CommonTestUtils::DEVICE_CPU), ov::intel_auto::device_bind_buffer("NO")},
32+
{ov::device::priorities(CommonTestUtils::DEVICE_CPU), ov::intel_auto::enable_startup_fallback("YES")},
33+
{ov::device::priorities(CommonTestUtils::DEVICE_CPU), ov::intel_auto::enable_startup_fallback("NO")}
3234
};
3335

3436
INSTANTIATE_TEST_SUITE_P(smoke_AutoMultiBehaviorTests, OVPropertiesTests,
@@ -81,6 +83,7 @@ const std::vector<ov::AnyMap> default_properties = {
8183
{ov::hint::allow_auto_batching(true)},
8284
{ov::auto_batch_timeout("1000")},
8385
{ov::intel_auto::device_bind_buffer(false)},
86+
{ov::intel_auto::enable_startup_fallback(true)},
8487
{ov::device::priorities("")}
8588
};
8689
INSTANTIATE_TEST_SUITE_P(smoke_AutoBehaviorTests, OVPropertiesDefaultTests,

src/tests/functional/plugin/gpu/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ auto auto_multi_properties = []() {
3333
{ov::device::priorities(CommonTestUtils::DEVICE_GPU),
3434
ov::hint::performance_mode(ov::hint::PerformanceMode::CUMULATIVE_THROUGHPUT)},
3535
{ov::device::priorities(CommonTestUtils::DEVICE_GPU), ov::intel_auto::device_bind_buffer("YES")},
36-
{ov::device::priorities(CommonTestUtils::DEVICE_GPU), ov::intel_auto::device_bind_buffer("NO")}};
36+
{ov::device::priorities(CommonTestUtils::DEVICE_GPU), ov::intel_auto::device_bind_buffer("NO")},
37+
{ov::device::priorities(CommonTestUtils::DEVICE_GPU), ov::intel_auto::enable_startup_fallback("YES")},
38+
{ov::device::priorities(CommonTestUtils::DEVICE_GPU), ov::intel_auto::enable_startup_fallback("NO")}};
3739
};
3840

3941
const std::vector<ov::AnyMap> multi_properties = {
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// Copyright (C) 2018-2023 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include <ie_metric_helpers.hpp>
6+
#include <common_test_utils/test_constants.hpp>
7+
#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_icore.hpp"
8+
#include "unit_test_utils/mocks/mock_iinfer_request.hpp"
9+
#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_inference_plugin_internal.hpp"
10+
#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp"
11+
#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_ivariable_state_internal.hpp"
12+
#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp"
13+
#include <ie_core.hpp>
14+
#include <multi-device/multi_device_config.hpp>
15+
#include <ngraph_functions/subgraph_builders.hpp>
16+
#include <gtest/gtest.h>
17+
#include <gmock/gmock.h>
18+
#include "plugin/mock_auto_device_plugin.hpp"
19+
#include "mock_common.hpp"
20+
#include <thread>
21+
22+
using ::testing::_;
23+
using ::testing::StrEq;
24+
using ::testing::Return;
25+
using ::testing::NiceMock;
26+
using Config = std::map<std::string, std::string>;
27+
using namespace MockMultiDevice;
28+
29+
using ConfigParams = std::tuple<bool,
30+
Config>;
31+
32+
// define a matcher if all the elements of subMap are contained in the map.
33+
MATCHER_P(MapContains, subMap, "Check if all the elements of the subMap are contained in the map.") {
34+
if (subMap.empty())
35+
return true;
36+
for (auto& item : subMap) {
37+
auto key = item.first;
38+
auto value = item.second;
39+
auto dest = arg.find(key);
40+
if (dest == arg.end()) {
41+
return false;
42+
} else if (dest->second != value) {
43+
return false;
44+
}
45+
}
46+
return true;
47+
}
48+
class AutoStartupFallback : public ::testing::TestWithParam<ConfigParams> {
49+
public:
50+
std::shared_ptr<ngraph::Function> function;
51+
InferenceEngine::CNNNetwork cnnNet;
52+
std::shared_ptr<NiceMock<MockICore>> core;
53+
std::shared_ptr<NiceMock<MockMultiDeviceInferencePlugin>> plugin;
54+
55+
//mock exeNetwork helper
56+
ov::SoPtr<IExecutableNetworkInternal> mockExeNetwork;
57+
// config for Auto device
58+
std::map<std::string, std::string> config;
59+
std::vector<DeviceInformation> metaDevices;
60+
std::shared_ptr<NiceMock<MockIInferRequestInternal>> inferReqInternal;
61+
size_t optimalNum;
62+
63+
public:
64+
void TearDown() override {
65+
core.reset();
66+
plugin.reset();
67+
//mockIExeNet.reset();
68+
mockExeNetwork = {};
69+
config.clear();
70+
metaDevices.clear();
71+
inferReqInternal.reset();
72+
}
73+
74+
void SetUp() override {
75+
// prepare mockExeNetwork
76+
auto mockIExeNet = std::make_shared<NiceMock<MockIExecutableNetworkInternal>>();
77+
mockExeNetwork = {mockIExeNet, {}};
78+
// prepare mockicore and cnnNetwork for loading
79+
core = std::make_shared<NiceMock<MockICore>>();
80+
NiceMock<MockMultiDeviceInferencePlugin>* mock_multi = new NiceMock<MockMultiDeviceInferencePlugin>();
81+
plugin.reset(mock_multi);
82+
function = ngraph::builder::subgraph::makeConvPoolRelu();
83+
cnnNet = InferenceEngine::CNNNetwork(function);
84+
// replace core with mock Icore
85+
plugin->SetCore(core);
86+
// mock execNetwork can work
87+
inferReqInternal = std::make_shared<NiceMock<MockIInferRequestInternal>>();
88+
ON_CALL(*mockIExeNet.get(), CreateInferRequest()).WillByDefault(Return(inferReqInternal));
89+
IE_SET_METRIC(OPTIMAL_NUMBER_OF_INFER_REQUESTS, optimalNum, 1);
90+
ON_CALL(*mockIExeNet.get(), GetMetric(StrEq(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS))))
91+
.WillByDefault(Return(optimalNum));
92+
IE_SET_METRIC(SUPPORTED_CONFIG_KEYS, supportConfigs, {});
93+
ON_CALL(*core, GetMetric(_, StrEq(METRIC_KEY(SUPPORTED_CONFIG_KEYS)), _))
94+
.WillByDefault(Return(supportConfigs));
95+
ON_CALL(*core, GetConfig(_, StrEq(GPU_CONFIG_KEY(MAX_NUM_THREADS))))
96+
.WillByDefault(Return(12));
97+
}
98+
};
99+
100+
TEST_P(AutoStartupFallback, releaseResource) {
101+
// get Parameter
102+
bool startup_fallback;
103+
Config config;
104+
std::tie(startup_fallback, config) = this->GetParam();
105+
// test auto plugin
106+
plugin->SetName("AUTO");
107+
108+
ON_CALL(*core, LoadNetwork(::testing::Matcher<const InferenceEngine::CNNNetwork&>(_),
109+
::testing::Matcher<const std::string&>(_),
110+
::testing::Matcher<const Config&>(_))).WillByDefault(Return(mockExeNetwork));
111+
112+
metaDevices = {{CommonTestUtils::DEVICE_CPU, {}, -1}, {CommonTestUtils::DEVICE_GPU, {}, -1}};
113+
// DeviceInformation devInfo;
114+
ON_CALL(*plugin, ParseMetaDevices(_, _)).WillByDefault(Return(metaDevices));
115+
ON_CALL(*plugin, GetValidDevice)
116+
.WillByDefault([this](const std::vector<DeviceInformation>& metaDevices, const std::string& netPrecision) {
117+
std::list<DeviceInformation> devices(metaDevices.begin(), metaDevices.end());
118+
return devices;
119+
});
120+
ON_CALL(*plugin, SelectDevice(_, _, _)).WillByDefault(Return(metaDevices[1]));
121+
122+
EXPECT_CALL(
123+
*core,
124+
LoadNetwork(::testing::Matcher<const InferenceEngine::CNNNetwork&>(_),
125+
::testing::Matcher<const std::string&>(CommonTestUtils::DEVICE_GPU),
126+
::testing::Matcher<const std::map<std::string, std::string>&>(_)))
127+
.Times(1);
128+
if (startup_fallback) {
129+
std::map<std::string, std::string> test_map = {{"PERFORMANCE_HINT", "LATENCY"}};
130+
EXPECT_CALL(
131+
*core,
132+
LoadNetwork(::testing::Matcher<const InferenceEngine::CNNNetwork&>(_),
133+
::testing::Matcher<const std::string&>(CommonTestUtils::DEVICE_CPU),
134+
::testing::Matcher<const std::map<std::string, std::string>&>(MapContains(test_map))))
135+
.Times(1);
136+
}
137+
138+
ASSERT_NO_THROW(plugin->LoadExeNetworkImpl(cnnNet, config));
139+
}
140+
141+
const std::vector<ConfigParams> testConfigs = {ConfigParams {true, {{"ENABLE_STARTUP_FALLBACK", "YES"}}},
142+
ConfigParams {false, {{"ENABLE_STARTUP_FALLBACK", "NO"}}}
143+
};
144+
145+
INSTANTIATE_TEST_SUITE_P(smoke_Auto_StartupFallback,
146+
AutoStartupFallback,
147+
::testing::ValuesIn(testConfigs));

0 commit comments

Comments
 (0)