[Remote Context] Add operate () overload method in class RemoteContext (#18186)

* [Remote Context] Add operate () overload method in class RemoteContext to check is initialized or not

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

* [Remote Context] fix format issue

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

---------

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>
This commit is contained in:
Xuejun Zhai 2023-06-23 13:10:55 +08:00 committed by GitHub
parent 2983b6abb0
commit 1b495e3221
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 6 deletions

View File

@ -101,6 +101,12 @@ public:
*/
RemoteContext& operator=(RemoteContext&& other) = default;
/**
* @brief Checks if current RemoteContext object is initialized
* @return `true` if current RemoteContext object is initialized, `false` - otherwise
*/
operator bool() const noexcept;
/**
* @brief Destructor that preserves unloading order of implementation object and reference to the library.
*/

View File

@ -50,6 +50,10 @@ void RemoteContext::type_check(const RemoteContext& context,
}
}
RemoteContext::operator bool() const noexcept {
return (!!_impl);
}
RemoteContext::~RemoteContext() {
_impl = {};
}

View File

@ -566,7 +566,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
const ov::RemoteContext& context,
const ov::AnyMap& config) const {
OV_ITT_SCOPE(FIRST_INFERENCE, ie::itt::domains::IE_LT, "Core::compile_model::RemoteContext");
if (context._impl == nullptr) {
if (!context) {
IE_THROW() << "Remote context is null";
}
std::string deviceName = context.get_device_name();
@ -607,8 +607,8 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model_with_preprocess(ov::Pl
preprocessed_model = cloned_model;
}
return context._impl ? plugin.compile_model(preprocessed_model, context, config)
: plugin.compile_model(preprocessed_model, config);
return context ? plugin.compile_model(preprocessed_model, context, config)
: plugin.compile_model(preprocessed_model, config);
}
ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::string& model_path,
@ -1213,8 +1213,8 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(
throw HeaderException();
}
compiled_model = context._impl ? plugin.import_model(networkStream, context, config)
: plugin.import_model(networkStream, config);
compiled_model = context ? plugin.import_model(networkStream, context, config)
: plugin.import_model(networkStream, config);
if (auto wrapper = std::dynamic_pointer_cast<InferenceEngine::ICompiledModelWrapper>(compiled_model._ptr)) {
wrapper->get_executable_network()->loadedFromCache();
}

View File

@ -114,7 +114,7 @@ std::shared_ptr<ov::IRemoteContext> ov::ICompiledModel::get_context() const {
if (auto wrapper = dynamic_cast<const InferenceEngine::ICompiledModelWrapper*>(this)) {
return ov::legacy_convert::convert_remote_context(wrapper->get_executable_network()->GetContext());
}
if (m_context._impl)
if (m_context)
return m_context._impl;
return m_plugin->get_default_context({});
}