forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CPU] Add Clamp before Convert when bool is replaced with u8 (openvin…
…otoolkit#25253) ### Details: CPU plugin doesn't natively support `boolean` data type, thus it's replaced with `u8` during the convert precision transformation pass. However, casting numerical types to `bool` implies clamping the numerical values with the interval [0; 1] (either true or false), so to mimic this behavior a Clamp operation should be inserted before the modified convert. ### Tickets: - CVS-145166
- Loading branch information
Showing
2 changed files
with
85 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
64 changes: 64 additions & 0 deletions
64
...plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/common/convert_bool_math.cpp
This file contains 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,64 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "shared_test_classes/base/ov_subgraph.hpp" | ||
#include "common_test_utils/ov_tensor_utils.hpp" | ||
|
||
namespace ov { | ||
namespace test { | ||
// ┌────────┐ | ||
// │ Param │ | ||
// └───┬────┘ | ||
// │ f32 | ||
// │ | ||
// ┌───┴────┐ | ||
// │Convert │ | ||
// └───┬────┘ | ||
// │ bool | ||
// │ | ||
// ┌───┴────┐ | ||
// │Reshape │ | ||
// └───┬────┘ | ||
// │ bool | ||
// │ | ||
// ┌───┴────┐ ┌────────┐ | ||
// │Convert │ │ Param │ | ||
// └───┬────┘ └───┬────┘ | ||
// │ f32 │ f32 | ||
// │ │ | ||
// │ ┌────────┐ │ | ||
// └─────┤ Add ├───┘ | ||
// └───┬────┘ | ||
// │ f32 | ||
// │ | ||
// ┌───┴────┐ | ||
// │Reshape │ | ||
// └────────┘ | ||
|
||
class ConvertBoolMathTest : public SubgraphBaseStaticTest { | ||
public: | ||
void SetUp() override { | ||
targetDevice = ov::test::utils::DEVICE_CPU; | ||
|
||
ov::ParameterVector inputParams{std::make_shared<ov::opset10::Parameter>(ov::element::f32, ov::Shape{24, 7}), | ||
std::make_shared<ov::opset10::Parameter>(ov::element::f32, ov::Shape{3, 8, 7})}; | ||
|
||
auto inputConvert = std::make_shared<ov::opset10::Convert>(inputParams.front(), ov::element::boolean); | ||
|
||
auto reshapeConst = ov::opset10::Constant::create<int32_t>(ov::element::i32, ov::Shape{3}, {3, 8, 7}); | ||
auto reshape = std::make_shared<ov::opset10::Reshape>(inputConvert, reshapeConst, false); | ||
|
||
auto secondConvert = std::make_shared<ov::opset10::Convert>(reshape, ov::element::f32); | ||
auto add = std::make_shared<ov::opset10::Add>(secondConvert, inputParams.back()); | ||
|
||
ov::ResultVector results{std::make_shared<ov::opset10::Result>(add)}; | ||
function = std::make_shared<ov::Model>(results, inputParams, "ConvertBoolMath"); | ||
} | ||
}; | ||
|
||
TEST_F(ConvertBoolMathTest, smoke_CompareWithRefs) { | ||
run(); | ||
} | ||
|
||
} // namespace test | ||
} // namespace ov |