Bell/fix gpu load model file wrong lifecycle (#14347)

* ensure correct lifecycle with load model file

Signed-off-by: fishbell <bell.song@intel.com>

* clang format

Signed-off-by: fishbell <bell.song@intel.com>

* enable tests

Signed-off-by: fishbell <bell.song@intel.com>

Signed-off-by: fishbell <bell.song@intel.com>
This commit is contained in:
yanlan song authored and GitHub committed 2022-12-06 11:29:07 +03:00
1 parent bf0d2cea4b
commit 4f1ad3bf3d
12 files changed
+50 -15

No files matched your search

@@ -199,8 +199,8 @@ public:
* @param config A string-string map of config parameters relevant only for this load operation
* @return Created Executable Network object
*/
virtual std::shared_ptr<IExecutableNetworkInternal> LoadNetwork(const std::string& modelPath,
const std::map<std::string, std::string>& config);
virtual ov::SoPtr<IExecutableNetworkInternal> LoadNetwork(const std::string& modelPath,
const std::map<std::string, std::string>& config);
/**
* @brief Registers extension within plugin
+10 -2
View File
@@ -78,7 +78,11 @@ struct InferencePlugin {
}
ov::SoPtr<IExecutableNetworkInternal> LoadNetwork(const std::string& modelPath, const std::map<std::string, std::string>& config) {
PLUGIN_CALL_STATEMENT(return {_ptr->LoadNetwork(modelPath, config), _so});
ov::SoPtr<IExecutableNetworkInternal> res;
PLUGIN_CALL_STATEMENT(res = _ptr->LoadNetwork(modelPath, config));
if (!res._so)
res._so = _so;
return res;
}
QueryNetworkResult QueryNetwork(const CNNNetwork& network,
@@ -196,7 +200,11 @@ public:
}
SoPtr<ie::IExecutableNetworkInternal> compile_model(const std::string& modelPath, const std::map<std::string, std::string>& config) {
OV_PLUGIN_CALL_STATEMENT(return {_ptr->LoadNetwork(modelPath, config), _so});
SoPtr<ie::IExecutableNetworkInternal> res;
OV_PLUGIN_CALL_STATEMENT(res = _ptr->LoadNetwork(modelPath, config));
if (!res._so)
res._so = _so;
return res;
}
ie::QueryNetworkResult query_model(const ie::CNNNetwork& network,
@@ -193,11 +193,10 @@ std::shared_ptr<IExecutableNetworkInternal> IInferencePlugin::LoadNetwork(
return impl;
}
std::shared_ptr<IExecutableNetworkInternal> IInferencePlugin::LoadNetwork(
const std::string& modelPath,
const std::map<std::string, std::string>& config) {
ov::SoPtr<IExecutableNetworkInternal> IInferencePlugin::LoadNetwork(const std::string& modelPath,
const std::map<std::string, std::string>& config) {
auto cnnNet = GetCore()->ReadNetwork(modelPath, std::string());
return GetCore()->LoadNetwork(cnnNet, GetName(), config)._ptr;
return GetCore()->LoadNetwork(cnnNet, GetName(), config);
}
void IInferencePlugin::AddExtension(const std::shared_ptr<IExtension>&) {
@@ -80,7 +80,7 @@ public:
MockCachingInferencePluginBase() = default;
~MockCachingInferencePluginBase() = default;
IExecutableNetworkInternal::Ptr LoadNetwork(const std::string& modelPath,
ov::SoPtr<IExecutableNetworkInternal> LoadNetwork(const std::string& modelPath,
const std::map<std::string, std::string>& config) override {
// In GTEST, it is not possible to call base implementation inside of mocked class
// Thus, we define a proxy callback and will use
+2 -2
View File
@@ -302,9 +302,9 @@ InferenceEngine::Parameter MultiDeviceInferencePlugin::GetMetric(const std::stri
}
// Is called only when caching is enabled
IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadNetwork(const std::string& modelPath,
ov::SoPtr<InferenceEngine::IExecutableNetworkInternal> MultiDeviceInferencePlugin::LoadNetwork(const std::string& modelPath,
const std::map<std::string, std::string>& config) {
return LoadNetworkImpl(modelPath, {}, config);
return {LoadNetworkImpl(modelPath, {}, config), nullptr};
}
IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadExeNetworkImpl(const CNNNetwork &network,
+1 -1
View File
@@ -33,7 +33,7 @@ public:
InferenceEngine::IExecutableNetworkInternal::Ptr LoadExeNetworkImpl(const InferenceEngine::CNNNetwork& network,
const std::map<std::string, std::string>& config) override;
InferenceEngine::IExecutableNetworkInternal::Ptr LoadNetwork(const std::string& modelPath,
ov::SoPtr<InferenceEngine::IExecutableNetworkInternal> LoadNetwork(const std::string& modelPath,
const std::map<std::string, std::string>& config) override;
void SetConfig(const std::map<std::string, std::string>& config) override;
@@ -49,4 +49,30 @@ namespace {
::testing::ValuesIn(autoConfigs)),
CompiledKernelsCacheTest::getTestCaseName);
const std::vector<ov::AnyMap> LoadFromFileConfigs = {
{ov::device::priorities(CommonTestUtils::DEVICE_GPU), ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT)},
{ov::device::priorities(CommonTestUtils::DEVICE_GPU), ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY)}
};
const std::vector<std::string> TestTargets =
{CommonTestUtils::DEVICE_AUTO,
CommonTestUtils::DEVICE_MULTI,
};
INSTANTIATE_TEST_SUITE_P(smoke_Auto_CachingSupportCase_GPU, CompileModelLoadFromFileTestBase,
::testing::Combine(
::testing::ValuesIn(TestTargets),
::testing::ValuesIn(LoadFromFileConfigs)),
CompileModelLoadFromFileTestBase::getTestCaseName);
const std::vector<ov::AnyMap> GPULoadFromFileConfigs = {
{ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT)},
{ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY)},
{},
};
INSTANTIATE_TEST_SUITE_P(smoke_CachingSupportCase_GPU, CompileModelLoadFromFileTestBase,
::testing::Combine(
::testing::Values(CommonTestUtils::DEVICE_GPU),
::testing::ValuesIn(GPULoadFromFileConfigs)),
CompileModelLoadFromFileTestBase::getTestCaseName);
} // namespace
@@ -71,6 +71,7 @@ public:
void TearDown() override;
void run() override;
};
using compileKernelsCacheParams = std::tuple<
std::string, // device name
std::pair<ov::AnyMap, std::string> // device and cache configuration
@@ -261,6 +261,7 @@ void CompileModelLoadFromFileTestBase::SetUp() {
void CompileModelLoadFromFileTestBase::TearDown() {
CommonTestUtils::removeFilesWithExt(m_cacheFolderName, "blob");
CommonTestUtils::removeFilesWithExt(m_cacheFolderName, "cl_cache");
CommonTestUtils::removeIRFiles(m_modelName, m_weightsName);
std::remove(m_cacheFolderName.c_str());
core->set_property(ov::cache_dir());
@@ -16,7 +16,7 @@ public:
MOCK_METHOD1(AddExtension, void(InferenceEngine::IExtensionPtr));
MOCK_METHOD2(LoadNetwork, std::shared_ptr<InferenceEngine::IExecutableNetworkInternal>(
const InferenceEngine::CNNNetwork&, const std::map<std::string, std::string>&));
MOCK_METHOD2(LoadNetwork, std::shared_ptr<InferenceEngine::IExecutableNetworkInternal>(
MOCK_METHOD2(LoadNetwork, ov::SoPtr<InferenceEngine::IExecutableNetworkInternal>(
const std::string&, const std::map<std::string, std::string>&));
MOCK_METHOD2(ImportNetwork, std::shared_ptr<InferenceEngine::IExecutableNetworkInternal>(
const std::string&, const std::map<std::string, std::string>&));
@@ -54,7 +54,7 @@ MockPlugin::LoadNetwork(const CNNNetwork& network,
}
}
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal>
ov::SoPtr<InferenceEngine::IExecutableNetworkInternal>
MockPlugin::LoadNetwork(const std::string &modelPath,
const std::map<std::string, std::string> &config) {
if (_target) {
@@ -31,7 +31,7 @@ public:
LoadExeNetworkImpl(const InferenceEngine::CNNNetwork& network,
const std::map<std::string, std::string>& config) override;
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal>
ov::SoPtr<InferenceEngine::IExecutableNetworkInternal>
LoadNetwork(const std::string &modelPath,
const std::map<std::string, std::string> &config) override;