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