forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathop_extension.cpp
181 lines (167 loc) · 8.65 KB
/
op_extension.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
// Copyright (C) 2018-2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "op_extension.hpp"
#include "openvino/core/so_extension.hpp"
#include "openvino/frontend/extension/op.hpp"
#include "openvino/frontend/paddle/extension/op.hpp"
#include "openvino/frontend/paddle/frontend.hpp"
#include "openvino/runtime/core.hpp"
#include "paddle_utils.hpp"
#include "utils.hpp"
using namespace ov::frontend;
class Relu1 : public Relu {
public:
OPENVINO_OP("relu");
OPENVINO_FRAMEWORK_MAP(paddle, {"X"}, {"Out"})
};
class Relu2 : public Relu {
public:
OPENVINO_FRAMEWORK_MAP(paddle, {"X"}, {"Out"}, "CustomRelu_2")
};
class Relu3 : public Relu {
public:
OPENVINO_FRAMEWORK_MAP(paddle,
{"X"},
{"Out"},
"CustomRelu_3",
{{"ov_attribute_1", "fw_attribute_1"}, {"ov_attribute_2", "fw_attribute_2"}})
};
class Relu4 : public Relu {
public:
OPENVINO_FRAMEWORK_MAP(paddle,
{"X"},
{"Out"},
"CustomRelu_4",
{{"ov_attribute_1", "fw_attribute_1"}, {"ov_attribute_2", "fw_attribute_2"}},
{
{"ov_attribute_str", "string"},
{"ov_attribute_int", 4},
{"ov_attribute_bool", true},
{"ov_attribute_float", 4.f},
{"ov_attribute_vec_string", std::vector<std::string>{"str1", "str2", "str3"}},
{"ov_attribute_vec_int", std::vector<int>{1, 2, 3, 4, 5, 6, 7}},
{"ov_attribute_vec_bool", std::vector<bool>{true, false, true}},
{"ov_attribute_vec_float", std::vector<float>{1., 2., 3., 4., 5., 6., 7.}},
})
};
static OpExtensionFEParam getTestDataOpExtensionViaUserClass() {
OpExtensionFEParam res;
res.m_frontEndName = PADDLE_FE;
res.m_modelsPath = std::string(TEST_PADDLE_MODELS_DIRNAME);
res.m_modelName = "relu/relu.pdmodel";
// use core OpExtension
res.m_extensions = std::vector<std::shared_ptr<ov::Extension>>{std::make_shared<ov::OpExtension<Relu1>>(),
std::make_shared<ov::OpExtension<Relu2>>(),
std::make_shared<ov::OpExtension<Relu3>>(),
std::make_shared<ov::OpExtension<Relu4>>()};
return res;
}
static OpExtensionFEParam getTestDataOpExtensionViaPaddleConstructor() {
OpExtensionFEParam res;
res.m_frontEndName = PADDLE_FE;
res.m_modelsPath = std::string(TEST_PADDLE_MODELS_DIRNAME);
res.m_modelName = "relu/relu.pdmodel";
// use ov::frontend::paddle OpExtension
res.m_extensions = std::vector<std::shared_ptr<ov::Extension>>{
std::make_shared<ov::frontend::paddle::OpExtension<>>("CustomRelu_5",
std::vector<std::string>{"X"},
std::vector<std::string>{"Out"}),
std::make_shared<ov::frontend::paddle::OpExtension<>>("ov_CustomRelu_6",
"fw_CustomRelu_6",
std::vector<std::string>{"X"},
std::vector<std::string>{"Out"}),
std::make_shared<ov::frontend::paddle::OpExtension<>>(
"ov_CustomRelu_7",
"fw_CustomRelu_7",
std::vector<std::string>{"X"},
std::vector<std::string>{"Out"},
std::map<std::string, std::string>{{"ov_attribute_1", "fw_attribute_1"},
{"ov_attribute_2", "fw_attribute_2"}}),
std::make_shared<ov::frontend::paddle::OpExtension<>>(
"ov_CustomRelu_8",
"fw_CustomRelu_8",
std::vector<std::string>{"X"},
std::vector<std::string>{"Out"},
std::map<std::string, std::string>{{"ov_attribute_1", "fw_attribute_1"},
{"ov_attribute_2", "fw_attribute_2"}},
std::map<std::string, ov::Any>{
{"ov_attribute_str", "string"},
{"ov_attribute_int", 4},
{"ov_attribute_bool", true},
{"ov_attribute_float", 4.f},
{"ov_attribute_vec_string", std::vector<std::string>{"str1", "str2", "str3"}},
{"ov_attribute_vec_int", std::vector<int>{1, 2, 3, 4, 5, 6, 7}},
{"ov_attribute_vec_bool", std::vector<bool>{true, false, true}},
{"ov_attribute_vec_float", std::vector<float>{1., 2., 3., 4., 5., 6., 7.}},
})};
return res;
}
static OpExtensionFEParam getTestDataOpExtensionViaCommonConstructor() {
OpExtensionFEParam res;
res.m_frontEndName = PADDLE_FE;
res.m_modelsPath = std::string(TEST_PADDLE_MODELS_DIRNAME);
res.m_modelName = "relu/relu.pdmodel";
// use ov::frontend::OpExtension
res.m_extensions = std::vector<std::shared_ptr<ov::Extension>>{
std::make_shared<ov::frontend::OpExtension<>>("CustomRelu_9",
std::vector<std::string>{"X"},
std::vector<std::string>{"Out"}),
std::make_shared<ov::frontend::OpExtension<>>("ov_CustomRelu_10",
"fw_CustomRelu_10",
std::vector<std::string>{"X"},
std::vector<std::string>{"Out"}),
std::make_shared<ov::frontend::OpExtension<>>(
"ov_CustomRelu_11",
"fw_CustomRelu_11",
std::vector<std::string>{"X"},
std::vector<std::string>{"Out"},
std::map<std::string, std::string>{{"ov_attribute_1", "fw_attribute_1"},
{"ov_attribute_2", "fw_attribute_2"}}),
std::make_shared<ov::frontend::OpExtension<>>(
"ov_CustomRelu_12",
"fw_CustomRelu_12",
std::vector<std::string>{"X"},
std::vector<std::string>{"Out"},
std::map<std::string, std::string>{{"ov_attribute_1", "fw_attribute_1"},
{"ov_attribute_2", "fw_attribute_2"}},
std::map<std::string, ov::Any>{
{"ov_attribute_str", "string"},
{"ov_attribute_int", 4},
{"ov_attribute_bool", true},
{"ov_attribute_float", 4.f},
{"ov_attribute_vec_string", std::vector<std::string>{"str1", "str2", "str3"}},
{"ov_attribute_vec_int", std::vector<int>{1, 2, 3, 4, 5, 6, 7}},
{"ov_attribute_vec_bool", std::vector<bool>{true, false, true}},
{"ov_attribute_vec_float", std::vector<float>{1., 2., 3., 4., 5., 6., 7.}},
})};
return res;
}
INSTANTIATE_TEST_SUITE_P(PaddleOpExtensionTestViaUserClass,
FrontEndOpExtensionTest,
::testing::Values(getTestDataOpExtensionViaUserClass()),
FrontEndOpExtensionTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(PaddleOpExtensionViaPaddleConstructor,
FrontEndOpExtensionTest,
::testing::Values(getTestDataOpExtensionViaPaddleConstructor()),
FrontEndOpExtensionTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(PaddleOpExtensionViaCommonConstructor,
FrontEndOpExtensionTest,
::testing::Values(getTestDataOpExtensionViaCommonConstructor()),
FrontEndOpExtensionTest::getTestCaseName);
TEST(FrontEndOpExtensionTest, paddle_opextension_relu) {
ov::Core core;
const auto extensions = std::vector<std::shared_ptr<ov::Extension>>{std::make_shared<ov::OpExtension<Relu1>>()};
core.add_extension(extensions);
std::string m_modelsPath = std::string(TEST_PADDLE_MODELS_DIRNAME);
std::string m_modelName = "relu/relu.pdmodel";
auto model = core.read_model(FrontEndTestUtils::make_model_path(m_modelsPath + m_modelName));
bool has_relu = false;
for (const auto& op : model->get_ops()) {
std::string name = op->get_type_info().name;
std::string version = op->get_type_info().version_id;
if (name == "relu" && version == "extension")
has_relu = true;
}
EXPECT_TRUE(has_relu);
}