forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock_frontend.cpp
213 lines (171 loc) · 7.96 KB
/
mock_frontend.cpp
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-2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/frontend/exception.hpp"
#include "openvino/frontend/manager.hpp"
#include "openvino/frontend/visibility.hpp"
#include "openvino/opsets/opset8.hpp"
#define MOCK_C_API OPENVINO_EXTERN_C OPENVINO_CORE_EXPORTS
using namespace ov::frontend;
class InputModelMock : public InputModel {
public:
bool m_throw = false;
std::vector<Place::Ptr> get_inputs() const override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
return {};
}
std::vector<Place::Ptr> get_outputs() const override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
return {};
}
Place::Ptr get_place_by_tensor_name(const std::string& tensor_name) const override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
return {};
}
Place::Ptr get_place_by_operation_name(const std::string& operation_name) const override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
return {};
}
Place::Ptr get_place_by_operation_name_and_input_port(const std::string& operation_name,
int input_port_index) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
return {};
}
Place::Ptr get_place_by_operation_name_and_output_port(const std::string& operation_name,
int output_port_index) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
return {};
}
void set_name_for_tensor(const Place::Ptr& tensor, const std::string& new_name) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void add_name_for_tensor(const Place::Ptr& tensor, const std::string& new_name) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void set_name_for_operation(const Place::Ptr& operation, const std::string& new_name) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void free_name_for_tensor(const std::string& name) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void free_name_for_operation(const std::string& name) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void set_name_for_dimension(const Place::Ptr& place, size_t shape_dim_index, const std::string& dim_name) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void cut_and_add_new_input(const Place::Ptr& place, const std::string& new_name_optional) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void cut_and_add_new_output(const Place::Ptr& place, const std::string& new_name_optional) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
Place::Ptr add_output(const Place::Ptr& place) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
return {};
}
void remove_output(const Place::Ptr& place) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void override_all_outputs(const std::vector<Place::Ptr>& outputs) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void override_all_inputs(const std::vector<Place::Ptr>& inputs) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void extract_subgraph(const std::vector<Place::Ptr>& inputs, const std::vector<Place::Ptr>& outputs) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void set_partial_shape(const Place::Ptr& place, const ov::PartialShape& shape) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
ov::PartialShape get_partial_shape(const Place::Ptr& place) const override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
return {};
}
void set_element_type(const Place::Ptr& place, const ov::element::Type& type) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void set_tensor_value(const Place::Ptr& place, const void* value) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
void set_tensor_partial_value(const Place::Ptr& place, const void* min_value, const void* max_value) override {
FRONT_END_GENERAL_CHECK(!m_throw, "Test exception");
}
};
class FrontEndMock : public FrontEnd {
mutable bool m_throw_next{false};
public:
std::string get_name() const override {
FRONT_END_GENERAL_CHECK(!m_throw_next, "Test exception");
return "mock1";
}
bool supported_impl(const std::vector<ov::Any>& variants) const override {
// Last boolean flag in `variants` (if presented) is reserved for FE configuration
size_t extra_variants_num = variants.size() > 0 && variants[variants.size() - 1].is<bool>() ? 1 : 0;
if (variants.size() == 1 + extra_variants_num && variants[0].is<std::string>()) {
std::string command = variants[0].as<std::string>();
FRONT_END_GENERAL_CHECK(command != "throw_now", "Test exception");
}
return false;
}
void add_extension(const std::shared_ptr<ov::Extension>& extension) override {
FRONT_END_GENERAL_CHECK(!m_throw_next, "Test exception");
}
InputModel::Ptr load_impl(const std::vector<ov::Any>& variants) const override {
// Last boolean flag in `variants` (if presented) is reserved for FE configuration
size_t extra_variants_num = variants.size() > 0 && variants[variants.size() - 1].is<bool>() ? 1 : 0;
auto input_model = std::make_shared<InputModelMock>();
if (variants.size() == 1 + extra_variants_num && variants[0].is<std::string>()) {
std::string command = variants[0].as<std::string>();
if (command == "throw_now") {
OPENVINO_THROW("Test throw load input model");
} else if (command == "throw_next") {
m_throw_next = true;
} else if (command == "throw_model") {
input_model->m_throw = true;
}
}
return input_model;
}
std::shared_ptr<ov::Model> convert_partially(const InputModel::Ptr& model) const override {
FRONT_END_GENERAL_CHECK(!m_throw_next, "Test exception");
return nullptr;
}
std::shared_ptr<ov::Model> decode(const InputModel::Ptr& model) const override {
FRONT_END_GENERAL_CHECK(!m_throw_next, "Test exception");
return nullptr;
}
void convert(const std::shared_ptr<ov::Model>& model) const override {
FRONT_END_GENERAL_CHECK(!m_throw_next, "Test exception");
}
void normalize(const std::shared_ptr<ov::Model>& model) const override {
FRONT_END_GENERAL_CHECK(!m_throw_next, "Test exception");
}
std::shared_ptr<ov::Model> convert(const InputModel::Ptr& model) const override {
FRONT_END_GENERAL_CHECK(!m_throw_next, "Test exception");
auto shape = ov::Shape{1, 2, 300, 300};
auto param = std::make_shared<ov::opset8::Parameter>(ov::element::f32, shape);
std::vector<float> data(ov::shape_size(shape), 1.f);
auto constant = ov::opset8::Constant::create(ov::element::f32, shape, data);
auto op = std::make_shared<ov::opset8::Add>(param, constant);
auto res = std::make_shared<ov::opset8::Result>(op);
auto ov_model =
std::make_shared<ov::Model>(ov::ResultVector({res}), ov::ParameterVector({param}), "mock1_model");
ov_model->get_rt_info()["mock_test"] = std::string(1024, 't');
return ov_model;
}
};
MOCK_C_API FrontEndVersion get_api_version();
MOCK_C_API void* get_front_end_data();
MOCK_C_API FrontEndVersion get_api_version() {
return OV_FRONTEND_API_VERSION;
}
MOCK_C_API void* get_front_end_data() {
auto* res = new FrontEndPluginInfo();
res->m_name = "mock1";
res->m_creator = []() {
return std::make_shared<FrontEndMock>();
};
return res;
}