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 <details/ie_exception.hpp>
15 #include <memory>
16 #include <ostream>
17 #include <string>
18 #include <vector>
19 
20 #include "ie_unicode.hpp"
21 
22 namespace InferenceEngine {
23 /**
24  * @brief Represents tensor size.
25  *
26  * The order is opposite to the order in Caffe*: (w,h,n,b) where the most frequently changing element in memory is
27  * first.
28  */
29 using SizeVector = std::vector<size_t>;
30 
31 /**
32  * @brief This class represents the generic layer.
33  */
34 class CNNLayer;
35 
36 /**
37  * @brief A smart pointer to the CNNLayer
38  */
39 using CNNLayerPtr = std::shared_ptr<CNNLayer>;
40 /**
41  * @brief A smart weak pointer to the CNNLayer
42  */
43 using CNNLayerWeakPtr = std::weak_ptr<CNNLayer>;
44 
45 /**
46  * @brief The main data representation node
47  */
48 class Data;
49 
50 /**
51  * @brief Smart pointer to Data
52  */
53 using DataPtr = std::shared_ptr<Data>;
54 
55 /**
56  * @brief Smart pointer to constant Data
57  */
58 using CDataPtr = std::shared_ptr<const Data>;
59 
60 /**
61  * @brief Smart weak pointer to Data
62  */
63 using DataWeakPtr = std::weak_ptr<Data>;
64 
65 /**
66  * @union UserValue
67  * @brief The method holds the user values to enable binding of data per graph node.
68  */
69 union UserValue {
70  int v_int; //!< An integer value
71  float v_float; //!< A floating point value
72  void* v_ptr; //!< A pointer to a void
73 };
74 
75 /**
76  * @enum Layout
77  * @brief Layouts that the inference engine supports
78  */
79 enum Layout : uint8_t {
80  ANY = 0, //!< "any" layout
81 
82  // I/O data layouts
83  NCHW = 1, //!< NCHW layout for input / output blobs
84  NHWC = 2, //!< NHWC layout for input / output blobs
85  NCDHW = 3, //!< NCDHW layout for input / output blobs
86  NDHWC = 4, //!< NDHWC layout for input / output blobs
87 
88  // weight layouts
89  OIHW = 64, //!< NDHWC layout for operation weights
90  GOIHW = 65, //!< NDHWC layout for operation weights
91  OIDHW = 66, //!< NDHWC layout for operation weights
92  GOIDHW = 67, //!< NDHWC layout for operation weights
93 
94  // Scalar
95  SCALAR = 95, //!< A scalar layout
96 
97  // bias layouts
98  C = 96, //!< A bias layout for opearation
99 
100  // Single image layouts
101  CHW = 128, //!< A single image layout (e.g. for mean image)
102 
103  // 2D
104  HW = 192, //!< HW 2D layout
105  NC = 193, //!< HC 2D layout
106  CN = 194, //!< CN 2D layout
107 
108  BLOCKED = 200, //!< A blocked layout
109 };
110 inline std::ostream& operator<<(std::ostream& out, const Layout& p) {
111  switch (p) {
112 #define PRINT_LAYOUT(name) \
113  case name: \
114  out << #name; \
115  break;
116 
117  PRINT_LAYOUT(ANY);
118  PRINT_LAYOUT(NCHW);
119  PRINT_LAYOUT(NHWC);
120  PRINT_LAYOUT(NCDHW);
121  PRINT_LAYOUT(NDHWC);
122  PRINT_LAYOUT(OIHW);
123  PRINT_LAYOUT(C);
124  PRINT_LAYOUT(CHW);
125  PRINT_LAYOUT(HW);
126  PRINT_LAYOUT(NC);
127  PRINT_LAYOUT(CN);
128  PRINT_LAYOUT(BLOCKED);
129 #undef PRINT_LAYOUT
130  default:
131  out << static_cast<int>(p);
132  break;
133  }
134  return out;
135 }
136 
137 /**
138  * @enum ColorFormat
139  * @brief Extra information about input color format for preprocessing
140  */
141 enum ColorFormat : uint32_t {
142  RAW = 0u, ///< Plain blob (default), no extra color processing required
143  RGB, ///< RGB color format
144  BGR, ///< BGR color format, default in DLDT
145  RGBX, ///< RGBX color format with X ignored during inference
146  BGRX, ///< BGRX color format with X ignored during inference
147  NV12, ///< NV12 color format represented as compound Y+UV blob
148  I420, ///< I420 color format represented as compound Y+U+V blob
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 exectued
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 };
242 
243 /**
244  * @struct ResponseDesc
245  * @brief Represents detailed information for an error
246  */
247 struct ResponseDesc {
248  /**
249  * @brief A character buffer that holds the detailed information for an error.
250  */
251  char msg[4096] = {};
252 };
253 
254 /** @brief This class represents StatusCode::GENERIC_ERROR exception */
255 class GeneralError : public std::logic_error {
256  using std::logic_error::logic_error;
257 };
258 
259 /** @brief This class represents StatusCode::NOT_IMPLEMENTED exception */
260 class NotImplemented : public std::logic_error {
261  using std::logic_error::logic_error;
262 };
263 
264 /** @brief This class represents StatusCode::NETWORK_NOT_LOADED exception */
265 class NetworkNotLoaded : public std::logic_error {
266  using std::logic_error::logic_error;
267 };
268 
269 /** @brief This class represents StatusCode::PARAMETER_MISMATCH exception */
270 class ParameterMismatch : public std::logic_error {
271  using std::logic_error::logic_error;
272 };
273 
274 /** @brief This class represents StatusCode::NOT_FOUND exception */
275 class NotFound : public std::logic_error {
276  using std::logic_error::logic_error;
277 };
278 
279 /** @brief This class represents StatusCode::OUT_OF_BOUNDS exception */
280 class OutOfBounds : public std::logic_error {
281  using std::logic_error::logic_error;
282 };
283 
284 /** @brief This class represents StatusCode::UNEXPECTED exception */
285 class Unexpected : public std::logic_error {
286  using std::logic_error::logic_error;
287 };
288 
289 /** @brief This class represents StatusCode::REQUEST_BUSY exception */
290 class RequestBusy : public std::logic_error {
291  using std::logic_error::logic_error;
292 };
293 
294 /** @brief This class represents StatusCode::RESULT_NOT_READY exception */
295 class ResultNotReady : public std::logic_error {
296  using std::logic_error::logic_error;
297 };
298 
299 /** @brief This class represents StatusCode::NOT_ALLOCATED exception */
300 class NotAllocated : public std::logic_error {
301  using std::logic_error::logic_error;
302 };
303 
304 /** @brief This class represents StatusCode::INFER_NOT_STARTED exception */
305 class InferNotStarted : public std::logic_error {
306  using std::logic_error::logic_error;
307 };
308 } // namespace InferenceEngine
309 
310 /** @brief This class represents StatusCode::NETWORK_NOT_READ exception */
311 class NetworkNotRead : public std::logic_error {
312  using std::logic_error::logic_error;
313 };
314 
315 #if defined(_WIN32)
316 #define __PRETTY_FUNCTION__ __FUNCSIG__
317 #else
318 #define __PRETTY_FUNCTION__ __PRETTY_FUNCTION__
319 #endif
This class represents StatusCode::PARAMETER_MISMATCH exception.
Definition: ie_common.h:270
"any" layout
Definition: ie_common.h:80
This class represents StatusCode::NETWORK_NOT_LOADED exception.
Definition: ie_common.h:265
This is a header file with common inference engine definitions.
This class represents StatusCode::REQUEST_BUSY exception.
Definition: ie_common.h:290
LayerStatus status
Defines a layer status.
Definition: ie_common.h:193
The method holds the user values to enable binding of data per graph node.
Definition: ie_common.h:69
std::vector< size_t > SizeVector
Represents tensor size.
Definition: ie_common.h:29
Definition: cldnn_config.hpp:16
std::shared_ptr< CNNLayer > CNNLayerPtr
A smart pointer to the CNNLayer.
Definition: ie_common.h:39
Layout
Layouts that the inference engine supports.
Definition: ie_common.h:79
std::weak_ptr< CNNLayer > CNNLayerWeakPtr
A smart weak pointer to the CNNLayer.
Definition: ie_common.h:43
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:224
float v_float
A floating point value.
Definition: ie_common.h:71
A bias layout for opearation.
Definition: ie_common.h:98
BGRX color format with X ignored during inference.
Definition: ie_common.h:146
LayerStatus
Defines the general status of the layer.
Definition: ie_common.h:184
NCDHW layout for input / output blobs.
Definition: ie_common.h:85
A layer is not exectued.
Definition: ie_common.h:185
long long cpu_uSec
The net host cpu time that the layer ran.
Definition: ie_common.h:202
NDHWC layout for operation weights.
Definition: ie_common.h:89
std::shared_ptr< const Data > CDataPtr
Smart pointer to constant Data.
Definition: ie_common.h:58
void * v_ptr
A pointer to a void.
Definition: ie_common.h:72
This class represents StatusCode::GENERIC_ERROR exception.
Definition: ie_common.h:255
A single image layout (e.g. for mean image)
Definition: ie_common.h:101
A layer is optimized out during graph optimization phase.
Definition: ie_common.h:186
Represents detailed information for an error.
Definition: ie_common.h:247
This class represents StatusCode::NETWORK_NOT_READ exception.
Definition: ie_common.h:311
I420 color format represented as compound Y+U+V blob.
Definition: ie_common.h:148
This class represents StatusCode::RESULT_NOT_READY exception.
Definition: ie_common.h:295
ColorFormat
Extra information about input color format for preprocessing.
Definition: ie_common.h:141
long long realTime_uSec
The absolute time in microseconds that the layer ran (in total)
Definition: ie_common.h:198
NDHWC layout for operation weights.
Definition: ie_common.h:91
This class represents StatusCode::OUT_OF_BOUNDS exception.
Definition: ie_common.h:280
BGR color format, default in DLDT.
Definition: ie_common.h:144
HW 2D layout.
Definition: ie_common.h:104
CN 2D layout.
Definition: ie_common.h:106
unsigned execution_index
An execution index of the unit.
Definition: ie_common.h:217
This class represents StatusCode::NOT_ALLOCATED exception.
Definition: ie_common.h:300
A blocked layout.
Definition: ie_common.h:108
NDHWC layout for input / output blobs.
Definition: ie_common.h:86
NHWC layout for input / output blobs.
Definition: ie_common.h:84
Plain blob (default), no extra color processing required.
Definition: ie_common.h:142
std::shared_ptr< Data > DataPtr
Smart pointer to Data.
Definition: ie_common.h:53
NV12 color format represented as compound Y+UV blob.
Definition: ie_common.h:147
This class represents StatusCode::NOT_FOUND exception.
Definition: ie_common.h:275
std::weak_ptr< Data > DataWeakPtr
Smart weak pointer to Data.
Definition: ie_common.h:63
This class represents StatusCode::UNEXPECTED exception.
Definition: ie_common.h:285
This class represents StatusCode::INFER_NOT_STARTED exception.
Definition: ie_common.h:305
NCHW layout for input / output blobs.
Definition: ie_common.h:83
This class represents the main Data representation node.
Definition: ie_data.h:30
int v_int
An integer value.
Definition: ie_common.h:70
RGBX color format with X ignored during inference.
Definition: ie_common.h:145
NDHWC layout for operation weights.
Definition: ie_common.h:92
RGB color format.
Definition: ie_common.h:143
NDHWC layout for operation weights.
Definition: ie_common.h:90
Represents basic inference profiling information per layer.
Definition: ie_common.h:180
HC 2D layout.
Definition: ie_common.h:105
A header file for the main Inference Engine exception.
This class represents StatusCode::NOT_IMPLEMENTED exception.
Definition: ie_common.h:260
A scalar layout.
Definition: ie_common.h:95