9
9
10
10
#include < unordered_set>
11
11
12
+ namespace ov {
13
+ namespace intel_cpu {
14
+
12
15
// Returns list of operations that support i64.
13
- bool isNativelySupported (const ov::Node::type_info_t & type) {
16
+ bool ConvertPrecisionI64ToI32:: isNativelySupported (const ov::Node::type_info_t & type) const {
14
17
static const std::unordered_set<ov::Node::type_info_t > i64Ops = {
15
- ov:: opset12::Parameter::get_type_info_static (),
16
- ov:: opset12::Result::get_type_info_static ()
18
+ opset12::Parameter::get_type_info_static (),
19
+ opset12::Result::get_type_info_static ()
17
20
};
18
21
19
22
return i64Ops.find (type) != i64Ops.end ();
20
23
}
21
24
22
- std::shared_ptr<ov::Node> changeConstantPrecision (std::shared_ptr<ov:: op::v0::Constant>& constant) {
25
+ std::shared_ptr<ov::Node> ConvertPrecisionI64ToI32:: changeConstantPrecision (std::shared_ptr<op::v0::Constant>& constant) const {
23
26
const auto * srcData = constant->get_data_ptr <int64_t >();
24
27
const auto size = shape_size (constant->get_shape ());
25
28
26
- auto newConstant = std::make_shared<ov:: op::v0::Constant>(ov:: element::i32, constant->get_shape ());
29
+ auto newConstant = std::make_shared<op::v0::Constant>(element::i32, constant->get_shape ());
27
30
newConstant->output (0 ).set_names (constant->output (0 ).get_names ());
28
- auto * dstData = const_cast <int32_t *>(reinterpret_cast <const int32_t *>(newConstant->get_data_ptr ()));
31
+ auto * dstData = const_cast <int32_t *>(reinterpret_cast <const int32_t *>(newConstant->get_data_ptr ()));
29
32
OPENVINO_ASSERT (dstData != nullptr , " Can't get destination data pointer" );
30
33
31
34
for (size_t i = 0 ; i < size; ++i) {
@@ -40,7 +43,7 @@ std::shared_ptr<ov::Node> changeConstantPrecision(std::shared_ptr<ov::op::v0::Co
40
43
return newConstant;
41
44
}
42
45
43
- bool ov::intel_cpu:: ConvertPrecisionI64ToI32::run_on_model (const std::shared_ptr<ov::Model> & model) {
46
+ bool ConvertPrecisionI64ToI32::run_on_model (const std::shared_ptr<ov::Model>& model) {
44
47
const auto orderedOps = model->get_ordered_ops ();
45
48
for (const auto & op : orderedOps) {
46
49
if (isNativelySupported (op->get_type_info ()) || TypeFromName (op->get_type_name ()) == Type::Unknown) {
@@ -49,18 +52,19 @@ bool ov::intel_cpu::ConvertPrecisionI64ToI32::run_on_model(const std::shared_ptr
49
52
50
53
bool convertForOutputsRequired = false ;
51
54
for (const auto & input : op->inputs ()) {
52
- if (input.get_element_type () == ov:: element::i64) {
55
+ if (input.get_element_type () == element::i64) {
53
56
auto parentOutput = input.get_source_output ();
54
57
auto parentNode = parentOutput.get_node_shared_ptr ();
55
- if (ov::is_type<ov::opset12::Convert>(parentNode) &&
56
- parentNode->get_rt_info ().find (" convert_i32_i64" ) != parentNode->get_rt_info ().end ()) {
58
+ if (is_type<opset12::Convert>(parentNode) &&
59
+ parentNode->get_input_element_type (0 ) == element::i32 &&
60
+ parentNode->get_output_element_type (0 ) == element::i64) {
57
61
input.replace_source_output (parentNode->input_value (0 ));
58
- } else if (auto constOp = ov:: as_type_ptr<ov:: op::v0::Constant>(parentNode)) {
62
+ } else if (auto constOp = as_type_ptr<op::v0::Constant>(parentNode)) {
59
63
auto newConst = changeConstantPrecision (constOp);
60
64
input.replace_source_output (newConst);
61
65
newConst->set_friendly_name (constOp->get_friendly_name ());
62
66
} else {
63
- auto convert = std::make_shared<ov:: opset12::Convert>(input.get_source_output (), ov:: element::i32);
67
+ auto convert = std::make_shared<opset12::Convert>(input.get_source_output (), element::i32);
64
68
convert->output (0 ).add_names (parentOutput.get_names ());
65
69
input.replace_source_output (convert);
66
70
}
@@ -72,29 +76,14 @@ bool ov::intel_cpu::ConvertPrecisionI64ToI32::run_on_model(const std::shared_ptr
72
76
// Propagate i32 precision into outputs.
73
77
op->validate_and_infer_types ();
74
78
for (auto & output : op->outputs ()) {
75
- if (output.get_element_type () == ov::element::i32) {
76
- auto targetInputs = output.get_target_inputs ();
77
- auto convert = std::make_shared<ov::opset12::Convert>(output, ov::element::i64);
78
-
79
- auto & rt_info = convert->get_rt_info ();
80
- rt_info[" convert_i32_i64" ] = " " ;
81
- for (const auto & targetInput : targetInputs) {
82
- targetInput.replace_source_output (convert);
83
- }
84
-
85
- auto & convertTensor = convert->output (0 ).get_tensor ();
86
- const std::string newName = ov::op::util::get_ie_output_name (output);
87
- if (ov::descriptor::get_ov_tensor_legacy_name (convertTensor).empty ()) {
88
- ov::descriptor::set_ov_tensor_legacy_name (convertTensor, newName);
89
- }
90
- if (!output.get_names ().empty ()) {
91
- convertTensor.set_names (output.get_names ());
92
- }
79
+ if (output.get_element_type () == element::i32) {
80
+ auto convert = std::make_shared<opset12::Convert>(output, element::i64);
81
+ replace_output_update_name (output, convert->input_value (0 ));
93
82
}
94
83
}
95
84
}
96
85
97
- if (auto multisubgraph_op = ov:: as_type_ptr<ov:: op::util::MultiSubGraphOp>(op)) {
86
+ if (auto multisubgraph_op = as_type_ptr<op::util::MultiSubGraphOp>(op)) {
98
87
for (size_t idx = 0 ; idx < multisubgraph_op->get_internal_subgraphs_size (); ++idx) {
99
88
run_on_model (multisubgraph_op->get_function (static_cast <int >(idx)));
100
89
}
@@ -103,3 +92,6 @@ bool ov::intel_cpu::ConvertPrecisionI64ToI32::run_on_model(const std::shared_ptr
103
92
104
93
return true ;
105
94
}
95
+
96
+ } // namespace intel_cpu
97
+ } // namespace ov
0 commit comments