Returned C++ wrappers creation from interface API (#5729)
This commit is contained in:
@@ -21,10 +21,10 @@
|
||||
#include "cpp/ie_cnn_network.h"
|
||||
#include "cpp/ie_infer_request.hpp"
|
||||
#include "details/ie_so_loader.h"
|
||||
#include "ie_iexecutable_network.hpp"
|
||||
|
||||
namespace InferenceEngine {
|
||||
class IExecutableNetworkInternal;
|
||||
class IExecutableNetwork;
|
||||
|
||||
/**
|
||||
* @brief This is an interface of an executable network
|
||||
@@ -32,6 +32,9 @@ class IExecutableNetwork;
|
||||
class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) {
|
||||
details::SharedObjectLoader _so;
|
||||
std::shared_ptr<IExecutableNetworkInternal> _impl;
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
std::shared_ptr<IExecutableNetwork> actual;
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
|
||||
/**
|
||||
* @brief Constructs ExecutableNetwork from the initialized std::shared_ptr
|
||||
@@ -48,6 +51,18 @@ public:
|
||||
*/
|
||||
ExecutableNetwork() = default;
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
/**
|
||||
* @deprecated This ctor will be removed in 2022.1
|
||||
* @brief Constructs ExecutableNetwork from the initialized std::shared_ptr
|
||||
* @param exec Initialized shared pointer
|
||||
* @param splg Plugin to use. This is required to ensure that ExecutableNetwork can work properly even if plugin object is destroyed.
|
||||
*/
|
||||
INFERENCE_ENGINE_DEPRECATED("This ctor will be removed in 2022.1")
|
||||
explicit ExecutableNetwork(std::shared_ptr<IExecutableNetwork> exec,
|
||||
std::shared_ptr<details::SharedObjectLoader> splg = {});
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
|
||||
/**
|
||||
* @brief Gets the Executable network output Data node information.
|
||||
*
|
||||
|
||||
@@ -22,6 +22,10 @@ namespace InferenceEngine {
|
||||
|
||||
class IInferRequestInternal;
|
||||
|
||||
namespace details {
|
||||
class ICompletionCallbackWrapper;
|
||||
} // namespace details
|
||||
|
||||
/**
|
||||
* @copybrief IInferRequest
|
||||
*
|
||||
@@ -29,8 +33,12 @@ class IInferRequestInternal;
|
||||
* It can throw exceptions safely for the application, where it is properly handled.
|
||||
*/
|
||||
class INFERENCE_ENGINE_API_CLASS(InferRequest) {
|
||||
details::SharedObjectLoader _so;
|
||||
std::shared_ptr<IInferRequestInternal> _impl;
|
||||
details::SharedObjectLoader _so;
|
||||
std::shared_ptr<IInferRequestInternal> _impl;
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
IInferRequest::Ptr actual;
|
||||
std::shared_ptr<details::ICompletionCallbackWrapper> callback;
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
|
||||
/**
|
||||
* @brief Constructs InferRequest from the initialized std::shared_ptr
|
||||
@@ -63,6 +71,18 @@ public:
|
||||
*/
|
||||
InferRequest() = default;
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
/**
|
||||
* @deprecated This ctor will be removed in 2022.1
|
||||
* @brief Constructs InferRequest from the initialized std::shared_ptr
|
||||
* @param request Initialized shared pointer
|
||||
* @param splg Plugin to use. This is required to ensure that InferRequest can work properly even if plugin object is destroyed.
|
||||
*/
|
||||
INFERENCE_ENGINE_DEPRECATED("This ctor will be removed in 2022.1")
|
||||
explicit InferRequest(IInferRequest::Ptr request,
|
||||
std::shared_ptr<details::SharedObjectLoader> splg = {});
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
|
||||
/**
|
||||
* @brief Sets input/output data to infer
|
||||
*
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "ie_api.h"
|
||||
#include "ie_blob.h"
|
||||
#include "details/ie_so_loader.h"
|
||||
#include "ie_imemory_state.hpp"
|
||||
|
||||
namespace InferenceEngine {
|
||||
|
||||
@@ -27,6 +28,9 @@ class IVariableStateInternal;
|
||||
class INFERENCE_ENGINE_API_CLASS(VariableState) {
|
||||
details::SharedObjectLoader _so;
|
||||
std::shared_ptr<IVariableStateInternal> _impl;
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
std::shared_ptr<IVariableState> actual;
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
|
||||
/**
|
||||
* @brief Constructs VariableState from the initialized std::shared_ptr
|
||||
@@ -44,6 +48,18 @@ public:
|
||||
*/
|
||||
VariableState() = default;
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
/**
|
||||
* @deprecated This ctor will be removed in 2022.1
|
||||
* @brief constructs VariableState from the initialized std::shared_ptr
|
||||
* @param pState Initialized shared pointer
|
||||
* @param plg Optional: Plugin to use. This is required to ensure that VariableState can work properly even if plugin object is destroyed.
|
||||
*/
|
||||
INFERENCE_ENGINE_DEPRECATED("This ctor will be removed in 2022.1")
|
||||
explicit VariableState(std::shared_ptr<IVariableState> pState,
|
||||
std::shared_ptr<details::SharedObjectLoader> plg = {});
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
|
||||
/**
|
||||
* @copybrief IVariableState::Reset
|
||||
*
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "ie_common.h"
|
||||
|
||||
#include "cpp/ie_executable_network.hpp"
|
||||
#include "cpp/exception2status.hpp"
|
||||
#include "ie_executable_network_base.hpp"
|
||||
#include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp"
|
||||
|
||||
@@ -26,17 +27,45 @@ ExecutableNetwork::ExecutableNetwork(const details::SharedObjectLoader& so,
|
||||
IE_ASSERT(_impl != nullptr);
|
||||
}
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
|
||||
ExecutableNetwork::ExecutableNetwork(IExecutableNetwork::Ptr exec,
|
||||
std::shared_ptr<details::SharedObjectLoader> splg)
|
||||
: _so(*splg), _impl(), actual(exec) {
|
||||
// plg can be null, but not the actual
|
||||
if (actual == nullptr)
|
||||
IE_THROW() << "ExecutableNetwork was not initialized.";
|
||||
}
|
||||
|
||||
ConstOutputsDataMap ExecutableNetwork::GetOutputsInfo() const {
|
||||
if (actual) {
|
||||
ConstOutputsDataMap data;
|
||||
CALL_STATUS_FNC(GetOutputsInfo, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
EXEC_NET_CALL_STATEMENT(return _impl->GetOutputsInfo());
|
||||
}
|
||||
|
||||
ConstInputsDataMap ExecutableNetwork::GetInputsInfo() const {
|
||||
if (actual) {
|
||||
ConstInputsDataMap info;
|
||||
CALL_STATUS_FNC(GetInputsInfo, info);
|
||||
return info;
|
||||
}
|
||||
|
||||
EXEC_NET_CALL_STATEMENT(return _impl->GetInputsInfo());
|
||||
}
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
|
||||
void ExecutableNetwork::reset(IExecutableNetwork::Ptr newActual) {
|
||||
if (actual) {
|
||||
if (newActual == nullptr) {
|
||||
THROW_IE_EXCEPTION << "ExecutableNetwork wrapper used for reset was not initialized.";
|
||||
}
|
||||
this->actual.swap(newActual);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized.";
|
||||
if (newActual == nullptr) IE_THROW() << "ExecutableNetwork wrapper used for reset was not initialized.";
|
||||
auto newBase = std::dynamic_pointer_cast<ExecutableNetworkBase>(newActual);
|
||||
@@ -47,10 +76,36 @@ void ExecutableNetwork::reset(IExecutableNetwork::Ptr newActual) {
|
||||
}
|
||||
|
||||
ExecutableNetwork::operator IExecutableNetwork::Ptr() {
|
||||
if (actual) {
|
||||
return actual;
|
||||
}
|
||||
|
||||
return std::make_shared<ExecutableNetworkBase>(_impl);
|
||||
}
|
||||
|
||||
std::vector<VariableState> ExecutableNetwork::QueryState() {
|
||||
if (actual) {
|
||||
if (actual == nullptr) THROW_IE_EXCEPTION << "ExecutableNetwork was not initialized.";
|
||||
IVariableState::Ptr pState = nullptr;
|
||||
auto res = OK;
|
||||
std::vector<VariableState> controller;
|
||||
for (size_t idx = 0; res == OK; ++idx) {
|
||||
ResponseDesc resp;
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
res = actual->QueryState(pState, idx, &resp);
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
if (res != OK && res != OUT_OF_BOUNDS) {
|
||||
THROW_IE_EXCEPTION << resp.msg;
|
||||
}
|
||||
if (res != OUT_OF_BOUNDS) {
|
||||
controller.push_back(VariableState(pState,
|
||||
std::make_shared<details::SharedObjectLoader>(_so)));
|
||||
}
|
||||
}
|
||||
|
||||
return controller;
|
||||
}
|
||||
|
||||
std::vector<VariableState> controller;
|
||||
EXEC_NET_CALL_STATEMENT(
|
||||
for (auto&& state : _impl->QueryState()) {
|
||||
@@ -59,49 +114,88 @@ std::vector<VariableState> ExecutableNetwork::QueryState() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
|
||||
InferRequest ExecutableNetwork::CreateInferRequest() {
|
||||
if (actual) {
|
||||
IInferRequest::Ptr req;
|
||||
CALL_STATUS_FNC(CreateInferRequest, req);
|
||||
if (req.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to infer request is null";
|
||||
return InferRequest(req, std::make_shared<details::SharedObjectLoader>(_so));
|
||||
}
|
||||
|
||||
EXEC_NET_CALL_STATEMENT(return {_so, _impl->CreateInferRequest()});
|
||||
}
|
||||
|
||||
InferRequest::Ptr ExecutableNetwork::CreateInferRequestPtr() {
|
||||
EXEC_NET_CALL_STATEMENT(return std::make_shared<InferRequest>(CreateInferRequest()));
|
||||
return std::make_shared<InferRequest>(CreateInferRequest());
|
||||
}
|
||||
|
||||
void ExecutableNetwork::Export(const std::string& modelFileName) {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC(Export, modelFileName);
|
||||
return;
|
||||
}
|
||||
EXEC_NET_CALL_STATEMENT(_impl->Export(modelFileName));
|
||||
}
|
||||
|
||||
void ExecutableNetwork::Export(std::ostream& networkModel) {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC(Export, networkModel);
|
||||
return;
|
||||
}
|
||||
EXEC_NET_CALL_STATEMENT(_impl->Export(networkModel));
|
||||
}
|
||||
|
||||
CNNNetwork ExecutableNetwork::GetExecGraphInfo() {
|
||||
if (actual) {
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
ICNNNetwork::Ptr ptr = nullptr;
|
||||
CALL_STATUS_FNC(GetExecGraphInfo, ptr);
|
||||
return CNNNetwork(ptr);
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
EXEC_NET_CALL_STATEMENT(return _impl->GetExecGraphInfo());
|
||||
}
|
||||
|
||||
void ExecutableNetwork::SetConfig(const std::map<std::string, Parameter>& config) {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC(SetConfig, config);
|
||||
return;
|
||||
}
|
||||
EXEC_NET_CALL_STATEMENT(_impl->SetConfig(config));
|
||||
}
|
||||
|
||||
Parameter ExecutableNetwork::GetConfig(const std::string& name) const {
|
||||
if (actual) {
|
||||
Parameter configValue;
|
||||
CALL_STATUS_FNC(GetConfig, name, configValue);
|
||||
return configValue;
|
||||
}
|
||||
EXEC_NET_CALL_STATEMENT(return _impl->GetConfig(name));
|
||||
}
|
||||
|
||||
Parameter ExecutableNetwork::GetMetric(const std::string& name) const {
|
||||
if (actual) {
|
||||
Parameter metricValue;
|
||||
CALL_STATUS_FNC(GetMetric, name, metricValue);
|
||||
return metricValue;
|
||||
}
|
||||
EXEC_NET_CALL_STATEMENT(return _impl->GetMetric(name));
|
||||
}
|
||||
|
||||
RemoteContext::Ptr ExecutableNetwork::GetContext() const {
|
||||
if (actual) {
|
||||
RemoteContext::Ptr pContext;
|
||||
CALL_STATUS_FNC(GetContext, pContext);
|
||||
return pContext;
|
||||
}
|
||||
EXEC_NET_CALL_STATEMENT(return _impl->GetContext());
|
||||
}
|
||||
|
||||
bool ExecutableNetwork::operator!() const noexcept {
|
||||
return !_impl;
|
||||
return !_impl || !actual;
|
||||
}
|
||||
|
||||
ExecutableNetwork::operator bool() const noexcept {
|
||||
return !!_impl;
|
||||
return !!_impl || !!actual;
|
||||
}
|
||||
} // namespace InferenceEngine
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "ie_remote_context.hpp"
|
||||
|
||||
#include "cpp/ie_infer_request.hpp"
|
||||
#include "cpp/exception2status.hpp"
|
||||
#include "ie_infer_async_request_base.hpp"
|
||||
#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp"
|
||||
|
||||
@@ -32,7 +33,7 @@ namespace InferenceEngine {
|
||||
CATCH_IE_EXCEPTION(InferCancelled)
|
||||
|
||||
#define INFER_REQ_CALL_STATEMENT(...) \
|
||||
if (_impl == nullptr) IE_THROW() << "Inference Request is not initialized"; \
|
||||
if (_impl == nullptr) IE_THROW() << "Inference Request is not initialized"; \
|
||||
try { \
|
||||
__VA_ARGS__ \
|
||||
} CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \
|
||||
@@ -43,15 +44,40 @@ namespace InferenceEngine {
|
||||
|
||||
InferRequest::InferRequest(const details::SharedObjectLoader& so,
|
||||
const IInferRequestInternal::Ptr& impl)
|
||||
: _so(so), _impl(impl) {
|
||||
: _so(so), _impl(impl), actual() {
|
||||
IE_ASSERT(_impl != nullptr);
|
||||
}
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
|
||||
InferRequest::InferRequest(IInferRequest::Ptr request,
|
||||
std::shared_ptr<details::SharedObjectLoader> splg)
|
||||
: _so(*splg), _impl(), actual(request) {
|
||||
// plg can be null, but not the actual
|
||||
if (actual == nullptr)
|
||||
IE_THROW() << "InferRequest was not initialized.";
|
||||
}
|
||||
|
||||
void InferRequest::SetBlob(const std::string& name, const Blob::Ptr& data) {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC(SetBlob, name.c_str(), data);
|
||||
return;
|
||||
}
|
||||
INFER_REQ_CALL_STATEMENT(_impl->SetBlob(name, data);)
|
||||
}
|
||||
|
||||
Blob::Ptr InferRequest::GetBlob(const std::string& name) {
|
||||
if (actual) {
|
||||
Blob::Ptr data;
|
||||
CALL_STATUS_FNC(GetBlob, name.c_str(), data);
|
||||
std::string error = "Internal error: blob with name `" + name + "` is not allocated!";
|
||||
auto blobPtr = data.get();
|
||||
const bool remoteBlobPassed = blobPtr->is<RemoteBlob>();
|
||||
if (blobPtr == nullptr) IE_THROW() << error;
|
||||
if (!remoteBlobPassed && blobPtr->buffer() == nullptr) IE_THROW() << error;
|
||||
return data;
|
||||
}
|
||||
|
||||
Blob::Ptr blobPtr;
|
||||
INFER_REQ_CALL_STATEMENT(blobPtr = _impl->GetBlob(name);)
|
||||
std::string error = "Internal error: blob with name `" + name + "` is not allocated!";
|
||||
@@ -62,26 +88,60 @@ Blob::Ptr InferRequest::GetBlob(const std::string& name) {
|
||||
}
|
||||
|
||||
void InferRequest::SetBlob(const std::string &name, const Blob::Ptr &data, const PreProcessInfo& info) {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC(SetBlob, name.c_str(), data, info);
|
||||
return;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(_impl->SetBlob(name, data, info);)
|
||||
}
|
||||
|
||||
const PreProcessInfo& InferRequest::GetPreProcess(const std::string& name) const {
|
||||
if (actual) {
|
||||
const PreProcessInfo* info = nullptr;
|
||||
CALL_STATUS_FNC(GetPreProcess, name.c_str(), &info);
|
||||
return *info;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(return _impl->GetPreProcess(name);)
|
||||
}
|
||||
|
||||
void InferRequest::Infer() {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC_NO_ARGS(Infer);
|
||||
return;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(_impl->Infer();)
|
||||
}
|
||||
|
||||
void InferRequest::Cancel() {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC_NO_ARGS(Cancel);
|
||||
return;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(_impl->Cancel();)
|
||||
}
|
||||
|
||||
std::map<std::string, InferenceEngineProfileInfo> InferRequest::GetPerformanceCounts() const {
|
||||
if (actual) {
|
||||
std::map<std::string, InferenceEngineProfileInfo> perfMap;
|
||||
CALL_STATUS_FNC(GetPerformanceCounts, perfMap);
|
||||
return perfMap;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(return _impl->GetPerformanceCounts();)
|
||||
}
|
||||
|
||||
void InferRequest::SetInput(const BlobMap& inputs) {
|
||||
if (actual) {
|
||||
for (auto&& input : inputs) {
|
||||
CALL_STATUS_FNC(SetBlob, input.first.c_str(), input.second);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(
|
||||
for (auto&& input : inputs) {
|
||||
_impl->SetBlob(input.first, input.second);
|
||||
@@ -90,6 +150,13 @@ void InferRequest::SetInput(const BlobMap& inputs) {
|
||||
}
|
||||
|
||||
void InferRequest::SetOutput(const BlobMap& results) {
|
||||
if (actual) {
|
||||
for (auto&& result : results) {
|
||||
CALL_STATUS_FNC(SetBlob, result.first.c_str(), result.second);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(
|
||||
for (auto&& result : results) {
|
||||
_impl->SetBlob(result.first, result.second);
|
||||
@@ -98,27 +165,113 @@ void InferRequest::SetOutput(const BlobMap& results) {
|
||||
}
|
||||
|
||||
void InferRequest::SetBatch(const int batch) {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC(SetBatch, batch);
|
||||
return;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(_impl->SetBatch(batch);)
|
||||
}
|
||||
|
||||
void InferRequest::StartAsync() {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC_NO_ARGS(StartAsync);
|
||||
return;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(_impl->StartAsync();)
|
||||
}
|
||||
|
||||
|
||||
StatusCode InferRequest::Wait(int64_t millis_timeout) {
|
||||
if (actual) {
|
||||
ResponseDesc resp;
|
||||
if (actual == nullptr) IE_THROW() << "InferRequest was not initialized.";
|
||||
auto res = actual->Wait(millis_timeout, &resp);
|
||||
if (res != OK && res != RESULT_NOT_READY &&
|
||||
res != INFER_NOT_STARTED && res != INFER_CANCELLED) {
|
||||
IE_EXCEPTION_SWITCH(res, ExceptionType,
|
||||
InferenceEngine::details::ThrowNow<ExceptionType>{}
|
||||
<<= std::stringstream{} << IE_LOCATION << resp.msg)
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(return _impl->Wait(millis_timeout);)
|
||||
}
|
||||
|
||||
void InferRequest::SetCompletionCallbackImpl(std::function<void()> callback) {
|
||||
namespace details {
|
||||
|
||||
class ICompletionCallbackWrapper {
|
||||
public:
|
||||
virtual ~ICompletionCallbackWrapper() = default;
|
||||
|
||||
virtual void call(InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode code) const noexcept = 0;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class CompletionCallbackWrapper : public ICompletionCallbackWrapper {
|
||||
T lambda;
|
||||
|
||||
public:
|
||||
explicit CompletionCallbackWrapper(const T& lambda): lambda(lambda) {}
|
||||
|
||||
void call(InferenceEngine::IInferRequest::Ptr /*request*/, InferenceEngine::StatusCode /*code*/) const
|
||||
noexcept override {
|
||||
lambda();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class CompletionCallbackWrapper<IInferRequest::CompletionCallback> : public ICompletionCallbackWrapper {
|
||||
IInferRequest::CompletionCallback callBack;
|
||||
|
||||
public:
|
||||
explicit CompletionCallbackWrapper(const IInferRequest::CompletionCallback& callBack): callBack(callBack) {}
|
||||
|
||||
void call(InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode code) const noexcept override {
|
||||
callBack(request, code);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class CompletionCallbackWrapper<std::function<void(InferRequest, StatusCode)>> : public ICompletionCallbackWrapper {
|
||||
std::function<void(InferRequest, StatusCode)> lambda;
|
||||
|
||||
public:
|
||||
explicit CompletionCallbackWrapper(const std::function<void(InferRequest, InferenceEngine::StatusCode)>& lambda)
|
||||
: lambda(lambda) {}
|
||||
|
||||
void call(InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode code) const noexcept override {
|
||||
lambda(InferRequest(request), code);
|
||||
}
|
||||
};
|
||||
|
||||
void callWrapper(InferenceEngine::IInferRequest::Ptr request, InferenceEngine::StatusCode code) {
|
||||
details::ICompletionCallbackWrapper* pWrapper = nullptr;
|
||||
ResponseDesc dsc;
|
||||
request->GetUserData(reinterpret_cast<void**>(&pWrapper), &dsc);
|
||||
pWrapper->call(request, code);
|
||||
}
|
||||
|
||||
} // namespace details
|
||||
|
||||
void InferRequest::SetCompletionCallbackImpl(std::function<void()> callbackToSet) {
|
||||
if (actual) {
|
||||
using T = std::function<void()>;
|
||||
callback.reset(new details::CompletionCallbackWrapper<T>(callbackToSet));
|
||||
CALL_STATUS_FNC(SetUserData, callback.get());
|
||||
actual->SetCompletionCallback(InferenceEngine::details::callWrapper);
|
||||
return;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(
|
||||
_impl->SetCallback([callback] (std::exception_ptr) {
|
||||
callback();
|
||||
_impl->SetCallback([callbackToSet] (std::exception_ptr) {
|
||||
callbackToSet();
|
||||
});
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
#define CATCH_IE_EXCEPTION_RETURN(StatusCode, ExceptionType) catch (const ExceptionType&) {return StatusCode;}
|
||||
|
||||
#define CATCH_IE_EXCEPTIONS_RETURN \
|
||||
@@ -137,10 +290,18 @@ void InferRequest::SetCompletionCallbackImpl(std::function<void()> callback) {
|
||||
CATCH_IE_EXCEPTION_RETURN(INFER_CANCELLED, InferCancelled)
|
||||
|
||||
|
||||
void InferRequest::SetCompletionCallbackImpl(std::function<void(InferRequest, StatusCode)> callback) {
|
||||
void InferRequest::SetCompletionCallbackImpl(std::function<void(InferRequest, StatusCode)> callbackToSet) {
|
||||
if (actual) {
|
||||
using T = std::function<void(InferRequest, StatusCode)>;
|
||||
callback.reset(new details::CompletionCallbackWrapper<T>(callbackToSet));
|
||||
CALL_STATUS_FNC(SetUserData, callback.get());
|
||||
actual->SetCompletionCallback(InferenceEngine::details::callWrapper);
|
||||
return;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(
|
||||
auto weakThis = InferRequest{_so, std::shared_ptr<IInferRequestInternal>{_impl.get(), [](IInferRequestInternal*){}}};
|
||||
_impl->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) {
|
||||
_impl->SetCallback([callbackToSet, weakThis] (std::exception_ptr exceptionPtr) {
|
||||
StatusCode statusCode = StatusCode::OK;
|
||||
if (exceptionPtr != nullptr) {
|
||||
statusCode = [&] {
|
||||
@@ -153,17 +314,23 @@ void InferRequest::SetCompletionCallbackImpl(std::function<void(InferRequest, St
|
||||
}
|
||||
} ();
|
||||
}
|
||||
callback(weakThis, statusCode);
|
||||
callbackToSet(weakThis, statusCode);
|
||||
});
|
||||
)
|
||||
}
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
void InferRequest::SetCompletionCallbackImpl(IInferRequest::CompletionCallback callbackToSet) {
|
||||
if (actual) {
|
||||
using T = IInferRequest::CompletionCallback;
|
||||
callback.reset(new details::CompletionCallbackWrapper<T>(callbackToSet));
|
||||
CALL_STATUS_FNC(SetUserData, callback.get());
|
||||
actual->SetCompletionCallback(InferenceEngine::details::callWrapper);
|
||||
return;
|
||||
}
|
||||
|
||||
void InferRequest::SetCompletionCallbackImpl(IInferRequest::CompletionCallback callback) {
|
||||
INFER_REQ_CALL_STATEMENT(
|
||||
IInferRequest::Ptr weakThis = InferRequest{_so, std::shared_ptr<IInferRequestInternal>{_impl.get(), [](IInferRequestInternal*){}}};
|
||||
_impl->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) {
|
||||
_impl->SetCallback([callbackToSet, weakThis] (std::exception_ptr exceptionPtr) {
|
||||
StatusCode statusCode = StatusCode::OK;
|
||||
if (exceptionPtr != nullptr) {
|
||||
statusCode = [&] {
|
||||
@@ -176,20 +343,44 @@ void InferRequest::SetCompletionCallbackImpl(IInferRequest::CompletionCallback c
|
||||
}
|
||||
} ();
|
||||
}
|
||||
callback(weakThis, statusCode);
|
||||
callbackToSet(weakThis, statusCode);
|
||||
});
|
||||
)
|
||||
}
|
||||
|
||||
InferRequest::operator IInferRequest::Ptr () {
|
||||
if (actual) {
|
||||
return actual;
|
||||
}
|
||||
|
||||
INFER_REQ_CALL_STATEMENT(
|
||||
return std::make_shared<InferRequestBase>(_impl);
|
||||
)
|
||||
}
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
|
||||
std::vector<VariableState> InferRequest::QueryState() {
|
||||
if (actual) {
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
if (actual == nullptr) IE_THROW() << "ExecutableNetwork was not initialized.";
|
||||
IVariableState::Ptr pState = nullptr;
|
||||
auto res = OK;
|
||||
std::vector<VariableState> controller;
|
||||
for (size_t idx = 0; res == OK; ++idx) {
|
||||
ResponseDesc resp;
|
||||
res = actual->QueryState(pState, idx, &resp);
|
||||
if (res != OK && res != OUT_OF_BOUNDS) {
|
||||
IE_THROW() << resp.msg;
|
||||
}
|
||||
if (res != OUT_OF_BOUNDS) {
|
||||
controller.push_back(VariableState(pState,
|
||||
std::make_shared<details::SharedObjectLoader>(_so)));
|
||||
}
|
||||
}
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
|
||||
return controller;
|
||||
}
|
||||
|
||||
std::vector<VariableState> controller;
|
||||
INFER_REQ_CALL_STATEMENT(
|
||||
for (auto&& state : _impl->QueryState()) {
|
||||
@@ -200,11 +391,11 @@ std::vector<VariableState> InferRequest::QueryState() {
|
||||
}
|
||||
|
||||
bool InferRequest::operator!() const noexcept {
|
||||
return !_impl;
|
||||
return !_impl || !actual;
|
||||
}
|
||||
|
||||
InferRequest::operator bool() const noexcept {
|
||||
return !!_impl;
|
||||
return (!!_impl) || (!!actual);
|
||||
}
|
||||
|
||||
bool InferRequest::operator!=(const InferRequest& r) const noexcept {
|
||||
@@ -212,6 +403,7 @@ bool InferRequest::operator!=(const InferRequest& r) const noexcept {
|
||||
}
|
||||
|
||||
bool InferRequest::operator==(const InferRequest& r) const noexcept {
|
||||
return r._impl == _impl;
|
||||
return r._impl == _impl && r.actual == actual;
|
||||
}
|
||||
|
||||
} // namespace InferenceEngine
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "details/ie_so_loader.h"
|
||||
#include "cpp/ie_memory_state.hpp"
|
||||
#include "ie_imemory_state.hpp"
|
||||
#include "cpp_interfaces/interface/ie_ivariable_state_internal.hpp"
|
||||
#include "exception2status.hpp"
|
||||
|
||||
@@ -27,25 +28,53 @@ VariableState::VariableState(const details::SharedObjectLoader& so,
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
|
||||
VariableState::VariableState(std::shared_ptr<IVariableState> state,
|
||||
std::shared_ptr<details::SharedObjectLoader> splg)
|
||||
: _so(*splg), _impl(), actual(state) {
|
||||
// plg can be null, but not the actual
|
||||
if (actual == nullptr)
|
||||
IE_THROW() << "VariableState was not initialized.";
|
||||
}
|
||||
|
||||
Blob::CPtr VariableState::GetLastState() const {
|
||||
return GetState();
|
||||
}
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_END
|
||||
|
||||
void VariableState::Reset() {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC_NO_ARGS(Reset);
|
||||
return;
|
||||
}
|
||||
|
||||
VARIABLE_CALL_STATEMENT(_impl->Reset());
|
||||
}
|
||||
|
||||
std::string VariableState::GetName() const {
|
||||
if (actual) {
|
||||
char name[256];
|
||||
CALL_STATUS_FNC(GetName, name, sizeof(name));
|
||||
return name;
|
||||
}
|
||||
|
||||
VARIABLE_CALL_STATEMENT(return _impl->GetName());
|
||||
}
|
||||
|
||||
Blob::CPtr VariableState::GetState() const {
|
||||
if (actual) {
|
||||
Blob::CPtr stateBlob;
|
||||
CALL_STATUS_FNC(GetState, stateBlob);
|
||||
return stateBlob;
|
||||
}
|
||||
|
||||
VARIABLE_CALL_STATEMENT(return _impl->GetState());
|
||||
}
|
||||
|
||||
void VariableState::SetState(Blob::Ptr state) {
|
||||
if (actual) {
|
||||
CALL_STATUS_FNC(SetState, state);
|
||||
return;
|
||||
}
|
||||
|
||||
VARIABLE_CALL_STATEMENT(_impl->SetState(state));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user