1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief This is a header file with common inference engine definitions.
20 namespace InferenceEngine {
22 * @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
27 using SizeVector = std::vector<size_t>;
30 * @brief The main data representation node
35 * @brief Smart pointer to Data
37 using DataPtr = std::shared_ptr<Data>;
40 * @brief Smart pointer to constant Data
42 using CDataPtr = std::shared_ptr<const Data>;
45 * @brief Smart weak pointer to Data
47 using DataWeakPtr = std::weak_ptr<Data>;
51 * @brief The method holds the user values to enable binding of data per graph node.
54 int v_int; //!< An integer value
55 float v_float; //!< A floating point value
56 void* v_ptr; //!< A pointer to a void
61 * @brief Layouts that the inference engine supports
63 enum Layout : uint8_t {
64 ANY = 0, //!< "any" layout
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
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
79 SCALAR = 95, //!< A scalar layout
82 C = 96, //!< A bias layout for opearation
84 // Single image layouts
85 CHW = 128, //!< A single image layout (e.g. for mean image)
88 HW = 192, //!< HW 2D layout
89 NC = 193, //!< HC 2D layout
90 CN = 194, //!< CN 2D layout
92 BLOCKED = 200, //!< A blocked layout
94 inline std::ostream& operator<<(std::ostream& out, const Layout& p) {
96 #define PRINT_LAYOUT(name) \
112 PRINT_LAYOUT(BLOCKED);
115 out << static_cast<int>(p);
123 * @brief Extra information about input color format for preprocessing
125 enum ColorFormat : uint32_t {
126 RAW = 0u, ///< Plain blob (default), no extra color processing required
127 RGB, ///< RGB color format
128 BGR, ///< BGR color format, default in DLDT
129 RGBX, ///< RGBX color format with X ignored during inference
130 BGRX, ///< BGRX color format with X ignored during inference
131 NV12, ///< NV12 color format represented as compound Y+UV blob
132 I420, ///< I420 color format represented as compound Y+U+V blob
134 inline std::ostream& operator<<(std::ostream& out, const ColorFormat& fmt) {
136 #define PRINT_COLOR_FORMAT(name) \
141 PRINT_COLOR_FORMAT(RAW);
142 PRINT_COLOR_FORMAT(RGB);
143 PRINT_COLOR_FORMAT(BGR);
144 PRINT_COLOR_FORMAT(RGBX);
145 PRINT_COLOR_FORMAT(BGRX);
146 PRINT_COLOR_FORMAT(NV12);
147 PRINT_COLOR_FORMAT(I420);
148 #undef PRINT_COLOR_FORMAT
151 out << static_cast<uint32_t>(fmt);
158 * @struct InferenceEngineProfileInfo
159 * @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.
164 struct InferenceEngineProfileInfo {
166 * @brief Defines the general status of the layer
169 NOT_RUN, //!< A layer is not exectued
170 OPTIMIZED_OUT, //!< A layer is optimized out during graph optimization phase
171 EXECUTED //!< A layer is executed
175 * @brief Defines a layer status
180 * @brief The absolute time in microseconds that the layer ran (in total)
182 long long realTime_uSec;
184 * @brief The net host cpu time that the layer ran
189 * @brief An execution type of unit
191 char exec_type[256] = {};
194 * @brief A layer type
196 char layer_type[256] = {};
199 * @brief An execution index of the unit
201 unsigned execution_index;
206 * @brief This enum contains codes for all possible return values of the interface functions
208 enum StatusCode : int {
211 NOT_IMPLEMENTED = -2,
212 NETWORK_NOT_LOADED = -3,
213 PARAMETER_MISMATCH = -4,
217 * @brief exception not of std::exception derived type was thrown
221 RESULT_NOT_READY = -9,
223 INFER_NOT_STARTED = -11,
224 NETWORK_NOT_READ = -12
228 * @struct ResponseDesc
229 * @brief Represents detailed information for an error
231 struct ResponseDesc {
233 * @brief A character buffer that holds the detailed information for an error.
240 * @brief Responce structure encapsulating information about supported layer
242 struct QueryNetworkResult {
244 * @brief A map of supported layers:
245 * - key - a layer name
246 * - value - a device name on which layer is assigned
248 std::map<std::string, std::string> supportedLayersMap;
251 * @brief A status code
256 * @brief Response message
261 /** @brief This class represents StatusCode::GENERIC_ERROR exception */
262 class GeneralError : public std::logic_error {
263 using std::logic_error::logic_error;
266 /** @brief This class represents StatusCode::NOT_IMPLEMENTED exception */
267 class NotImplemented : public std::logic_error {
268 using std::logic_error::logic_error;
271 /** @brief This class represents StatusCode::NETWORK_NOT_LOADED exception */
272 class NetworkNotLoaded : public std::logic_error {
273 using std::logic_error::logic_error;
276 /** @brief This class represents StatusCode::PARAMETER_MISMATCH exception */
277 class ParameterMismatch : public std::logic_error {
278 using std::logic_error::logic_error;
281 /** @brief This class represents StatusCode::NOT_FOUND exception */
282 class NotFound : public std::logic_error {
283 using std::logic_error::logic_error;
286 /** @brief This class represents StatusCode::OUT_OF_BOUNDS exception */
287 class OutOfBounds : public std::logic_error {
288 using std::logic_error::logic_error;
291 /** @brief This class represents StatusCode::UNEXPECTED exception */
292 class Unexpected : public std::logic_error {
293 using std::logic_error::logic_error;
296 /** @brief This class represents StatusCode::REQUEST_BUSY exception */
297 class RequestBusy : public std::logic_error {
298 using std::logic_error::logic_error;
301 /** @brief This class represents StatusCode::RESULT_NOT_READY exception */
302 class ResultNotReady : public std::logic_error {
303 using std::logic_error::logic_error;
306 /** @brief This class represents StatusCode::NOT_ALLOCATED exception */
307 class NotAllocated : public std::logic_error {
308 using std::logic_error::logic_error;
311 /** @brief This class represents StatusCode::INFER_NOT_STARTED exception */
312 class InferNotStarted : public std::logic_error {
313 using std::logic_error::logic_error;
315 } // namespace InferenceEngine
317 /** @brief This class represents StatusCode::NETWORK_NOT_READ exception */
318 class NetworkNotRead : public std::logic_error {
319 using std::logic_error::logic_error;
323 #define __PRETTY_FUNCTION__ __FUNCSIG__
325 #define __PRETTY_FUNCTION__ __PRETTY_FUNCTION__