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;
|
||||
|
||||
/**
|
||||
* @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:
|
||||
virtual ~IExecutableNetworkInternal() = default;
|
||||
|
||||
@ -196,6 +208,11 @@ protected:
|
||||
* @note Needed to correctly handle ownership between objects.
|
||||
*/
|
||||
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"};
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @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 {
|
||||
OV_EXEC_NET_CALL_STATEMENT({
|
||||
if (ov::loaded_from_cache == name) {
|
||||
return _impl->isLoadedFromCache();
|
||||
}
|
||||
if (ov::supported_properties == name) {
|
||||
try {
|
||||
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(ov::supported_properties.name(), PropertyMutability::RO);
|
||||
supported_properties.emplace_back(ov::loaded_from_cache.name(), PropertyMutability::RO);
|
||||
return supported_properties;
|
||||
}
|
||||
}
|
||||
|
@ -117,6 +117,14 @@ std::shared_ptr<IInferRequestInternal> IExecutableNetworkInternal::CreateInferRe
|
||||
IE_THROW(NotImplemented);
|
||||
}
|
||||
|
||||
void IExecutableNetworkInternal::loadedFromCache() {
|
||||
_loadedFromCache = true;
|
||||
}
|
||||
|
||||
bool IExecutableNetworkInternal::isLoadedFromCache() const {
|
||||
return _loadedFromCache;
|
||||
}
|
||||
|
||||
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>>& 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)
|
||||
: plugin.import_model(networkStream, config);
|
||||
networkIsImported = true;
|
||||
execNetwork->loadedFromCache();
|
||||
});
|
||||
} catch (const HeaderException&) {
|
||||
// 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 "behavior/ov_plugin/caching_tests.hpp"
|
||||
@ -190,6 +191,7 @@ void CompileModelCacheTestBase::run() {
|
||||
configure_model();
|
||||
try {
|
||||
compiledModel = core->compile_model(function, targetDevice, configuration);
|
||||
ASSERT_FALSE(compiledModel.get_property(ov::loaded_from_cache));
|
||||
generate_inputs(targetStaticShapes.front());
|
||||
infer();
|
||||
} catch (const Exception &ex) {
|
||||
@ -207,6 +209,9 @@ void CompileModelCacheTestBase::run() {
|
||||
{
|
||||
core->set_property(ov::cache_dir(m_cacheFolderName));
|
||||
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());
|
||||
ASSERT_NO_THROW(infer());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user