Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

Fix the crash issue of PRelu reference implementation on rank-0 (scalar) data input (#36841)

Wei Wang6f0ed6d4daa1
diff --git a/src/core/reference/include/openvino/reference/prelu.hpp b/src/core/reference/include/openvino/reference/prelu.hpp
index 4934cce26b2..4101cbd4bf1 100644
--- a/src/core/reference/include/openvino/reference/prelu.hpp
+++ b/src/core/reference/include/openvino/reference/prelu.hpp
@@ -28,7 +28,7 @@ template <typename T>
void prelu(const T* arg, const T* slope, T* out, const Shape& arg_shape, const Shape& slope_shape) {
Shape slope_shape_tmp = slope_shape;
const auto channel_dim_idx = arg_shape.size() > 1 ? 1 : 0;
- if (slope_shape.size() == 1 && arg_shape[channel_dim_idx] == slope_shape[0]) {
+ if (!arg_shape.empty() && slope_shape.size() == 1 && arg_shape[channel_dim_idx] == slope_shape[0]) {
Shape channel_slope_shape(arg_shape.size(), 1);
channel_slope_shape[channel_dim_idx] = slope_shape[0];
std::swap(slope_shape_tmp, channel_slope_shape);
diff --git a/src/plugins/template/tests/functional/op_reference/prelu.cpp b/src/plugins/template/tests/functional/op_reference/prelu.cpp
index a22e4f5c7e2..97e1fe6c548 100644
--- a/src/plugins/template/tests/functional/op_reference/prelu.cpp
+++ b/src/plugins/template/tests/functional/op_reference/prelu.cpp
@@ -84,6 +84,13 @@ std::vector<PreluParams> generatePreluFloatParams() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<PreluParams> preluParams{
+ PreluParams(ov::Shape{},
+ IN_ET,
+ std::vector<T>{-4},
+ std::vector<T>{-2},
+ ov::Shape{1},
+ std::vector<T>{0.5},
+ "scalar_data"),
PreluParams(ov::Shape{6},
IN_ET,
std::vector<T>{1, 2, -3, -4, 5, 6},