ie_infer_async_request_internal.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 
11 #include "cpp_interfaces/impl/ie_infer_request_internal.hpp"
12 #include "cpp_interfaces/interface/ie_iinfer_async_request_internal.hpp"
13 
14 namespace InferenceEngine {
15 
16 #if defined(_MSC_VER)
17 #pragma warning(disable : 4250)
18 #endif
19 
20 /**
21  * @brief minimum API to be implemented by plugin, which is used in InferRequestBase forwarding mechanism
22  * @ingroup ie_dev_api_async_infer_request_api
23  */
25 public:
26  /**
27  * @brief A shared pointer to a AsyncInferRequestInternal implementation
28  */
29  typedef std::shared_ptr<AsyncInferRequestInternal> Ptr;
30 
31  /**
32  * @brief Constructs a new instance.
33  * @param[in] networkInputs The network inputs info
34  * @param[in] networkOutputs The network outputs data
35  */
36  AsyncInferRequestInternal(const InputsDataMap& networkInputs, const OutputsDataMap& networkOutputs)
37  : InferRequestInternal(networkInputs, networkOutputs), _callback(nullptr), _userData(nullptr) {}
38 
40  _callback = callback;
41  }
42 
43  void GetUserData(void** data) override {
44  if (data == nullptr) THROW_IE_EXCEPTION << NOT_ALLOCATED_str;
45  *data = _userData;
46  }
47 
48  void SetUserData(void* data) override {
49  _userData = data;
50  }
51 
52  /**
53  * @brief Set weak pointer to the corresponding public interface: IInferRequest. This allow to pass it to
54  * IInferRequest::CompletionCallback
55  * @param ptr A weak pointer to InferRequestBase
56  */
58  _publicInterface = ptr;
59  }
60 
61  void StartAsync() override {
62  checkBlobs();
64  };
65 
66 protected:
67  /**
68  * @brief The minimal asynchronous inference function to be implemented by plugins.
69  * It starts inference of specified input(s) in asynchronous mode
70  * @note
71  * * The methos is used in AsyncInferRequestInternal::StartAsync which performs common steps first and
72  * calls plugin dependent implementation of this method after.
73  * * It returns immediately. Inference starts also immediately.
74  */
75  virtual void StartAsyncImpl() = 0;
76 
77  IInferRequest::WeakPtr _publicInterface; //!< A weak pointer to a IInferRequest interface for callback calling
79  void* _userData; //!< A callback user data
80 };
81 
82 } // namespace InferenceEngine
minimum API to be implemented by plugin, which is used in InferRequestBase forwarding mechanism
Definition: ie_infer_async_request_internal.hpp:24
std::shared_ptr< AsyncInferRequestInternal > Ptr
A shared pointer to a AsyncInferRequestInternal implementation.
Definition: ie_infer_async_request_internal.hpp:29
AsyncInferRequestInternal(const InputsDataMap &networkInputs, const OutputsDataMap &networkOutputs)
Constructs a new instance.
Definition: ie_infer_async_request_internal.hpp:36
void SetCompletionCallback(IInferRequest::CompletionCallback callback) override
Set callback function which will be called on success or failure of asynchronous request.
Definition: ie_infer_async_request_internal.hpp:39
void SetUserData(void *data) override
Set arbitrary data for the request.
Definition: ie_infer_async_request_internal.hpp:48
void SetPointerToPublicInterface(IInferRequest::Ptr ptr)
Set weak pointer to the corresponding public interface: IInferRequest. This allow to pass it to IInfe...
Definition: ie_infer_async_request_internal.hpp:57
InferenceEngine::IInferRequest::CompletionCallback _callback
A callback.
Definition: ie_infer_async_request_internal.hpp:78
IInferRequest::WeakPtr _publicInterface
A weak pointer to a IInferRequest interface for callback calling.
Definition: ie_infer_async_request_internal.hpp:77
virtual void StartAsyncImpl()=0
The minimal asynchronous inference function to be implemented by plugins. It starts inference of spec...
void * _userData
A callback user data.
Definition: ie_infer_async_request_internal.hpp:79
void StartAsync() override
Start inference of specified input(s) in asynchronous mode.
Definition: ie_infer_async_request_internal.hpp:61
void GetUserData(void **data) override
Get arbitrary data for the request.
Definition: ie_infer_async_request_internal.hpp:43
An internal API of asynchronous inference request to be implemented by plugin, which is used in Infer...
Definition: ie_iinfer_async_request_internal.hpp:22
std::weak_ptr< IInferRequest > WeakPtr
void(* CompletionCallback)(InferenceEngine::IInferRequest::Ptr context, InferenceEngine::StatusCode code)
std::shared_ptr< IInferRequest > Ptr
An optimal implementation of IInferRequestInternal interface to avoid duplication in all plugins This...
Definition: ie_infer_request_internal.hpp:32
virtual void checkBlobs()
Checks that both inputs and outputs blob are valid. Throws an exception if they are not.
Definition: ie_infer_request_internal.hpp:233
#define NOT_ALLOCATED_str
Defines the not allocated message.
Definition: exception2status.hpp:142
#define THROW_IE_EXCEPTION
Inference Engine Plugin API namespace.
std::map< std::string, InputInfo::Ptr > InputsDataMap
std::map< std::string, DataPtr > OutputsDataMap