Skip to content

Commit

Permalink
Fix as per comments 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
nshchego committed Jul 25, 2023
1 parent 3382509 commit 0fe3ba6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ bool ConvertPrecisionI64ToI32::run_on_model(const std::shared_ptr<ov::Model>& mo
parentNode->get_input_element_type(0) == element::i32 &&
parentNode->get_output_element_type(0) == element::i64) {
input.replace_source_output(parentNode->input_value(0));
} else if (is_type<opset12::Convert>(op) &&
op->get_input_element_type(0) == element::i64 &&
op->get_output_element_type(0) == element::i32) {
continue;
} else if (auto constOp = as_type_ptr<op::v0::Constant>(parentNode)) {
auto newConst = changeConstantPrecision(constOp);
input.replace_source_output(newConst);
Expand All @@ -78,7 +82,7 @@ bool ConvertPrecisionI64ToI32::run_on_model(const std::shared_ptr<ov::Model>& mo
for (auto& output : op->outputs()) {
if (output.get_element_type() == element::i32) {
auto convert = std::make_shared<opset12::Convert>(output, element::i64);
replace_output_update_name(output, convert->input_value(0));
replace_output_update_name(output, convert->output(0));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "openvino/pass/pass.hpp"

// This transformation inserts Conversion node (i64->i32) before a node that does not support i64 execution.
// If the Conversion i64->i32 was added before the target node, it also inserts the Conversion i32->i64 after
// the target node to leave the child nodes with i64 type.

namespace ov {
namespace intel_cpu {
class ConvertPrecisionI64ToI32: public ov::pass::ModelPass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ class CustomOpConvertI64CPUTest : public testing::WithParamInterface<CustomOpI64

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

const InputShape inputShapes = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <shared_test_classes/base/ov_subgraph.hpp>
#include <ngraph_functions/builders.hpp>
#include "test_utils/cpu_test_utils.hpp"
#include <cpp_interfaces/interface/ie_internal_plugin_config.hpp>

using namespace ov::test;
using namespace CPUTestUtils;

namespace CPULayerTestsDefinitions {
using InsertConvertI64I32CPUTestParams = std::tuple<ElementType, InputShape>;

class InsertConvertI64I32CPUTest : public testing::WithParamInterface<InsertConvertI64I32CPUTestParams>,
virtual public SubgraphBaseTest,
public CPUTestsBase {
public:
static std::string getTestCaseName(const testing::TestParamInfo<InsertConvertI64I32CPUTestParams>& obj) {
ElementType inType;
InputShape inputShape;
std::tie(inType, inputShape) = obj.param;

std::ostringstream result;
result << "IS=" << inputShape << "_";
result << "Prc=" << inType;
return result.str();
}

protected:
void SetUp() override {
targetDevice = CommonTestUtils::DEVICE_CPU;
configuration[InferenceEngine::PluginConfigInternalParams::KEY_CPU_NATIVE_I64] = InferenceEngine::PluginConfigParams::YES;

InputShape inputShape;
std::tie(inType, inputShape) = this->GetParam();

init_input_shapes({inputShape});
auto inputParams = ngraph::builder::makeDynamicParams(inType, inputDynamicShapes);
auto nonZero = std::make_shared<ov::op::v3::NonZero>(inputParams[0]);

ov::ResultVector results{std::make_shared<ov::op::v0::Result>(nonZero)};
function = std::make_shared<ov::Model>(results, inputParams, "insertConvertI64I32");
}
};

TEST_P(InsertConvertI64I32CPUTest, CompareWithRefs) {
run();
CheckNumberOfNodesWithType(compiledModel, "Convert", 2);
}

const InputShape inputShapes = {
{}, {{1, 3, 32, 32}}
};

INSTANTIATE_TEST_SUITE_P(smoke_CustomOp,
InsertConvertI64I32CPUTest,
::testing::Combine(::testing::Values(ElementType::i64), ::testing::Values(inputShapes)),
InsertConvertI64I32CPUTest::getTestCaseName);

} // namespace CPULayerTestsDefinitions

0 comments on commit 0fe3ba6

Please sign in to comment.