99
1010#include < unordered_set>
1111
12+ namespace ov {
13+ namespace intel_cpu {
14+
1215// 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 {
1417 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 ()
1720 };
1821
1922 return i64Ops.find (type) != i64Ops.end ();
2023}
2124
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 {
2326 const auto * srcData = constant->get_data_ptr <int64_t >();
2427 const auto size = shape_size (constant->get_shape ());
2528
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 ());
2730 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 ()));
2932 OPENVINO_ASSERT (dstData != nullptr , " Can't get destination data pointer" );
3033
3134 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
4043 return newConstant;
4144}
4245
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) {
4447 const auto orderedOps = model->get_ordered_ops ();
4548 for (const auto & op : orderedOps) {
4649 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
4952
5053 bool convertForOutputsRequired = false ;
5154 for (const auto & input : op->inputs ()) {
52- if (input.get_element_type () == ov:: element::i64 ) {
55+ if (input.get_element_type () == element::i64 ) {
5356 auto parentOutput = input.get_source_output ();
5457 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 ) {
5761 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)) {
5963 auto newConst = changeConstantPrecision (constOp);
6064 input.replace_source_output (newConst);
6165 newConst->set_friendly_name (constOp->get_friendly_name ());
6266 } 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 );
6468 convert->output (0 ).add_names (parentOutput.get_names ());
6569 input.replace_source_output (convert);
6670 }
@@ -72,29 +76,14 @@ bool ov::intel_cpu::ConvertPrecisionI64ToI32::run_on_model(const std::shared_ptr
7276 // Propagate i32 precision into outputs.
7377 op->validate_and_infer_types ();
7478 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 ));
9382 }
9483 }
9584 }
9685
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)) {
9887 for (size_t idx = 0 ; idx < multisubgraph_op->get_internal_subgraphs_size (); ++idx) {
9988 run_on_model (multisubgraph_op->get_function (static_cast <int >(idx)));
10089 }
@@ -103,3 +92,6 @@ bool ov::intel_cpu::ConvertPrecisionI64ToI32::run_on_model(const std::shared_ptr
10392
10493 return true ;
10594}
95+
96+ } // namespace intel_cpu
97+ } // namespace ov
0 commit comments