[HETERO]: support caching properties (#16451)

* Fixed build

* [HETERO]: support caching properties

* Fix caching test

* Code style

* Change result type from map to vector

* Review comments

---------

Co-authored-by: Ilya Churaev <ilya.churaev@intel.com>
This commit is contained in:
Nadezhda AgeevaandIlya Churaev authored and GitHub committed 2023-03-24 12:25:55 +04:00
1 parent 16933efc06
commit 65e5ed7dd7
3 files changed
+52 -19

No files matched your search

@@ -0,0 +1,17 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/runtime/properties.hpp"
namespace ov {
namespace hetero {
/**
* @brief Read-only property to get device caching properties
*/
static constexpr Property<std::string, PropertyMutability::RO> caching_device_properties{"CACHING_DEVICE_PROPERTIES"};
} // namespace hetero
} // namespace ov
+34 -18
View File
@@ -17,6 +17,8 @@
#include "executable_network.hpp"
#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp"
#include "openvino/runtime/properties.hpp"
#include "internal_properties.hpp"
#include "openvino/util/common_util.hpp"
// clang-format on
using namespace InferenceEngine;
@@ -159,16 +161,21 @@ Parameter Engine::GetMetric(const std::string& name, const std::map<std::string,
if (ov::supported_properties == name) {
return decltype(ov::supported_properties)::value_type{
ov::PropertyName{ov::supported_properties.name(), ov::PropertyMutability::RO},
ov::PropertyName{ov::caching_properties.name(), ov::PropertyMutability::RO},
ov::PropertyName{ov::device::full_name.name(), ov::PropertyMutability::RO},
ov::PropertyName{ov::device::architecture.name(), ov::PropertyMutability::RO},
ov::PropertyName{ov::device::capabilities.name(), ov::PropertyMutability::RO},
ov::PropertyName{ov::device::priorities.name(), ov::PropertyMutability::RW}};
} else if (ov::caching_properties == name) {
return decltype(ov::caching_properties)::value_type{ov::hetero::caching_device_properties.name()};
} else if (ov::hetero::caching_device_properties == name) {
auto tconfig = mergeConfigs(_config, options);
std::string targetFallback = GetTargetFallback(tconfig);
return decltype(ov::hetero::caching_device_properties)::value_type{DeviceCachingProperties(targetFallback)};
} else if (METRIC_KEY(SUPPORTED_METRICS) == name) {
IE_SET_METRIC_RETURN(SUPPORTED_METRICS,
std::vector<std::string>{METRIC_KEY(SUPPORTED_METRICS),
ov::device::full_name.name(),
METRIC_KEY(SUPPORTED_CONFIG_KEYS),
ov::device::architecture.name(),
METRIC_KEY(IMPORT_EXPORT_SUPPORT),
ov::device::capabilities.name()});
} else if (METRIC_KEY(SUPPORTED_CONFIG_KEYS) == name) {
@@ -179,30 +186,39 @@ Parameter Engine::GetMetric(const std::string& name, const std::map<std::string,
IE_SET_METRIC_RETURN(IMPORT_EXPORT_SUPPORT, true);
} else if (ov::device::capabilities == name) {
return decltype(ov::device::capabilities)::value_type{{ov::device::capability::EXPORT_IMPORT}};
} else if (ov::device::architecture == name) {
auto tconfig = mergeConfigs(_config, options);
std::string targetFallback = GetTargetFallback(tconfig);
return decltype(ov::device::architecture)::value_type{DeviceArchitecture(targetFallback)};
} else {
IE_THROW() << "Unsupported metric key: " << name;
}
}
std::string Engine::DeviceArchitecture(const std::string& targetFallback) const {
std::string Engine::DeviceCachingProperties(const std::string& targetFallback) const {
auto fallbackDevices = ov::DeviceIDParser::get_hetero_devices(targetFallback);
std::string resArch;
// Vector of caching configs for devices
std::vector<ov::AnyMap> result = {};
for (const auto& device : fallbackDevices) {
ov::DeviceIDParser parser(device);
auto supportedMetricKeys = GetCore()
->GetMetric(parser.get_device_name(), METRIC_KEY(SUPPORTED_METRICS))
.as<std::vector<std::string>>();
auto it = std::find(supportedMetricKeys.begin(), supportedMetricKeys.end(), METRIC_KEY(DEVICE_ARCHITECTURE));
auto arch = (it != supportedMetricKeys.end())
? GetCore()->GetMetric(device, METRIC_KEY(DEVICE_ARCHITECTURE)).as<std::string>()
: parser.get_device_name();
resArch += " " + arch;
ov::AnyMap properties = {};
// Use name without id
auto device_name = parser.get_device_name();
auto supported_properties =
GetCore()->GetMetric(device, ov::supported_properties.name()).as<std::vector<ov::PropertyName>>();
if (ov::util::contains(supported_properties, ov::caching_properties.name())) {
auto caching_properties =
GetCore()->GetMetric(device, ov::caching_properties.name()).as<std::vector<ov::PropertyName>>();
for (auto& property_name : caching_properties) {
properties[property_name] = GetCore()->GetMetric(device, property_name);
}
// If caching properties are not supported by device, try to add at least device architecture
} else if (ov::util::contains(supported_properties, ov::device::architecture.name())) {
auto device_architecture = GetCore()->GetMetric(device, ov::device::architecture.name());
properties = ov::AnyMap{{ov::device::architecture.name(), device_architecture}};
// Device architecture is not supported, add device name as achitecture
} else {
properties = ov::AnyMap{{ov::device::architecture.name(), device_name}};
}
result.emplace_back(properties);
}
return resArch;
return result.empty() ? "" : ov::Any(result).as<std::string>();
}
Parameter Engine::GetConfig(const std::string& name, const std::map<std::string, Parameter>& /*options*/) const {
+1 -1
View File
@@ -49,6 +49,6 @@ public:
std::string GetTargetFallback(const Engine::Configs& config, bool raise_exception = true) const;
private:
std::string DeviceArchitecture(const std::string& targetFallback) const;
std::string DeviceCachingProperties(const std::string& targetFallback) const;
};
} // namespace HeteroPlugin