Skip to content

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

[GPU] Fix PReLU NaN propagation (#37929)

Abhinave7b7c07f6c0e
diff --git a/src/plugins/intel_gpu/src/graph/common_utils/jit_term.hpp b/src/plugins/intel_gpu/src/graph/common_utils/jit_term.hpp
index 1fdd8255e70..6f75e001419 100644
--- a/src/plugins/intel_gpu/src/graph/common_utils/jit_term.hpp
+++ b/src/plugins/intel_gpu/src/graph/common_utils/jit_term.hpp
@@ -248,6 +248,9 @@ inline JitTerm ternary(const JitTerm& condition, const JitTerm& true_expr, const
inline JitTerm isinf(const JitTerm& arg) {
return JitTerm{"isinf(" + arg.str() + ")"};
}
+inline JitTerm isnan(const JitTerm& arg) {
+ return JitTerm{"isnan(" + arg.str() + ")"};
+}
inline JitTerm exp(const JitTerm& arg) {
return JitTerm{"exp(" + arg.str() + ")"};
}
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/utils/fused_ops_jitter.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/utils/fused_ops_jitter.cpp
index 0161ccbe733..29bf33758b4 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/utils/fused_ops_jitter.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/utils/fused_ops_jitter.cpp
@@ -545,10 +545,18 @@ JitConstants FusedOpsCodeGenerator::make_op_jit_constants(const FusedOpsConfigur
}
if (dep_data.size() == 2) {
- if (dep_data[1].m_element_type != out_type) {
- nl_m = convert_to_output_type(get_input_var_name(0), vec_size);
+ // The slope must be referenced the same way make_load_jit_constants()
+ // names it (get_input_var_name(m_idx), keyed by the graph input index),
+ // not by its position in dep_data - otherwise the generated kernel uses
+ // an undeclared variable and fails with CL_BUILD_PROGRAM_FAILURE.
+ const auto& slope_dep = dep_data[1];
+ auto slope_name = (slope_dep.m_type == FusedInputType::ORIGINAL) ? in_var
+ : (slope_dep.m_type == FusedInputType::INTERNAL) ? get_output_var_name(in_var, slope_dep.m_idx)
+ : get_input_var_name(slope_dep.m_idx, is_shuffled, shuffle_var);
+ if (slope_dep.m_element_type != out_type) {
+ nl_m = convert_to_output_type(slope_name, vec_size);
} else {
- nl_m = get_input_var_name(0);
+ nl_m = slope_name;
}
} else {
nl_m = broadcast(nl_m, out_type, vec_size);
@@ -840,7 +848,14 @@ JitConstants make_activation_jit_constants(const std::string& suffix,
break;
case activation_func::relu_negative_slope: {
const JitTerm slope = convert_to_type("m"_jit, calc_dt);
- jit.add(make_jit_constant(macro_def, ternary(isinf(slope), ternary(input.ge(zero), input, neg(slope)), max(input, zero) + (slope * min(input, zero)))));
+ // OpenCL max/min may drop the NaN operand, so select on the input
+ // explicitly to keep NaN propagating instead of turning into zero.
+ // A ternary is used for the NaN branch instead of select(): select()
+ // requires the condition to be a signed integer of the same width as
+ // the operands (short for half), while isnan() returns int, so f16
+ // kernels do not compile with select().
+ const JitTerm prelu_body = ternary(isinf(slope), ternary(input.ge(zero), input, neg(slope)), max(input, zero) + (slope * min(input, zero)));
+ jit.add(make_jit_constant(macro_def, ternary(isnan(input), input, prelu_body)));
break;
}
case activation_func::elu: {
diff --git a/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp b/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp
index f15e17083c6..4b88f59a41f 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp
@@ -88,6 +88,11 @@ JitTerm isinf(const JitTerm& arg) {
return jit_term;
}
+JitTerm isnan(const JitTerm& arg) {
+ JitTerm jit_term{"(isnan(" + arg.str() + "))"};
+ return jit_term;
+}
+
JitTerm exp(const JitTerm& arg) {
JitTerm jit_term{"(exp(" + arg.str() + "))"};
return jit_term;
@@ -1176,12 +1181,17 @@ JitConstants MakeActivationJitConstants(ActivationFunction activation_function,
break;
case ActivationFunction::RELU_NEGATIVE_SLOPE: {
const JitTerm slope = disable_type_conversion ? "m"_jit : to_type("m"_jit);
- jitConstants.AddConstant(MakeJitConstant(
- macro_def,
- ternary(isinf(slope),
- ternary(input.ge(zero), input, neg(slope)),
- max_func(input, zero) + (slope * min_func(input, zero)))
- .str()));
+ // OpenCL fmax/fmin return the non-NaN operand, so the naive
+ // fmax(x, 0) + slope * fmin(x, 0) form silently turns a NaN input
+ // into zero. Select on the input explicitly to keep NaN propagating.
+ // A ternary is used for the NaN branch instead of select(): select()
+ // requires the condition to be a signed integer of the same width as
+ // the operands (short for half), while isnan() returns int, so f16
+ // kernels do not compile with select().
+ const JitTerm prelu_body = ternary(isinf(slope),
+ ternary(input.ge(zero), input, neg(slope)),
+ max_func(input, zero) + (slope * min_func(input, zero)));
+ jitConstants.AddConstant(MakeJitConstant(macro_def, ternary(isnan(input), input, prelu_body).str()));
break;
}
case ActivationFunction::ELU: {
diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/prelu_nan.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/prelu_nan.cpp
new file mode 100644
index 00000000000..91354e67b38
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/prelu_nan.cpp
@@ -0,0 +1,139 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <algorithm>
+#include <cmath>
+#include <limits>
+#include <map>
+#include <vector>
+
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "openvino/core/type/float16.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/prelu.hpp"
+#include "openvino/op/result.hpp"
+#include "shared_test_classes/base/ov_subgraph.hpp"
+
+namespace {
+
+using PReluNaNPropagationParams = std::tuple<ov::Shape, // input data shape
+ ov::Shape, // slope shape
+ ov::element::Type>; // input precision
+
+// PReLU must propagate NaN from the input to the output. The GPU kernel
+// returned the finite bound for a NaN input instead (ticket 37731).
+class PReluNaNPropagationTest : public testing::WithParamInterface<PReluNaNPropagationParams>, virtual public ov::test::SubgraphBaseStaticTest {
+public:
+ static std::string getTestCaseName(const testing::TestParamInfo<PReluNaNPropagationParams>& obj) {
+ const auto& [data_shape, slope_shape, precision] = obj.param;
+ std::ostringstream result;
+ result << "data_shape=" << ov::test::utils::vec2str(data_shape) << "_";
+ result << "slope_shape=" << ov::test::utils::vec2str(slope_shape) << "_";
+ result << "precision=" << precision.get_type_name();
+ return result.str();
+ }
+
+protected:
+ std::shared_ptr<ov::Model> init_subgraph(const ov::Shape& data_shape, const ov::Shape& slope_shape, const ov::element::Type precision) {
+ auto data = std::make_shared<ov::op::v0::Parameter>(precision, data_shape);
+ data->set_friendly_name("data");
+ std::vector<float> slope_values(ov::shape_size(slope_shape), 0.5f);
+ auto slope = std::make_shared<ov::op::v0::Constant>(precision, slope_shape, slope_values);
+ auto prelu = std::make_shared<ov::op::v0::PRelu>(data, slope);
+ prelu->set_friendly_name("prelu");
+ auto result = std::make_shared<ov::op::v0::Result>(prelu);
+ return std::make_shared<ov::Model>(result, ov::ParameterVector{data}, "PReluNaNPropagation");
+ }
+
+ void SetUp() override {
+ targetDevice = ov::test::utils::DEVICE_GPU;
+
+ const auto& [data_shape, slope_shape, precision] = GetParam();
+
+ inType = outType = precision;
+ function = init_subgraph(data_shape, slope_shape, precision);
+ }
+
+ void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {
+ inputs.clear();
+ const auto& funcInputs = function->inputs();
+ for (size_t i = 0; i < funcInputs.size(); ++i) {
+ const auto& funcInput = funcInputs[i];
+ const auto& shape = targetInputStaticShapes[i];
+ auto tensor = ov::Tensor(funcInput.get_element_type(), shape);
+ const size_t size = tensor.get_size();
+ // Negative, positive and NaN values exercise every PReLU branch.
+ std::vector<float> values;
+ values.reserve(size);
+ for (size_t j = 0; j < size; ++j) {
+ if (j % 3 == 0) {
+ values.push_back(-std::sqrt(static_cast<float>(j + 1)));
+ } else if (j % 3 == 1) {
+ values.push_back(std::sqrt(static_cast<float>(j + 1)));
+ } else {
+ values.push_back(std::numeric_limits<float>::quiet_NaN());
+ }
+ }
+ if (funcInput.get_element_type() == ov::element::f32) {
+ std::copy(values.begin(), values.end(), tensor.data<float>());
+ } else if (funcInput.get_element_type() == ov::element::f16) {
+ for (size_t j = 0; j < size; ++j) {
+ tensor.data<ov::float16>()[j] = ov::float16(values[j]);
+ }
+ } else {
+ OPENVINO_THROW("Unsupported precision: ", funcInput.get_element_type());
+ }
+ inputs.insert({funcInput.get_node_shared_ptr(), tensor});
+ }
+ }
+
+ // The default comparator may not match NaN against NaN, so compare here:
+ // NaN must stay NaN, everything else must match the reference value.
+ void compare(const std::vector<ov::Tensor>& expected, const std::vector<ov::Tensor>& actual) override {
+ ASSERT_EQ(expected.size(), actual.size());
+ for (size_t j = 0; j < expected.size(); ++j) {
+ ASSERT_EQ(expected[j].get_element_type(), actual[j].get_element_type());
+ const size_t size = expected[j].get_size();
+ const float tolerance = expected[j].get_element_type() == ov::element::f16 ? 2e-3f : 1e-6f;
+ for (size_t i = 0; i < size; ++i) {
+ const float exp_value = get_value(expected[j], i);
+ const float act_value = get_value(actual[j], i);
+ if (std::isnan(exp_value)) {
+ ASSERT_TRUE(std::isnan(act_value)) << "at index " << i << ": expected NaN, got " << act_value;
+ } else {
+ ASSERT_NEAR(exp_value, act_value, tolerance) << "at index " << i;
+ }
+ }
+ }
+ }
+
+private:
+ static float get_value(const ov::Tensor& tensor, size_t index) {
+ if (tensor.get_element_type() == ov::element::f32) {
+ return tensor.data<const float>()[index];
+ }
+ return static_cast<float>(tensor.data<const ov::float16>()[index]);
+ }
+};
+
+TEST_P(PReluNaNPropagationTest, NansArePropagated) {
+ run();
+}
+
+const std::vector<PReluNaNPropagationParams> preluNaNParams = {
+ {{1, 8}, {8}, ov::element::f32},
+ {{2, 3, 4}, {4}, ov::element::f32},
+ {{1, 4, 5, 6}, {4}, ov::element::f32},
+ {{6}, {1}, ov::element::f32},
+ {{1, 8}, {8}, ov::element::f16},
+ {{2, 3, 4}, {4}, ov::element::f16},
+ // Single-value slope goes through the separate CreateUnaryEltwiseOp lowering
+ // path, while the cases above use an activation primitive with a slope
+ // dependency - cover both for f16 as well.
+ {{6}, {1}, ov::element::f16},
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_PRelu_NaN_Propagation, PReluNaNPropagationTest, ::testing::ValuesIn(preluNaNParams), PReluNaNPropagationTest::getTestCaseName);
+} // namespace
diff --git a/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp
index 764d58e9ff6..c4df31a35a3 100644
--- a/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp
@@ -15,6 +15,7 @@
#include <intel_gpu/primitives/concatenation.hpp>
#include <cmath>
+#include <limits>
using namespace cldnn;
using namespace ::tests;
@@ -1153,6 +1154,137 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_prelu_eltwise, ::testing::Values
convolution_test_params{ CASE_CONV_FP16_4, 2, 2, 4 },
}));
+// Fused PReLU must propagate NaN the same way the standalone activation kernel
+// does: a NaN reaching the activation input (carried here through the
+// convolution) must reach the output unchanged whether the PReLU is fused into
+// the conv kernel or executed standalone.
+class conv_prelu_nan : public ConvFusingTest {};
+TEST_P(conv_prelu_nan, basic) {
+ auto p = GetParam();
+ create_topologies(
+ input_layout("input", get_input_layout(p)),
+ // Small weights and bias keep the finite outputs well inside the f16 range,
+ // so only the injected NaN values show up as special values in the output.
+ data("weights", get_mem(get_weights_layout(p), -1, 1)),
+ data("bias", get_mem(get_per_channel_layout(p), 0.25f)),
+ data("slope_data", get_mem(get_per_channel_layout(p), 0.5f)),
+ convolution("conv_prim", input_info("input"), "weights", "bias", p.groups, p.stride, p.dilation, p.pad, p.pad, format::is_grouped(get_weights_layout(p).format)),
+ activation("activation", input_info("conv_prim"), "slope_data", activation_func::relu_negative_slope),
+ reorder("reorder_bfyx", input_info("activation"), p.default_format, data_types::f32)
+ );
+
+ // Force the OCL conv implementation so the PReLU is fused into the CL kernel
+ // and the fused activation code generation is exercised, not a oneDNN post-op.
+ // Same forcing as conv_fp32_prelu_eltwise, the green fused-PReLU test on this
+ // runner: b_fs_yx_fsv16 + ocl is the configuration where conv fusion actually
+ // happens on the iGPU device.
+ ov::intel_gpu::ImplementationDesc conv_impl = { format::b_fs_yx_fsv16, "", impl_types::ocl };
+ cfg_fused.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ { "conv_prim", conv_impl } }));
+
+ tolerance = default_tolerance(p.data_type);
+
+ // Fill by physical linear index with the column mapping derived from the
+ // format's blocked feature: in b_fs_yx_fsv16 the feature block is the
+ // innermost axis, so x has pitch 16 and x == 0 is (i / 16) % x_size == 0;
+ // for unblocked layouts x has pitch 1. With a 3x3 kernel and no padding the
+ // leftmost output column carries NaN while the others stay finite, so both
+ // NaN and finite values reach the fused activation. Both cases use 16
+ // features, so there is no padding and every physical slot is logical.
+ auto in_layout = get_input_layout(p);
+ auto input_prim = engine.allocate_memory(in_layout);
+ const size_t phys_size = in_layout.get_linear_size();
+ const int64_t x_size = in_layout.get_tensor().spatial[0];
+ size_t x_pitch = 1;
+ for (const auto& block : format::logic_block_sizes(in_layout.get_format())) {
+ if (block.first == 1) {
+ x_pitch = static_cast<size_t>(block.second);
+ }
+ }
+ auto is_nan_slot = [&](size_t i) { return (static_cast<int64_t>(i / x_pitch)) % x_size == 0; };
+ if (in_layout.data_type == data_types::f16) {
+ std::vector<ov::float16> input_vals;
+ input_vals.reserve(phys_size);
+ for (size_t i = 0; i < phys_size; ++i) {
+ const float v = is_nan_slot(i) ? std::numeric_limits<float>::quiet_NaN()
+ : -1.0f - static_cast<float>(i % 7);
+ input_vals.push_back(ov::float16(v));
+ }
+ set_values(input_prim, input_vals);
+ } else {
+ std::vector<float> input_vals;
+ input_vals.reserve(phys_size);
+ for (size_t i = 0; i < phys_size; ++i) {
+ input_vals.push_back(is_nan_slot(i) ? std::numeric_limits<float>::quiet_NaN()
+ : -1.0f - static_cast<float>(i % 7));
+ }
+ set_values(input_prim, input_vals);
+ }
+
+ network network_not_fused(this->engine, this->topology_non_fused, cfg_not_fused);
+ network network_fused(this->engine, this->topology_fused, cfg_fused);
+ network_fused.set_input_data("input", input_prim);
+ network_not_fused.set_input_data("input", input_prim);
+
+ // The fused producer keeps the activation in the conv primitive's fused-id
+ // list only on configurations where the CL conv kernel actually absorbs it.
+ // If an optimizer/partitioner rewrites the conv (or picks a path without the
+ // fused activation), the fused codegen is simply not what this run would
+ // test - skip with the observed state logged rather than failing on it; the
+ // PReLU NaN regression itself is also covered by the standalone functional
+ // PReluNaNPropagationTest and the scatter f16 fused case, which pass.
+ {
+ const auto prim_list = network_fused.get_primitives_info();
+ const auto conv_info = std::find_if(prim_list.begin(), prim_list.end(), [](const primitive_info& info) {
+ return info.original_id == "conv_prim";
+ });
+ bool prelu_fused = conv_info != prim_list.end() &&
+ std::find(conv_info->c_fused_ids.begin(), conv_info->c_fused_ids.end(),
+ std::string("activation")) != conv_info->c_fused_ids.end();
+ if (!prelu_fused) {
+ std::string all_ids;
+ for (const auto& info : prim_list) {
+ all_ids += info.original_id + "(";
+ for (const auto& fid : info.c_fused_ids)
+ all_ids += fid + ",";
+ all_ids += ") ";
+ }
+ GTEST_SKIP() << "PReLU not fused into conv on this configuration (ids/fused: "
+ << all_ids << ")";
+ }
+ }
+ check_fusions_correctness(network_fused, {{"conv_prim", {"activation"}}});
+
+ auto outputs_ref = network_not_fused.execute();
+ auto outputs_fused = network_fused.execute();
+ auto val_ref = get_output_values_to_float(network_not_fused, outputs_ref.begin()->second);
+ auto val_opt = get_output_values_to_float(network_fused, outputs_fused.begin()->second);
+ ASSERT_EQ(val_ref.size(), val_opt.size());
+
+ // ASSERT_NEAR fails on NaN == NaN, so compare NaN and finite lanes separately.
+ bool has_nan = false;
+ bool has_finite = false;
+ for (size_t i = 0; i < val_ref.size(); ++i) {
+ if (std::isnan(val_ref[i])) {
+ has_nan = true;
+ ASSERT_TRUE(std::isnan(val_opt[i])) << "i = " << i << ": expected NaN, got " << val_opt[i];
+ } else {
+ has_finite = true;
+ ASSERT_NEAR(val_ref[i], val_opt[i], tolerance) << "i = " << i;
+ }
+ }
+ ASSERT_TRUE(has_nan) << "no NaN reached the output - input injection failed";
+ ASSERT_TRUE(has_finite) << "no finite value reached the output - input injection failed";
+}
+
+INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_prelu_nan, ::testing::ValuesIn(std::vector<convolution_test_params>{
+ // Same cases + forcing as the green conv_fp32_prelu_eltwise suite: fsv16
+ // conv with 16 features is the configuration where the iGPU runner actually
+ // fuses the activation into the conv kernel; both have exactly 16 features,
+ // so the fsv16 block has no padding.
+ convolution_test_params{ CASE_CONV_FP32_2, 2, 2 },
+ convolution_test_params{ CASE_CONV_FP16_2, 2, 2 },
+}));
+
class conv_fp32_multi_eltwise_2 : public ConvFusingTest {};
TEST_P(conv_fp32_multi_eltwise_2, basic) {
if (engine.get_device_info().supports_immad) {
diff --git a/src/plugins/intel_gpu/tests/unit/fusions/scatter_nd_update_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/scatter_nd_update_fusion_test.cpp
index 646c5271428..48cf57df531 100644
--- a/src/plugins/intel_gpu/tests/unit/fusions/scatter_nd_update_fusion_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/fusions/scatter_nd_update_fusion_test.cpp
@@ -11,7 +11,10 @@
#include <intel_gpu/primitives/data.hpp>
#include <intel_gpu/primitives/scatter_nd_update.hpp>
+#include <intel_gpu/primitives/activation.hpp>
+
#include <cmath>
+#include <limits>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
@@ -211,6 +214,90 @@ public:
#define CASE_SCATTER_ND_UPDATE_FP32_BSV32_FSV16_4D_6 { 6, 7, 8, 9 }, { 6, 3, 1, 1 }, { 6, 8, 1, 1 }, 2, data_types::f32, format::bs_fs_yx_bsv32_fsv16, data_types::f32, format::bfyx
+class scatter_nd_update_prelu_nan : public ScatterNDUpdatePrimitiveFusingTest {};
+TEST_P(scatter_nd_update_prelu_nan, basic) {
+ auto p = GetParam();
+ const float nan = std::numeric_limits<float>::quiet_NaN();
+ auto input = engine.allocate_memory(get_input_layout(p));
+ auto updates = engine.allocate_memory(get_updates_layout(p));
+ auto indices = engine.allocate_memory(get_indices_layout(p));
+ auto slopes = engine.allocate_memory(get_per_channel_layout(p));
+ set_values<int32_t>(indices, {1});
+ if (p.data_type == data_types::f16) {
+ set_values<ov::float16>(input, {nan, -4, 8, -8, 1, 2, 3, 4});
+ set_values<ov::float16>(updates, {-6, nan, -12, 16});
+ set_values<ov::float16>(slopes, {0.5f, 0.25f});
+ } else {
+ set_values<float>(input, {nan, -4, 8, -8, 1, 2, 3, 4});
+ set_values<float>(updates, {-6, nan, -12, 16});
+ set_values<float>(slopes, {0.5f, 0.25f});
+ }
+
+ create_topologies(
+ input_layout("input", get_input_layout(p)),
+ data("indices", indices),
+ data("updates", updates),
+ data("slopes", slopes),
+ scatter_nd_update("scatter", input_info("input"), input_info("indices"), input_info("updates"), p.indices_rank),
+ activation("prelu", input_info("scatter"), "slopes", activation_func::relu_negative_slope),
+ reorder("output", input_info("prelu"), format::bfyx, data_types::f32)
+ );
+
+ ov::intel_gpu::ImplementationDesc scatter_impl = {format::bfyx, "ocl::scatter_nd_update", impl_types::ocl};
+ cfg_fused.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{{"scatter", scatter_impl}}));
+ network network_fused(engine, topology_fused, cfg_fused);
+ network_fused.set_input_data("input", input);
+ {
+ // The producer keeps its id only while the scatter stays a GPU node:
+ // an optimizer may merge it into a copy, or (immad f32) partitioning
+ // may move execution elsewhere, in which case this fused ocl_v2 path
+ // is not what is being run and the case contributes no signal. The
+ // f16 case on the same device does hit the fused path and gates the
+ // regression; skip the others with the actual ids in the log rather
+ // than failing on a topology-shape difference unrelated to the fix.
+ const auto prim_list = network_fused.get_primitives_info();
+ bool has_scatter = false;
+ std::string all_ids;
+ for (const auto& info : prim_list) {
+ has_scatter = has_scatter || info.original_id == "scatter";
+ all_ids += info.original_id + " ";
+ }
+ if (!has_scatter)
+ GTEST_SKIP() << "no primitive with id scatter (ids: " << all_ids
+ << ") - fused ocl_v2 path not exercised for this configuration";
+ }
+ ASSERT_NO_FATAL_FAILURE(check_fusions_correctness(network_fused, {{"scatter", {"prelu"}}}));
+ const auto primitives = network_fused.get_primitives_info();
+ const auto producer = std::find_if(primitives.begin(), primitives.end(), [](const primitive_info& info) {
+ return info.original_id == "scatter";
+ });
+ ASSERT_NE(producer, primitives.end());
+ ASSERT_NE(producer->kernel_id.find("ocl::scatter_nd_update"), std::string::npos);
+
+ auto outputs = network_fused.execute();
+ const auto executed = network_fused.get_executed_primitives();
+ ASSERT_EQ(executed.count("scatter"), 1);
+ ASSERT_EQ(executed.count("prelu"), 0);
+ ASSERT_EQ(outputs.size(), 1);
+ const auto actual = get_output_values_to_float(network_fused, outputs.begin()->second);
+ // Both the untouched batch and the updated batch contain NaN, so the copy
+ // and update kernels must each preserve it through the fused PReLU.
+ const std::vector<float> expected = {nan, -2, 8, -2, -3, nan, -3, 16};
+ ASSERT_EQ(actual.size(), expected.size());
+ for (size_t i = 0; i < expected.size(); ++i) {
+ if (std::isnan(expected[i])) {
+ ASSERT_TRUE(std::isnan(actual[i])) << "at index " << i << ": got " << actual[i];
+ } else {
+ ASSERT_FLOAT_EQ(actual[i], expected[i]) << "at index " << i;
+ }
+ }
+}
+
+INSTANTIATE_TEST_SUITE_P(fusings_gpu, scatter_nd_update_prelu_nan, ::testing::ValuesIn(std::vector<scatter_nd_update_test_params>{
+ {{2, 2, 2, 1}, {1, 1, 1, 1}, {1, 2, 2, 1}, 2, data_types::f16, format::bfyx, data_types::f16, format::bfyx, 2, 3},
+ {{2, 2, 2, 1}, {1, 1, 1, 1}, {1, 2, 2, 1}, 2, data_types::f32, format::bfyx, data_types::f32, format::bfyx, 2, 3},
+}));
+
class scatter_nd_update_quantize : public ScatterNDUpdatePrimitiveFusingTest {};
TEST_P(scatter_nd_update_quantize, basic) {
auto p = GetParam();