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