ie_common.h
Go to the documentation of this file.
1 // Copyright (C) 2018 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  // bias layouts
89  C = 96,
90 
91  // Single image layout (for mean image)
92  CHW = 128,
93 
94  // 2D
95  HW = 192,
96  NC = 193,
97  CN = 194,
98 
99  BLOCKED = 200,
100 };
101 inline std::ostream & operator << (std::ostream &out, const Layout & p) {
102  switch (p) {
103 #define PRINT_LAYOUT(name)\
104  case name : out << #name; break;
105 
106  PRINT_LAYOUT(ANY);
107  PRINT_LAYOUT(NCHW);
108  PRINT_LAYOUT(NHWC);
109  PRINT_LAYOUT(OIHW);
110  PRINT_LAYOUT(C);
111  PRINT_LAYOUT(CHW);
112  PRINT_LAYOUT(HW);
113  PRINT_LAYOUT(NC);
114  PRINT_LAYOUT(CN);
115  PRINT_LAYOUT(BLOCKED);
116 #undef PRINT_LAYOUT
117  default:
118  out << static_cast<int>(p);
119  break;
120  }
121  return out;
122  }
123 
124 
125 /**
126  * @struct InferenceEngineProfileInfo
127  * @brief Represents basic inference profiling information per layer.
128  * If the layer is executed using tiling, the sum time per each tile is indicated as the total execution time.
129  * Due to parallel execution, the total execution time for all layers might be greater than the total inference time.
130  */
132  /**
133  * @brief Defines the general status of the layer
134  */
135  enum LayerStatus {
136  NOT_RUN,
137  OPTIMIZED_OUT,
138  EXECUTED
139  };
140 
141  LayerStatus status;
142  /**
143  * @brief The absolute time in microseconds that the layer ran (in total)
144  */
145  long long realTime_uSec;
146  /**
147  * @brief The net host cpu time that the layer ran
148  */
149  long long cpu_uSec;
150 
151  /**
152  * @brief An execution type of unit
153  */
154  char exec_type[256] = {};
155 
156  /**
157  * @brief A layer type
158  */
159  char layer_type[256] = {};
160 
161  /**
162  * @brief An execution index of the unit
163  */
164  unsigned execution_index;
165 };
166 
167 
168 /**
169  * @enum StatusCode
170  * @brief This enum contains codes for all possible return values of the interface functions
171  */
172 enum StatusCode : int {
173  OK = 0,
174  GENERAL_ERROR = -1,
175  NOT_IMPLEMENTED = -2,
176  NETWORK_NOT_LOADED = -3,
177  PARAMETER_MISMATCH = -4,
178  NOT_FOUND = -5,
179  OUT_OF_BOUNDS = -6,
180  /*
181  * @brief exception not of std::exception derived type was thrown
182  */
183  UNEXPECTED = -7,
184  REQUEST_BUSY = -8,
185  RESULT_NOT_READY = -9,
186  NOT_ALLOCATED = -10,
187  INFER_NOT_STARTED = -11,
188  NETWORK_NOT_READ = -12
189 };
190 
191 /**
192  * @struct ResponseDesc
193  * @brief Represents detailed information for an error
194  */
195 struct ResponseDesc {
196  /**
197  * @brief A character buffer that holds the detailed information for an error.
198  */
199  char msg[256] = {};
200 };
201 
202 /** @brief This class represents StatusCode::GENERIC_ERROR exception */
203 class GeneralError : public std::logic_error
204 { using std::logic_error::logic_error; };
205 
206 /** @brief This class represents StatusCode::NOT_IMPLEMENTED exception */
207 class NotImplemented : public std::logic_error
208 { using std::logic_error::logic_error; };
209 
210 /** @brief This class represents StatusCode::NETWORK_NOT_LOADED exception */
211 class NetworkNotLoaded : public std::logic_error
212 { using std::logic_error::logic_error; };
213 
214 /** @brief This class represents StatusCode::PARAMETER_MISMATCH exception */
215 class ParameterMismatch : public std::logic_error
216 { using std::logic_error::logic_error; };
217 
218 /** @brief This class represents StatusCode::NOT_FOUND exception */
219 class NotFound : public std::logic_error
220 { using std::logic_error::logic_error; };
221 
222 /** @brief This class represents StatusCode::OUT_OF_BOUNDS exception */
223 class OutOfBounds : public std::logic_error
224 { using std::logic_error::logic_error; };
225 
226 /** @brief This class represents StatusCode::UNEXPECTED exception */
227 class Unexpected : public std::logic_error
228 { using std::logic_error::logic_error; };
229 
230 /** @brief This class represents StatusCode::REQUEST_BUSY exception */
231 class RequestBusy : public std::logic_error
232 { using std::logic_error::logic_error; };
233 
234 /** @brief This class represents StatusCode::RESULT_NOT_READY exception */
235 class ResultNotReady : public std::logic_error
236 { using std::logic_error::logic_error; };
237 
238 /** @brief This class represents StatusCode::NOT_ALLOCATED exception */
239 class NotAllocated : public std::logic_error
240 { using std::logic_error::logic_error; };
241 
242 /** @brief This class represents StatusCode::INFER_NOT_STARTED exception */
243 class InferNotStarted : public std::logic_error
244 { using std::logic_error::logic_error; };
245 } // namespace InferenceEngine
246 
247 /** @brief This class represents StatusCode::NETWORK_NOT_READ exception */
248 class NetworkNotRead : public std::logic_error
249 { using std::logic_error::logic_error; };
250 
251 #if defined(_WIN32)
252  #define __PRETTY_FUNCTION__ __FUNCSIG__
253 #else
254  #define __PRETTY_FUNCTION__ __PRETTY_FUNCTION__
255 #endif
This class represents StatusCode::PARAMETER_MISMATCH exception.
Definition: ie_common.h:215
This class represents StatusCode::NETWORK_NOT_LOADED exception.
Definition: ie_common.h:211
This class represents StatusCode::REQUEST_BUSY exception.
Definition: ie_common.h:231
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:172
LayerStatus
Defines the general status of the layer.
Definition: ie_common.h:135
long long cpu_uSec
The net host cpu time that the layer ran.
Definition: ie_common.h:149
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:203
Represents detailed information for an error.
Definition: ie_common.h:195
This class represents StatusCode::NETWORK_NOT_READ exception.
Definition: ie_common.h:248
This class represents StatusCode::RESULT_NOT_READY exception.
Definition: ie_common.h:235
long long realTime_uSec
The absolute time in microseconds that the layer ran (in total)
Definition: ie_common.h:145
This class represents StatusCode::OUT_OF_BOUNDS exception.
Definition: ie_common.h:223
unsigned execution_index
An execution index of the unit.
Definition: ie_common.h:164
This class represents StatusCode::NOT_ALLOCATED exception.
Definition: ie_common.h:239
This is a base abstraction Layer - all DNN Layers inherit from this class.
Definition: ie_layers.h:40
std::shared_ptr< Data > DataPtr
Smart pointer to Data.
Definition: ie_common.h:50
This class represents StatusCode::NOT_FOUND exception.
Definition: ie_common.h:219
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:227
This class represents StatusCode::INFER_NOT_STARTED exception.
Definition: ie_common.h:243
This class represents the main Data representation node.
Definition: ie_data.h:27
Represents basic inference profiling information per layer. If the layer is executed using tiling...
Definition: ie_common.h:131
A header file for the main Inference Engine exception.
This class represents StatusCode::NOT_IMPLEMENTED exception.
Definition: ie_common.h:207