Skip to content

Commit

Permalink
[core]Coverity fix of dead code in (pr)elu reference implementation (#…
Browse files Browse the repository at this point in the history
…28407)

### Details:
- Fix Coverity issue in reference implementation of `ELU`, `PReLU`
operators of dead code for unsigned types.

### Tickets:
 - N/A

Signed-off-by: Raasz, Pawel <[email protected]>
  • Loading branch information
praasz authored Jan 13, 2025
1 parent 7391a66 commit e166f9f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 10 additions & 6 deletions src/core/reference/include/openvino/reference/elu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::reference
12 changes: 7 additions & 5 deletions src/core/reference/include/openvino/reference/prelu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

0 comments on commit e166f9f

Please sign in to comment.