Skip to content

Commit 0fe3ba6

Browse files
committed
Fix as per comments 2.
1 parent 3382509 commit 0fe3ba6

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

src/plugins/intel_cpu/src/transformations/cpu_opset/x64/pass/convert_precision_i64_i32.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ bool ConvertPrecisionI64ToI32::run_on_model(const std::shared_ptr<ov::Model>& mo
5959
parentNode->get_input_element_type(0) == element::i32 &&
6060
parentNode->get_output_element_type(0) == element::i64) {
6161
input.replace_source_output(parentNode->input_value(0));
62+
} else if (is_type<opset12::Convert>(op) &&
63+
op->get_input_element_type(0) == element::i64 &&
64+
op->get_output_element_type(0) == element::i32) {
65+
continue;
6266
} else if (auto constOp = as_type_ptr<op::v0::Constant>(parentNode)) {
6367
auto newConst = changeConstantPrecision(constOp);
6468
input.replace_source_output(newConst);
@@ -78,7 +82,7 @@ bool ConvertPrecisionI64ToI32::run_on_model(const std::shared_ptr<ov::Model>& mo
7882
for (auto& output : op->outputs()) {
7983
if (output.get_element_type() == element::i32) {
8084
auto convert = std::make_shared<opset12::Convert>(output, element::i64);
81-
replace_output_update_name(output, convert->input_value(0));
85+
replace_output_update_name(output, convert->output(0));
8286
}
8387
}
8488
}

src/plugins/intel_cpu/src/transformations/cpu_opset/x64/pass/convert_precision_i64_i32.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
#include "openvino/pass/pass.hpp"
88

9+
// This transformation inserts Conversion node (i64->i32) before a node that does not support i64 execution.
10+
// If the Conversion i64->i32 was added before the target node, it also inserts the Conversion i32->i64 after
11+
// the target node to leave the child nodes with i64 type.
12+
913
namespace ov {
1014
namespace intel_cpu {
1115
class ConvertPrecisionI64ToI32: public ov::pass::ModelPass {

src/plugins/intel_cpu/tests/functional/subgraph_tests/src/custom_op_insert_convert_i64.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ class CustomOpConvertI64CPUTest : public testing::WithParamInterface<CustomOpI64
134134

135135
TEST_P(CustomOpConvertI64CPUTest, CompareWithRefs) {
136136
run();
137-
// TODO: Graph could not be dumped with int64 for now. Swith on this in scope of int64 enabling.
138-
// CPUTestUtils::CheckNumberOfNodesWithType(compiledModel, "Convert", 1);
137+
CPUTestUtils::CheckNumberOfNodesWithType(compiledModel, "Convert", 1);
139138
}
140139

141140
const InputShape inputShapes = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (C) 2018-2023 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include <shared_test_classes/base/ov_subgraph.hpp>
6+
#include <ngraph_functions/builders.hpp>
7+
#include "test_utils/cpu_test_utils.hpp"
8+
#include <cpp_interfaces/interface/ie_internal_plugin_config.hpp>
9+
10+
using namespace ov::test;
11+
using namespace CPUTestUtils;
12+
13+
namespace CPULayerTestsDefinitions {
14+
using InsertConvertI64I32CPUTestParams = std::tuple<ElementType, InputShape>;
15+
16+
class InsertConvertI64I32CPUTest : public testing::WithParamInterface<InsertConvertI64I32CPUTestParams>,
17+
virtual public SubgraphBaseTest,
18+
public CPUTestsBase {
19+
public:
20+
static std::string getTestCaseName(const testing::TestParamInfo<InsertConvertI64I32CPUTestParams>& obj) {
21+
ElementType inType;
22+
InputShape inputShape;
23+
std::tie(inType, inputShape) = obj.param;
24+
25+
std::ostringstream result;
26+
result << "IS=" << inputShape << "_";
27+
result << "Prc=" << inType;
28+
return result.str();
29+
}
30+
31+
protected:
32+
void SetUp() override {
33+
targetDevice = CommonTestUtils::DEVICE_CPU;
34+
configuration[InferenceEngine::PluginConfigInternalParams::KEY_CPU_NATIVE_I64] = InferenceEngine::PluginConfigParams::YES;
35+
36+
InputShape inputShape;
37+
std::tie(inType, inputShape) = this->GetParam();
38+
39+
init_input_shapes({inputShape});
40+
auto inputParams = ngraph::builder::makeDynamicParams(inType, inputDynamicShapes);
41+
auto nonZero = std::make_shared<ov::op::v3::NonZero>(inputParams[0]);
42+
43+
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(nonZero)};
44+
function = std::make_shared<ov::Model>(results, inputParams, "insertConvertI64I32");
45+
}
46+
};
47+
48+
TEST_P(InsertConvertI64I32CPUTest, CompareWithRefs) {
49+
run();
50+
CheckNumberOfNodesWithType(compiledModel, "Convert", 2);
51+
}
52+
53+
const InputShape inputShapes = {
54+
{}, {{1, 3, 32, 32}}
55+
};
56+
57+
INSTANTIATE_TEST_SUITE_P(smoke_CustomOp,
58+
InsertConvertI64I32CPUTest,
59+
::testing::Combine(::testing::Values(ElementType::i64), ::testing::Values(inputShapes)),
60+
InsertConvertI64I32CPUTest::getTestCaseName);
61+
62+
} // namespace CPULayerTestsDefinitions

0 commit comments

Comments
 (0)