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
[GPU] Select byxf per node for a list of dynamic-batch fp16 oneDNN convolution shapes (#38838)
Wilson Seokb63f0947bd9c
diff --git a/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h b/src/plugins/intel_gpu/src/graph/include/layout_optimizer.hindex 67371aa4789..81a5aff4ecf 100644--- a/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h+++ b/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h@@ -212,6 +212,7 @@ public:impl_types get_forced_impl_type_by_config(program_node& node);bool is_primitive_implemented_for_onednn(program_node& node);bool is_format_supported(program_node& node, format::type fmt);+ static bool is_byxf_onednn_conv_compatible(primitive_type_id type);// Returns whether reorder between "prev" with format fmt_prev and "next" with format fmt_next// can be fused into next.diff --git a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp b/src/plugins/intel_gpu/src/graph/layout_optimizer.cppindex c93270dffb5..207ada34bb3 100644--- a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp+++ b/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp@@ -8,6 +8,12 @@#include "primitive_inst.h"#include "program_helpers.h"#include "intel_gpu/runtime/debug_configuration.hpp"+#include "activation_inst.h"+#include "crop_inst.h"+#include "input_layout_inst.h"+#include "range_inst.h"+#include "softmax_inst.h"+#include "tile_inst.h"#include "data_inst.h"#include "reorder_inst.h"#include "resample_inst.h"@@ -49,6 +55,7 @@#include "impls/ocl/kernel_selector_helper.h"#include <vector>#include <memory>+#include <unordered_set>#include <utility>#include <openvino/op/constant.hpp>@@ -1037,6 +1044,110 @@ bool layout_optimizer::is_mixed_layout(program_node& prev, program_node& next, breturn false;}+// Primitive types allowed next to a byxf oneDNN convolution (CVS-176149). See set_onednn_dyn_conv_preferred_format().+bool layout_optimizer::is_byxf_onednn_conv_compatible(primitive_type_id type) {+ static const std::unordered_set<primitive_type_id> byxf_onednn_conv_whitelist = {cldnn::activation::type_id(),+ cldnn::arg_max_min::type_id(),+ cldnn::broadcast::type_id(),+ cldnn::concatenation::type_id(),+ cldnn::convolution::type_id(),+ cldnn::crop::type_id(),+ cldnn::deconvolution::type_id(),+ cldnn::eltwise::type_id(),+ cldnn::fully_connected::type_id(),+ cldnn::gather::type_id(),+ cldnn::input_layout::type_id(),+ cldnn::non_max_suppression::type_id(),+ cldnn::non_max_suppression_gather::type_id(),+ cldnn::permute::type_id(),+ cldnn::pooling::type_id(),+ cldnn::range::type_id(),+ cldnn::reduce::type_id(),+ cldnn::reorder::type_id(),+ cldnn::reshape::type_id(),+ cldnn::select::type_id(),+ cldnn::shape_of::type_id(),+ cldnn::softmax::type_id(),+ cldnn::strided_slice::type_id(),+ cldnn::tile::type_id()};+ return byxf_onednn_conv_whitelist.count(type) > 0;+}++namespace {+// IC, OC, kernel y / x, stride y / x, pad begin y / x, pad end y / x, dilation y / x, groups, input y / x.+constexpr std::array<std::array<int64_t, 15>, 10> dynamic_batch_byxf_conv_shapes = {{+ {64, 64, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 28, 28},+ {64, 128, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 28, 28},+ {64, 128, 1, 1, 2, 2, 0, 0, 0, 0, 1, 1, 1, 28, 28},+ {128, 128, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 14, 14},+ {128, 256, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 14, 14},+ {128, 256, 1, 1, 2, 2, 0, 0, 0, 0, 1, 1, 1, 14, 14},+ {256, 256, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7},+ {256, 512, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 7, 7},+ {256, 512, 1, 1, 2, 2, 0, 0, 0, 0, 1, 1, 1, 7, 7},+ {512, 512, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4},+}};++bool is_dynamic_batch_byxf_shape_whitelisted(const convolution_node& node) {+ const auto prim = node.get_primitive();+ const auto& in_shape = node.get_input_layout(0).get_partial_shape();+ const auto& weights_shape = node.weights().get_output_layout().get_partial_shape();+ const auto ic = get_convolution_channel_count(node, node.get_input_layout(0), true);+ const auto oc = get_convolution_channel_count(node, node.get_output_layout(), false);+ if (ic < 0 || oc < 0 || weights_shape.is_dynamic() || in_shape[2].is_dynamic() || in_shape[3].is_dynamic())+ return false;++ const auto kernel_y = weights_shape[weights_shape.size() - 2].get_length();+ const auto kernel_x = weights_shape[weights_shape.size() - 1].get_length();+ const std::array<int64_t, 15> key = {ic,+ oc,+ kernel_y,+ kernel_x,+ static_cast<int64_t>(prim->stride[0]),+ static_cast<int64_t>(prim->stride[1]),+ prim->padding_begin[0],+ prim->padding_begin[1],+ prim->padding_end[0],+ prim->padding_end[1],+ static_cast<int64_t>(prim->dilation[0]),+ static_cast<int64_t>(prim->dilation[1]),+ node.get_groups(),+ in_shape[2].get_length(),+ in_shape[3].get_length()};+ return std::find(dynamic_batch_byxf_conv_shapes.begin(), dynamic_batch_byxf_conv_shapes.end(), key) != dynamic_batch_byxf_conv_shapes.end();+}+} // namespace++// Layout policy for dynamic oneDNN convolutions:+//+// Default:+// - The default layout uses blocked formats based on the data type and channel count.+// For example, f16 uses b_fs_yx_fsv16.+// - With these formats, oneDNN jit:ir rejects runtime batch sizes of 16 or more.+// The reference implementation runs instead.+//+// byxf selection:+// - byxf (bzyxf for rank 5) supports jit:ir at all tested batch sizes.+// - The optimizer selects byxf in the following cases:+//+// 1. Network-wide selection:+// program::set_layout_optimizer_attributes() sets byxf_onednn_convolution.+// The model has dynamic-batch oneDNN convolutions and data flow with rank <= 4.+// All data-flow primitives pass is_byxf_onednn_conv_compatible().+// An exception applies when the model has SDPA and at most 5 such convolutions.+//+// 2. Per-node selection:+// The convolution has rank 4, uses f16, and has a dynamic batch.+// Its non-constant inputs and users pass is_byxf_onednn_conv_compatible().+// This check limits the risk of extra reorders and slower kernels in adjacent nodes.+// Its static parameters match an entry in dynamic_batch_byxf_conv_shapes.+// This list contains shapes from a customer video model with a dynamic batch.+// For some convolutions with batch sizes below 16, jit:ir is slower with byxf than with b_fs_yx_fsv16.+// The list restricts byxf selection because of this performance issue (CVS-196865).+//+// Static batch:+// - A convolution with a static batch and dynamic height or width keeps the default layout.+// node.is_dynamic() is true, but the batch is fixed.void layout_optimizer::set_onednn_dyn_conv_preferred_format(convolution_node& node) {OPENVINO_ASSERT(node.is_dynamic());@@ -1047,7 +1158,21 @@ void layout_optimizer::set_onednn_dyn_conv_preferred_format(convolution_node& noOPENVINO_ASSERT(rank == output_layout.get_partial_shape().size(), "Input and output ranks must match");OPENVINO_ASSERT(rank <= 5, "Not supported rank");- if (_optimization_attributes.byxf_onednn_convolution) {+ auto byxf_compatible_neighbors = [&node]() {+ for (const auto& dep : node.get_dependencies()) {+ if (!dep.first->is_constant() && !is_byxf_onednn_conv_compatible(dep.first->type()))+ return false;+ }+ for (const auto* user : node.get_users()) {+ if (!is_byxf_onednn_conv_compatible(user->type()))+ return false;+ }+ return true;+ };+ const bool dynamic_batch_byxf = rank == 4 && input_layout.data_type == data_types::f16 && output_layout.get_partial_shape()[0].is_dynamic() &&+ byxf_compatible_neighbors() && is_dynamic_batch_byxf_shape_whitelisted(node);++ if (_optimization_attributes.byxf_onednn_convolution || dynamic_batch_byxf) {if (rank <= 4) {node.set_preferred_input_fmt(0, cldnn::format::byxf);node.set_preferred_output_fmt(0, cldnn::format::byxf);diff --git a/src/plugins/intel_gpu/src/graph/program.cpp b/src/plugins/intel_gpu/src/graph/program.cppindex 5fbb1d02a4c..337b3b1aa9e 100644--- a/src/plugins/intel_gpu/src/graph/program.cpp+++ b/src/plugins/intel_gpu/src/graph/program.cpp@@ -1512,35 +1512,6 @@ void program::set_layout_optimizer_attributes(layout_optimizer& lo) {size_t total_non_byxf_onednn_conv_whitelist_layers = 0;// Dynamic reorder and JIT pitch handling for this optimization support rank <= 4 only.bool has_rank_gt4_data_flow = false;-- // OneDNN previously selects formats like b_fs_yx_fsv16 or bs_fs_yx_bsv16_fsv16 based on batch size.- // For dynamic batches, this approach is inefficient.- // We plan to switch to byxf for better flexibility across varying batch sizes.- // The whitelist below defines the initial target scope (CVS-176149).- const std::unordered_set<primitive_type_id> byxf_onednn_conv_whitelist = {cldnn::activation::type_id(),- cldnn::arg_max_min::type_id(),- cldnn::broadcast::type_id(),- cldnn::concatenation::type_id(),- cldnn::convolution::type_id(),- cldnn::crop::type_id(),- cldnn::deconvolution::type_id(),- cldnn::eltwise::type_id(),- cldnn::fully_connected::type_id(),- cldnn::gather::type_id(),- cldnn::input_layout::type_id(),- cldnn::non_max_suppression::type_id(),- cldnn::non_max_suppression_gather::type_id(),- cldnn::permute::type_id(),- cldnn::pooling::type_id(),- cldnn::range::type_id(),- cldnn::reduce::type_id(),- cldnn::reorder::type_id(),- cldnn::reshape::type_id(),- cldnn::select::type_id(),- cldnn::shape_of::type_id(),- cldnn::softmax::type_id(),- cldnn::strided_slice::type_id(),- cldnn::tile::type_id()};#endiffor (const auto& node : get_processing_order()) {auto &prim = *node;@@ -1725,7 +1696,7 @@ void program::set_layout_optimizer_attributes(layout_optimizer& lo) {can_use_bs_fs_yx_bsv16_fsv16 = false;}#ifdef ENABLE_ONEDNN_FOR_GPU- if (prim.is_in_data_flow() && (byxf_onednn_conv_whitelist.count(prim.type()) == 0)) {+ if (prim.is_in_data_flow() && !layout_optimizer::is_byxf_onednn_conv_compatible(prim.type())) {total_non_byxf_onednn_conv_whitelist_layers++;}if (prim.type() == cldnn::scaled_dot_product_attention::type_id()) {diff --git a/src/plugins/intel_gpu/tests/functional/CMakeLists.txt b/src/plugins/intel_gpu/tests/functional/CMakeLists.txtindex 7637f0385d0..b3dc2a3fcfc 100644--- a/src/plugins/intel_gpu/tests/functional/CMakeLists.txt+++ b/src/plugins/intel_gpu/tests/functional/CMakeLists.txt@@ -55,6 +55,13 @@ if(ENABLE_PROXY)target_compile_definitions(${TARGET_NAME} PUBLIC PROXY_PLUGIN_ENABLED)endif()+# Same view of intel_gpu/runtime headers as the plugin, which compiles them with ENABLE_ONEDNN_FOR_GPU.+if(ENABLE_ONEDNN_FOR_GPU)+ target_compile_definitions(${TARGET_NAME} PRIVATE ENABLE_ONEDNN_FOR_GPU)+ target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $<TARGET_PROPERTY:onednn_gpu_tgt,INTERFACE_INCLUDE_DIRECTORIES>)+ add_dependencies(${TARGET_NAME} onednn_gpu_tgt)+endif()+# try to find VA librariesfind_package(PkgConfig QUIET)if(PkgConfig_FOUND)diff --git a/src/plugins/intel_gpu/tests/functional/sources.cmake b/src/plugins/intel_gpu/tests/functional/sources.cmakeindex c9bad775e9d..865dcdb6132 100644--- a/src/plugins/intel_gpu/tests/functional/sources.cmake+++ b/src/plugins/intel_gpu/tests/functional/sources.cmake@@ -329,6 +329,7 @@ set(GPU_FUNCTIONAL_TEST_SOURCES${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/dynamic/broadcast_eltwise.cpp${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/dynamic/concat_in_place_dynamic_batch.cpp${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/dynamic/convert_bf16_fp32_fp16.cpp+ ${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/dynamic/dynamic_batch_convolution_byxf.cpp${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/dynamic/dynamic_fc_horizontal_fusion.cpp${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/dynamic/dynamic_model_static_split_layer.cpp${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/dynamic/dynamic_smoke_test_conv_reshape_fully_connected.cppdiff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/dynamic_batch_convolution_byxf.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/dynamic_batch_convolution_byxf.cppnew file mode 100644index 00000000000..2988b5dca1d--- /dev/null+++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/dynamic_batch_convolution_byxf.cpp@@ -0,0 +1,113 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_test_utils/node_builders/convolution.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/relu.hpp"+#include "openvino/op/result.hpp"+#include "openvino/op/roll.hpp"+#include "openvino/runtime/exec_model_info.hpp"+#include "openvino/runtime/intel_gpu/properties.hpp"+#include "shared_test_classes/base/ov_subgraph.hpp"++// The test checks layouts chosen for oneDNN convolutions.+#ifdef ENABLE_ONEDNN_FOR_GPU+namespace {+using ov::test::InputShape;++using DynamicBatchConvolutionByxfParams = std::tuple<InputShape, // input shape+ std::vector<size_t>, // kernel+ std::vector<size_t>, // strides+ size_t, // output channels+ std::string>; // expected convolution layout++// The Roll branch keeps the network-wide byxf rule off, so the convolution gets byxf from the per-node rule.+class DynamicBatchConvolutionByxf : public testing::WithParamInterface<DynamicBatchConvolutionByxfParams>, virtual public ov::test::SubgraphBaseTest {+public:+ static std::string getTestCaseName(const testing::TestParamInfo<DynamicBatchConvolutionByxfParams>& obj) {+ const auto& [input_shape, kernel, strides, out_channels, expected_layout] = obj.param;+ std::ostringstream result;+ result << "IS=" << ov::test::utils::partialShape2str({input_shape.first}) << "_TS=";+ for (const auto& shape : input_shape.second) {+ result << ov::test::utils::vec2str(shape) << "_";+ }+ result << "K=" << ov::test::utils::vec2str(kernel) << "_S=" << ov::test::utils::vec2str(strides) << "_O=" << out_channels;+ result << "_L=" << expected_layout;+ return result.str();+ }++protected:+ void SetUp() override {+ const auto& [input_shape, kernel, strides, out_channels, expected_layout] = GetParam();+ targetDevice = ov::test::utils::DEVICE_GPU;+ const auto caps = core->get_property(targetDevice, ov::device::capabilities);+ if (std::find(caps.begin(), caps.end(), ov::intel_gpu::capability::HW_MATMUL) == caps.end()) {+ GTEST_SKIP() << "oneDNN convolutions are only used on GPUs with the HW_MATMUL capability";+ }+ abs_threshold = 0.05;+ rel_threshold = 0.05;++ init_input_shapes({input_shape});+ const auto pad = static_cast<ptrdiff_t>(kernel[0] / 2);+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, inputDynamicShapes[0]);+ auto conv = ov::test::utils::make_convolution(param,+ ov::element::f16,+ kernel,+ strides,+ {pad, pad},+ {pad, pad},+ {1, 1},+ ov::op::PadType::EXPLICIT,+ out_channels,+ true);+ auto relu = std::make_shared<ov::op::v0::Relu>(conv);+ auto shift = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});+ auto axes = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {3});+ auto roll = std::make_shared<ov::op::v7::Roll>(param, shift, axes);+ function = std::make_shared<ov::Model>(ov::ResultVector{std::make_shared<ov::op::v0::Result>(relu), std::make_shared<ov::op::v0::Result>(roll)},+ ov::ParameterVector{param});+ }++ // oneDNN jit:ir supports byxf at any batch. With b_fs_yx_fsv16, batches of 16 or more fall back to the reference impl.+ void check_convolution_format() const {+ const auto& expected_layout = std::get<4>(GetParam());+ size_t conv_count = 0;+ for (const auto& op : compiledModel.get_runtime_model()->get_ordered_ops()) {+ const auto& rt_info = op->get_rt_info();+ if (rt_info.at(ov::exec_model_info::LAYER_TYPE).as<std::string>() != "Convolution") {+ continue;+ }+ ++conv_count;+ EXPECT_EQ(rt_info.at(ov::exec_model_info::OUTPUT_LAYOUTS).as<std::string>(), expected_layout) << op->get_friendly_name();+ }+ EXPECT_EQ(conv_count, 1u);+ }+};++TEST_P(DynamicBatchConvolutionByxf, Inference) {+ run();+ check_convolution_format();+}++const InputShape trunk_28 = {{-1, 64, 28, 28}, {{1, 64, 28, 28}, {16, 64, 28, 28}, {25, 64, 28, 28}, {8, 64, 28, 28}}};+const InputShape trunk_14 = {{-1, 128, 14, 14}, {{25, 128, 14, 14}, {1, 128, 14, 14}, {17, 128, 14, 14}}};+const InputShape unlisted_32 = {{-1, 64, 32, 32}, {{1, 64, 32, 32}, {2, 64, 32, 32}}};++// Per-node byxf applies only to the customer video model convolution shapes listed in layout_optimizer.cpp.+const std::vector<DynamicBatchConvolutionByxfParams> params = {+ {trunk_28, {3, 3}, {1, 1}, 64, "byxf"},+ {trunk_28, {3, 3}, {2, 2}, 128, "byxf"},+ {trunk_28, {1, 1}, {2, 2}, 128, "byxf"},+ {trunk_14, {3, 3}, {1, 1}, 128, "byxf"},+ {trunk_14, {1, 1}, {2, 2}, 256, "byxf"},+ {unlisted_32, {3, 3}, {1, 1}, 64, "b_fs_yx_fsv16"},+};++INSTANTIATE_TEST_SUITE_P(smoke_DynamicBatchConvolutionByxf,+ DynamicBatchConvolutionByxf,+ ::testing::ValuesIn(params),+ DynamicBatchConvolutionByxf::getTestCaseName);+} // namespace+#endif // ENABLE_ONEDNN_FOR_GPUdiff --git a/src/plugins/intel_gpu/tests/unit/dynamic_execution/conv_dynamic_batch_per_node_byxf_test.cpp b/src/plugins/intel_gpu/tests/unit/dynamic_execution/conv_dynamic_batch_per_node_byxf_test.cppnew file mode 100644index 00000000000..a3310352cb9--- /dev/null+++ b/src/plugins/intel_gpu/tests/unit/dynamic_execution/conv_dynamic_batch_per_node_byxf_test.cpp@@ -0,0 +1,437 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <algorithm>+#include <cmath>+#include <intel_gpu/primitives/activation.hpp>+#include <intel_gpu/primitives/convolution.hpp>+#include <intel_gpu/primitives/data.hpp>+#include <intel_gpu/primitives/eltwise.hpp>+#include <intel_gpu/primitives/input_layout.hpp>+#include <intel_gpu/primitives/mvn.hpp>+#include <intel_gpu/primitives/reorder.hpp>+#include <map>+#include <string>+#include <vector>++#include "layout_optimizer.h"+#include "primitive_inst.h"+#include "random_generator.hpp"+#include "test_utils.h"++using namespace cldnn;+using namespace ::tests;++namespace {++struct conv_geometry {+ int64_t in_features;+ int64_t out_features;+ int64_t in_size;+ int64_t kernel;+ int64_t stride;+ int64_t pad;++ int64_t out_size() const {+ return (in_size + 2 * pad - kernel) / stride + 1;+ }+};++std::string geometry_name(const conv_geometry& g) {+ return "ic" + std::to_string(g.in_features) + "_oc" + std::to_string(g.out_features) + "_in" + std::to_string(g.in_size) + "_k" + std::to_string(g.kernel) ++ "_s" + std::to_string(g.stride);+}++void PrintTo(const conv_geometry& g, std::ostream* os) {+ *os << geometry_name(g);+}++// ResNet-18 trunk of the dynamic-batch customer video model at a 28x28 stage input (the per-node byxf shape list in layout_optimizer.cpp).+// With b_fs_yx_fsv16, oneDNN only has its reference impl for these at a batch of 16 or more.+const std::vector<conv_geometry> trunk_geometries = {+ {64, 64, 28, 3, 1, 1},+ {64, 128, 28, 3, 2, 1},+ {64, 128, 28, 1, 2, 0},+ {128, 128, 14, 3, 1, 1},+ {128, 256, 14, 3, 2, 1},+ {128, 256, 14, 1, 2, 0},+ {256, 256, 7, 3, 1, 1},+ {256, 512, 7, 3, 2, 1},+ {256, 512, 7, 1, 2, 0},+ {512, 512, 4, 3, 1, 1},+};++class conv_dynamic_batch_per_node_byxf : public ::testing::Test {+public:+ void SetUp() override {+ if (!get_test_engine().get_device_info().supports_immad) {+ GTEST_SKIP() << "oneDNN convolutions are only used on devices with immad support";+ }+ rg.set_seed(GET_SUITE_NAME);+ }++protected:+ struct conv_branch {+ primitive_id id;+ conv_geometry geometry;+ memory::ptr weights;+ memory::ptr bias;+ };++ using tensors = std::map<primitive_id, memory::ptr>;+ using results = std::map<primitive_id, std::vector<float>>;++ // All convolutions read the same input, so they must share in_features and in_size.+ void add_conv(const primitive_id& id, const conv_geometry& g, bool with_bias) {+ auto& engine = get_test_engine();+ const layout weights_layout{ov::PartialShape{g.out_features, g.in_features, g.kernel, g.kernel}, data_types::f16, format::bfyx};+ // Keeps outputs near unit scale for every fan-in.+ const double range = 3.0 / std::sqrt(static_cast<double>(g.in_features * g.kernel * g.kernel));+ auto weights = engine.allocate_memory(weights_layout);+ set_values(weights, rg.generate_random_1d<ov::float16>(weights_layout.count(), -range, range, 64));++ memory::ptr bias;+ if (with_bias) {+ const layout bias_layout{ov::PartialShape{1, g.out_features, 1, 1}, data_types::f16, format::bfyx};+ bias = engine.allocate_memory(bias_layout);+ set_values(bias, rg.generate_random_1d<ov::float16>(bias_layout.count(), -1, 1));+ }+ branches.push_back({id, g, weights, bias});+ }++ topology build_topology(const ov::Dimension& batch, const ov::Dimension& size) const {+ const auto& in = branches.front().geometry;+ topology topo;+ topo.add(input_layout("input", layout{ov::PartialShape{batch, in.in_features, size, size}, data_types::f16, format::bfyx}));+ // MVN is not in the byxf_onednn_convolution whitelist, so only the per-node rule can select byxf.+ topo.add(mvn("mvn", input_info("input"), true, 1e-5f, false, {2, 3}));+ topo.add(reorder("mvn_out", input_info("mvn"), format::bfyx, data_types::f32));+ for (const auto& branch : branches) {+ const auto& g = branch.geometry;+ const auto stride = static_cast<size_t>(g.stride);+ topo.add(data(branch.id + "_weights", branch.weights));+ primitive_id bias_id;+ if (branch.bias) {+ bias_id = branch.id + "_bias";+ topo.add(data(bias_id, branch.bias));+ }+ topo.add(convolution(branch.id,+ input_info("input"),+ branch.id + "_weights",+ bias_id,+ 1,+ {stride, stride},+ {1, 1},+ {g.pad, g.pad},+ {g.pad, g.pad},+ false));+ primitive_id last = branch.id;+ if (residual_relu) {+ const ov::PartialShape out_shape{batch, g.out_features, g.out_size(), g.out_size()};+ topo.add(input_layout(branch.id + "_residual", layout{out_shape, data_types::f16, format::bfyx}));+ topo.add(eltwise(branch.id + "_add", {input_info(branch.id), input_info(branch.id + "_residual")}, eltwise_mode::sum));+ topo.add(activation(branch.id + "_relu", input_info(branch.id + "_add"), activation_func::relu));+ last = branch.id + "_relu";+ }+ topo.add(reorder(branch.id + "_out", input_info(last), format::bfyx, data_types::f32));+ }+ return topo;+ }++ // MVN is not in the byxf_onednn_convolution whitelist, so this branch keeps the network-wide byxf rule off.+ static void add_mvn_side_branch(topology& topo) {+ topo.add(input_layout("side", layout{ov::PartialShape{1, 16, 8, 8}, data_types::f16, format::bfyx}));+ topo.add(mvn("side_mvn", input_info("side"), true, 1e-5f, false, {2, 3}));+ topo.add(reorder("side_out", input_info("side_mvn"), format::bfyx, data_types::f32));+ }++ static ExecutionConfig make_config() {+ auto config = get_test_default_config(get_test_engine());+ config.set_property(ov::intel_gpu::optimize_data(true));+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));+ return config;+ }++ network::ptr build_network(const ov::Dimension& batch, const ov::Dimension& size) const {+ return std::make_shared<network>(get_test_engine(), build_topology(batch, size), make_config());+ }++ network::ptr build_network(const ov::Dimension& batch) const {+ return build_network(batch, ov::Dimension(branches.front().geometry.in_size));+ }++ tensors make_inputs(int64_t batch) {+ auto& engine = get_test_engine();+ tensors inputs;+ auto add_input = [&](const primitive_id& id, int64_t features, int64_t size) {+ const layout mem_layout{ov::PartialShape{batch, features, size, size}, data_types::f16, format::bfyx};+ auto mem = engine.allocate_memory(mem_layout);+ set_values(mem, rg.generate_random_1d<ov::float16>(mem_layout.count(), -1, 1));+ inputs[id] = mem;+ };++ const auto& in = branches.front().geometry;+ add_input("input", in.in_features, in.in_size);+ if (residual_relu) {+ for (const auto& branch : branches) {+ add_input(branch.id + "_residual", branch.geometry.out_features, branch.geometry.out_size());+ }+ }+ return inputs;+ }++ static results run(network& net, const tensors& inputs) {+ for (const auto& [id, mem] : inputs) {+ net.set_input_data(id, mem);+ }+ auto outputs = net.execute();+ results values;+ for (auto& [id, output] : outputs) {+ auto mem = output.get_memory();+ mem_lock<float, mem_lock_type::read> lock(mem, get_test_stream());+ // Dynamic outputs may sit in a larger, preallocated buffer.+ values[id].assign(lock.data(), lock.data() + output.get_layout().count());+ }+ return values;+ }++ static std::vector<float> to_float(const memory::ptr& mem) {+ mem_lock<ov::float16, mem_lock_type::read> lock(mem, get_test_stream());+ std::vector<float> values(mem->count());+ for (size_t i = 0; i < values.size(); ++i) {+ values[i] = static_cast<float>(lock[i]);+ }+ return values;+ }++ // Accumulates in f32 like oneDNN; the OCL reference kernel accumulates f16 inputs in f16.+ std::vector<float> reference_output(const conv_branch& branch, int64_t batch, const tensors& inputs) const {+ const auto& g = branch.geometry;+ const auto src = to_float(inputs.at("input"));+ const auto weights = to_float(branch.weights);+ const auto bias = branch.bias ? to_float(branch.bias) : std::vector<float>(g.out_features, 0.0f);+ const auto residual = residual_relu ? to_float(inputs.at(branch.id + "_residual")) : std::vector<float>{};+ const int64_t out_size = g.out_size();+ std::vector<float> dst(batch * g.out_features * out_size * out_size);+ for (int64_t n = 0; n < batch; ++n) {+ for (int64_t oc = 0; oc < g.out_features; ++oc) {+ for (int64_t oy = 0; oy < out_size; ++oy) {+ for (int64_t ox = 0; ox < out_size; ++ox) {+ float acc = bias[oc];+ for (int64_t ic = 0; ic < g.in_features; ++ic) {+ for (int64_t ky = 0; ky < g.kernel; ++ky) {+ const int64_t iy = oy * g.stride - g.pad + ky;+ if (iy < 0 || iy >= g.in_size) {+ continue;+ }+ for (int64_t kx = 0; kx < g.kernel; ++kx) {+ const int64_t ix = ox * g.stride - g.pad + kx;+ if (ix < 0 || ix >= g.in_size) {+ continue;+ }+ acc += src[((n * g.in_features + ic) * g.in_size + iy) * g.in_size + ix] *+ weights[((oc * g.in_features + ic) * g.kernel + ky) * g.kernel + kx];+ }+ }+ }+ const int64_t idx = ((n * g.out_features + oc) * out_size + oy) * out_size + ox;+ if (residual_relu) {+ acc = std::max(acc + residual[idx], 0.0f);+ }+ dst[idx] = static_cast<float>(ov::float16(acc));+ }+ }+ }+ }+ return dst;+ }++ void compare_with_reference(const results& actual, int64_t batch, const tensors& inputs) const {+ for (const auto& branch : branches) {+ const auto out_id = branch.id + "_out";+ const auto exp = reference_output(branch, batch, inputs);+ const auto& act = actual.at(out_id);+ ASSERT_EQ(exp.size(), act.size()) << out_id << ", batch " << batch;+ for (size_t i = 0; i < exp.size(); ++i) {+ ASSERT_NEAR(exp[i], act[i], 0.02f + 0.01f * std::abs(exp[i])) << out_id << ", batch " << batch << ", index " << i;+ }+ }+ }++ void check_onednn_conv_formats(network& net, format expected) const {+ ASSERT_EQ(net.get_program()->get_layout_optimizer().get_optimization_attributes().byxf_onednn_convolution, 0);+ for (const auto& branch : branches) {+ const auto& node = net.get_primitive(branch.id)->get_node();+ ASSERT_TRUE(node.is_dynamic()) << branch.id;+ ASSERT_EQ(node.get_preferred_impl_type(), impl_types::onednn) << branch.id;+ ASSERT_EQ(node.get_input_layout(0).format, expected) << branch.id;+ ASSERT_EQ(node.get_output_layout(0).format, expected) << branch.id;+ }+ }++ void run_and_check(network& net, int64_t batch) {+ const auto inputs = make_inputs(batch);+ const auto actual = run(net, inputs);++ for (const auto& branch : branches) {+ const auto* impl = net.get_primitive(branch.id)->get_impl();+ ASSERT_NE(impl, nullptr) << branch.id;+ const auto& name = impl->get_kernel_name();+ EXPECT_TRUE(impl->is_onednn()) << branch.id << ", batch " << batch << ": " << name;+ EXPECT_EQ(name.rfind("jit:ir", 0), 0u) << branch.id << ", batch " << batch << ": " << name;+ }+ compare_with_reference(actual, batch, inputs);+ }++ tests::random_generator rg;+ std::vector<conv_branch> branches;+ bool residual_relu = false;+};++TEST_F(conv_dynamic_batch_per_node_byxf, fused_residual_relu_uses_byxf_jit) {+ add_conv("conv", trunk_geometries[0], true);+ residual_relu = true;+ auto net = build_network(ov::Dimension::dynamic());+ ASSERT_NO_FATAL_FAILURE(check_onednn_conv_formats(*net, format::byxf));+ ASSERT_EQ(net->get_primitive("conv")->get_node().get_fused_primitives().size(), 2u);++ ASSERT_NO_FATAL_FAILURE(run_and_check(*net, 25));+ run_and_check(*net, 150);+}++TEST_F(conv_dynamic_batch_per_node_byxf, byxf_jit_at_every_runtime_batch) {+ add_conv("conv_3x3", trunk_geometries[1], true);+ add_conv("conv_1x1", trunk_geometries[2], false);+ auto net = build_network(ov::Dimension::dynamic());+ ASSERT_NO_FATAL_FAILURE(check_onednn_conv_formats(*net, format::byxf));++ for (const int64_t batch : {1, 8, 16, 25, 150, 25}) {+ ASSERT_NO_FATAL_FAILURE(run_and_check(*net, batch)) << "batch " << batch;+ }+}++// Convolutions with a static batch keep the blocked format, even when other dimensions are dynamic.+TEST_F(conv_dynamic_batch_per_node_byxf, static_batch1_conv_keeps_fsv16) {+ add_conv("conv", trunk_geometries[0], true);+ auto net = build_network(ov::Dimension(1), ov::Dimension::dynamic());+ ASSERT_NO_FATAL_FAILURE(check_onednn_conv_formats(*net, format::b_fs_yx_fsv16));++ run_and_check(*net, 1);+}++TEST_F(conv_dynamic_batch_per_node_byxf, int8_dynamic_batch_conv_keeps_fsv32) {+ auto& engine = get_test_engine();+ auto weights = engine.allocate_memory({ov::PartialShape{64, 64, 3, 3}, data_types::i8, format::bfyx});+ set_values(weights, rg.generate_random_1d<int8_t>(weights->get_layout().count(), -4, 4));++ topology topo(input_layout("input", layout{ov::PartialShape{ov::Dimension::dynamic(), 64, 28, 28}, data_types::i8, format::bfyx}),+ data("weights", weights),+ convolution("conv", input_info("input"), "weights", "", 1, {1, 1}, {1, 1}, {1, 1}, {1, 1}, false),+ reorder("out", input_info("conv"), format::bfyx, data_types::f32));+ add_mvn_side_branch(topo);+ network net(engine, topo, make_config());++ ASSERT_EQ(net.get_program()->get_layout_optimizer().get_optimization_attributes().byxf_onednn_convolution, 0);+ const auto& node = net.get_primitive("conv")->get_node();+ ASSERT_EQ(node.get_preferred_impl_type(), impl_types::onednn);+ EXPECT_EQ(node.get_input_layout(0).format, format::b_fs_yx_fsv32);+}++TEST_F(conv_dynamic_batch_per_node_byxf, rank5_dynamic_batch_conv_keeps_fsv16) {+ auto& engine = get_test_engine();+ auto weights = engine.allocate_memory({ov::PartialShape{32, 32, 3, 3, 3}, data_types::f16, format::bfzyx});+ set_values(weights, rg.generate_random_1d<ov::float16>(weights->get_layout().count(), -1, 1));++ topology topo(input_layout("input", layout{ov::PartialShape{ov::Dimension::dynamic(), 32, 8, 8, 8}, data_types::f16, format::bfzyx}),+ data("weights", weights),+ convolution("conv", input_info("input"), "weights", "", 1, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, false),+ reorder("out", input_info("conv"), format::bfzyx, data_types::f32));+ add_mvn_side_branch(topo);+ network net(engine, topo, make_config());++ ASSERT_EQ(net.get_program()->get_layout_optimizer().get_optimization_attributes().byxf_onednn_convolution, 0);+ const auto& node = net.get_primitive("conv")->get_node();+ ASSERT_EQ(node.get_preferred_impl_type(), impl_types::onednn);+ EXPECT_EQ(node.get_input_layout(0).format, format::b_fs_zyx_fsv16);+ EXPECT_EQ(node.get_output_layout(0).format, format::b_fs_zyx_fsv16);+}++TEST_F(conv_dynamic_batch_per_node_byxf, rank3_dynamic_batch_conv_keeps_fsv16) {+ auto& engine = get_test_engine();+ auto weights = engine.allocate_memory({ov::PartialShape{64, 64, 3}, data_types::f16, format::bfyx});+ set_values(weights, rg.generate_random_1d<ov::float16>(weights->get_layout().count(), -1, 1));++ topology topo(input_layout("input", layout{ov::PartialShape{ov::Dimension::dynamic(), 64, 100}, data_types::f16, format::bfyx}),+ data("weights", weights),+ convolution("conv", input_info("input"), "weights", "", 1, {1}, {1}, {1}, {1}, false),+ reorder("out", input_info("conv"), format::bfyx, data_types::f32));+ add_mvn_side_branch(topo);+ network net(engine, topo, make_config());++ ASSERT_EQ(net.get_program()->get_layout_optimizer().get_optimization_attributes().byxf_onednn_convolution, 0);+ const auto& node = net.get_primitive("conv")->get_node();+ ASSERT_EQ(node.get_preferred_impl_type(), impl_types::onednn);+ EXPECT_EQ(node.get_input_layout(0).format, format::b_fs_yx_fsv16);+ EXPECT_EQ(node.get_output_layout(0).format, format::b_fs_yx_fsv16);+}++// MVN has no fast byxf kernel, so a convolution next to it keeps the blocked format.+TEST_F(conv_dynamic_batch_per_node_byxf, mvn_user_keeps_fsv16) {+ auto& engine = get_test_engine();+ auto weights = engine.allocate_memory({ov::PartialShape{64, 64, 3, 3}, data_types::f16, format::bfyx});+ set_values(weights, rg.generate_random_1d<ov::float16>(weights->get_layout().count(), -1, 1));++ topology topo(input_layout("input", layout{ov::PartialShape{ov::Dimension::dynamic(), 64, 28, 28}, data_types::f16, format::bfyx}),+ data("weights", weights),+ convolution("conv", input_info("input"), "weights", "", 1, {1, 1}, {1, 1}, {1, 1}, {1, 1}, false),+ mvn("mvn", input_info("conv"), true, 1e-5f, false, {2, 3}),+ reorder("out", input_info("mvn"), format::bfyx, data_types::f32));+ network net(engine, topo, make_config());++ ASSERT_EQ(net.get_program()->get_layout_optimizer().get_optimization_attributes().byxf_onednn_convolution, 0);+ const auto& node = net.get_primitive("conv")->get_node();+ ASSERT_EQ(node.get_preferred_impl_type(), impl_types::onednn);+ EXPECT_EQ(node.get_input_layout(0).format, format::b_fs_yx_fsv16);+ EXPECT_EQ(node.get_output_layout(0).format, format::b_fs_yx_fsv16);+}++class conv_dynamic_batch_per_node_byxf_geometry : public conv_dynamic_batch_per_node_byxf, public ::testing::WithParamInterface<conv_geometry> {};++TEST_P(conv_dynamic_batch_per_node_byxf_geometry, uses_byxf_jit_at_batch25) {+ add_conv("conv", GetParam(), true);+ auto net = build_network(ov::Dimension::dynamic());+ ASSERT_NO_FATAL_FAILURE(check_onednn_conv_formats(*net, format::byxf));++ run_and_check(*net, 25);+}++INSTANTIATE_TEST_SUITE_P(resnet18_trunk,+ conv_dynamic_batch_per_node_byxf_geometry,+ ::testing::ValuesIn(trunk_geometries),+ [](const ::testing::TestParamInfo<conv_geometry>& info) {+ return geometry_name(info.param);+ });++// Shapes outside the shape list keep the blocked format: an SD 1.5 UNet convolution, and a trunk convolution with a larger input.+const std::vector<conv_geometry> unlisted_geometries = {+ {320, 320, 64, 3, 1, 1},+ {64, 64, 32, 3, 1, 1},+};++class conv_dynamic_batch_per_node_byxf_unlisted_geometry : public conv_dynamic_batch_per_node_byxf, public ::testing::WithParamInterface<conv_geometry> {};++TEST_P(conv_dynamic_batch_per_node_byxf_unlisted_geometry, keeps_fsv16) {+ add_conv("conv", GetParam(), true);+ auto net = build_network(ov::Dimension::dynamic());+ check_onednn_conv_formats(*net, format::b_fs_yx_fsv16);+}++INSTANTIATE_TEST_SUITE_P(unlisted,+ conv_dynamic_batch_per_node_byxf_unlisted_geometry,+ ::testing::ValuesIn(unlisted_geometries),+ [](const ::testing::TestParamInfo<conv_geometry>& info) {+ return geometry_name(info.param);+ });++} // namespacediff --git a/src/plugins/intel_gpu/tests/unit/sources.cmake b/src/plugins/intel_gpu/tests/unit/sources.cmakeindex a3c4aebda36..6eecb5fc468 100644--- a/src/plugins/intel_gpu/tests/unit/sources.cmake+++ b/src/plugins/intel_gpu/tests/unit/sources.cmake@@ -521,6 +521,7 @@ list(APPEND GPU_UNIT_TESTS_SRCS ${GPU_UNIT_TESTS_TRANSFORMATIONS_SRCS})# oneDNN-specific tests - only compiled when oneDNN is enabled for the GPU plugin.set(GPU_UNIT_TESTS_ONEDNN_SRCS+ ${CMAKE_CURRENT_LIST_DIR}/dynamic_execution/conv_dynamic_batch_per_node_byxf_test.cpp${CMAKE_CURRENT_LIST_DIR}/onednn/profiling_test.cpp${CMAKE_CURRENT_LIST_DIR}/onednn/utils_test.cpp)