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