From 42d2a0d1e71a1fe635f8422d99b50b329d8bc194 Mon Sep 17 00:00:00 2001 From: eshoguli Date: Sun, 22 Oct 2023 13:37:10 +0100 Subject: [PATCH] refactoring --- src/plugins/intel_cpu/src/nodes/eltwise.cpp | 50 ++++++++++--------- .../instances/common/eltwise.cpp | 35 ++++++------- 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/eltwise.cpp b/src/plugins/intel_cpu/src/nodes/eltwise.cpp index 48d20cf0a2a206..999fd105945446 100644 --- a/src/plugins/intel_cpu/src/nodes/eltwise.cpp +++ b/src/plugins/intel_cpu/src/nodes/eltwise.cpp @@ -17,6 +17,7 @@ #include "ie_ngraph_utils.hpp" #include #include +#include #include #include @@ -36,7 +37,10 @@ #include "ngraph/ngraph.hpp" #include -#include +#include +#include +#include +#include #include "transformations/cpu_opset/common/op/power_static.hpp" #include "transformations/cpu_opset/common/op/leaky_relu.hpp" #include "transformations/cpu_opset/common/op/swish_cpu.hpp" @@ -718,7 +722,7 @@ struct jit_uni_eltwise_generic : public jit_uni_eltwise_kernel, public jit_gener uni_vpmovzxbd(vmm_src, op); break; default: - IE_THROW() << "unknown src_prc: " << src_prc; + OPENVINO_THROW("unknown src_prc: " + src_prc); } switch (dst_prc) { @@ -731,7 +735,7 @@ struct jit_uni_eltwise_generic : public jit_uni_eltwise_kernel, public jit_gener uni_vcvtps2dq(vmm_src, vmm_src); break; default: - IE_THROW() << "unknown dst_prc: " << dst_prc; + OPENVINO_THROW("unknown dst_prc: " + dst_prc); } } } @@ -766,7 +770,7 @@ struct jit_uni_eltwise_generic : public jit_uni_eltwise_kernel, public jit_gener uni_vmovq(xmm_src, reg_tmp_64); break; default: - IE_THROW() << "unknown src_prc: " << src_prc; + OPENVINO_THROW("unknown src_prc: " + src_prc); } switch (dst_prc) { @@ -779,7 +783,7 @@ struct jit_uni_eltwise_generic : public jit_uni_eltwise_kernel, public jit_gener uni_vcvtps2dq(xmm_src, xmm_src); break; default: - IE_THROW() << "unknown dst_prc: " << dst_prc; + OPENVINO_THROW("unknown dst_prc: " + dst_prc); } } @@ -797,7 +801,7 @@ struct jit_uni_eltwise_generic : public jit_uni_eltwise_kernel, public jit_gener uni_vcvtdq2ps(vmm_dst, vmm_dst); break; default: - IE_THROW() << "unknown src_prc: " << src_prc; + OPENVINO_THROW("unknown src_prc: " + src_prc); } switch (dst_prc) { @@ -869,7 +873,7 @@ struct jit_uni_eltwise_generic : public jit_uni_eltwise_kernel, public jit_gener } break; default: - IE_THROW() << "unknown dst_prc: " << dst_prc; + OPENVINO_THROW("unknown dst_prc: " + dst_prc); } } @@ -884,7 +888,7 @@ struct jit_uni_eltwise_generic : public jit_uni_eltwise_kernel, public jit_gener uni_vcvtdq2ps(xmm_dst, xmm_dst); break; default: - IE_THROW() << "unknown src_prc: " << src_prc; + OPENVINO_THROW("unknown src_prc: " + src_prc); } switch (dst_prc) { @@ -924,7 +928,7 @@ struct jit_uni_eltwise_generic : public jit_uni_eltwise_kernel, public jit_gener mov(op, reg_tmp_8); break; default: - IE_THROW() << "unknown dst_prc: " << dst_prc; + OPENVINO_THROW("unknown dst_prc: " + dst_prc); } } }; @@ -1162,7 +1166,7 @@ const std::map& Eltwise::g node.algorithm = Algorithm::EltwiseLog; }}, {op::v13::BitwiseAnd::get_type_info_static(), [](const std::shared_ptr& op, Eltwise& node) { - node.algorithm = Algorithm::EltwiseBitwiseAnd; + node.algorithm = Algorithm::EltwiseBitwiseAnd; }}, {op::v13::BitwiseNot::get_type_info_static(), [](const std::shared_ptr& op, Eltwise& node) { node.algorithm = Algorithm::EltwiseBitwiseNot; @@ -2011,17 +2015,17 @@ size_t Eltwise::getOpInputsNum() const { case Algorithm::EltwiseLogicalAnd: case Algorithm::EltwiseLogicalOr: case Algorithm::EltwiseLogicalXor: - case Algorithm::EltwisePrelu: - return 2; - case Algorithm::EltwiseMulAdd: - case Algorithm::EltwiseSelect: - return 3; case Algorithm::EltwiseBitwiseAnd: case Algorithm::EltwiseBitwiseOr: case Algorithm::EltwiseBitwiseXor: return 2; case Algorithm::EltwiseBitwiseNot: return 1; + case Algorithm::EltwisePrelu: + return 2; + case Algorithm::EltwiseMulAdd: + case Algorithm::EltwiseSelect: + return 3; default: IE_THROW() << "Unsupported operation for Eltwise node with name `" << getName() << "`."; } } @@ -2047,10 +2051,12 @@ void Eltwise::getSupportedDescriptors() { void Eltwise::initSupportedPrimitiveDescriptors() { const auto isBitwise = [](const Algorithm& algorithm) { - return (algorithm == Algorithm::EltwiseBitwiseAnd) || - (algorithm == Algorithm::EltwiseBitwiseNot) || - (algorithm == Algorithm::EltwiseBitwiseOr) || - (algorithm == Algorithm::EltwiseBitwiseXor); + return one_of( + algorithm, + Algorithm::EltwiseBitwiseAnd, + Algorithm::EltwiseBitwiseNot, + Algorithm::EltwiseBitwiseOr, + Algorithm::EltwiseBitwiseXor); }; std::vector supportedPrecisions = isBitwise(algorithm) ? @@ -2077,11 +2083,7 @@ void Eltwise::initSupportedPrimitiveDescriptors() { // if dim rank is greater than the maximum possible, we should use the reference execution bool canUseOptimizedImpl = mayiuse(x64::sse41) && getInputShapeAtPort(0).getRank() <= MAX_ELTWISE_DIM_RANK; // TODO: Add EltwiseLog algorithm support for JIT implementation - canUseOptimizedImpl &= !(one_of(getAlgorithm(), Algorithm::EltwiseLog) || - one_of(getAlgorithm(), Algorithm::EltwiseBitwiseAnd) || - one_of(getAlgorithm(), Algorithm::EltwiseBitwiseNot) || - one_of(getAlgorithm(), Algorithm::EltwiseBitwiseOr) || - one_of(getAlgorithm(), Algorithm::EltwiseBitwiseXor)); + canUseOptimizedImpl &= !(one_of(getAlgorithm(), Algorithm::EltwiseLog) || isBitwise(getAlgorithm())); bool canUseOptimizedShapeAgnosticImpl = isDynamicNode() && canUseOptimizedImpl; diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/eltwise.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/eltwise.cpp index 8fb6787504cc73..a152027d1d376b 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/eltwise.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/eltwise.cpp @@ -219,15 +219,21 @@ const auto params_5D_dyn_param = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_MemOrder_dyn_param, EltwiseLayerCPUTest, params_5D_dyn_param, EltwiseLayerCPUTest::getTestCaseName); -static const std::vector> bitwise_in_shapes_4D = { - {{1, 3, 4, 4}, {1, 3, 4, 4}}, - {{1, 3, 4, 4}, {1, 3, 1, 1}}, - {{1, 1, 1, 1}, {1, 1, 1, 1}} +static const std::vector bitwise_in_shapes_4D = { + { + {1, -1, -1, -1}, + { + {1, 3, 4, 4}, + {1, 3, 1, 1}, + {1, 1, 1, 1} + } + }, + {{1, 3, 4, 4}, {{1, 3, 4, 4}}} }; const auto params_4D_bitwise = ::testing::Combine( ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(bitwise_in_shapes_4D)), + ::testing::Values(bitwise_in_shapes_4D), ::testing::ValuesIn({ ngraph::helpers::EltwiseTypes::BITWISE_AND, ngraph::helpers::EltwiseTypes::BITWISE_OR, @@ -248,7 +254,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_Bitwise, EltwiseLayerCPUTest, const auto params_4D_bitwise_i16 = ::testing::Combine( ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(bitwise_in_shapes_4D)), + ::testing::Values(bitwise_in_shapes_4D), ::testing::ValuesIn({ ngraph::helpers::EltwiseTypes::BITWISE_AND, ngraph::helpers::EltwiseTypes::BITWISE_OR, @@ -268,17 +274,10 @@ const auto params_4D_bitwise_i16 = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_Bitwise_i16, EltwiseLayerCPUTest, params_4D_bitwise_i16, EltwiseLayerCPUTest::getTestCaseName); -static const std::vector> bitwise_in_shapes_4D_NOT = { - {{1, 3, 4, 4}}, - {{1, 1, 1, 1}} -}; - const auto params_4D_bitwise_NOT = ::testing::Combine( ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(bitwise_in_shapes_4D_NOT)), - ::testing::ValuesIn({ - ngraph::helpers::EltwiseTypes::BITWISE_NOT - }), + ::testing::Values(bitwise_in_shapes_4D), + ::testing::ValuesIn({ ngraph::helpers::EltwiseTypes::BITWISE_NOT }), ::testing::ValuesIn({ ngraph::helpers::InputLayerType::NONE }), ::testing::ValuesIn({ ov::test::utils::OpType::VECTOR }), ::testing::ValuesIn({ ov::element::Type_t::i8, ov::element::Type_t::u8, ov::element::Type_t::i32 }), @@ -294,10 +293,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_Bitwise_NOT, EltwiseLayerCPUTe const auto params_4D_bitwise_NOT_i16 = ::testing::Combine( ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(bitwise_in_shapes_4D_NOT)), - ::testing::ValuesIn({ - ngraph::helpers::EltwiseTypes::BITWISE_NOT - }), + ::testing::Values(bitwise_in_shapes_4D), + ::testing::ValuesIn({ ngraph::helpers::EltwiseTypes::BITWISE_NOT }), ::testing::ValuesIn({ ngraph::helpers::InputLayerType::NONE }), ::testing::ValuesIn({ ov::test::utils::OpType::VECTOR }), ::testing::ValuesIn({ ov::element::Type_t::i16, ov::element::Type_t::u16 }),