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] Align INT4 FC weights for oneDNN (#39073)
Mingyu Kim4883e74c3b76
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_padding.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_padding.cppindex 4bba0a844f1..fc136156971 100644--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_padding.cpp+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_padding.cpp@@ -24,19 +24,24 @@ void prepare_padding::run(program& p) {auto& weight_node = node->get_dependency(1);if (weight_node.is_constant()) {- const size_t alignment = 2;auto weight_layout = weight_node.get_output_layout(false);const auto const_shape = weight_layout.get_partial_shape().to_shape();OPENVINO_ASSERT(!const_shape.empty(), "Data padding for int4 type data with an odd innermost dimension does not support zero dimension.");auto inner_most_idx = node->as<fully_connected>().get_primitive()->weights_rank - 1;+ bool is_k_odd = const_shape[inner_most_idx] % 2 != 0;+ const bool is_onednn_int4 = node->get_preferred_impl_type() == impl_types::onednn &&+ weight_node.is_type<data>() &&+ (weight_layout.data_type == cldnn::data_types::u4 ||+ weight_layout.data_type == cldnn::data_types::i4);++ if (is_onednn_int4) {+ // Align odd packed int4 weight rows to 4 bytes for oneDNN FC performance.+ const size_t weight_alignment = 8;+ const auto weight_padding = (weight_alignment - const_shape[inner_most_idx] % weight_alignment) % weight_alignment;+ if (is_k_odd) {+ std::vector<ov::Dimension::value_type> new_paddings(const_shape.size(), 0);+ new_paddings[inner_most_idx] = static_cast<ov::Dimension::value_type>(weight_padding);- if (const_shape[inner_most_idx] % alignment != 0) {- std::vector<ov::Dimension::value_type> new_paddings(const_shape.size(), 0);- new_paddings[inner_most_idx] = 1;-- if (node->get_preferred_impl_type() == impl_types::onednn && weight_node.is_type<data>() &&- (weight_node.get_output_layout(false).data_type == cldnn::data_types::u4 ||- weight_node.get_output_layout(false).data_type == cldnn::data_types::i4)) {auto weight_in_layout = weight_layout.convert_to_weights_layout(false);auto weight_out_layout = weight_in_layout;weight_out_layout.data_padding = padding::max(weight_out_layout.data_padding, padding({0}, new_paddings));@@ -45,7 +50,49 @@ void prepare_padding::run(program& p) {auto& new_reorder_node = p.get_or_create(new_reorder);p.add_intermediate(new_reorder_node, *node, weight_node, new_reorder_node.get_dependencies().empty());new_reorder_node.recalc_output_layouts(false);- } else if (node->get_preferred_impl_type() == impl_types::ocl &&++ // Align activation rows to 4 bytes alongside the int4 weights.+ // This will cause some amount of runtime performance overhead.+ // However, this is necessary to avoid ref kernel selection, and to take advantage of block loading instruction of xe2+ architecture.+ // In the future, we may back-propagate padding information to the producer so that it generates padded result directly.+ const auto input_layout = node->get_input_layout(0);+ const auto input_shape = input_layout.get_partial_shape();+ const auto input_element_size = data_type_traits::size_of(input_layout.data_type);+ bool activation_aligned = input_element_size % 4 == 0;+ if (!activation_aligned && input_shape.size() == 2) { // Limited to 2d activation only, because it is the only validated path.+ const auto input_feature_idx = input_shape.size() - 1;+ if (input_shape[input_feature_idx].is_static()) {+ const auto input_alignment = 4 / input_element_size;+ const auto row_size = input_shape[input_feature_idx].get_length() ++ input_layout.data_padding._lower_size[input_feature_idx] ++ input_layout.data_padding._upper_size[input_feature_idx];+ const auto input_padding = (input_alignment - row_size % input_alignment) % input_alignment;+ activation_aligned = input_padding == 0;+ if (!activation_aligned) {+ auto input0_new_layout = input_layout;+ std::vector<ov::Dimension::value_type> input_paddings(input_shape.size(), 0);+ input_paddings[input_feature_idx] = input_layout.data_padding._upper_size[input_feature_idx] + input_padding;+ input0_new_layout.data_padding = padding::max(input0_new_layout.data_padding, padding({0}, input_paddings));+ auto new_input_reorder = std::make_shared<reorder>("padding_reorder_for_" + node->get_dependency(0).id(),+ input_info(node->get_dependency(0).id()),+ input0_new_layout);+ auto& new_input_reorder_node = p.get_or_create(new_input_reorder);+ p.add_intermediate(new_input_reorder_node, *node, node->get_dependency(0), new_input_reorder_node.get_dependencies().empty());+ new_input_reorder_node.recalc_output_layouts(false);+ activation_aligned = true;+ }+ }+ }+ if (!activation_aligned) {+ GPU_DEBUG_INFO << "[WARNING] " << node->id() << ": INT4 weights were padded, but activation padding was not added. Input layout: "+ << input_layout.to_short_string() << std::endl;+ }+ }+ } else if (is_k_odd) {+ std::vector<ov::Dimension::value_type> new_paddings(const_shape.size(), 0);+ new_paddings[inner_most_idx] = 1;++ if (node->get_preferred_impl_type() == impl_types::ocl &&p.get_config().get_force_implementations().find(node->id()) == p.get_config().get_force_implementations().end() &&node->get_input_layout(0).data_type == cldnn::data_types::f16 && node->get_input_layout(0).format == cldnn::format::bfyx &&node->get_input_layout(0).get_partial_shape()[1].is_static() && // feature dim of input should be staticdiff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.cpp b/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.cppindex cf180dae74b..c46c64cb689 100644--- a/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.cpp@@ -186,7 +186,12 @@ protected:weights_md = onednn::layout_to_memory_desc(weights_layout, weights_fmt);}- dnnl::memory::desc input_md = onednn::layout_to_memory_desc(input_layout, target_fmt);+ dnnl::memory::desc input_md;+ if (input_layout.data_padding && format::is_default_format(input_layout.format)) {+ input_md = onednn::layout_to_memory_desc_strides(input_layout, target_fmt);+ } else {+ input_md = onednn::layout_to_memory_desc(input_layout, target_fmt);+ }dnnl::memory::desc output_md = onednn::layout_to_memory_desc(output_layout, target_fmt);if (has_bias) {diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cppindex f13ea6d63af..09db044101c 100644--- a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp@@ -483,8 +483,9 @@ private:switch (fmt) {case dnnl::memory::format_tag::ab:+ strides.push_back(std::accumulate(padded_dims.begin() + 1, padded_dims.end(), int64_t{1},+ [](int64_t stride, int64_t dim) { return stride * dim; }));strides.push_back(1);- strides.push_back(padded_dims[0]);break;case dnnl::memory::format_tag::abc:diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights_int4.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights_int4.clindex 9332c491b3d..6885c1e436a 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights_int4.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights_int4.cl@@ -10,6 +10,10 @@ KERNEL(reorder_weights_int4)(const __global INPUT0_TYPE* input, __global OUTPUT_const uint output_index = out_byte_offset * 2;const uint w = output_index % OUTPUT_INNERMOST_NUM;const uint h = output_index / OUTPUT_INNERMOST_NUM;+ if (w >= INPUT0_INNERMOST_NUM) {+ output[out_byte_offset] = 0;+ return;+ }const uint in_byte_offset = (h * INPUT0_INNERMOST_NUM + w) / 2;const bool within_pitch = (w + 1 < INPUT0_INNERMOST_NUM);diff --git a/src/plugins/intel_gpu/tests/unit/onednn/utils_test.cpp b/src/plugins/intel_gpu/tests/unit/onednn/utils_test.cppindex f4a21545b7e..9677e2754b4 100644--- a/src/plugins/intel_gpu/tests/unit/onednn/utils_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/onednn/utils_test.cpp@@ -419,6 +419,17 @@ TEST_F(test_layout_to_memory_desc, strides_with_padding) {EXPECT_GT(strides[2], 56); // Stride should account for padding}+TEST_F(test_layout_to_memory_desc, fc_source_stride_with_feature_padding) {+ layout l = layout{ov::PartialShape{32, 9}, data_types::f16, format::bfyx};+ l.data_padding = padding{{0, 0}, {0, 1}};++ auto desc = layout_to_memory_desc_strides(l, dnnl::memory::format_tag::ab);+ const auto strides = desc.get_strides();++ EXPECT_EQ(desc.get_dims(), (dnnl::memory::dims{32, 9}));+ EXPECT_EQ(strides, (dnnl::memory::dims{10, 1}));+}+TEST_F(test_layout_to_memory_desc, strides_cannot_flatten) {layout l = layout{ov::PartialShape{1, 64, 56, 56}, data_types::f32, format::bfyx};l.data_padding = padding{{0, 0, 1, 1}, {0, 0, 1, 1}};diff --git a/src/plugins/intel_gpu/tests/unit/passes/prepare_padding_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/prepare_padding_test.cppindex c8a3bce1010..981bdde8c4c 100644--- a/src/plugins/intel_gpu/tests/unit/passes/prepare_padding_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/passes/prepare_padding_test.cpp@@ -7,6 +7,7 @@#include "intel_gpu/runtime/engine.hpp"#include "intel_gpu/graph/program.hpp"+#include "intel_gpu/primitives/fully_connected.hpp"#include "data_inst.h"#include "mvn_inst.h"#include "col2im_inst.h"@@ -43,6 +44,100 @@ TEST(prepare_padding, groupconv_with_output) {ASSERT_EQ(params->get_output_layout().data_padding._upper_size[2 + 0], 2);}+TEST(prepare_padding, onednn_int4_fc_aligns_rows_to_4_bytes) {+ auto& engine = get_test_engine();+ auto input_mem = engine.allocate_memory({{32, 9}, data_types::f16, format::bfyx});+ auto weights_mem = engine.allocate_memory({{4, 9}, data_types::u4, format::bfyx});++ topology topo;+ topo.add(input_layout("input", input_mem->get_layout()));+ topo.add(data("weights", weights_mem));+ topo.add(fully_connected("fc", input_info("input"), "weights", "", 2, 2));++ ExecutionConfig config = get_test_default_config(engine);+ config.set_property(ov::intel_gpu::force_implementations(+ ov::intel_gpu::ImplForcingMap{{"fc", {format::bfyx, "", impl_types::onednn}}}));+ auto prog = program::build_program(engine, topo, config, false, true);++ prog->get_node("fc").set_preferred_impl_type(impl_types::onednn);+ program_wrapper::apply_opt_pass<prepare_padding>(*prog, false);++ const auto& input_reorder = prog->get_node("padding_reorder_for_input");+ const auto& weights_reorder = prog->get_node("padding_reorder_for_weights");+ EXPECT_EQ(input_reorder.get_output_layout(false).data_padding._upper_size[1], 1);+ EXPECT_EQ(weights_reorder.get_output_layout(false).data_padding._upper_size[1], 7);+}++TEST(prepare_padding, onednn_int4_fc_does_not_pad_f32_activation) {+ auto& engine = get_test_engine();+ auto weights_mem = engine.allocate_memory({{4, 9}, data_types::u4, format::bfyx});++ topology topo;+ topo.add(input_layout("input", layout{{32, 9}, data_types::f32, format::bfyx}));+ topo.add(data("weights", weights_mem));+ topo.add(fully_connected("fc", input_info("input"), "weights", "", 2, 2));++ auto prog = program::build_program(engine, topo, get_test_default_config(engine), false, true);+ prog->get_node("fc").set_preferred_impl_type(impl_types::onednn);+ program_wrapper::apply_opt_pass<prepare_padding>(*prog, false);++ const auto& fc = prog->get_node("fc");+ EXPECT_EQ(fc.get_dependency(0).id(), "input");+ EXPECT_FALSE(fc.get_input_layout(0).data_padding);+ EXPECT_EQ(fc.get_input_layout(1).data_padding._upper_size[1], 7);+}++TEST(prepare_padding, onednn_int4_fc_does_not_pad_even_k) {+ auto& engine = get_test_engine();+ for (const int64_t k : {10, 12, 14, 16}) {+ SCOPED_TRACE(k);+ auto weights_mem = engine.allocate_memory({{4, k}, data_types::u4, format::bfyx});++ topology topo;+ topo.add(input_layout("input", layout{{32, k}, data_types::f16, format::bfyx}));+ topo.add(data("weights", weights_mem));+ topo.add(fully_connected("fc", input_info("input"), "weights", "", 2, 2));++ auto prog = program::build_program(engine, topo, get_test_default_config(engine), false, true);+ prog->get_node("fc").set_preferred_impl_type(impl_types::onednn);+ program_wrapper::apply_opt_pass<prepare_padding>(*prog, false);++ const auto& fc = prog->get_node("fc");+ EXPECT_EQ(fc.get_dependency(0).id(), "input");+ EXPECT_EQ(fc.get_dependency(1).id(), "weights");+ EXPECT_FALSE(fc.get_input_layout(0).data_padding);+ EXPECT_FALSE(fc.get_input_layout(1).data_padding);+ }+}++TEST(prepare_padding, onednn_int4_fc_aligns_existing_activation_padding) {+ auto& engine = get_test_engine();+ auto weights_mem = engine.allocate_memory({{4, 9}, data_types::u4, format::bfyx});+ for (const int64_t upper_pad : {1, 2, 3}) {+ SCOPED_TRACE(upper_pad);+ const layout in_layout{{32, 9}, data_types::f16, format::bfyx, padding({0}, {0, upper_pad})};++ topology topo;+ topo.add(input_layout("input", in_layout));+ topo.add(data("weights", weights_mem));+ topo.add(fully_connected("fc", input_info("input"), "weights", "", 2, 2));++ auto prog = program::build_program(engine, topo, get_test_default_config(engine), false, true);+ prog->get_node("fc").set_preferred_impl_type(impl_types::onednn);+ program_wrapper::apply_opt_pass<prepare_padding>(*prog, false);++ const auto& fc = prog->get_node("fc");+ if (upper_pad % 2 != 0) {+ EXPECT_EQ(fc.get_dependency(0).id(), "input");+ EXPECT_EQ(fc.get_input_layout(0), in_layout);+ } else {+ EXPECT_EQ(fc.get_dependency(0).id(), "padding_reorder_for_input");+ EXPECT_EQ(fc.get_input_layout(0).data_padding._upper_size[1], upper_pad + 1);+ }+ EXPECT_EQ(fc.get_input_layout(1).data_padding._upper_size[1], 7);+ }+}+TEST(prepare_padding, mvn_conv) {tests::random_generator rg(GET_SUITE_NAME);auto& engine = get_test_engine();diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cppindex 18831e38c18..64eb8144c40 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp@@ -7007,3 +7007,128 @@ TEST(fully_connected_gpu_ternocl_int2_dynamic, non_ternary_zero_point_falls_backnet->execute();ASSERT_NE(net->get_primitive("fc_prim")->get_impl()->get_kernel_name(), "ternocl_int2");}++#ifdef ENABLE_ONEDNN_FOR_GPU+namespace {+struct onednn_int4_fc_params {+ size_t k;+ bool is_3d;+ bool is_u4;+ bool expect_onednn;+ bool is_f32 = false;+};++class fully_connected_onednn_int4_alignment : public ::testing::TestWithParam<onednn_int4_fc_params> {+public:+ static std::string GetTestCaseName(const testing::TestParamInfo<onednn_int4_fc_params>& obj) {+ const auto& p = obj.param;+ return std::string(p.is_u4 ? "u4" : "i4") + "_k" + std::to_string(p.k) + (p.is_3d ? "_3d" : "_2d") + (p.is_f32 ? "_f32" : "_f16");+ }+};++template <typename T>+void run_onednn_int4_fc_alignment(const onednn_int4_fc_params& p) {+ auto& engine = get_test_engine();+ if (!engine.get_device_info().supports_immad)+ GTEST_SKIP() << "oneDNN INT4 FC requires XMX";++ tests::random_generator rg(GET_SUITE_NAME);+ constexpr size_t rows = 32;+ constexpr size_t ofm = 32;+ const size_t k = p.k;+ const int zero_point = p.is_u4 ? 8 : 0;+ const float scale_value = 1.0f / 16;+ const auto activation_type = p.is_f32 ? data_types::f32 : data_types::f16;++ const auto in_shape = p.is_3d ? ov::PartialShape{2, static_cast<int64_t>(rows / 2), static_cast<int64_t>(k)}+ : ov::PartialShape{static_cast<int64_t>(rows), static_cast<int64_t>(k)};+ auto input_mem = engine.allocate_memory({in_shape, activation_type, format::bfyx});+ auto weights_mem = engine.allocate_memory({ov::PartialShape{static_cast<int64_t>(ofm), static_cast<int64_t>(k)},+ p.is_u4 ? data_types::u4 : data_types::i4, format::bfyx});+ auto scale_mem = engine.allocate_memory({ov::PartialShape{static_cast<int64_t>(ofm), 1}, data_types::f16, format::bfyx});++ auto input = rg.generate_random_1d<T>(rows * k, -1.0f, 1.0f);+ std::vector<uint8_t> weights((ofm * k + 1) / 2);+ for (size_t i = 0; i < weights.size(); ++i)+ weights[i] = static_cast<uint8_t>((i * 5 + 3) % 16 | ((i * 7 + 1) % 16) << 4);+ set_values(input_mem, input);+ set_values(weights_mem, weights);+ set_values(scale_mem, std::vector<ov::float16>(ofm, ov::float16(scale_value)));++ topology topo;+ topo.add(input_layout("input", input_mem->get_layout()));+ topo.add(data("weights", weights_mem));+ topo.add(data("scale", scale_mem));+ if (p.is_u4) {+ auto zp_mem = engine.allocate_memory({ov::PartialShape{1, 1}, data_types::u8, format::bfyx});+ set_values<uint8_t>(zp_mem, {static_cast<uint8_t>(zero_point)});+ topo.add(data("zp", zp_mem));+ }+ auto fc = fully_connected("fc", input_info("input"), "weights", "", "scale", p.is_u4 ? "zp" : "", activation_type, in_shape.size(), 2);+ if (p.is_u4)+ fc.decompression_zero_point_scalar = zero_point;+ topo.add(fc);++ auto config = get_test_default_config(engine);+ config.set_property(ov::intel_gpu::optimize_data(true));+ config.set_property(ov::intel_gpu::force_implementations(+ ov::intel_gpu::ImplForcingMap{{"fc", {format::bfyx, "", impl_types::onednn}}}));+ network net(engine, topo, config);+ net.set_input_data("input", input_mem);+ auto outputs = net.execute();++ const auto impl = net.get_primitive("fc")->get_impl();+ if (!p.is_3d) {+ ASSERT_TRUE(impl->is_onednn());+ }+ if (p.expect_onednn) {+ EXPECT_EQ(impl->get_kernel_name().find("ref"), std::string::npos) << "oneDNN kernel: " << impl->get_kernel_name();+ }++ auto output_mem = outputs.at("fc").get_memory();+ cldnn::mem_lock<T, mem_lock_type::read> output(output_mem, get_test_stream());+ ASSERT_EQ(output.size(), rows * ofm);+ for (size_t r = 0; r < rows; ++r) {+ for (size_t n = 0; n < ofm; ++n) {+ float expected = 0.0f;+ for (size_t c = 0; c < k; ++c) {+ const auto index = n * k + c;+ int w = (weights[index / 2] >> (4 * (index % 2))) & 0xf;+ if (!p.is_u4 && w >= 8)+ w -= 16;+ expected += static_cast<float>(input[r * k + c]) * static_cast<float>(w - zero_point) * scale_value;+ }+ ASSERT_NEAR(static_cast<float>(output[r * ofm + n]), expected, 0.1f) << "row=" << r << ", ofm=" << n;+ }+ }+}++TEST_P(fully_connected_onednn_int4_alignment, compare_with_host_reference) {+ const auto p = GetParam();+ if (p.is_f32)+ run_onednn_int4_fc_alignment<float>(p);+ else+ run_onednn_int4_fc_alignment<ov::float16>(p);+}++INSTANTIATE_TEST_SUITE_P(smoke,+ fully_connected_onednn_int4_alignment,+ ::testing::Values(onednn_int4_fc_params{9, false, true, true},+ onednn_int4_fc_params{9, false, false, true},+ onednn_int4_fc_params{33, false, true, true},+ onednn_int4_fc_params{33, false, false, true},+ onednn_int4_fc_params{11, false, true, true},+ onednn_int4_fc_params{11, false, false, true},+ onednn_int4_fc_params{13, false, true, true},+ onednn_int4_fc_params{13, false, false, true},+ onednn_int4_fc_params{15, false, true, true},+ onednn_int4_fc_params{15, false, false, true},+ onednn_int4_fc_params{10, false, true, false},+ onednn_int4_fc_params{10, false, false, false},+ onednn_int4_fc_params{9, false, true, false, true},+ onednn_int4_fc_params{9, false, false, false, true},+ onednn_int4_fc_params{9, true, true, false},+ onednn_int4_fc_params{33, true, false, false}),+ fully_connected_onednn_int4_alignment::GetTestCaseName);+} // namespace+#endifdiff --git a/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cppindex 7f70d90c2cc..4bbfae674c1 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp@@ -5053,12 +5053,9 @@ static void run_reorder_weight_int4(const ov::Shape in_shape, const std::vector<layout in_layout({in_shape, data_types::i4, format::bfyx});auto input = engine.allocate_memory(in_layout);- std::vector<uint8_t> input_data = {- 0x21, 0x43, 0x65, 0x87, 0xa9, 0xcb, 0xed,- 0x1f, 0x25, 0x83, 0x2a, 0x7d, 0x9f, 0xe8,- 0x21, 0x43, 0x65, 0x87, 0xa9, 0xcb, 0xed,- 0x1f, 0x25, 0x83, 0x2a, 0x7d, 0x9f, 0xe8- };+ std::vector<uint8_t> input_data(in_layout.bytes_count());+ for (size_t i = 0; i < input_data.size(); ++i)+ input_data[i] = static_cast<uint8_t>(i * 37 + 0x21);set_values(input, input_data);@@ -5085,16 +5082,18 @@ static void run_reorder_weight_int4(const ov::Shape in_shape, const std::vector<auto output = outputs.begin()->second.get_memory();- std::vector<uint8_t> expected_data = {- 0x21, 0x43, 0x65, 0x07,- 0x98, 0xba, 0xdc, 0x0e,- 0x1f, 0x25, 0x83, 0x0a,- 0xd2, 0xf7, 0x89, 0x0e,- 0x21, 0x43, 0x65, 0x07,- 0x98, 0xba, 0xdc, 0x0e,- 0x1f, 0x25, 0x83, 0x0a,- 0xd2, 0xf7, 0x89, 0x0e- };+ const auto row_size = in_shape.back();+ const auto padded_row_size = row_size + upper_size.back();+ const auto rows = in_layout.count() / row_size;+ std::vector<uint8_t> expected_data(rows * padded_row_size / 2, 0);+ for (size_t row = 0; row < rows; ++row) {+ for (size_t col = 0; col < row_size; ++col) {+ const auto input_index = row * row_size + col;+ const auto value = (input_data[input_index / 2] >> (4 * (input_index % 2))) & 0x0f;+ const auto output_index = row * padded_row_size + col;+ expected_data[output_index / 2] |= value << (4 * (output_index % 2));+ }+ }cldnn::mem_lock<uint8_t> output_ptr(output, get_test_stream());@@ -5119,6 +5118,17 @@ TEST(reorder_weight_gpu_i4, reorder_for_padding_4d)run_reorder_weight_int4({2, 2, 2, 7}, {0, 0, 0, 1});}+TEST(reorder_weight_gpu_i4, reorder_for_padding_alignment_8)+{+ for (const size_t k : {1, 3, 5, 7, 9, 11, 13, 15}) {+ SCOPED_TRACE(k);+ const auto pad = static_cast<ov::Dimension::value_type>(8 - k % 8);+ run_reorder_weight_int4({3, k}, {0, pad});+ run_reorder_weight_int4({2, 2, k}, {0, 0, pad});+ run_reorder_weight_int4({2, 2, 2, k}, {0, 0, 0, pad});+ }+}+template <typename T>static void run_reorder_uint4(const ov::Shape in_shape) {auto& engine = get_test_engine();