-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Enable CPU accelerate FIL in MULTI #7380
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,34 +219,50 @@ IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadNetworkImpl(cons | |
bool workModeAuto = workMode != fullConfig.end() && workMode->second == InferenceEngine::PluginConfigParams::YES; | ||
auto priorities = fullConfig.find(MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES); | ||
|
||
// not found device priorities for -d AUTO use case | ||
if (priorities == fullConfig.end()) { | ||
if (workModeAuto) { | ||
std::string allDevices; | ||
auto availableDevices = GetCore()->GetAvailableDevices(); | ||
if (availableDevices.empty()) { | ||
IE_THROW(NotFound) << "No available device found"; | ||
} | ||
for (auto&& device : availableDevices) { | ||
allDevices += device; | ||
allDevices += ((device == availableDevices[availableDevices.size()-1]) ? "" : ","); | ||
} | ||
metaDevices = ParseMetaDevices(allDevices, fullConfig); | ||
multiNetworkConfig.insert({MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, allDevices}); | ||
} else { | ||
IE_THROW() << "KEY_MULTI_DEVICE_PRIORITIES key is not set for " << GetName() << " device"; | ||
// if workMode is AUTO | ||
if (workModeAuto) { | ||
// check the configure and check if need to set PerfCounters configure to device | ||
// and set filter configure | ||
bool needPerfCounters = false; | ||
std::map<std::string, std::string> filterConfig; | ||
CheckConfig(fullConfig, needPerfCounters, filterConfig); | ||
// filter the device that supports filter configure | ||
auto strDevices = GetDeviceList(fullConfig); | ||
auto metaDevices = ParseMetaDevices(strDevices, fullConfig); | ||
auto supportDevices = FilterDevice(metaDevices, filterConfig); | ||
if (supportDevices.size() == 0) { | ||
IE_THROW() << "there is no device support the configure"; | ||
} | ||
// replace the configure with configure that auto want to pass to device | ||
// and reset the strDevices to support devices | ||
std::vector<std::string> validConfigKey; | ||
validConfigKey.push_back(PluginConfigParams::KEY_PERF_COUNT); | ||
validConfigKey.push_back(PluginConfigParams::KEY_EXCLUSIVE_ASYNC_REQUESTS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor comment: I assume this ASYNC_REQUESTS config key is only needed becuase OV has legacy impl and tests for that. but not sure of new devices like VPUX will support that, as the mode that is triggered by this key is obslolete. So let's check that this checking this (evetually useless) config capability doesn't prevent us form using new devices like CUDA and KMB, and if this is the case- will need to remove maybe in the next PR |
||
validConfigKey.push_back(PluginConfigParams::KEY_PERFORMANCE_HINT); | ||
validConfigKey.push_back(PluginConfigParams::KEY_PERFORMANCE_HINT_NUM_REQUESTS); | ||
strDevices = ""; | ||
for (auto iter = supportDevices.begin(); iter != supportDevices.end(); iter++) { | ||
std::map<std::string, std::string> deviceConfig; | ||
auto& configs = iter->config; | ||
for (auto& config : configs) { | ||
if (std::find(validConfigKey.begin(), validConfigKey.end(), config.first) != validConfigKey.end()) { | ||
deviceConfig.insert({config.first, config.second}); | ||
} | ||
} | ||
iter->config = deviceConfig; | ||
strDevices = iter->deviceName; | ||
strDevices += ((iter + 1) == supportDevices.end()) ? "" : ","; | ||
} | ||
|
||
return std::make_shared<MultiDeviceExecutableNetwork>(modelPath, network, supportDevices, strDevices, this, needPerfCounters); | ||
} | ||
|
||
if (priorities == fullConfig.end()) { | ||
IE_THROW() << "KEY_MULTI_DEVICE_PRIORITIES key is not set for " << GetName() << " device"; | ||
} else { // for use case -d MULTI:xPU or -d AUTO:xPU | ||
metaDevices = ParseMetaDevices(priorities->second, fullConfig); | ||
multiNetworkConfig.insert(*priorities); | ||
} | ||
// check if it is -d AUTO or -d AUTO:xPU use case | ||
if (workModeAuto) { | ||
// select the device | ||
auto device = SelectDevice(metaDevices, networkPrecision).deviceName; | ||
// parse the config for the device | ||
metaDevices = ParseMetaDevices(SelectDevice(metaDevices, networkPrecision).deviceName, fullConfig); | ||
} | ||
|
||
DeviceMap<SoExecutableNetworkInternal> executableNetworkPerDevice; | ||
std::mutex load_mutex; | ||
|
@@ -345,7 +361,6 @@ QueryNetworkResult MultiDeviceInferencePlugin::QueryNetwork(const CNNNetwork& | |
return queryResult; | ||
} | ||
|
||
|
||
DeviceInformation MultiDeviceInferencePlugin::SelectDevice(const std::vector<DeviceInformation>& metaDevices, const std::string& networkPrecision) { | ||
if (metaDevices.empty()) { | ||
IE_THROW(NotFound) << "No available device to select in " << GetName() << " plugin"; | ||
|
@@ -466,4 +481,94 @@ DeviceInformation MultiDeviceInferencePlugin::SelectDevice(const std::vector<Dev | |
return CPU[0]; | ||
} | ||
|
||
std::string MultiDeviceInferencePlugin::GetDeviceList(const std::map<std::string, std::string>& config) const { | ||
std::string allDevices; | ||
|
||
auto deviceListConfig = config.find(MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES); | ||
if (deviceListConfig == config.end()) { | ||
auto deviceList = GetCore()->GetAvailableDevices(); | ||
for (auto&& device : deviceList) { | ||
allDevices += device; | ||
allDevices += ((device == deviceList[deviceList.size()-1]) ? "" : ","); | ||
} | ||
} else { | ||
allDevices = deviceListConfig->second; | ||
} | ||
|
||
if (allDevices.empty()) { | ||
IE_THROW() << "Please, check environment due to no supported devices can be used"; | ||
} | ||
|
||
return allDevices; | ||
} | ||
|
||
void MultiDeviceInferencePlugin::CheckConfig(const std::map<std::string, std::string>& config, | ||
bool& needPerfCounters, std::map<std::string, std::string>& filterConfig) { | ||
// TODO need to optimize this code, too much duplicated code | ||
const auto perf_hints_configs = PerfHintsConfig::SupportedKeys(); | ||
for (auto&& kvp : config) { | ||
if (kvp.first.find("AUTO_") == 0) { | ||
continue; | ||
} else if (kvp.first == PluginConfigParams::KEY_PERF_COUNT) { | ||
if (kvp.second == PluginConfigParams::YES) { | ||
needPerfCounters = true; | ||
filterConfig.insert({kvp.first, kvp.second}); | ||
} else if (kvp.second == PluginConfigParams::NO) { | ||
needPerfCounters = false; | ||
} else { | ||
IE_THROW() << "Unsupported config value: " << kvp.second | ||
<< " for key: " << kvp.first; | ||
} | ||
} else if (kvp.first == PluginConfigParams::KEY_EXCLUSIVE_ASYNC_REQUESTS) { | ||
if (kvp.second == PluginConfigParams::YES || | ||
kvp.second == PluginConfigParams::NO) { | ||
continue; | ||
} else { | ||
IE_THROW() << "Unsupported config value: " << kvp.second | ||
<< " for key: " << kvp.first; | ||
} | ||
} else if (std::find(perf_hints_configs.begin(), perf_hints_configs.end(), kvp.first) != perf_hints_configs.end()) { | ||
PerfHintsConfig::CheckConfigAndValue(kvp); | ||
} else if (supported_configKeys.end() == std::find(supported_configKeys.begin(), supported_configKeys.end(), kvp.first)) { | ||
IE_THROW() << "Unsupported config key: " << kvp.first; | ||
} | ||
} | ||
} | ||
|
||
std::vector<DeviceInformation> MultiDeviceInferencePlugin::FilterDevice(const std::vector<DeviceInformation>& metaDevices, | ||
const std::map<std::string, std::string>& config) { | ||
if (metaDevices.empty()) { | ||
IE_THROW(NotFound) << "No available device to filter " << GetName() << " plugin"; | ||
} | ||
|
||
if (config.size() == 0) { | ||
return metaDevices; | ||
} | ||
|
||
std::vector<DeviceInformation> filterDevice; | ||
for (auto&& item : metaDevices) { | ||
bool support = true; | ||
std::vector<std::string> supportedMetrics = GetCore()->GetMetric(item.deviceName, METRIC_KEY(SUPPORTED_METRICS)); | ||
if (std::find(supportedMetrics.begin(), supportedMetrics.end(), METRIC_KEY(SUPPORTED_CONFIG_KEYS)) != supportedMetrics.end()) { | ||
std::vector<std::string> supportKeys = GetCore()->GetMetric(item.deviceName, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); | ||
for (auto&& kvp : config) { | ||
auto targetKey = std::find(supportKeys.begin(), supportKeys.end(), kvp.first); | ||
// if device have the key, we think the device support it | ||
if (targetKey != supportKeys.end()) { | ||
continue; | ||
} else { | ||
support = false; | ||
break; | ||
} | ||
} | ||
} else { | ||
support = false; | ||
} | ||
|
||
if (support) { | ||
filterDevice.push_back(item); | ||
} | ||
} | ||
return filterDevice; | ||
} | ||
} // namespace MultiDevicePlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor but better to do std::vectorstd::string validConfigKey = PerfHintsConfig::SupportedKeys(); rather than explicitly add the specific values in the lines 241-242 below ( since if the new config is added to the hints impl, you will need to explicitly add that)