ie_infer_async_request_base.hpp
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <map>
8 #include <memory>
9 #include <string>
10 
13 #include <cpp_interfaces/base/ie_variable_state_base.hpp>
14 #include <cpp_interfaces/interface/ie_iinfer_async_request_internal.hpp>
15 #include "ie_iinfer_request.hpp"
16 #include "ie_preprocess.hpp"
17 
18 namespace InferenceEngine {
19 
20 /**
21  * @brief Inference request `noexcept` wrapper which accepts IAsyncInferRequestInternal derived instance which can throw exceptions
22  * @ingroup ie_dev_api_async_infer_request_api
23  */
25  std::shared_ptr<IAsyncInferRequestInternal> _impl;
26 
27 public:
28  /**
29  * @brief Constructor with actual underlying implementation.
30  * @param impl Underlying implementation of type IAsyncInferRequestInternal
31  */
32  explicit InferRequestBase(std::shared_ptr<IAsyncInferRequestInternal> impl): _impl(impl) {}
33 
34  StatusCode Infer(ResponseDesc* resp) noexcept override {
35  OV_ITT_SCOPED_TASK(itt::domains::Plugin, "Infer");
36  TO_STATUS(_impl->Infer());
37  }
38 
39  StatusCode Cancel(ResponseDesc* resp) noexcept override {
40  OV_ITT_SCOPED_TASK(itt::domains::Plugin, "Cancel");
41  TO_STATUS(_impl->Cancel());
42  }
43 
44  StatusCode GetPerformanceCounts(std::map<std::string, InferenceEngineProfileInfo>& perfMap,
45  ResponseDesc* resp) const noexcept override {
46  TO_STATUS(perfMap = _impl->GetPerformanceCounts());
47  }
48 
49  StatusCode SetBlob(const char* name, const Blob::Ptr& data, ResponseDesc* resp) noexcept override {
50  TO_STATUS(_impl->SetBlob(name, data));
51  }
52 
53  StatusCode SetBlob(const char* name, const Blob::Ptr& data, const PreProcessInfo& info, ResponseDesc* resp) noexcept override {
54  TO_STATUS(_impl->SetBlob(name, data, info));
55  }
56 
57  StatusCode GetBlob(const char* name, Blob::Ptr& data, ResponseDesc* resp) noexcept override {
58  TO_STATUS(data = _impl->GetBlob(name));
59  }
60 
61  StatusCode GetPreProcess(const char* name, const PreProcessInfo** info, ResponseDesc *resp) const noexcept override {
62  TO_STATUS(*info = &(_impl->GetPreProcess(name)));
63  }
64 
65  StatusCode StartAsync(ResponseDesc* resp) noexcept override {
66  OV_ITT_SCOPED_TASK(itt::domains::Plugin, "StartAsync");
67  TO_STATUS(_impl->StartAsync());
68  }
69 
70  StatusCode Wait(int64_t millis_timeout, ResponseDesc* resp) noexcept override {
71  OV_ITT_SCOPED_TASK(itt::domains::Plugin, "Wait");
72  NO_EXCEPT_CALL_RETURN_STATUS(_impl->Wait(millis_timeout));
73  }
74 
75  StatusCode SetCompletionCallback(CompletionCallback callback) noexcept override {
76  TO_STATUS_NO_RESP(_impl->SetCompletionCallback(callback));
77  }
78 
79  StatusCode GetUserData(void** data, ResponseDesc* resp) noexcept override {
80  TO_STATUS(_impl->GetUserData(data));
81  }
82 
83  StatusCode SetUserData(void* data, ResponseDesc* resp) noexcept override {
84  TO_STATUS(_impl->SetUserData(data));
85  }
86 
87  void Release() noexcept override {
88  delete this;
89  }
90 
91  StatusCode SetBatch(int batch_size, ResponseDesc* resp) noexcept override {
92  TO_STATUS(_impl->SetBatch(batch_size));
93  }
94 
95  IE_SUPPRESS_DEPRECATED_START
96  StatusCode QueryState(IVariableState::Ptr& pState, size_t idx, ResponseDesc* resp) noexcept override {
97  try {
98  auto v = _impl->QueryState();
99  if (idx >= v.size()) {
100  return OUT_OF_BOUNDS;
101  }
102  pState = std::make_shared<VariableStateBase>(v[idx]);
103  return OK;
104  } catch (const std::exception& ex) {
105  return InferenceEngine::DescriptionBuffer(GENERAL_ERROR, resp) << ex.what();
106  } catch (...) {
107  return InferenceEngine::DescriptionBuffer(UNEXPECTED);
108  }
109  }
110  IE_SUPPRESS_DEPRECATED_END
111 
112 private:
113  ~InferRequestBase() = default;
114 };
115 
116 } // namespace InferenceEngine
std::shared_ptr< Blob > Ptr
void(* CompletionCallback)(InferenceEngine::IInferRequest::Ptr context, InferenceEngine::StatusCode code)
std::shared_ptr< IVariableState > Ptr
Inference request noexcept wrapper which accepts IAsyncInferRequestInternal derived instance which ca...
Definition: ie_infer_async_request_base.hpp:24
InferRequestBase(std::shared_ptr< IAsyncInferRequestInternal > impl)
Constructor with actual underlying implementation.
Definition: ie_infer_async_request_base.hpp:32
Wrappers from c++ function to c-style one.
#define NO_EXCEPT_CALL_RETURN_STATUS(x)
Returns a status code of a called function, handles exeptions and converts to a status code.
Definition: exception2status.hpp:64
#define TO_STATUS_NO_RESP(x)
Converts C++ exceptioned function call into a status code. Does not work with a ResponseDesc object.
Definition: exception2status.hpp:47
#define TO_STATUS(x)
Converts C++ exceptioned function call into a c-style one.
Definition: exception2status.hpp:29
Inference Engine Plugin API namespace.
Defines openvino domains for tracing.
A description buffer wrapping StatusCode and ResponseDesc.
Definition: description_buffer.hpp:24