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