ie_common.h
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 This is a header file with common inference engine definitions.
7  *
8  * @file ie_common.h
9  */
10 #pragma once
11 
12 #include <algorithm>
13 #include <cstdlib>
14 #include <memory>
15 #include <ostream>
16 #include <string>
17 #include <vector>
18 #include <map>
19 
20 namespace InferenceEngine {
21 /**
22  * @brief Represents tensor size.
23  *
24  * The order is opposite to the order in Caffe*: (w,h,n,b) where the most frequently changing element in memory is
25  * first.
26  */
27 using SizeVector = std::vector<size_t>;
28 
29 /**
30  * @brief The main data representation node
31  */
32 class Data;
33 
34 /**
35  * @brief Smart pointer to Data
36  */
37 using DataPtr = std::shared_ptr<Data>;
38 
39 /**
40  * @brief Smart pointer to constant Data
41  */
42 using CDataPtr = std::shared_ptr<const Data>;
43 
44 /**
45  * @brief Smart weak pointer to Data
46  */
47 using DataWeakPtr = std::weak_ptr<Data>;
48 
49 /**
50  * @union UserValue
51  * @brief The method holds the user values to enable binding of data per graph node.
52  */
53 union UserValue {
54  int v_int; //!< An integer value
55  float v_float; //!< A floating point value
56  void* v_ptr; //!< A pointer to a void
57 };
58 
59 /**
60  * @enum Layout
61  * @brief Layouts that the inference engine supports
62  */
63 enum Layout : uint8_t {
64  ANY = 0, //!< "any" layout
65 
66  // I/O data layouts
67  NCHW = 1, //!< NCHW layout for input / output blobs
68  NHWC = 2, //!< NHWC layout for input / output blobs
69  NCDHW = 3, //!< NCDHW layout for input / output blobs
70  NDHWC = 4, //!< NDHWC layout for input / output blobs
71 
72  // weight layouts
73  OIHW = 64, //!< NDHWC layout for operation weights
74  GOIHW = 65, //!< NDHWC layout for operation weights
75  OIDHW = 66, //!< NDHWC layout for operation weights
76  GOIDHW = 67, //!< NDHWC layout for operation weights
77 
78  // Scalar
79  SCALAR = 95, //!< A scalar layout
80 
81  // bias layouts
82  C = 96, //!< A bias layout for operation
83 
84  // Single image layouts
85  CHW = 128, //!< A single image layout (e.g. for mean image)
86  HWC = 129, //!< A single image layout (e.g. for mean image)
87 
88  // 2D
89  HW = 192, //!< HW 2D layout
90  NC = 193, //!< HC 2D layout
91  CN = 194, //!< CN 2D layout
92 
93  BLOCKED = 200, //!< A blocked layout
94 };
95 
96 /**
97  * @brief Prints a string representation of InferenceEngine::Layout to a stream
98  * @param out An output stream to send to
99  * @param p A layout value to print to a stream
100  * @return A reference to the `out` stream
101  */
102 inline std::ostream& operator<<(std::ostream& out, const Layout& p) {
103  switch (p) {
104 #define PRINT_LAYOUT(name) \
105  case name: \
106  out << #name; \
107  break;
108 
109  PRINT_LAYOUT(ANY);
110  PRINT_LAYOUT(NCHW);
111  PRINT_LAYOUT(NHWC);
112  PRINT_LAYOUT(NCDHW);
113  PRINT_LAYOUT(NDHWC);
114  PRINT_LAYOUT(OIHW);
115  PRINT_LAYOUT(C);
116  PRINT_LAYOUT(CHW);
117  PRINT_LAYOUT(HWC);
118  PRINT_LAYOUT(HW);
119  PRINT_LAYOUT(NC);
120  PRINT_LAYOUT(CN);
121  PRINT_LAYOUT(BLOCKED);
122 #undef PRINT_LAYOUT
123  default:
124  out << static_cast<int>(p);
125  break;
126  }
127  return out;
128 }
129 
130 /**
131  * @enum ColorFormat
132  * @brief Extra information about input color format for preprocessing
133  */
134 enum ColorFormat : uint32_t {
135  RAW = 0u, ///< Plain blob (default), no extra color processing required
136  RGB, ///< RGB color format
137  BGR, ///< BGR color format, default in DLDT
138  RGBX, ///< RGBX color format with X ignored during inference
139  BGRX, ///< BGRX color format with X ignored during inference
140  NV12, ///< NV12 color format represented as compound Y+UV blob
141  I420, ///< I420 color format represented as compound Y+U+V blob
142 };
143 
144 /**
145  * @brief Prints a string representation of InferenceEngine::ColorFormat to a stream
146  * @param out An output stream to send to
147  * @param fmt A color format value to print to a stream
148  * @return A reference to the `out` stream
149  */
150 inline std::ostream& operator<<(std::ostream& out, const ColorFormat& fmt) {
151  switch (fmt) {
152 #define PRINT_COLOR_FORMAT(name) \
153  case name: \
154  out << #name; \
155  break;
156 
157  PRINT_COLOR_FORMAT(RAW);
158  PRINT_COLOR_FORMAT(RGB);
159  PRINT_COLOR_FORMAT(BGR);
160  PRINT_COLOR_FORMAT(RGBX);
161  PRINT_COLOR_FORMAT(BGRX);
162  PRINT_COLOR_FORMAT(NV12);
163  PRINT_COLOR_FORMAT(I420);
164 #undef PRINT_COLOR_FORMAT
165 
166  default:
167  out << static_cast<uint32_t>(fmt);
168  break;
169  }
170  return out;
171 }
172 
173 /**
174  * @struct InferenceEngineProfileInfo
175  * @brief Represents basic inference profiling information per layer.
176  *
177  * If the layer is executed using tiling, the sum time per each tile is indicated as the total execution time.
178  * Due to parallel execution, the total execution time for all layers might be greater than the total inference time.
179  */
181  /**
182  * @brief Defines the general status of the layer
183  */
184  enum LayerStatus {
185  NOT_RUN, //!< A layer is not executed
186  OPTIMIZED_OUT, //!< A layer is optimized out during graph optimization phase
187  EXECUTED //!< A layer is executed
188  };
189 
190  /**
191  * @brief Defines a layer status
192  */
194 
195  /**
196  * @brief The absolute time in microseconds that the layer ran (in total)
197  */
198  long long realTime_uSec;
199  /**
200  * @brief The net host cpu time that the layer ran
201  */
202  long long cpu_uSec;
203 
204  /**
205  * @brief An execution type of unit
206  */
207  char exec_type[256] = {};
208 
209  /**
210  * @brief A layer type
211  */
212  char layer_type[256] = {};
213 
214  /**
215  * @brief An execution index of the unit
216  */
217  unsigned execution_index;
218 };
219 
220 /**
221  * @enum StatusCode
222  * @brief This enum contains codes for all possible return values of the interface functions
223  */
224 enum StatusCode : int {
225  OK = 0,
226  GENERAL_ERROR = -1,
227  NOT_IMPLEMENTED = -2,
228  NETWORK_NOT_LOADED = -3,
229  PARAMETER_MISMATCH = -4,
230  NOT_FOUND = -5,
231  OUT_OF_BOUNDS = -6,
232  /*
233  * @brief exception not of std::exception derived type was thrown
234  */
235  UNEXPECTED = -7,
236  REQUEST_BUSY = -8,
237  RESULT_NOT_READY = -9,
238  NOT_ALLOCATED = -10,
239  INFER_NOT_STARTED = -11,
240  NETWORK_NOT_READ = -12,
241  INFER_CANCELLED = -13
242 };
243 
244 /**
245  * @struct ResponseDesc
246  * @brief Represents detailed information for an error
247  */
248 struct ResponseDesc {
249  /**
250  * @brief A character buffer that holds the detailed information for an error.
251  */
252  char msg[4096] = {};
253 };
254 
255 /**
256  * @brief Response structure encapsulating information about supported layer
257  */
259  /**
260  * @brief A map of supported layers:
261  * - key - a layer name
262  * - value - a device name on which layer is assigned
263  */
264  std::map<std::string, std::string> supportedLayersMap;
265 
266  /**
267  * @brief A status code
268  */
270 
271  /**
272  * @brief Response message
273  */
275 };
276 
277 /** @brief This class represents StatusCode::GENERIC_ERROR exception */
278 class GeneralError : public std::logic_error {
279  using std::logic_error::logic_error;
280 };
281 
282 /** @brief This class represents StatusCode::NOT_IMPLEMENTED exception */
283 class NotImplemented : public std::logic_error {
284  using std::logic_error::logic_error;
285 };
286 
287 /** @brief This class represents StatusCode::NETWORK_NOT_LOADED exception */
288 class NetworkNotLoaded : public std::logic_error {
289  using std::logic_error::logic_error;
290 };
291 
292 /** @brief This class represents StatusCode::PARAMETER_MISMATCH exception */
293 class ParameterMismatch : public std::logic_error {
294  using std::logic_error::logic_error;
295 };
296 
297 /** @brief This class represents StatusCode::NOT_FOUND exception */
298 class NotFound : public std::logic_error {
299  using std::logic_error::logic_error;
300 };
301 
302 /** @brief This class represents StatusCode::OUT_OF_BOUNDS exception */
303 class OutOfBounds : public std::logic_error {
304  using std::logic_error::logic_error;
305 };
306 
307 /** @brief This class represents StatusCode::UNEXPECTED exception */
308 class Unexpected : public std::logic_error {
309  using std::logic_error::logic_error;
310 };
311 
312 /** @brief This class represents StatusCode::REQUEST_BUSY exception */
313 class RequestBusy : public std::logic_error {
314  using std::logic_error::logic_error;
315 };
316 
317 /** @brief This class represents StatusCode::RESULT_NOT_READY exception */
318 class ResultNotReady : public std::logic_error {
319  using std::logic_error::logic_error;
320 };
321 
322 /** @brief This class represents StatusCode::NOT_ALLOCATED exception */
323 class NotAllocated : public std::logic_error {
324  using std::logic_error::logic_error;
325 };
326 
327 /** @brief This class represents StatusCode::INFER_NOT_STARTED exception */
328 class InferNotStarted : public std::logic_error {
329  using std::logic_error::logic_error;
330 };
331 
332 /** @brief This class represents StatusCode::NETWORK_NOT_READ exception */
333 class NetworkNotRead : public std::logic_error {
334  using std::logic_error::logic_error;
335 };
336 
337 /** @brief This class represents StatusCode::INFER_CANCELLED exception */
338 class InferCancelled : public std::logic_error {
339  using std::logic_error::logic_error;
340 };
341 
342 } // namespace InferenceEngine
343 
344 #if defined(_WIN32)
345 #define __PRETTY_FUNCTION__ __FUNCSIG__
346 #else
347 #define __PRETTY_FUNCTION__ __PRETTY_FUNCTION__
348 #endif
This class represents the main Data representation node.
Definition: ie_data.h:28
This class represents StatusCode::GENERIC_ERROR exception.
Definition: ie_common.h:278
This class represents StatusCode::INFER_CANCELLED exception.
Definition: ie_common.h:338
This class represents StatusCode::INFER_NOT_STARTED exception.
Definition: ie_common.h:328
This class represents StatusCode::NETWORK_NOT_LOADED exception.
Definition: ie_common.h:288
This class represents StatusCode::NETWORK_NOT_READ exception.
Definition: ie_common.h:333
This class represents StatusCode::NOT_ALLOCATED exception.
Definition: ie_common.h:323
This class represents StatusCode::NOT_FOUND exception.
Definition: ie_common.h:298
This class represents StatusCode::NOT_IMPLEMENTED exception.
Definition: ie_common.h:283
This class represents StatusCode::OUT_OF_BOUNDS exception.
Definition: ie_common.h:303
This class represents StatusCode::PARAMETER_MISMATCH exception.
Definition: ie_common.h:293
This class represents StatusCode::REQUEST_BUSY exception.
Definition: ie_common.h:313
This class represents StatusCode::RESULT_NOT_READY exception.
Definition: ie_common.h:318
This class represents StatusCode::UNEXPECTED exception.
Definition: ie_common.h:308
Inference Engine C++ API.
Definition: cldnn_config.hpp:15
std::shared_ptr< const Data > CDataPtr
Smart pointer to constant Data.
Definition: ie_common.h:42
Layout
Layouts that the inference engine supports.
Definition: ie_common.h:63
@ CHW
A single image layout (e.g. for mean image)
Definition: ie_common.h:85
@ OIDHW
NDHWC layout for operation weights.
Definition: ie_common.h:75
@ HWC
A single image layout (e.g. for mean image)
Definition: ie_common.h:86
@ C
A bias layout for operation.
Definition: ie_common.h:82
@ ANY
"any" layout
Definition: ie_common.h:64
@ NCDHW
NCDHW layout for input / output blobs.
Definition: ie_common.h:69
@ NHWC
NHWC layout for input / output blobs.
Definition: ie_common.h:68
@ GOIHW
NDHWC layout for operation weights.
Definition: ie_common.h:74
@ OIHW
NDHWC layout for operation weights.
Definition: ie_common.h:73
@ NDHWC
NDHWC layout for input / output blobs.
Definition: ie_common.h:70
@ HW
HW 2D layout.
Definition: ie_common.h:89
@ CN
CN 2D layout.
Definition: ie_common.h:91
@ GOIDHW
NDHWC layout for operation weights.
Definition: ie_common.h:76
@ BLOCKED
A blocked layout.
Definition: ie_common.h:93
@ NCHW
NCHW layout for input / output blobs.
Definition: ie_common.h:67
@ NC
HC 2D layout.
Definition: ie_common.h:90
@ SCALAR
A scalar layout.
Definition: ie_common.h:79
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:224
std::ostream & operator<<(std::ostream &out, const Layout &p)
Prints a string representation of InferenceEngine::Layout to a stream.
Definition: ie_common.h:102
ColorFormat
Extra information about input color format for preprocessing.
Definition: ie_common.h:134
@ BGR
BGR color format, default in DLDT.
Definition: ie_common.h:137
@ RAW
Plain blob (default), no extra color processing required.
Definition: ie_common.h:135
@ NV12
NV12 color format represented as compound Y+UV blob.
Definition: ie_common.h:140
@ RGBX
RGBX color format with X ignored during inference.
Definition: ie_common.h:138
@ BGRX
BGRX color format with X ignored during inference.
Definition: ie_common.h:139
@ I420
I420 color format represented as compound Y+U+V blob.
Definition: ie_common.h:141
@ RGB
RGB color format.
Definition: ie_common.h:136
std::shared_ptr< Data > DataPtr
Smart pointer to Data.
Definition: ie_common.h:37
std::vector< size_t > SizeVector
Represents tensor size.
Definition: ie_common.h:27
std::weak_ptr< Data > DataWeakPtr
Smart weak pointer to Data.
Definition: ie_common.h:47
Represents basic inference profiling information per layer.
Definition: ie_common.h:180
long long cpu_uSec
The net host cpu time that the layer ran.
Definition: ie_common.h:202
LayerStatus status
Defines a layer status.
Definition: ie_common.h:193
long long realTime_uSec
The absolute time in microseconds that the layer ran (in total)
Definition: ie_common.h:198
char layer_type[256]
A layer type.
Definition: ie_common.h:212
LayerStatus
Defines the general status of the layer.
Definition: ie_common.h:184
@ NOT_RUN
A layer is not executed.
Definition: ie_common.h:185
@ OPTIMIZED_OUT
A layer is optimized out during graph optimization phase.
Definition: ie_common.h:186
@ EXECUTED
A layer is executed.
Definition: ie_common.h:187
unsigned execution_index
An execution index of the unit.
Definition: ie_common.h:217
char exec_type[256]
An execution type of unit.
Definition: ie_common.h:207
Response structure encapsulating information about supported layer.
Definition: ie_common.h:258
StatusCode rc
A status code.
Definition: ie_common.h:269
ResponseDesc resp
Response message.
Definition: ie_common.h:274
std::map< std::string, std::string > supportedLayersMap
A map of supported layers:
Definition: ie_common.h:264
Represents detailed information for an error.
Definition: ie_common.h:248
char msg[4096]
A character buffer that holds the detailed information for an error.
Definition: ie_common.h:252
The method holds the user values to enable binding of data per graph node.
Definition: ie_common.h:53
void * v_ptr
A pointer to a void.
Definition: ie_common.h:56
float v_float
A floating point value.
Definition: ie_common.h:55
int v_int
An integer value.
Definition: ie_common.h:54