-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[CPU] Fix u8 Subtract to use wrap-around instead of saturation #33453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nishant-ZFYII
wants to merge
8
commits into
openvinotoolkit:master
Choose a base branch
from
Nishant-ZFYII:fix/33164-u8-subtract-wrap-around
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+216
−13
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4ca0fc2
[CPU] Fix u8 Subtract to use wrap-around instead of saturation
Nishant-ZFYII 6a70449
[CPU] Fix u8 subtract to wrap instead of saturate
Nishant-ZFYII d8e9383
[CPU] Fix u8 subtract to wrap instead of saturate
Nishant-ZFYII debffa0
[CPU] Address reviewer feedback for u8 eltwise wrap-around fix
Nishant-ZFYII b5561fa
[CPU] Add u8 wrap-around support for Add operation and address review…
Nishant-ZFYII 1badae9
Fix get_supported_precisions crash: use if-guard with OPENVINO_ASSERT
Nishant-ZFYII 6f33255
Clang-18 fix
Nishant-ZFYII d03bed1
Update copyright headers to 2026
Nishant-ZFYII File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/eltwise_overflow.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright (C) 2025 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| #include "eltwise_overflow.hpp" | ||
|
|
||
| #include "common_test_utils/ov_tensor_utils.hpp" | ||
| #include "openvino/op/add.hpp" | ||
| #include "openvino/op/result.hpp" | ||
| #include "openvino/op/subtract.hpp" | ||
|
|
||
| namespace ov { | ||
| namespace test { | ||
|
|
||
| std::string EltwiseOverflowLayerCPUTest::getTestCaseName(const testing::TestParamInfo<EltwiseOverflowTestParams>& obj) { | ||
| const auto& [kind, shape] = obj.param; | ||
| std::ostringstream result; | ||
| result << "kind=" << (kind == EltwiseOverflowKind::UNDERFLOW ? "UNDERFLOW" : "OVERFLOW"); | ||
| result << "_shape=" << shape; | ||
| return result.str(); | ||
| } | ||
|
|
||
| void EltwiseOverflowLayerCPUTest::SetUp() { | ||
| targetDevice = ov::test::utils::DEVICE_CPU; | ||
| abs_threshold = 0; | ||
|
|
||
| const auto& [kind, shape] = GetParam(); | ||
| overflowKind = kind; | ||
|
|
||
| InputShape inShape = {{}, {shape}}; | ||
| init_input_shapes({inShape, inShape}); | ||
|
|
||
| auto a = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::PartialShape(shape)); | ||
| auto b = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::PartialShape(shape)); | ||
|
|
||
| std::shared_ptr<ov::Node> op; | ||
| if (kind == EltwiseOverflowKind::UNDERFLOW) { | ||
| op = std::make_shared<ov::op::v1::Subtract>(a, b); | ||
| } else { | ||
| op = std::make_shared<ov::op::v1::Add>(a, b); | ||
| } | ||
|
|
||
| auto result = std::make_shared<ov::op::v0::Result>(op); | ||
| function = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{a, b}, "EltwiseOverflow"); | ||
| } | ||
|
|
||
| void EltwiseOverflowLayerCPUTest::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) { | ||
| inputs.clear(); | ||
| const auto& modelInputs = function->inputs(); | ||
| ASSERT_EQ(modelInputs.size(), 2u); | ||
| ASSERT_EQ(targetInputStaticShapes.size(), 2u); | ||
|
|
||
| const size_t size = ov::shape_size(targetInputStaticShapes[0]); | ||
|
|
||
| // Hardcoded values that guarantee underflow/overflow regardless of shape size. | ||
| // Pattern repeats to fill any shape. | ||
| static const std::vector<uint8_t> underflow_a = {3, 0, 1, 5, 10, 0, 100, 50}; | ||
| static const std::vector<uint8_t> underflow_b = {4, 1, 2, 3, 20, 1, 200, 51}; | ||
| // Expected results (wrap): 255, 255, 255, 2, 246, 255, 156, 255 | ||
|
|
||
| static const std::vector<uint8_t> overflow_a = {255, 254, 200, 128, 255, 250, 255, 1}; | ||
| static const std::vector<uint8_t> overflow_b = {1, 2, 100, 128, 255, 10, 128, 255}; | ||
| // Expected results (wrap): 0, 0, 44, 0, 254, 4, 127, 0 | ||
|
|
||
| const auto& src_a = (overflowKind == EltwiseOverflowKind::UNDERFLOW) ? underflow_a : overflow_a; | ||
| const auto& src_b = (overflowKind == EltwiseOverflowKind::UNDERFLOW) ? underflow_b : overflow_b; | ||
|
|
||
| std::vector<uint8_t> data0(size); | ||
| std::vector<uint8_t> data1(size); | ||
|
|
||
| for (size_t i = 0; i < size; ++i) { | ||
| data0[i] = src_a[i % src_a.size()]; | ||
| data1[i] = src_b[i % src_b.size()]; | ||
| } | ||
|
|
||
| auto t0 = ov::Tensor(ov::element::u8, targetInputStaticShapes[0]); | ||
| auto t1 = ov::Tensor(ov::element::u8, targetInputStaticShapes[1]); | ||
| std::copy(data0.begin(), data0.end(), t0.data<uint8_t>()); | ||
| std::copy(data1.begin(), data1.end(), t1.data<uint8_t>()); | ||
|
|
||
| inputs.insert({modelInputs[0].get_node_shared_ptr(), t0}); | ||
| inputs.insert({modelInputs[1].get_node_shared_ptr(), t1}); | ||
| } | ||
|
|
||
| TEST_P(EltwiseOverflowLayerCPUTest, CompareWithRefs) { | ||
| run(); | ||
| } | ||
|
|
||
| } // namespace test | ||
| } // namespace ov | ||
32 changes: 32 additions & 0 deletions
32
...plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/eltwise_overflow.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||||||||||
| // Copyright (C) 2025 Intel Corporation | ||||||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||||||
| // | ||||||||||||||
|
||||||||||||||
| // Copyright (C) 2025 Intel Corporation | |
| // SPDX-License-Identifier: Apache-2.0 | |
| // | |
| // Copyright (C) 2018-2026 Intel Corporation | |
| // SPDX-License-Identifier: Apache-2.0 | |
| // |
24 changes: 24 additions & 0 deletions
24
...ntel_cpu/tests/functional/custom/single_layer_tests/instances/common/eltwise_overflow.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||
| // Copyright (C) 2025 Intel Corporation | ||||||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||||||
| // | ||||||||||||||
|
||||||||||||||
| // Copyright (C) 2025 Intel Corporation | |
| // SPDX-License-Identifier: Apache-2.0 | |
| // | |
| // Copyright (C) 2018-2026 Intel Corporation | |
| // SPDX-License-Identifier: Apache-2.0 | |
| // |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.