From ce0d9d887a997311074501ec5f0f3e1bbe9db743 Mon Sep 17 00:00:00 2001 From: eshoguli Date: Sun, 22 Oct 2023 00:23:34 +0200 Subject: [PATCH] refactoring --- src/plugins/intel_cpu/src/nodes/eltwise.cpp | 82 ++++++++------------- 1 file changed, 31 insertions(+), 51 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/eltwise.cpp b/src/plugins/intel_cpu/src/nodes/eltwise.cpp index 9fb7cc5a5da63c..b57accdab1fc09 100644 --- a/src/plugins/intel_cpu/src/nodes/eltwise.cpp +++ b/src/plugins/intel_cpu/src/nodes/eltwise.cpp @@ -1555,26 +1555,6 @@ class EltwiseJitExecutor : public Eltwise::IEltwiseExecutor { static const int optimalTensorRank = 6; }; -namespace { - -template -inline Result bitwise_cast(Current* value) { - assert(sizeof(Current) == sizeof(Result)); - assert((typeid(Current) != typeid(float)) && (typeid(Current) != typeid(dnnl::impl::float16_t))); - assert((typeid(Result) != typeid(float)) && (typeid(Result) != typeid(dnnl::impl::float16_t))); - return *reinterpret_cast(value); -} - -template -inline Result* bitwise_ptr_cast(Current* value) { - assert(sizeof(Current) == sizeof(Result)); - assert((typeid(Current) != typeid(float)) && (typeid(Current) != typeid(dnnl::impl::float16_t))); - assert((typeid(Result) != typeid(float)) && (typeid(Result) != typeid(dnnl::impl::float16_t))); - return reinterpret_cast(value); -} - -} // namespace - /* enabled only for float at float16_t at the moment * can be extended in the future */ template @@ -1686,52 +1666,52 @@ template class EltwiseRefExecutor : public EltwiseRefBaseExecutor { public: - EltwiseRefExecutor(Eltwise::EltwiseData opData, + EltwiseRefExecutor(Eltwise::EltwiseData opData, const VectorDims& outBlkDims, - std::vector inpDims) : EltwiseRefBaseExecutor(opData, outBlkDims, inpDims) { + std::vector inpDims) : EltwiseRefBaseExecutor(opData, outBlkDims, inpDims) { } void exec(const jit_eltwise_call_args_ptrs &args_ptrs, const VectorDims &dims_out) override { - if (_opData.algo == Algorithm::EltwiseLog) { + if (this->_opData.algo == Algorithm::EltwiseLog) { const T* src_ptr_f = reinterpret_cast(args_ptrs.src_ptr[0]); T* dst_ptr_f = reinterpret_cast(args_ptrs.dst_ptr); - parallel_for(_fullWorkAmount, [&](size_t i) { + parallel_for(this->_fullWorkAmount, [&](size_t i) { dst_ptr_f[i] = logf(src_ptr_f[i]); }); return; } - if (_opData.algo == Algorithm::EltwisePowerStatic) { + if (this->_opData.algo == Algorithm::EltwisePowerStatic) { const T* src_ptr_f = reinterpret_cast(args_ptrs.src_ptr[0]); T* dst_ptr_f = reinterpret_cast(args_ptrs.dst_ptr); - if (_opData.alpha == 2) { - parallel_for(_fullWorkAmount, [&](size_t i) { - dst_ptr_f[i] = (_opData.beta * src_ptr_f[i] + _opData.gamma) * - (_opData.beta * src_ptr_f[i] + _opData.gamma); + if (this->_opData.alpha == 2) { + parallel_for(this->_fullWorkAmount, [&](size_t i) { + dst_ptr_f[i] = (this->_opData.beta * src_ptr_f[i] + this->_opData.gamma) * + (this->_opData.beta * src_ptr_f[i] + this->_opData.gamma); }); } else { - parallel_for(_fullWorkAmount, [&](size_t i) { - dst_ptr_f[i] = powf(_opData.beta * src_ptr_f[i] + _opData.gamma, _opData.alpha); + parallel_for(this->_fullWorkAmount, [&](size_t i) { + dst_ptr_f[i] = powf(this->_opData.beta * src_ptr_f[i] + this->_opData.gamma, this->_opData.alpha); }); } return; } - if (_opData.algo == Algorithm::EltwisePowerDynamic) { + if (this->_opData.algo == Algorithm::EltwisePowerDynamic) { const T* src_ptr_f = reinterpret_cast(args_ptrs.src_ptr[0]); const T* src_ptr_f_pow = reinterpret_cast(args_ptrs.src_ptr[1]); T* dst_ptr_f = reinterpret_cast(args_ptrs.dst_ptr); uint32_t count_of_power_values = 1; - for (unsigned long i : _inpDims[1]) { + for (unsigned long i : this->_inpDims[1]) { count_of_power_values *= i; } if (count_of_power_values == 1) { if (src_ptr_f_pow[0] != 2) { - parallel_for(_fullWorkAmount, [&](size_t i) { + parallel_for(this->_fullWorkAmount, [&](size_t i) { dst_ptr_f[i] = powf(src_ptr_f[i], src_ptr_f_pow[0]); }); } else { - parallel_for(_fullWorkAmount, [&](size_t i) { + parallel_for(this->_fullWorkAmount, [&](size_t i) { dst_ptr_f[i] = src_ptr_f[i] * src_ptr_f[i]; }); } @@ -1740,23 +1720,23 @@ class EltwiseRefExecutor : public EltwiseRefBaseExecutor { } std::shared_ptr ref_eltwise_injector = nullptr; - if (_opData.onednnAlgorithm != dnnl::algorithm::undef) { + if (this->_opData.onednnAlgorithm != dnnl::algorithm::undef) { ref_eltwise_injector = std::make_shared( - static_cast(_opData.onednnAlgorithm), _opData.alpha, _opData.beta, 1.f); + static_cast(this->_opData.onednnAlgorithm), this->_opData.alpha, this->_opData.beta, 1.f); } parallel_nt(0, [&](const int ithr, const int nthr) { size_t start = 0, end = 0; - splitter(_fullWorkAmount, nthr, ithr, start, end); + splitter(this->_fullWorkAmount, nthr, ithr, start, end); std::vector counters(dims_out.size(), 0); for (size_t iwork = start; iwork < end; ++iwork) { - std::vector src_f(_inputNum); + std::vector src_f(this->_inputNum); T* dst_ptr_f; - init_ptr(args_ptrs, dims_out, counters, iwork, src_f, dst_ptr_f); + this->init_ptr(args_ptrs, dims_out, counters, iwork, src_f, dst_ptr_f); - switch (_opData.algo) { + switch (this->_opData.algo) { case Algorithm::EltwiseRelu: case Algorithm::EltwiseGeluErf: case Algorithm::EltwiseGeluTanh: @@ -1803,8 +1783,8 @@ class EltwiseRefExecutor : public EltwiseRefBaseExecutor { // @todo implement proper isinfinite for non-float precisions case Algorithm::EltwiseIsFinite: *dst_ptr_f = std::isfinite(static_cast(src_f[0])); break; case Algorithm::EltwiseIsInf: - *dst_ptr_f = (_opData.alpha && (src_f[0] == -std::numeric_limits::infinity())) || - (_opData.beta && (src_f[0] == std::numeric_limits::infinity())); + *dst_ptr_f = (this->_opData.alpha && (src_f[0] == -std::numeric_limits::infinity())) || + (this->_opData.beta && (src_f[0] == std::numeric_limits::infinity())); break; case Algorithm::EltwiseIsNaN: { if (sizeof(T) == 4) { @@ -1832,30 +1812,30 @@ template class BitwiseRefExecutor : public EltwiseRefBaseExecutor { public: - BitwiseRefExecutor(Eltwise::EltwiseData opData, + BitwiseRefExecutor(Eltwise::EltwiseData opData, const VectorDims& outBlkDims, - std::vector inpDims) : EltwiseRefBaseExecutor(opData, outBlkDims, inpDims) { + std::vector inpDims) : EltwiseRefBaseExecutor(opData, outBlkDims, inpDims) { } void exec(const jit_eltwise_call_args_ptrs &args_ptrs, const VectorDims &dims_out) override { std::shared_ptr ref_eltwise_injector = nullptr; - if (_opData.onednnAlgorithm != dnnl::algorithm::undef) { + if (this->_opData.onednnAlgorithm != dnnl::algorithm::undef) { ref_eltwise_injector = std::make_shared( - static_cast(_opData.onednnAlgorithm), _opData.alpha, _opData.beta, 1.f); + static_cast(this->_opData.onednnAlgorithm), this->_opData.alpha, this->_opData.beta, 1.f); } parallel_nt(0, [&](const int ithr, const int nthr) { size_t start = 0, end = 0; - splitter(_fullWorkAmount, nthr, ithr, start, end); + splitter(this->_fullWorkAmount, nthr, ithr, start, end); std::vector counters(dims_out.size(), 0); for (size_t iwork = start; iwork < end; ++iwork) { - std::vector src_f(_inputNum); + std::vector src_f(this->_inputNum); T* dst_ptr_f; - init_ptr(args_ptrs, dims_out, counters, iwork, src_f, dst_ptr_f); + this->init_ptr(args_ptrs, dims_out, counters, iwork, src_f, dst_ptr_f); - switch (_opData.algo) { + switch (this->_opData.algo) { case Algorithm::EltwiseBitwiseAnd: { *dst_ptr_f = src_f[0] & src_f[1]; break;