Remove try catch

This commit is contained in:
Ilya Churaev 2023-07-19 17:19:43 +04:00
parent 55f47196a0
commit 08b478c070
4 changed files with 76 additions and 34 deletions

View File

@ -140,6 +140,13 @@ public:
virtual ~ICompiledModel() = default;
/**
* @brief Detects that compiled model supports caching and import/export
*
* @return true if caching is supported, else in other case
*/
bool supports_caching() const;
private:
std::shared_ptr<const ov::IPlugin> m_plugin;
std::vector<ov::Output<const ov::Node>> m_inputs;

View File

@ -6,8 +6,13 @@
#include "dev/converter_utils.hpp"
#include "icompiled_model_wrapper.hpp"
#include "ie_common.h"
#include "ie_plugin_config.hpp"
#include "openvino/core/except.hpp"
#include "openvino/core/model.hpp"
#include "openvino/runtime/internal_properties.hpp"
#include "openvino/runtime/properties.hpp"
#include "openvino/util/common_util.hpp"
#include "transformations/utils/utils.hpp"
ov::ICompiledModel::ICompiledModel(const std::shared_ptr<const ov::Model>& model,
@ -144,3 +149,26 @@ ov::SoPtr<ov::IRemoteContext> ov::ICompiledModel::get_context() const {
return m_context;
return m_plugin->get_default_context({});
}
bool ov::ICompiledModel::supports_caching() const {
bool supported(false);
try {
auto supportedMetricKeys = get_property(METRIC_KEY(SUPPORTED_METRICS)).as<std::vector<std::string>>();
supported = util::contains(supportedMetricKeys, METRIC_KEY(IMPORT_EXPORT_SUPPORT)) &&
get_property(METRIC_KEY(IMPORT_EXPORT_SUPPORT)).as<bool>();
} catch (const InferenceEngine::Exception& ex) {
} catch (const ov::Exception& ex) {
}
if (!supported) {
supported = util::contains(get_property(ov::supported_properties.name()).as<std::vector<PropertyName>>(),
ov::device::capabilities) &&
util::contains(get_property(ov::device::capabilities.name()).as<std::vector<std::string>>(),
ov::device::capability::EXPORT_IMPORT);
}
if (supported) {
supported =
util::contains(get_property(ov::internal::supported_properties.name()).as<std::vector<PropertyName>>(),
ov::internal::caching_properties);
}
return supported;
}

View File

@ -687,33 +687,30 @@ void ov::hetero::CompiledModel::export_model(std::ostream& model_stream) const {
model_stream << std::endl;
for (const auto& comp_model_desc : m_compiled_submodels) {
if (get_plugin()->get_core()->device_supports_model_caching(comp_model_desc.device)) {
try {
// Batch plugin reports property of low level plugin
// If we use Batch plugin inside hetero, we won't be able to call export
// Auto batch plugin will throw NOT_IMPLEMENTED
comp_model_desc.compiled_model->export_model(model_stream);
continue;
} catch (ov::NotImplemented&) {
}
if (comp_model_desc.compiled_model->supports_caching()) {
// Batch plugin reports property of low level plugin
// If we use Batch plugin inside hetero, we won't be able to call export
// Auto batch plugin will throw NOT_IMPLEMENTED
comp_model_desc.compiled_model->export_model(model_stream);
} else {
auto model = comp_model_desc.model;
if (!model)
OPENVINO_THROW("OpenVINO Model is empty");
std::stringstream xmlFile, binFile;
ov::pass::Serialize serializer(xmlFile, binFile);
serializer.run_on_model(model);
auto constants = binFile.str();
auto model_str = xmlFile.str();
auto dataSize = static_cast<std::uint64_t>(model_str.size());
model_stream.write(reinterpret_cast<char*>(&dataSize), sizeof(dataSize));
model_stream.write(model_str.c_str(), dataSize);
dataSize = static_cast<std::uint64_t>(constants.size());
model_stream.write(reinterpret_cast<char*>(&dataSize), sizeof(dataSize));
model_stream.write(reinterpret_cast<char*>(&constants[0]), dataSize);
}
auto model = comp_model_desc.model;
if (!model)
OPENVINO_THROW("OpenVINO Model is empty");
std::stringstream xmlFile, binFile;
ov::pass::Serialize serializer(xmlFile, binFile);
serializer.run_on_model(model);
auto constants = binFile.str();
auto model_str = xmlFile.str();
auto dataSize = static_cast<std::uint64_t>(model_str.size());
model_stream.write(reinterpret_cast<char*>(&dataSize), sizeof(dataSize));
model_stream.write(model_str.c_str(), dataSize);
dataSize = static_cast<std::uint64_t>(constants.size());
model_stream.write(reinterpret_cast<char*>(&dataSize), sizeof(dataSize));
model_stream.write(reinterpret_cast<char*>(&constants[0]), dataSize);
}
}

View File

@ -197,7 +197,17 @@ public:
}
ov::Any get_property(const std::string& name) const override {
OPENVINO_NOT_IMPLEMENTED;
if (name == ov::internal::supported_properties) {
return decltype(ov::internal::supported_properties)::value_type(
{ov::PropertyName{ov::internal::caching_properties.name(), ov::PropertyMutability::RO}});
} else if (name == ov::supported_properties) {
std::vector<ov::PropertyName> supportedProperties;
return decltype(ov::supported_properties)::value_type(
{ov::PropertyName{ov::device::capability::EXPORT_IMPORT, ov::PropertyMutability::RO}});
} else if (ov::device::capability::EXPORT_IMPORT == name) {
return true;
}
OPENVINO_THROW("Property ", name, " wasn't found!");
}
std::shared_ptr<ov::ISyncInferRequest> create_sync_infer_request() const override;
@ -547,7 +557,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_support_reshape(ov::Core& cor
RO_property(ov::available_devices.name()),
RO_property(ov::loaded_from_cache.name()),
RO_property(ov::device::uuid.name()),
RO_property(METRIC_KEY(IMPORT_EXPORT_SUPPORT)),
RO_property(ov::device::capability::EXPORT_IMPORT),
RO_property(ov::optimal_batch_size.name()),
RW_property(ov::hint::performance_mode.name()),
RW_property(ov::hint::num_requests.name()),
@ -602,7 +612,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_support_reshape(ov::Core& cor
configs.emplace_back(property);
}
return configs;
} else if (METRIC_KEY(IMPORT_EXPORT_SUPPORT) == name) {
} else if (ov::device::capability::EXPORT_IMPORT == name) {
return true;
} else if (ov::internal::caching_properties == name) {
std::vector<ov::PropertyName> caching_properties = {ov::device::uuid};
@ -680,7 +690,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_support_subtract(ov::Core& co
RO_property(ov::available_devices.name()),
RO_property(ov::loaded_from_cache.name()),
RO_property(ov::device::uuid.name()),
RO_property(METRIC_KEY(IMPORT_EXPORT_SUPPORT)),
RO_property(ov::device::capability::EXPORT_IMPORT),
};
// the whole config is RW before network is loaded.
const static std::vector<ov::PropertyName> rwProperties{
@ -728,7 +738,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_support_subtract(ov::Core& co
configs.emplace_back(property);
}
return configs;
} else if (METRIC_KEY(IMPORT_EXPORT_SUPPORT) == name) {
} else if (ov::device::capability::EXPORT_IMPORT == name) {
return true;
} else if (ov::internal::caching_properties == name) {
std::vector<ov::PropertyName> caching_properties = {ov::device::uuid};
@ -787,7 +797,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_without_devices(ov::Core& cor
RO_property(ov::supported_properties.name()),
RO_property(ov::available_devices.name()),
RO_property(ov::loaded_from_cache.name()),
RO_property(METRIC_KEY(IMPORT_EXPORT_SUPPORT)),
RO_property(ov::device::capability::EXPORT_IMPORT),
};
// the whole config is RW before network is loaded.
const static std::vector<ov::PropertyName> rwProperties{
@ -823,7 +833,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_without_devices(ov::Core& cor
configs.emplace_back(property);
}
return configs;
} else if (METRIC_KEY(IMPORT_EXPORT_SUPPORT) == name) {
} else if (ov::device::capability::EXPORT_IMPORT == name) {
return true;
} else if (name == "SUPPORTED_METRICS") { // TODO: Remove this key
std::vector<std::string> configs;