Skip to content

Commit

Permalink
Use .as<std::AnyMap>() to convert std::string to std::AnyMap
Browse files Browse the repository at this point in the history
  • Loading branch information
riverlijunjie committed Dec 8, 2023
1 parent 599496a commit cae554a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/inference/src/dev/core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(
if (util::contains(plugin.get_property(ov::internal::supported_properties),
ov::internal::compiled_model_format_supported.name())) {
ov::AnyMap compiled_model_format = {
{ov::internal::compiled_model_format_supported.name(), std::string(header.getRuntimeInfo())}};
{ov::internal::compiled_model_format.name(), std::string(header.getRuntimeInfo())}};
auto res = plugin.get_property(ov::internal::compiled_model_format_supported.name(),
compiled_model_format);
if (!res.as<bool>()) {
Expand Down
2 changes: 1 addition & 1 deletion src/inference/tests/functional/caching_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ TEST_P(CachingTest, TestCacheFileWithCompiledModelFormat) {
EXPECT_CALL(*mockPlugin, get_property(ov::internal::compiled_model_format_supported.name(), _))
.Times(AtLeast(1))
.WillRepeatedly(Invoke([&](const std::string&, const ov::AnyMap& options) {
auto it = options.find(ov::internal::compiled_model_format_supported.name());
auto it = options.find(ov::internal::compiled_model_format.name());
ov::Any ret = true;
if (it == options.end() || it->second.as<std::string>() != compiled_model_format)
ret = false;
Expand Down
24 changes: 17 additions & 7 deletions src/plugins/intel_cpu/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ Engine::Engine() :
#if defined(OV_CPU_WITH_ACL)
scheduler_guard = SchedulerGuard::instance();
#endif
auto& ov_version = ov::get_openvino_version();
compiled_model_format_info = std::string(ov_version.buildNumber);
auto& ov_version = ov::get_openvino_version();
m_compiled_model_format["OV_VERSION"] = std::string(ov_version.buildNumber);
}

Engine::~Engine() {
Expand Down Expand Up @@ -691,12 +691,22 @@ ov::Any Engine::get_property(const std::string& name, const ov::AnyMap& options)
} else if (name == ov::hint::execution_mode) {
return engConfig.executionMode;
} else if (name == ov::internal::compiled_model_format.name()) {
return decltype(ov::internal::compiled_model_format)::value_type(compiled_model_format_info);
auto model_format = ov::Any(m_compiled_model_format);
return decltype(ov::internal::compiled_model_format)::value_type(model_format.as<std::string>());
} else if (name == ov::internal::compiled_model_format_supported.name()) {
ov::Any res = false;
auto it = options.find(ov::internal::compiled_model_format_supported.name());
if (it != options.end() && it->second.as<std::string>() == compiled_model_format_info) {
res = true;
ov::Any res = true;
auto it = options.find(ov::internal::compiled_model_format.name());
if (it == options.end()) {
res = false;
} else {
ov::AnyMap input_map = it->second.as<ov::AnyMap>();
for (auto& item : m_compiled_model_format) {
auto it = input_map.find(item.first);
if (it == input_map.end() || it->second.as<std::string>() != item.second.as<std::string>()) {
res = false;
break;
}
}
}
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_cpu/src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Engine : public ov::IPlugin {
So track if streams is set explicitly (not auto-configured) */
bool streamsExplicitlySetForEngine = false;
const std::string deviceFullName;
std::string compiled_model_format_info;
ov::AnyMap m_compiled_model_format;

std::shared_ptr<void> specialSetup;

Expand Down
1 change: 0 additions & 1 deletion src/plugins/intel_gpu/include/intel_gpu/plugin/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Plugin : public ov::IPlugin {
std::vector<std::string> get_device_capabilities(const cldnn::device_info& info) const;
uint32_t get_optimal_batch_size(const ov::AnyMap& options) const;
uint32_t get_max_batch_size(const ov::AnyMap& options) const;
ov::AnyMap parse_compiled_model_format(const std::string& input) const;

ov::AnyMap preprocess_config(const ov::AnyMap& orig_config) const;
bool is_metric(const std::string& name) const;
Expand Down
37 changes: 6 additions & 31 deletions src/plugins/intel_gpu/src/plugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,6 @@ std::string Plugin::get_device_id(const ov::AnyMap& config) const {
return id;
}

/** Parse compiled model format to be ov::AnyMap
* input:"aaa:1234;ccc:xyzw;"
* output:
* out["aaa"] = "1234"
* out["ccc"] = "xyzw"
*/
ov::AnyMap Plugin::parse_compiled_model_format(const std::string& input) const {
ov::AnyMap res = {};
auto in = input;
while (!in.empty()) {
auto pos_1 = in.find_first_of(':');
auto pos_2 = in.find_first_of(';');
if (pos_1 == std::string::npos || pos_2 == std::string::npos) {
break;
}
res[in.substr(0, pos_1)] = in.substr(pos_1 + 1, pos_2 - pos_1 - 1);
in = in.substr(pos_2 + 1);
}
return res;
}

void Plugin::transform_model(std::shared_ptr<ov::Model>& model, const ExecutionConfig& config) const {
OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "Plugin::transform_model");
auto deviceInfo = m_device_map.at(config.get_property(ov::device::id))->get_info();
Expand Down Expand Up @@ -360,22 +339,18 @@ ov::Any Plugin::get_property(const std::string& name, const ov::AnyMap& options)
} else if (name == ov::internal::caching_properties) {
return decltype(ov::internal::caching_properties)::value_type(get_caching_properties());
} else if (name == ov::internal::compiled_model_format.name()) {
std::string format_info;
for (auto& it : m_compiled_model_format) {
format_info += it.first + ":" + it.second.as<std::string>() + ";";
}
return decltype(ov::internal::compiled_model_format)::value_type(format_info);
auto model_format = ov::Any(m_compiled_model_format);
return decltype(ov::internal::compiled_model_format)::value_type(model_format.as<std::string>());
} else if (name == ov::internal::compiled_model_format_supported.name()) {
ov::Any res = true;
auto it = options.find(ov::internal::compiled_model_format_supported.name());
auto it = options.find(ov::internal::compiled_model_format.name());
if (it == options.end()) {
res = false;
} else {
const auto data = it->second.as<std::string>();
auto input = parse_compiled_model_format(data);
ov::AnyMap input_map = it->second.as<ov::AnyMap>();
for (auto& item : m_compiled_model_format) {
auto it = input.find(item.first);
if (it == input.end() || it->second.as<std::string>() != item.second.as<std::string>()) {
auto it = input_map.find(item.first);
if (it == input_map.end() || it->second.as<std::string>() != item.second.as<std::string>()) {
res = false;
break;
}
Expand Down

0 comments on commit cae554a

Please sign in to comment.