Skip to content

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

[GPU] Fix MVN across-channels perf regression from blocked layouts (#36922)

Wilson Seok8c799bc67cd4
diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/mvn.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/mvn.hpp
index 8b9e8519906..8a526fe872f 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/primitives/mvn.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/mvn.hpp
@@ -98,10 +98,5 @@ struct mvn : public primitive_base<mvn> {
return false;
}
-
- // Returns false when the given layout needs a reorder to planar before an aligned MVN (see requires_alignment):
- // the normalized-axes flattening in mvn_impl::static_canonicalize_shapes is only valid for planar / single-fsv
- // layouts.
- bool is_aligned_layout_supported(const layout& input_layout) const;
};
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp b/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp
index e8aef9b3ecf..888361270cf 100644
--- a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp
+++ b/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp
@@ -137,15 +137,6 @@ bool layout_optimizer::is_format_supported(program_node& node, format::type fmt)
if (node.is_type<fully_connected>() && fmt == format::byxf)
return false;
- // Aligned MVN flattens the normalized axes into the innermost dimension, which is only valid for planar /
- // single feature-blocked layouts; reject other layouts (e.g. byxf) so a reorder to planar is inserted instead.
- if (node.is_type<mvn>()) {
- const auto& input_layout = node.get_input_layout(0);
- const layout candidate{input_layout.get_partial_shape(), input_layout.data_type, fmt};
- if (!node.as<mvn>().get_primitive()->is_aligned_layout_supported(candidate))
- return false;
- }
-
if (node.is_type<input_layout>())
return node.get_output_layout().format == fmt;
diff --git a/src/plugins/intel_gpu/src/graph/mvn.cpp b/src/plugins/intel_gpu/src/graph/mvn.cpp
index 4a02b26fe94..95191495445 100644
--- a/src/plugins/intel_gpu/src/graph/mvn.cpp
+++ b/src/plugins/intel_gpu/src/graph/mvn.cpp
@@ -5,37 +5,11 @@
#include "mvn_inst.h"
#include "primitive_type_base.h"
#include "json_object.h"
-#include <algorithm>
#include <string>
namespace cldnn {
GPU_DEFINE_PRIMITIVE_TYPE_ID(mvn)
-bool mvn::is_aligned_layout_supported(const layout& input_layout) const {
- const auto& input_pshape = input_layout.get_partial_shape();
- if (!requires_alignment(input_pshape))
- return true;
-
- const auto& fmt = input_layout.format;
- if (format::is_default_format(fmt))
- return true;
-
- //defer to dyn_formats
- if (input_pshape.is_dynamic())
- return true;
-
- // Mirror the single feature-blocked case handled by mvn_impl::static_canonicalize_shapes.
- const auto& block_sizes = format::block_sizes(fmt);
- auto axes = reduction_axes;
- const auto rank = static_cast<int64_t>(input_pshape.size());
- std::for_each(axes.begin(), axes.end(), [rank](int64_t& v) {
- v = (v < 0) ? v + rank : v;
- });
- return block_sizes.size() == 1 && block_sizes[0].first == 1 &&
- (input_pshape[block_sizes[0].first].get_length() % block_sizes[0].second == 0) &&
- (std::count(axes.begin(), axes.end(), static_cast<int64_t>(block_sizes[0].first)) == 0);
-}
-
layout mvn_inst::calc_output_layout(mvn_node const& node, kernel_impl_params const& impl_param) {
auto input_node_layout = impl_param.get_non_padded_input_layout();
auto output_type = impl_param.desc->output_data_types[0].value_or(input_node_layout.data_type);
diff --git a/src/plugins/intel_gpu/src/graph/registry/mvn_impls.cpp b/src/plugins/intel_gpu/src/graph/registry/mvn_impls.cpp
new file mode 100644
index 00000000000..8a17f79cd22
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/registry/mvn_impls.cpp
@@ -0,0 +1,80 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "registry.hpp"
+#include "intel_gpu/primitives/mvn.hpp"
+#include "primitive_inst.h"
+
+#include <algorithm>
+
+namespace ov::intel_gpu {
+
+using namespace cldnn;
+
+namespace {
+
+struct MvnImplementationManager : public ImplementationManagerLegacy<mvn> {
+ using parent = ImplementationManagerLegacy<mvn>;
+
+ explicit MvnImplementationManager(const parent& impl) : parent(impl) {}
+
+ bool validate_impl(const program_node& node) const override {
+ if (!parent::validate_impl(node))
+ return false;
+
+ const auto& prim = node.as<mvn>().get_primitive();
+ const auto& input_layout = node.get_input_layout(0);
+ const auto& fmt = input_layout.format;
+
+ // Planar (default) layouts are always handled by the bfyx opt / ref kernels.
+ if (format::is_default_format(fmt))
+ return true;
+
+ // Across-channels normalization has no optimized blocked-layout kernel: the bfyx opt kernel is
+ // planar-only and the fsv16/fsv32 kernels implement WITHIN_CHANNELS only. Reject non-planar
+ // layouts - for static and dynamic shapes alike - so a reorder to planar bfyx is inserted and the
+ // fast bfyx opt kernel runs instead of falling back to the slow reference (mvn_gpu_ref) kernel.
+ if (prim->across_channels())
+ return false;
+
+ const auto& input_pshape = input_layout.get_partial_shape();
+ if (input_pshape.is_dynamic())
+ return true;
+
+ if (!prim->requires_alignment(input_pshape))
+ return true;
+
+ // Aligned MVN flattens the normalized axes into the innermost dimension (see
+ // mvn_impl::static_canonicalize_shapes), which is only valid for planar or single feature-blocked
+ // layouts; reject anything else (e.g. byxf) so a reorder to planar is inserted instead.
+ const auto& block_sizes = format::block_sizes(fmt);
+ auto axes = prim->reduction_axes;
+ const auto rank = static_cast<int64_t>(input_pshape.size());
+ std::for_each(axes.begin(), axes.end(), [rank](int64_t& v) {
+ v = (v < 0) ? v + rank : v;
+ });
+ return block_sizes.size() == 1 && block_sizes[0].first == 1 &&
+ (input_pshape[block_sizes[0].first].get_length() % block_sizes[0].second == 0) &&
+ (std::count(axes.begin(), axes.end(), static_cast<int64_t>(block_sizes[0].first)) == 0);
+ }
+};
+
+std::shared_ptr<ImplementationManager> get_mvn_implementation(shape_types shape_type) {
+ const auto impl = std::dynamic_pointer_cast<ImplementationManagerLegacy<mvn>>(
+ implementation_map<mvn>::get(impl_types::ocl, shape_type));
+ return std::make_shared<MvnImplementationManager>(*impl);
+}
+
+} // namespace
+
+const std::vector<std::shared_ptr<cldnn::ImplementationManager>>& Registry<mvn>::get_implementations() {
+ static const std::vector<std::shared_ptr<ImplementationManager>> impls = {
+ get_mvn_implementation(shape_types::static_shape),
+ get_mvn_implementation(shape_types::dynamic_shape),
+ };
+
+ return impls;
+}
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/graph/registry/registry.hpp b/src/plugins/intel_gpu/src/graph/registry/registry.hpp
index f0f5cd66daa..54873dbc8af 100644
--- a/src/plugins/intel_gpu/src/graph/registry/registry.hpp
+++ b/src/plugins/intel_gpu/src/graph/registry/registry.hpp
@@ -161,6 +161,7 @@ REGISTER_IMPLS(lora);
REGISTER_IMPLS(lstm_cell);
REGISTER_IMPLS(lstm_seq);
REGISTER_IMPLS(gru_seq);
+REGISTER_IMPLS(mvn);
REGISTER_IMPLS(non_max_suppression);
REGISTER_IMPLS(paged_attention);
REGISTER_IMPLS(paged_gated_delta_net);
@@ -224,7 +225,6 @@ REGISTER_DEFAULT_IMPLS(lrn, OCL_S);
REGISTER_DEFAULT_IMPLS(multiclass_nms, OCL_S);
REGISTER_DEFAULT_IMPLS(multinomial, OCL_S);
REGISTER_DEFAULT_IMPLS(mutable_data, OCL_S);
-REGISTER_DEFAULT_IMPLS(mvn, OCL_S, OCL_D);
REGISTER_DEFAULT_IMPLS(matrix_nms, OCL_S);
REGISTER_DEFAULT_IMPLS(normalize, OCL_S);
REGISTER_DEFAULT_IMPLS(one_hot, OCL_S);
diff --git a/src/plugins/intel_gpu/tests/unit/passes/reorder_inputs_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/reorder_inputs_test.cpp
index 69df9dbde31..08649e5596f 100644
--- a/src/plugins/intel_gpu/tests/unit/passes/reorder_inputs_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/passes/reorder_inputs_test.cpp
@@ -510,6 +510,83 @@ TEST(reorder_inputs, mvn_expected_plain_format) {
ASSERT_EQ(mvn_node.get_input_layouts()[0].format, format::bfyx);
ASSERT_EQ(mvn_node.get_output_layout().format, format::bfyx);
}
+
+// Across-channels MVN has no optimized blocked-layout kernel: the bfyx opt kernel is planar-only and
+// the fsv16/fsv32 kernels implement WITHIN_CHANNELS only. The OCL MVN impl must therefore report no
+// support for non-planar layouts on an across-channels MVN, so layout_optimizer::is_format_supported
+// (via has_impl_for) rejects the blocked format, a reorder to planar bfyx is inserted, and the fast
+// bfyx opt kernel runs instead of falling back to the slow reference (mvn_gpu_ref) kernel.
+// Reduction over axis 1 (channel) makes an MVN across-channels; axes={1,2} mirrors DialogSeparator.
+TEST(reorder_inputs, mvn_across_channels_rejects_blocked_layout) {
+ auto& engine = get_test_engine();
+ ExecutionConfig config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::optimize_data(true));
+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+
+ const ov::PartialShape shape{1, 256, 60, 60};
+ const ov::PartialShape dyn_shape = ov::PartialShape::dynamic(4);
+
+ auto build = [&](const std::vector<int64_t>& axes, const ov::PartialShape& in_shape) {
+ topology topology;
+ topology.add(input_layout("input", layout{in_shape, data_types::f16, format::bfyx}));
+ topology.add(mvn("mvn", input_info("input"), true, 1e-10f, true, axes));
+ return program::build_program(engine, topology, config, false, true);
+ };
+
+ auto supports = [](program::ptr prog, format::type fmt) {
+ auto& node = prog->get_node("mvn");
+ return test_format<bool>(node, fmt, [](program_node& n) { return n.type()->has_impl_for(n); });
+ };
+
+ // Across-channels (axes include channel axis 1): blocked layouts must be rejected, planar allowed.
+ auto across = build({1, 2, 3}, shape);
+ ASSERT_TRUE(across->get_node("mvn").as<mvn>().get_primitive()->across_channels());
+ EXPECT_FALSE(supports(across, format::b_fs_yx_fsv16));
+ EXPECT_FALSE(supports(across, format::b_fs_yx_fsv32));
+ EXPECT_FALSE(supports(across, format::byxf));
+ EXPECT_TRUE(supports(across, format::bfyx));
+
+ // Within-channels (spatial-only reduction): the fsv16/fsv32 opt kernels support this mode, so the
+ // blocked layout must remain supported (no unnecessary reorder-to-planar; preserves the fast path).
+ auto within = build({2, 3}, shape);
+ ASSERT_FALSE(within->get_node("mvn").as<mvn>().get_primitive()->across_channels());
+ EXPECT_TRUE(supports(within, format::b_fs_yx_fsv16));
+ EXPECT_TRUE(supports(within, format::bfyx));
+
+ // Dynamic shapes: the rejection must apply for dynamic across-channels MVN too. A dynamic node can
+ // still be assigned a blocked layout (e.g. inherited from an fsv16-producing dynamic convolution),
+ // and across-channels + blocked selects the slow mvn_gpu_ref kernel just like the static case, so
+ // the across_channels() check must precede the dynamic-shape early-return. Within-channels dynamic
+ // keeps deferring to the dynamic-shape format list (blocked stays supported).
+ auto across_dyn = build({1, 2, 3}, dyn_shape);
+ EXPECT_FALSE(supports(across_dyn, format::b_fs_yx_fsv16));
+ EXPECT_FALSE(supports(across_dyn, format::b_fs_yx_fsv32));
+ EXPECT_TRUE(supports(across_dyn, format::bfyx));
+
+ auto within_dyn = build({2, 3}, dyn_shape);
+ EXPECT_TRUE(supports(within_dyn, format::b_fs_yx_fsv16));
+
+ // Aligned MVN (PR #36649): a last-axis LayerNorm (axes={3}) reduces a strict subset of the spatial
+ // axes, so requires_alignment() holds and the impl flattens the normalized axes into the innermost
+ // dimension. That reinterpretation is only valid for planar or single feature-blocked layouts, so
+ // byxf (feature innermost) must be rejected - otherwise the GPU normalizes over the wrong physical
+ // axis and silently returns incorrect results in f16. This is the case none of the branches above
+ // reach: it passes the across_channels() and requires_alignment() gates and exercises the
+ // block_sizes logic itself.
+ auto last_axis = build({3}, shape);
+ ASSERT_FALSE(last_axis->get_node("mvn").as<mvn>().get_primitive()->across_channels());
+ EXPECT_FALSE(supports(last_axis, format::byxf));
+ EXPECT_TRUE(supports(last_axis, format::bfyx));
+ // Single feature-blocked layout with a channel count divisible by the block size stays supported
+ // (the flatten_axis=1 special case), and the channel axis is not normalized.
+ EXPECT_TRUE(supports(last_axis, format::b_fs_yx_fsv16));
+
+ // Same aligned case, but the channel count is not divisible by the fsv16 block size, so the
+ // flattening would cross block padding: must be rejected.
+ auto last_axis_unaligned = build({3}, ov::PartialShape{1, 8, 64, 64});
+ EXPECT_FALSE(supports(last_axis_unaligned, format::b_fs_yx_fsv16));
+ EXPECT_TRUE(supports(last_axis_unaligned, format::bfyx));
+}
// TODO Not yet implemented
//TEST(reorder_inputs, impl_forcing_conv_format_kernel) {
// auto& engine = get_test_engine();