ie_iinfer_request.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief a header file for IInferRequest interface
7  *
8  * @file ie_iinfer_request.hpp
9  */
10 
11 #pragma once
12 
13 #include <map>
14 #include <memory>
15 #include <string>
16 
17 #include "ie_blob.h"
18 #include "ie_common.h"
19 #include "ie_preprocess.hpp"
20 #include "ie_imemory_state.hpp"
21 #include "details/ie_irelease.hpp"
22 
23 namespace InferenceEngine {
24 
25 /**
26  * @brief This is an interface of asynchronous infer request
27  *
28  */
29 class IInferRequest : public details::IRelease {
30 public:
31  /**
32  * @enum WaitMode
33  * @brief Enumeration to hold wait mode for IInferRequest
34  */
35  enum WaitMode : int64_t {
36  /** Wait until inference result becomes available */
38  /** IInferRequest doesn't block or interrupt current thread and immediately returns inference status */
40  };
41  /**
42  * @brief A shared pointer to the IInferRequest object
43  */
44  using Ptr = std::shared_ptr<IInferRequest>;
45  /**
46  * @brief A smart pointer to the IInferRequest object
47  */
48  using WeakPtr = std::weak_ptr<IInferRequest>;
49 
50  /**
51  * @brief Sets input/output data to infer
52  *
53  * @note Memory allocation does not happen
54  * @param name Name of input or output blob.
55  * @param data Reference to input or output blob. The type of a blob must match the network input precision and
56  * size.
57  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
58  * @return Status code of the operation: InferenceEngine::OK (0) for success
59  */
60  virtual StatusCode SetBlob(const char* name, const Blob::Ptr& data, ResponseDesc* resp) noexcept = 0;
61 
62  /**
63  * @brief Gets input/output data for inference
64  *
65  * @note Memory allocation does not happen
66  * @param name Name of input or output blob.
67  * @param data Reference to input or output blob. The type of Blob must match the network input precision and size.
68  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
69  * @return Status code of the operation: InferenceEngine::OK (0) for success
70  */
71  virtual StatusCode GetBlob(const char* name, Blob::Ptr& data, ResponseDesc* resp) noexcept = 0;
72 
73  /**
74  * @brief Sets pre-process for input data
75  * @param name Name of input blob.
76  * @param data Reference to input or output blob. The type of Blob must match the network input precision and size.
77  * @param info Preprocess info for blob.
78  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
79  * @return Status code of the operation: OK (0) for success
80  */
81  virtual StatusCode SetBlob(const char *name, const Blob::Ptr &data, const PreProcessInfo& info, ResponseDesc *resp) noexcept = 0;
82 
83  /**
84  * @brief Gets pre-process for input data
85  * @param name Name of input blob.
86  * @param info pointer to a pointer to PreProcessInfo structure
87  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
88  * @return Status code of the operation: OK (0) for success
89  */
90  virtual StatusCode GetPreProcess(const char* name, const PreProcessInfo** info, ResponseDesc *resp) const noexcept = 0;
91  /**
92  * @brief Infers specified input(s) in synchronous mode
93  *
94  * @note blocks all methods of IInferRequest while request is ongoing (running or waiting in queue)
95  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
96  * @return Status code of the operation: InferenceEngine::OK (0) for success
97  */
98  virtual StatusCode Infer(ResponseDesc* resp) noexcept = 0;
99  /**
100  * @brief Cancels current async inference request
101  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
102  * @return Status code of the operation: InferenceEngine::OK (0) for success
103  */
104  virtual StatusCode Cancel(ResponseDesc* resp) noexcept = 0;
105 
106  /**
107  * @brief Queries performance measures per layer to get feedback of what is the most time consuming layer
108  *
109  * @note not all plugins provide meaningful data
110  * @param perfMap Map of layer names to profiling information for that layer
111  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
112  * @return Status code of the operation: InferenceEngine::OK (0) for success
113  */
114  virtual StatusCode GetPerformanceCounts(std::map<std::string, InferenceEngineProfileInfo>& perfMap,
115  ResponseDesc* resp) const noexcept = 0;
116 
117  /**
118  * @brief Waits for the result to become available. Blocks until specified millis_timeout has elapsed or the result
119  * becomes available, whichever comes first.
120  *
121  * @param millis_timeout Maximum duration in milliseconds to block for
122  * @note There are special cases when millis_timeout is equal some value of the WaitMode enum:
123  * * STATUS_ONLY - immediately returns inference status (IInferRequest::RequestStatus). It does not block or
124  * interrupt current thread
125  * * RESULT_READY - waits until inference result becomes available
126  * @param resp Optional: a pointer to an already allocated object to contain extra information of a failure (if
127  * occurred)
128  * @return Enumeration of the resulted action: InferenceEngine::OK (0) for success
129  */
130  virtual InferenceEngine::StatusCode Wait(int64_t millis_timeout, ResponseDesc* resp) noexcept = 0;
131 
132  /**
133  * @brief Starts inference of specified input(s) in asynchronous mode
134  *
135  * @note It returns immediately. Inference starts also immediately
136  * @param resp Optional: a pointer to an already allocated object to contain extra information of a failure (if
137  * occurred)
138  * @return Enumeration of the resulted action: InferenceEngine::OK (0) for success
139  */
140  virtual StatusCode StartAsync(ResponseDesc* resp) noexcept = 0;
141 
142  /**
143  * @brief Completion callback definition as pointer to a function
144  *
145  * @param context Pointer to request for providing context inside callback
146  * @param code Completion result status: InferenceEngine::OK (0) for success
147  */
149 
150  /**
151  * @brief Sets a callback function that will be called on success or failure of asynchronous request
152  *
153  * @param callback A function to be called
154  * @return Enumeration of the resulted action: InferenceEngine::OK (0) for success
155  */
156  virtual StatusCode SetCompletionCallback(CompletionCallback callback) noexcept = 0;
157 
158  /**
159  * @brief Gets arbitrary data for the request and stores a pointer to a pointer to the obtained data
160  *
161  * @param data Pointer to a pointer to the gotten arbitrary data
162  * @param resp Optional: a pointer to an already allocated object to contain extra information of a failure (if
163  * occurred)
164  * @return Enumeration of the resulted action: InferenceEngine::OK (0) for success
165  */
166  virtual StatusCode GetUserData(void** data, ResponseDesc* resp) noexcept = 0;
167 
168  /**
169  * @brief Sets arbitrary data for the request
170  *
171  * @param data Pointer to a pointer to arbitrary data to set
172  * @param resp Optional: a pointer to an already allocated object to contain extra information of a failure (if
173  * occurred)
174  * @return Enumeration of the resulted action: InferenceEngine::OK (0) for success
175  */
176  virtual StatusCode SetUserData(void* data, ResponseDesc* resp) noexcept = 0;
177 
178  /**
179  * @brief Sets new batch size when dynamic batching is enabled in executable network that created this request.
180  *
181  * @param batch_size new batch size to be used by all the following inference calls for this request.
182  * @param resp Optional: a pointer to an already allocated object to contain extra information of a failure (if
183  * occurred)
184  * @return Enumeration of the resulted action: InferenceEngine::OK (0) for success
185  */
186  virtual InferenceEngine::StatusCode SetBatch(int batch_size, ResponseDesc* resp) noexcept = 0;
187 
188  IE_SUPPRESS_DEPRECATED_START
189  /**
190  * @brief Gets state control interface for given infer request.
191  *
192  * State control essential for recurrent networks
193  *
194  * @param pState reference to a pointer that receives internal states
195  * @param idx requested index for receiving memory state
196  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
197  * @return Status code of the operation: InferenceEngine::OK (0) for success, OUT_OF_BOUNDS (-6) no memory state for
198  * given index
199  */
200  virtual StatusCode QueryState(IVariableState::Ptr& pState, size_t idx, ResponseDesc* resp) noexcept = 0;
201  IE_SUPPRESS_DEPRECATED_END
202 };
203 
204 } // namespace InferenceEngine
std::shared_ptr< Blob > Ptr
A smart pointer containing Blob object.
Definition: ie_blob.h:43
This is an interface of asynchronous infer request.
Definition: ie_iinfer_request.hpp:29
virtual StatusCode QueryState(IVariableState::Ptr &pState, size_t idx, ResponseDesc *resp) noexcept=0
Gets state control interface for given infer request.
virtual StatusCode GetUserData(void **data, ResponseDesc *resp) noexcept=0
Gets arbitrary data for the request and stores a pointer to a pointer to the obtained data.
std::weak_ptr< IInferRequest > WeakPtr
A smart pointer to the IInferRequest object.
Definition: ie_iinfer_request.hpp:48
void(* CompletionCallback)(InferenceEngine::IInferRequest::Ptr context, InferenceEngine::StatusCode code)
Completion callback definition as pointer to a function.
Definition: ie_iinfer_request.hpp:148
virtual InferenceEngine::StatusCode Wait(int64_t millis_timeout, ResponseDesc *resp) noexcept=0
Waits for the result to become available. Blocks until specified millis_timeout has elapsed or the re...
std::shared_ptr< IInferRequest > Ptr
A shared pointer to the IInferRequest object.
Definition: ie_iinfer_request.hpp:44
virtual StatusCode SetBlob(const char *name, const Blob::Ptr &data, ResponseDesc *resp) noexcept=0
Sets input/output data to infer.
WaitMode
Enumeration to hold wait mode for IInferRequest.
Definition: ie_iinfer_request.hpp:35
@ STATUS_ONLY
Definition: ie_iinfer_request.hpp:39
@ RESULT_READY
Definition: ie_iinfer_request.hpp:37
virtual StatusCode GetPreProcess(const char *name, const PreProcessInfo **info, ResponseDesc *resp) const noexcept=0
Gets pre-process for input data.
virtual StatusCode SetUserData(void *data, ResponseDesc *resp) noexcept=0
Sets arbitrary data for the request.
virtual StatusCode Infer(ResponseDesc *resp) noexcept=0
Infers specified input(s) in synchronous mode.
virtual StatusCode SetCompletionCallback(CompletionCallback callback) noexcept=0
Sets a callback function that will be called on success or failure of asynchronous request.
virtual StatusCode SetBlob(const char *name, const Blob::Ptr &data, const PreProcessInfo &info, ResponseDesc *resp) noexcept=0
Sets pre-process for input data.
virtual StatusCode GetPerformanceCounts(std::map< std::string, InferenceEngineProfileInfo > &perfMap, ResponseDesc *resp) const noexcept=0
Queries performance measures per layer to get feedback of what is the most time consuming layer.
virtual InferenceEngine::StatusCode SetBatch(int batch_size, ResponseDesc *resp) noexcept=0
Sets new batch size when dynamic batching is enabled in executable network that created this request.
virtual StatusCode StartAsync(ResponseDesc *resp) noexcept=0
Starts inference of specified input(s) in asynchronous mode.
virtual StatusCode Cancel(ResponseDesc *resp) noexcept=0
Cancels current async inference request.
virtual StatusCode GetBlob(const char *name, Blob::Ptr &data, ResponseDesc *resp) noexcept=0
Gets input/output data for inference.
std::shared_ptr< IVariableState > Ptr
A shared pointer to the IVariableState interface.
Definition: ie_imemory_state.hpp:32
This class stores pre-process information for the input.
Definition: ie_preprocess.hpp:55
A header file for Blob and generic TBlob<>
This is a header file with common inference engine definitions.
a header file for IVariableState interface
A header file for the Inference Engine plugins destruction mechanism.
This header file provides structures to store info about pre-processing of network inputs (scale,...
Inference Engine C++ API.
Definition: cldnn_config.hpp:15
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:224
Represents detailed information for an error.
Definition: ie_common.h:248