[AUTO] Benchmark failed to pass nthreads and pin to AUTO/MULTI (#13396)

* Create device property for passing nthreads or pin to AUTO or MULTI in benchmark app.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Update the logic of the multi device properties setting for the same target device.

* refactor the logic to pass nthreads and pin to AUTO and MULTI.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

Signed-off-by: Wang, Yang <yang4.wang@intel.com>
This commit is contained in:
Wang, Yang 2022-10-26 14:43:02 +08:00 committed by GitHub
parent 632378c930
commit 82942a12b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -277,18 +277,14 @@ int main(int argc, char* argv[]) {
// check if using the virtual device
auto if_auto = std::find(devices.begin(), devices.end(), "AUTO") != devices.end();
auto if_multi = std::find(devices.begin(), devices.end(), "MULTI") != devices.end();
auto hardware_devices = devices;
// Remove the hardware devices if AUTO/MULTI appears in the devices list.
if (if_auto || if_multi) {
devices.clear();
std::string virtual_device;
if (if_auto) {
virtual_device = "AUTO";
devices.push_back("AUTO");
}
if (if_multi) {
virtual_device = "MULTI";
devices.push_back("MULTI");
}
std::string virtual_device = if_auto ? "AUTO" : "MULTI";
auto iter_virtual = std::find(hardware_devices.begin(), hardware_devices.end(), virtual_device);
hardware_devices.erase(iter_virtual);
devices.push_back(virtual_device);
parse_value_for_virtual_device(virtual_device, device_nstreams);
parse_value_for_virtual_device(virtual_device, device_infer_precision);
}
@ -358,9 +354,15 @@ int main(int argc, char* argv[]) {
std::stringstream strm(it_device_nstreams->second);
std::map<std::string, std::string> devices_property;
ov::util::Read<std::map<std::string, std::string>>{}(strm, devices_property);
for (auto& it : devices_property) {
device_config.insert(
ov::device::properties(it.first, ov::num_streams(std::stoi(it.second))));
for (auto it : devices_property) {
if (device_config.find(it.first) == device_config.end())
device_config.insert(
ov::device::properties(it.first, ov::num_streams(std::stoi(it.second))));
else {
auto& property = device_config[it.first].as<ov::AnyMap>();
property.emplace(ov::num_streams(std::stoi(it.second)));
device_config.insert(ov::device::properties(it.first, property));
}
}
}
} else {
@ -419,12 +421,29 @@ int main(int argc, char* argv[]) {
return str;
};
if (supported(ov::inference_num_threads.name()) && isFlagSetInCommandLine("nthreads")) {
device_config.emplace(ov::inference_num_threads(FLAGS_nthreads));
}
if (supported(ov::affinity.name()) && isFlagSetInCommandLine("pin")) {
device_config.emplace(ov::affinity(fix_pin_option(FLAGS_pin)));
}
auto set_nthreads_pin = [&](const std::string& str) {
auto property_name = str == "nthreads" ? ov::inference_num_threads.name() : ov::affinity.name();
auto property = str == "nthreads" ? ov::inference_num_threads(FLAGS_nthreads)
: ov::affinity(fix_pin_option(FLAGS_pin));
if (supported(property_name) || if_multi) {
device_config.emplace(property);
} else if (if_auto) {
for (auto& device : hardware_devices) {
if (device_config.find(device) == device_config.end()) {
device_config.insert(ov::device::properties(device, property));
} else {
auto& properties = device_config[device].as<ov::AnyMap>();
properties.emplace(property);
device_config.insert(ov::device::properties(device, properties));
}
}
}
};
if (isFlagSetInCommandLine("nthreads"))
set_nthreads_pin("nthreads");
if (isFlagSetInCommandLine("pin"))
set_nthreads_pin("pin");
if (device.find("CPU") != std::string::npos || device.find("GPU") != std::string::npos) {
// CPU supports few special performance-oriented keys