Skip to content

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

[GPU] Fix dynamic weight preparation and blocked reorder offsets (#38045)

Wilson Seokb23962a2cc85
diff --git a/src/plugins/intel_gpu/include/intel_gpu/graph/serialization/weights_reorder_params.hpp b/src/plugins/intel_gpu/include/intel_gpu/graph/serialization/weights_reorder_params.hpp
index 60716004fdf..a5588e4007f 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/graph/serialization/weights_reorder_params.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/graph/serialization/weights_reorder_params.hpp
@@ -17,14 +17,14 @@ namespace cldnn {
_transposed(transposed),
_grouped(grouped) {}
- size_t hash() const {
+ virtual size_t hash() const {
size_t seed = hash_combine(_in_layout.hash(), _out_layout.hash());
seed = hash_combine(seed, _transposed);
seed = hash_combine(seed, _grouped);
return seed;
}
- bool operator==(const WeightsReorderParams& rhs) const {
+ virtual bool operator==(const WeightsReorderParams& rhs) const {
if (typeid(*this) != typeid(rhs)) {
return false;
}
@@ -81,6 +81,24 @@ namespace cldnn {
std::shared_ptr<dnnl::memory::desc> _in_desc = std::make_shared<dnnl::memory::desc>();
std::shared_ptr<dnnl::memory::desc> _out_desc = std::make_shared<dnnl::memory::desc>();
+ size_t hash() const override {
+ size_t seed = cldnn::WeightsReorderParams::hash();
+ const auto in_desc_blob = _in_desc->get_blob();
+ const auto out_desc_blob = _out_desc->get_blob();
+ seed = hash_range(seed, in_desc_blob.begin(), in_desc_blob.end());
+ return hash_range(seed, out_desc_blob.begin(), out_desc_blob.end());
+ }
+
+ bool operator==(const WeightsReorderParams& rhs) const override {
+ if (!cldnn::WeightsReorderParams::operator==(rhs)) {
+ return false;
+ }
+
+ const auto& rhs_onednn = static_cast<const WeightsReorderParamsOneDNN&>(rhs);
+ return _in_desc->get_blob() == rhs_onednn._in_desc->get_blob() &&
+ _out_desc->get_blob() == rhs_onednn._out_desc->get_blob();
+ }
+
void save(cldnn::BinaryOutputBuffer& ob) const override {
cldnn::WeightsReorderParams::save(ob);
dnnl::memory::desc inTemp(*_in_desc);
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/post_optimize_weights.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/post_optimize_weights.cpp
index 5667c005ba8..76f40ad165e 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/post_optimize_weights.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/post_optimize_weights.cpp
@@ -45,6 +45,15 @@ void post_optimize_weights::optimize_weights(T& node, program& p) {
auto offsets = get_weights_bias_offset(node);
auto impl = node.get_selected_impl();
+ if (!impl && node.type() == gru_seq::type_id() && node.is_dynamic()) {
+ for (auto i = offsets.weights_offset; i < offsets.bias_offset; i++) {
+ auto& prev_node = node.get_dependency(i);
+ add_gru_weights_reorder(prev_node.id(), p, prev_node, node, i);
+ node.get_dependency(i).get_output_layout(false);
+ }
+ return;
+ }
+
// Skip load-time weights reordering if impl is not selected
if (!impl) {
return;
@@ -140,7 +149,7 @@ void post_optimize_weights::optimize_weights(T& node, program& p) {
} else if (node.type() == gru_seq::type_id()) {
program_node& prev_node = node.get_dependency(i);
if (i == 2 || i == 3) {
- add_gru_weights_reorder(prev_node.id(), weights_reorder_params, p, prev_node, node, i);
+ add_gru_weights_reorder(prev_node.id(), p, prev_node, node, i);
}
auto& weights_reorder_node = node.get_dependency(i);
weights_reorder_node.get_output_layout(false);
@@ -171,10 +180,13 @@ void post_optimize_weights::select_implementation(program& p, program_node& node
}
}
-void post_optimize_weights::add_gru_weights_reorder(primitive_id input_id, std::shared_ptr<WeightsReorderParams> reorder_params, program& p, \
- cldnn::program_node& prev, cldnn::program_node& node, size_t i) {
- OPENVINO_ASSERT(reorder_params != nullptr, "[GPU] WeightsReorderParams is not initialized.");
- std::string permute_id = input_id + "_permute" + to_string(i);
+void post_optimize_weights::add_gru_weights_reorder(primitive_id input_id,
+ program& p,
+ cldnn::program_node& prev,
+ cldnn::program_node& node,
+ size_t i) {
+ // Id is consumer specific so two sequences sharing one weight node do not reuse a connected permute.
+ std::string permute_id = input_id + "_" + node.id() + "_permute" + to_string(i);
std::vector<uint16_t> ord{0, 2, 1};
auto permute = std::make_shared<cldnn::permute>(permute_id, input_info{input_id}, ord);
auto& permute_node = p.get_or_create(permute);
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/gru_seq_onednn.cpp b/src/plugins/intel_gpu/src/graph/impls/onednn/gru_seq_onednn.cpp
index b9121a4fa1a..a52c2c7a929 100644
--- a/src/plugins/intel_gpu/src/graph/impls/onednn/gru_seq_onednn.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/gru_seq_onednn.cpp
@@ -120,13 +120,11 @@ protected:
auto initial_hidden_shape_mod = impl_params.get_input_layout(1).get_shape();
initial_hidden_shape_mod = { 1, num_dir, initial_hidden_shape_mod[0], initial_hidden_shape_mod[2] };
auto initial_hidden = onednn::layout_to_memory_desc(impl_params.get_input_layout(1).clone_with_other_shape(initial_hidden_shape_mod));
- auto W_shape_mod = impl_params.get_input_layout(2).get_shape();
- W_shape_mod = {1, num_dir, W_shape_mod[2], 3, W_shape_mod[1]/3};
+ auto W_shape_mod = ov::Shape{1, num_dir, src_shape[2], 3, initial_hidden_shape_mod[3]};
auto w_layout = impl_params.get_input_layout(2).clone_with_other_shape(W_shape_mod);
w_layout.format = cldnn::format::bfzyx;
auto W_md = onednn::layout_to_memory_desc(w_layout);
- auto R_shape_mod = impl_params.get_input_layout(3).get_shape();
- R_shape_mod = {1, num_dir, R_shape_mod[2], 3, R_shape_mod[1]/3};
+ auto R_shape_mod = ov::Shape{1, num_dir, initial_hidden_shape_mod[3], 3, initial_hidden_shape_mod[3]};
auto r_layout = impl_params.get_input_layout(3).clone_with_other_shape(R_shape_mod);
r_layout.format = cldnn::format::bfzyx;
auto R_md = onednn::layout_to_memory_desc(r_layout);
@@ -201,19 +199,18 @@ void save(BinaryOutputBuffer& ob) const override {
gru_desc_dir = dnnl::rnn_direction::bidirectional_concat;
num_dir = 2;
}
- auto mod_src_shape = impl_params->get_input_layout(0).get_shape();
+ const auto& src_shape = impl_params->get_input_layout(0).get_shape();
+ auto mod_src_shape = src_shape;
std::swap(mod_src_shape[0], mod_src_shape[1]);
auto input_md = onednn::layout_to_memory_desc(impl_params->get_input_layout(0).clone_with_other_shape(mod_src_shape), dnnl::memory::format_tag::abc);
auto initial_hidden_shape_mod = impl_params->get_input_layout(1).get_shape();
initial_hidden_shape_mod = {1, num_dir, initial_hidden_shape_mod[0], initial_hidden_shape_mod[2]};
auto initial_hidden_md = onednn::layout_to_memory_desc(impl_params->get_input_layout(1).clone_with_other_shape(initial_hidden_shape_mod));
- auto W_shape_mod = impl_params->get_input_layout(2).get_shape();
- W_shape_mod = {1, num_dir, W_shape_mod[1], 3, W_shape_mod[2]/3};
+ auto W_shape_mod = ov::Shape{1, num_dir, src_shape[2], 3, initial_hidden_shape_mod[3]};
auto w_layout = impl_params->get_input_layout(2).clone_with_other_shape(W_shape_mod);
w_layout.format = cldnn::format::bfzyx;
auto W_md = onednn::layout_to_memory_desc(w_layout);
- auto R_shape_mod = impl_params->get_input_layout(3).get_shape();
- R_shape_mod = {1, num_dir, R_shape_mod[1], 3, R_shape_mod[2]/3};
+ auto R_shape_mod = ov::Shape{1, num_dir, initial_hidden_shape_mod[3], 3, initial_hidden_shape_mod[3]};
auto r_layout = impl_params->get_input_layout(3).clone_with_other_shape(R_shape_mod);
r_layout.format = cldnn::format::bfzyx;
auto R_md = onednn::layout_to_memory_desc(r_layout);
diff --git a/src/plugins/intel_gpu/src/graph/include/pass_manager.h b/src/plugins/intel_gpu/src/graph/include/pass_manager.h
index 658e242ea99..c86259e71a6 100644
--- a/src/plugins/intel_gpu/src/graph/include/pass_manager.h
+++ b/src/plugins/intel_gpu/src/graph/include/pass_manager.h
@@ -218,7 +218,6 @@ private:
cldnn::program_node&,
size_t);
void add_gru_weights_reorder(primitive_id input_id,
- std::shared_ptr<WeightsReorderParams> reorder_params,
program& p,
cldnn::program_node&,
cldnn::program_node&,
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_data_bfyx_to_blocked_format.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_data_bfyx_to_blocked_format.cl
index 950c2d0cd2e..de1f71a31a5 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_data_bfyx_to_blocked_format.cl
+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_data_bfyx_to_blocked_format.cl
@@ -75,43 +75,15 @@ KERNEL (reorder_data_bfyx_to_blocked_format)(
const uint f = fsv + fs * FSV_ALIGNMENT;
#if DOUBLE_BLOCKED_FORMAT
- const uint bs = b / BSV_ALIGNMENT;
- const uint bsv = b % BSV_ALIGNMENT;
const uint x_pitch = BSV_ALIGNMENT * FSV_ALIGNMENT;
#else
const uint x_pitch = FSV_ALIGNMENT;
#endif
- const uint y_pitch = x_pitch * (OUTPUT_SIZE_X);
#if INPUT0_DIMS == 4
- #if DOUBLE_BLOCKED_FORMAT
- const uint bsv_pitch = FSV_ALIGNMENT;
- const uint fs_pitch = y_pitch * (OUTPUT_SIZE_Y);
- const uint bs_pitch = fs_pitch * (INPUT0_FEATURE_SLICE_NUM);
- const uint output_idx_tile = (bs * bs_pitch) + (fs * fs_pitch) + (y * y_pitch) + (x * x_pitch) + (bsv * bsv_pitch) + (fsv);
- #else
- #if FS_B_YX_FSV
- const uint b_pitch = y_pitch * (OUTPUT_SIZE_Y);
- const uint fs_pitch = b_pitch * (INPUT0_BATCH_NUM);
- #else
- const uint fs_pitch = y_pitch * (OUTPUT_SIZE_Y);
- const uint b_pitch = fs_pitch * (INPUT0_FEATURE_SLICE_NUM);
- #endif
- const uint output_idx_tile = (b * b_pitch) + (fs * fs_pitch) + (y * y_pitch) + (x * x_pitch) + (fsv);
- #endif
+ const uint output_idx_tile = OUTPUT_GET_INDEX(b, f, y, x);
#elif INPUT0_DIMS == 5
- #if DOUBLE_BLOCKED_FORMAT
- const uint bsv_pitch = FSV_ALIGNMENT;
- const uint z_pitch = y_pitch * (OUTPUT_SIZE_Y);
- const uint fs_pitch = z_pitch * (OUTPUT_SIZE_Z);
- const uint bs_pitch = fs_pitch * (INPUT0_FEATURE_SLICE_NUM);
- const uint output_idx_tile = (bs * bs_pitch) + (fs * fs_pitch) + (z * z_pitch) + (y * y_pitch) + (x * x_pitch) + (bsv * bsv_pitch) + (fsv);
- #else
- const uint z_pitch = y_pitch * (OUTPUT_SIZE_Y);
- const uint fs_pitch = z_pitch * (OUTPUT_SIZE_Z);
- const uint b_pitch = fs_pitch * (INPUT0_FEATURE_SLICE_NUM);
- const uint output_idx_tile = (b * b_pitch) + (fs * fs_pitch) + (z * z_pitch) + (y * y_pitch) + (x * x_pitch) + (fsv);
- #endif
+ const uint output_idx_tile = OUTPUT_GET_INDEX(b, f, z, y, x);
#endif
// get local buf offset
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel_bfyx_to_blocked_format.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel_bfyx_to_blocked_format.cpp
index 735e136496d..5cd101c34ed 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel_bfyx_to_blocked_format.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel_bfyx_to_blocked_format.cpp
@@ -189,10 +189,6 @@ JitConstants ReorderKernel_bfyx_to_blocked_format::GetJitConstants(const reorder
jit.AddConstant(MakeJitConstant("TILE_SIZE", tile_size));
jit.AddConstant(MakeJitConstant("FSV_ALIGNMENT", fsv_alignment));
- if (params.outputs[0].GetLayout() == DataLayout::fs_b_yx_fsv32) {
- jit.AddConstant(MakeJitConstant("FS_B_YX_FSV", 1));
- }
-
const bool is_double_blocked = params.outputs[0].GetLayout() == DataLayout::bs_fs_yx_bsv16_fsv16 ||
params.outputs[0].GetLayout() == DataLayout::bs_fs_yx_bsv16_fsv32 ||
params.outputs[0].GetLayout() == DataLayout::bs_fs_zyx_bsv16_fsv16 ||
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp
index 3a1ed4f0344..77a085d7f18 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp
@@ -55,11 +55,21 @@ namespace {
{{1, 1, 1}, {{1, 1, 1}}},
{{1}, {{1}}},
};
+ const std::vector<InputShape> input_shapes_b1_nontrivial = {
+ {{1, -1, 4}, {{1, 5, 4}}},
+ {{1, 1, 3}, {{1, 1, 3}}},
+ {{1}, {{1}}},
+ };
const std::vector<InputShape> input_shapes_bidirect_b1 = {
{{1, -1, 1}, {{1, 5, 1}}},
{{1, 2, 1}, {{1, 2, 1}}},
{{1}, {{1}}},
};
+ const std::vector<InputShape> input_shapes_bidirect_b1_nontrivial = {
+ {{1, -1, 4}, {{1, 5, 4}}},
+ {{1, 2, 3}, {{1, 2, 3}}},
+ {{1}, {{1}}},
+ };
std::vector<size_t> seq_lengths_zero_clip{2};
std::vector<size_t> seq_lengths_clip_non_zero{20};
std::vector<size_t> batch{10};
@@ -138,7 +148,7 @@ namespace {
INSTANTIATE_TEST_SUITE_P(smoke_GRUSequenceCommonZeroClip_B1, GRUSequenceTest,
::testing::Combine(
::testing::ValuesIn(mode_onednn),
- ::testing::Values(input_shapes_b1),
+ ::testing::Values(input_shapes_b1, input_shapes_b1_nontrivial),
// ::testing::ValuesIn(input_size), // hardcoded to 10 due to Combine supports up to 10 args
::testing::ValuesIn(activations_onednn),
::testing::ValuesIn(clip),
@@ -152,7 +162,7 @@ namespace {
INSTANTIATE_TEST_SUITE_P(smoke_GRUSequenceCommonZeroClipBidirect_B1, GRUSequenceTest,
::testing::Combine(
::testing::ValuesIn(mode_onednn),
- ::testing::Values(input_shapes_bidirect_b1),
+ ::testing::Values(input_shapes_bidirect_b1, input_shapes_bidirect_b1_nontrivial),
// ::testing::ValuesIn(input_size), // hardcoded to 10 due to Combine supports up to 10 args
::testing::ValuesIn(activations_onednn),
::testing::ValuesIn(clip),
diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/weights_reorder_factory_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/weights_reorder_factory_test.cpp
index bb695274bba..19915c37e94 100644
--- a/src/plugins/intel_gpu/tests/unit/module_tests/weights_reorder_factory_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/module_tests/weights_reorder_factory_test.cpp
@@ -15,12 +15,46 @@
#include "fully_connected_inst.h"
#include "registry/registry.hpp"
#include "graph/impls/ocl/register.hpp"
+#include "intel_gpu/graph/serialization/weights_reorder_params.hpp"
#include <memory>
using namespace cldnn;
using namespace ::tests;
+#ifdef ENABLE_ONEDNN_FOR_GPU
+TEST(weights_factory, onednn_memory_descriptors_are_part_of_cache_identity) {
+ const auto weights_layout = layout{ov::PartialShape{2, 16, 3, 3}, data_types::f16, format::bfyx};
+ const auto plain_desc = dnnl::memory::desc({2, 16, 3, 3},
+ dnnl::memory::data_type::f16,
+ dnnl::memory::format_tag::abcd);
+ const auto transposed_desc = dnnl::memory::desc({2, 16, 3, 3},
+ dnnl::memory::data_type::f16,
+ dnnl::memory::format_tag::acdb);
+
+ const cldnn::onednn::WeightsReorderParamsOneDNN plain(weights_layout,
+ weights_layout,
+ plain_desc,
+ plain_desc,
+ false);
+ const cldnn::onednn::WeightsReorderParamsOneDNN same(weights_layout,
+ weights_layout,
+ plain_desc,
+ plain_desc,
+ false);
+ const cldnn::onednn::WeightsReorderParamsOneDNN different(weights_layout,
+ weights_layout,
+ plain_desc,
+ transposed_desc,
+ false);
+
+ EXPECT_TRUE(plain == same);
+ EXPECT_EQ(plain.hash(), same.hash());
+ EXPECT_FALSE(plain == different);
+ EXPECT_NE(plain.hash(), different.hash());
+}
+#endif
+
TEST(weights_factory, reorder_test) {
auto& engine = get_test_engine();
tests::random_generator rg(GET_SUITE_NAME);
diff --git a/src/plugins/intel_gpu/tests/unit/passes/post_optimize_weights.cpp b/src/plugins/intel_gpu/tests/unit/passes/post_optimize_weights.cpp
index b7f9d6e2826..9f01ae6169f 100644
--- a/src/plugins/intel_gpu/tests/unit/passes/post_optimize_weights.cpp
+++ b/src/plugins/intel_gpu/tests/unit/passes/post_optimize_weights.cpp
@@ -6,6 +6,7 @@
#include "program_wrapper.h"
#include "fully_connected_inst.h"
#include "convolution_inst.h"
+#include "gru_seq_inst.h"
#ifdef ENABLE_ONEDNN_FOR_GPU
#include "graph/impls/onednn/utils.hpp"
#endif
@@ -13,6 +14,54 @@
using namespace cldnn;
using namespace ::tests;
+TEST(post_optimize_weights, dynamic_gru_weights_are_permuted) {
+ auto& engine = get_test_engine();
+
+ auto hidden = engine.allocate_memory({ov::PartialShape{1, 1, 3}, data_types::f16, format::bfyx});
+ auto weights = engine.allocate_memory({ov::PartialShape{1, 9, 4}, data_types::f16, format::bfyx});
+ auto recurrent = engine.allocate_memory({ov::PartialShape{1, 9, 3}, data_types::f16, format::bfyx});
+ auto bias = engine.allocate_memory({ov::PartialShape{1, 12}, data_types::f16, format::bfyx});
+ auto sequence_lengths = engine.allocate_memory({ov::PartialShape{1}, data_types::i32, format::bfyx});
+
+ gru_seq gru("gru",
+ input_info("input"),
+ input_info("hidden"),
+ input_info(),
+ input_info("weights"),
+ input_info("recurrent"),
+ input_info("bias"),
+ input_info("sequence_lengths"),
+ 0.f,
+ false,
+ {activation_func::logistic, activation_func::hyperbolic_tan},
+ {},
+ lstm_weights_order::iofz,
+ ov::op::RecurrentSequenceDirection::FORWARD,
+ 2);
+ gru.linear_before_reset = true;
+
+ topology topology(input_layout("input", {ov::PartialShape{1, -1, 4}, data_types::f16, format::bfyx}),
+ data("hidden", hidden),
+ data("weights", weights),
+ data("recurrent", recurrent),
+ data("bias", bias),
+ data("sequence_lengths", sequence_lengths),
+ gru);
+
+ 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));
+ auto prog = program::build_program(engine, topology, config, false, true);
+
+ reorder_factory rf;
+ program_wrapper::apply_opt_pass<compile_graph>(*prog);
+ program_wrapper::apply_opt_pass<post_optimize_weights>(*prog, rf);
+
+ auto& gru_node = prog->get_node("gru");
+ EXPECT_EQ(gru_node.get_dependency(2).get_output_layout().get_shape(), ov::Shape({1, 4, 9}));
+ EXPECT_EQ(gru_node.get_dependency(3).get_output_layout().get_shape(), ov::Shape({1, 3, 9}));
+}
+
TEST(post_optimize_weights, fuse_reorder_to_weights_reorder_test) {
auto& engine = get_test_engine();
diff --git a/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp
index c480bcce66a..3f0c52ea736 100644
--- a/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp
@@ -1740,6 +1740,71 @@ TEST(prepare_buffer_fusing, in_place_onednn_concat_static) {
}
#endif // ENABLE_ONEDNN_FOR_GPU
+TEST(prepare_buffer_fusing, in_place_concat_dynamic_bfyx_to_fsv16_reorder_feature_padding) {
+ // Runtime in-place concat gives the second producer a lower feature padding, which the static
+ // path rejects, so only the shape agnostic kernel sees it. With batch > 1 it must span padded
+ // feature slices instead of overwriting batch 0.
+ auto& engine = get_test_engine();
+ tests::random_generator rg(GET_SUITE_NAME);
+
+ const size_t batch = 2, feature = 16, y_size = 4, x_size = 8;
+ auto dyn_layout = layout{ov::PartialShape::dynamic(4), data_types::f32, format::bfyx};
+ auto in_layout = layout{ov::PartialShape{2, 16, 4, 8}, data_types::f32, format::bfyx};
+
+ topology topology;
+ topology.add(input_layout("input1", dyn_layout));
+ topology.add(input_layout("input2", dyn_layout));
+ topology.add(reorder("input1_fsv16", input_info("input1"), format::b_fs_yx_fsv16, data_types::f32));
+ topology.add(reorder("input2_fsv16", input_info("input2"), format::b_fs_yx_fsv16, data_types::f32));
+ topology.add(concatenation("concat", {input_info("input1_fsv16"), input_info("input2_fsv16")}, 1));
+ topology.add(reorder("output", input_info("concat"), format::bfyx, data_types::f32));
+
+ 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));
+ // In-place concat rejects batch > 1 when the producers prefer onednn, so pin them to the ocl
+ // path. The kernel itself is still chosen by the selector and asserted on below.
+ ov::intel_gpu::ImplementationDesc ocl_reorder = {format::b_fs_yx_fsv16, "", impl_types::ocl};
+ config.set_property(ov::intel_gpu::force_implementations(
+ ov::intel_gpu::ImplForcingMap{{"input1_fsv16", ocl_reorder}, {"input2_fsv16", ocl_reorder}}));
+
+ network net(engine, topology, config);
+
+ auto input_memory1 = engine.allocate_memory(in_layout);
+ auto input_memory2 = engine.allocate_memory(in_layout);
+ auto input1_vals = rg.generate_random_1d<float>(in_layout.count(), -10, 10);
+ auto input2_vals = rg.generate_random_1d<float>(in_layout.count(), -10, 10);
+ set_values(input_memory1, input1_vals);
+ set_values(input_memory2, input2_vals);
+
+ net.set_input_data("input1", input_memory1);
+ net.set_input_data("input2", input_memory2);
+
+ std::map<cldnn::primitive_id, cldnn::network_output> output;
+ EXPECT_NO_THROW(output = net.execute());
+ ASSERT_TRUE(net.get_primitive("concat")->can_be_optimized());
+
+ // The padded producer must really run the tiled kernel, otherwise this is not a regression.
+ auto* padded_impl = net.get_primitive("input2_fsv16")->get_impl();
+ ASSERT_TRUE(padded_impl != nullptr);
+ ASSERT_NE(padded_impl->get_kernel_name().find("reorder_data_bfyx_to_blocked_format"), std::string::npos);
+
+ auto out_mem = output.at("output").get_memory();
+ cldnn::mem_lock<float> output_ptr(out_mem, get_test_stream());
+ ASSERT_EQ(out_mem->count(), input1_vals.size() + input2_vals.size());
+
+ const size_t per_batch_in = feature * y_size * x_size;
+ const size_t per_batch_out = 2 * per_batch_in;
+ for (size_t b = 0; b < batch; ++b) {
+ for (size_t i = 0; i < per_batch_in; ++i) {
+ ASSERT_EQ(output_ptr[b * per_batch_out + i], input1_vals[b * per_batch_in + i])
+ << "input1 b=" << b << " i=" << i;
+ ASSERT_EQ(output_ptr[b * per_batch_out + per_batch_in + i], input2_vals[b * per_batch_in + i])
+ << "input2 b=" << b << " i=" << i;
+ }
+ }
+}
+
TEST(prepare_buffer_fusing, in_place_concat_with_fsv32_to_fsv16_reorder_regression) {
// Regression test for fsv32->fsv16 reorder + in-place concat path.
// Keep in-place enabled, then verify buffer sharing and output channel order.