Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
eshoguli committed Oct 22, 2023
1 parent 80fad20 commit 42d2a0d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
50 changes: 26 additions & 24 deletions src/plugins/intel_cpu/src/nodes/eltwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ie_ngraph_utils.hpp"
#include <cpu/x64/injectors/jit_uni_quantization_injector.hpp>
#include <cpu/ref_eltwise.hpp>
#include <openvino/core/except.hpp>

#include <onednn/dnnl.h>
#include <dnnl_extension_utils.h>
Expand All @@ -36,7 +37,10 @@

#include "ngraph/ngraph.hpp"
#include <ngraph/opsets/opset1.hpp>
#include <openvino/opsets/opset13.hpp>
#include <openvino/op/bitwise_and.hpp>
#include <openvino/op/bitwise_not.hpp>
#include <openvino/op/bitwise_or.hpp>
#include <openvino/op/bitwise_xor.hpp>
#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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
};
Expand Down Expand Up @@ -1162,7 +1166,7 @@ const std::map<const ngraph::DiscreteTypeInfo, Eltwise::Initializer>& Eltwise::g
node.algorithm = Algorithm::EltwiseLog;
}},
{op::v13::BitwiseAnd::get_type_info_static(), [](const std::shared_ptr<ngraph::Node>& op, Eltwise& node) {
node.algorithm = Algorithm::EltwiseBitwiseAnd;
node.algorithm = Algorithm::EltwiseBitwiseAnd;
}},
{op::v13::BitwiseNot::get_type_info_static(), [](const std::shared_ptr<ngraph::Node>& op, Eltwise& node) {
node.algorithm = Algorithm::EltwiseBitwiseNot;
Expand Down Expand Up @@ -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() << "`.";
}
}
Expand All @@ -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<Precision> supportedPrecisions = isBitwise(algorithm) ?
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<ov::Shape>> 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<InputShape> 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,
Expand All @@ -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,
Expand All @@ -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<std::vector<ov::Shape>> 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 }),
Expand All @@ -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 }),
Expand Down

0 comments on commit 42d2a0d

Please sign in to comment.