Add property to understand that model was loaded from cache (#14159)
* Add property to understand that model was loaded from cache * Fixed tests * Disabled from cache property for auto plugin * Rename property to loaded_from_cache * Add to supported properties list
This commit is contained in:
parent
f5a52dd732
commit
74bae530c1
@ -155,6 +155,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual std::shared_ptr<RemoteContext> GetContext() const;
|
virtual std::shared_ptr<RemoteContext> GetContext() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Raises the flag that model was loaded from cache
|
||||||
|
*/
|
||||||
|
void loadedFromCache();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Provides an information how model was loaded
|
||||||
|
*
|
||||||
|
* @return true if model was loaded from cache
|
||||||
|
*/
|
||||||
|
bool isLoadedFromCache() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~IExecutableNetworkInternal() = default;
|
virtual ~IExecutableNetworkInternal() = default;
|
||||||
|
|
||||||
@ -196,6 +208,11 @@ protected:
|
|||||||
* @note Needed to correctly handle ownership between objects.
|
* @note Needed to correctly handle ownership between objects.
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<void> _so;
|
std::shared_ptr<void> _so;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief If true, it means that model was loaded from cache
|
||||||
|
*/
|
||||||
|
bool _loadedFromCache = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -456,6 +456,12 @@ static constexpr Property<Level> level{"LOG_LEVEL"};
|
|||||||
*/
|
*/
|
||||||
static constexpr Property<std::string> cache_dir{"CACHE_DIR"};
|
static constexpr Property<std::string> cache_dir{"CACHE_DIR"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read-only property to notify user that compiled model was loaded from the cache
|
||||||
|
* @ingroup ov_runtime_cpp_prop_api
|
||||||
|
*/
|
||||||
|
static constexpr Property<bool, PropertyMutability::RO> loaded_from_cache{"LOADED_FROM_CACHE"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read-only property to provide information about a range for streams on platforms where streams are supported.
|
* @brief Read-only property to provide information about a range for streams on platforms where streams are supported.
|
||||||
* @ingroup ov_runtime_cpp_prop_api
|
* @ingroup ov_runtime_cpp_prop_api
|
||||||
|
@ -214,6 +214,9 @@ void CompiledModel::set_property(const AnyMap& config) {
|
|||||||
|
|
||||||
Any CompiledModel::get_property(const std::string& name) const {
|
Any CompiledModel::get_property(const std::string& name) const {
|
||||||
OV_EXEC_NET_CALL_STATEMENT({
|
OV_EXEC_NET_CALL_STATEMENT({
|
||||||
|
if (ov::loaded_from_cache == name) {
|
||||||
|
return _impl->isLoadedFromCache();
|
||||||
|
}
|
||||||
if (ov::supported_properties == name) {
|
if (ov::supported_properties == name) {
|
||||||
try {
|
try {
|
||||||
auto supported_properties = _impl->GetMetric(name).as<std::vector<PropertyName>>();
|
auto supported_properties = _impl->GetMetric(name).as<std::vector<PropertyName>>();
|
||||||
@ -239,6 +242,7 @@ Any CompiledModel::get_property(const std::string& name) const {
|
|||||||
supported_properties.emplace_back(rw_property, PropertyMutability::RW);
|
supported_properties.emplace_back(rw_property, PropertyMutability::RW);
|
||||||
}
|
}
|
||||||
supported_properties.emplace_back(ov::supported_properties.name(), PropertyMutability::RO);
|
supported_properties.emplace_back(ov::supported_properties.name(), PropertyMutability::RO);
|
||||||
|
supported_properties.emplace_back(ov::loaded_from_cache.name(), PropertyMutability::RO);
|
||||||
return supported_properties;
|
return supported_properties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,14 @@ std::shared_ptr<IInferRequestInternal> IExecutableNetworkInternal::CreateInferRe
|
|||||||
IE_THROW(NotImplemented);
|
IE_THROW(NotImplemented);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IExecutableNetworkInternal::loadedFromCache() {
|
||||||
|
_loadedFromCache = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IExecutableNetworkInternal::isLoadedFromCache() const {
|
||||||
|
return _loadedFromCache;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<IInferRequestInternal> IExecutableNetworkInternal::CreateInferRequestImpl(
|
std::shared_ptr<IInferRequestInternal> IExecutableNetworkInternal::CreateInferRequestImpl(
|
||||||
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
|
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
|
||||||
const std::vector<std::shared_ptr<const ov::Node>>& outputs) {
|
const std::vector<std::shared_ptr<const ov::Node>>& outputs) {
|
||||||
|
@ -472,6 +472,7 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this<ie::ICore
|
|||||||
execNetwork = context ? plugin.import_model(networkStream, context, config)
|
execNetwork = context ? plugin.import_model(networkStream, context, config)
|
||||||
: plugin.import_model(networkStream, config);
|
: plugin.import_model(networkStream, config);
|
||||||
networkIsImported = true;
|
networkIsImported = true;
|
||||||
|
execNetwork->loadedFromCache();
|
||||||
});
|
});
|
||||||
} catch (const HeaderException&) {
|
} catch (const HeaderException&) {
|
||||||
// For these exceptions just remove old cache and set that import didn't work
|
// For these exceptions just remove old cache and set that import didn't work
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "behavior/ov_plugin/caching_tests.hpp"
|
#include "behavior/ov_plugin/caching_tests.hpp"
|
||||||
@ -190,6 +191,7 @@ void CompileModelCacheTestBase::run() {
|
|||||||
configure_model();
|
configure_model();
|
||||||
try {
|
try {
|
||||||
compiledModel = core->compile_model(function, targetDevice, configuration);
|
compiledModel = core->compile_model(function, targetDevice, configuration);
|
||||||
|
ASSERT_FALSE(compiledModel.get_property(ov::loaded_from_cache));
|
||||||
generate_inputs(targetStaticShapes.front());
|
generate_inputs(targetStaticShapes.front());
|
||||||
infer();
|
infer();
|
||||||
} catch (const Exception &ex) {
|
} catch (const Exception &ex) {
|
||||||
@ -207,6 +209,9 @@ void CompileModelCacheTestBase::run() {
|
|||||||
{
|
{
|
||||||
core->set_property(ov::cache_dir(m_cacheFolderName));
|
core->set_property(ov::cache_dir(m_cacheFolderName));
|
||||||
ASSERT_NO_THROW(compiledModel = core->compile_model(function, targetDevice, configuration));
|
ASSERT_NO_THROW(compiledModel = core->compile_model(function, targetDevice, configuration));
|
||||||
|
if (targetDevice.find("AUTO") == std::string::npos)
|
||||||
|
// Apply check only for HW plugins
|
||||||
|
ASSERT_EQ(i != 0, compiledModel.get_property(ov::loaded_from_cache));
|
||||||
generate_inputs(targetStaticShapes.front());
|
generate_inputs(targetStaticShapes.front());
|
||||||
ASSERT_NO_THROW(infer());
|
ASSERT_NO_THROW(infer());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user