forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
213 lines (187 loc) · 5.53 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <cassert>
#include <fstream>
#include <iterator>
#include <map>
#include <streambuf>
#include <string>
#include "openvino/core/except.hpp"
#include "openvino/openvino.hpp"
#include "openvino/runtime/exception.hpp"
#define CATCH_OV_EXCEPTION(StatusCode, ExceptionType) \
catch (const ov::ExceptionType& ex) { \
dup_last_err_msg(ex.what()); \
return ov_status_e::StatusCode; \
}
#define CATCH_OV_EXCEPTIONS \
CATCH_OV_EXCEPTION(REQUEST_BUSY, Busy) \
CATCH_OV_EXCEPTION(INFER_CANCELLED, Cancelled) \
CATCH_OV_EXCEPTION(NOT_IMPLEMENTED, NotImplemented) \
CATCH_OV_EXCEPTION(GENERAL_ERROR, Exception) \
catch (...) { \
dup_last_err_msg("An unknown exception occurred"); \
return ov_status_e::UNKNOW_EXCEPTION; \
}
#define GET_PROPERTY_FROM_ARGS_LIST \
std::string property_key = va_arg(args_ptr, char*); \
std::string _value = va_arg(args_ptr, char*); \
ov::Any value = _value; \
property[property_key] = value;
/**
* @struct ov_core
* @brief This struct represents OpenVINO Core entity.
*/
struct ov_core {
std::shared_ptr<ov::Core> object;
};
/**
* @struct ov_model
* @brief This is an interface of ov::Model
*/
struct ov_model {
std::shared_ptr<ov::Model> object;
};
/**
* @struct ov_output_const_port
* @brief This is an interface of ov::Output<const ov::Node>
*/
struct ov_output_const_port {
std::shared_ptr<ov::Output<const ov::Node>> object;
};
/**
* @struct ov_output_port
* @brief This is an interface of ov::Output<ov::Node>
*/
struct ov_output_port {
std::shared_ptr<ov::Output<ov::Node>> object;
};
/**
* @struct ov_compiled_model
* @brief This is an interface of ov::CompiledModel
*/
struct ov_compiled_model {
std::shared_ptr<ov::CompiledModel> object;
};
/**
* @struct ov_infer_request
* @brief This is an interface of ov::InferRequest
*/
struct ov_infer_request {
std::shared_ptr<ov::InferRequest> object;
};
/**
* @struct ov_layout
* @brief This is an interface of ov::Layout
*/
struct ov_layout {
ov::Layout object;
};
/**
* @struct ov_tensor
* @brief This is an interface of ov_tensor
*/
struct ov_tensor {
std::shared_ptr<ov::Tensor> object;
};
/**
* @struct ov_preprocess_prepostprocessor
* @brief This is an interface of ov::preprocess::PrePostProcessor
*/
struct ov_preprocess_prepostprocessor {
std::shared_ptr<ov::preprocess::PrePostProcessor> object;
};
/**
* @struct ov_preprocess_input_info
* @brief This is an interface of ov::preprocess::InputInfo
*/
struct ov_preprocess_input_info {
ov::preprocess::InputInfo* object;
};
/**
* @struct ov_preprocess_input_tensor_info
* @brief This is an interface of ov::preprocess::InputTensorInfo
*/
struct ov_preprocess_input_tensor_info {
ov::preprocess::InputTensorInfo* object;
};
/**
* @struct ov_preprocess_output_info
* @brief This is an interface of ov::preprocess::OutputInfo
*/
struct ov_preprocess_output_info {
ov::preprocess::OutputInfo* object;
};
/**
* @struct ov_preprocess_output_tensor_info
* @brief This is an interface of ov::preprocess::OutputTensorInfo
*/
struct ov_preprocess_output_tensor_info {
ov::preprocess::OutputTensorInfo* object;
};
/**
* @struct ov_preprocess_input_model_info
* @brief This is an interface of ov::preprocess::InputModelInfo
*/
struct ov_preprocess_input_model_info {
ov::preprocess::InputModelInfo* object;
};
/**
* @struct ov_preprocess_preprocess_steps
* @brief This is an interface of ov::preprocess::PreProcessSteps
*/
struct ov_preprocess_preprocess_steps {
ov::preprocess::PreProcessSteps* object;
};
/**
* @struct ov_remote_context
* @brief This is an interface of ov::RemoteContext
*/
struct ov_remote_context {
std::shared_ptr<ov::RemoteContext> object;
};
/**
* @struct mem_stringbuf
* @brief This struct puts memory buffer to stringbuf.
*/
struct mem_stringbuf : std::streambuf {
mem_stringbuf(const char* buffer, size_t sz) {
char* bptr(const_cast<char*>(buffer));
setg(bptr, bptr, bptr + sz);
}
pos_type seekoff(off_type off,
std::ios_base::seekdir dir,
std::ios_base::openmode which = std::ios_base::in) override {
switch (dir) {
case std::ios_base::beg:
setg(eback(), eback() + off, egptr());
break;
case std::ios_base::end:
setg(eback(), egptr() + off, egptr());
break;
case std::ios_base::cur:
setg(eback(), gptr() + off, egptr());
break;
default:
return pos_type(off_type(-1));
}
return (gptr() < eback() || gptr() > egptr()) ? pos_type(off_type(-1)) : pos_type(gptr() - eback());
}
pos_type seekpos(pos_type pos, std::ios_base::openmode which) override {
return seekoff(pos, std::ios_base::beg, which);
}
};
/**
* @struct mem_istream
* @brief This struct puts stringbuf buffer to istream.
*/
struct mem_istream : virtual mem_stringbuf, std::istream {
mem_istream(const char* buffer, size_t sz)
: mem_stringbuf(buffer, sz),
std::istream(static_cast<std::streambuf*>(this)) {}
};
char* str_to_char_array(const std::string& str);
ov::element::Type get_element_type(ov_element_type_e type);
void dup_last_err_msg(const char* msg);