OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[core]Coverity fix of dead code in (pr)elu reference implementation (#28407)
Pawel Raasze166f9fb3a0f
diff --git a/src/core/reference/include/openvino/reference/elu.hpp b/src/core/reference/include/openvino/reference/elu.hppindex fc49a7a4a5a..30d0eb3e44e 100644--- a/src/core/reference/include/openvino/reference/elu.hpp+++ b/src/core/reference/include/openvino/reference/elu.hpp@@ -7,13 +7,17 @@#include <cmath>#include <cstddef>-namespace ov {-namespace reference {+#include "openvino/reference/copy.hpp"++namespace ov::reference {template <typename T>void elu(const T* arg, T* out, size_t count, double alpha) {- for (size_t i = 0; i < count; i++) {- out[i] = arg[i] < T(0) ? T(alpha * (std::exp(arg[i]) - 1.0)) : arg[i];+ if constexpr (std::is_unsigned_v<T>) {+ copy(arg, out, count);+ } else {+ for (size_t i = 0; i < count; i++) {+ out[i] = arg[i] < T(0) ? T(alpha * (std::exp(arg[i]) - 1.0)) : arg[i];+ }}}-} // namespace reference-} // namespace ov+} // namespace ov::referencediff --git a/src/core/reference/include/openvino/reference/prelu.hpp b/src/core/reference/include/openvino/reference/prelu.hppindex 7dd569debde..6dff68bc5cc 100644--- a/src/core/reference/include/openvino/reference/prelu.hpp+++ b/src/core/reference/include/openvino/reference/prelu.hpp@@ -11,13 +11,16 @@#include "openvino/op/util/attr_types.hpp"#include "openvino/reference/autobroadcast_binop.hpp"-namespace ov {-namespace reference {+namespace ov::reference {namespace func {// Usage of custom function instead of lambda, gives smaller binary size.template <class T>T prelu(const T x, const T y) {- return x < T(0) ? x * y : x;+ if constexpr (std::is_unsigned_v<T>) {+ return x;+ } else {+ return x < T(0) ? x * y : x;+ }}} // namespace func@@ -32,5 +35,4 @@ void prelu(const T* arg, const T* slope, T* out, const Shape& arg_shape, const S}autobroadcast_binop(arg, slope, out, arg_shape, slope_shape_tmp, op::AutoBroadcastType::NUMPY, func::prelu<T>);}-} // namespace reference-} // namespace ov+} // namespace ov::reference