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] Fix bug causing failure to create some oneDNN primitive descrip… (#31466)
Jade Chofe7612a58d6a
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.cppindex c7296ea35b8..f339d937b74 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@@ -109,6 +109,8 @@ void post_optimize_weights::optimize_weights(T& node, program& p) {if (onednn_weights_params &&(updated_input_layout.format != onednn::find_data_format(onednn_weights_params->_in_desc) ||onednn::convert_data_type(updated_input_layout.data_type) != onednn_weights_params->_in_desc.get_data_type())) {+ auto shape_consistent = onednn::keep_weights_reorder_shape_consistent(updated_input_layout, onednn_weights_params->_out_desc);+ OPENVINO_ASSERT(shape_consistent, "[GPU] Input shape and output shape of weight reorder should be same.");onednn_weights_params->_in_desc = onednn::layout_to_memory_desc(updated_input_layout);}#endif // ENABLE_ONEDNN_FOR_GPUdiff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_quantization.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_quantization.cppindex 566d822c663..9f67ec1d2f9 100644--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_quantization.cpp+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_quantization.cpp@@ -52,6 +52,7 @@ void prepare_quantization::prepare_scale_shift_opt(program &p, quantize_node& quauto mem_output_high = output_high.get_attached_memory_ptr();auto scales_layout = mem_input_low->get_layout();+auto max_size = tensor(0);max_size = tensor::max(max_size, mem_input_high->get_layout().get_tensor());max_size = tensor::max(max_size, mem_output_low->get_layout().get_tensor());@@ -59,6 +60,24 @@ void prepare_quantization::prepare_scale_shift_opt(program &p, quantize_node& quscales_layout.set_tensor(max_size);+ // cldnn::layout::set_tensor() internally uses cldnn::format::dimension()+ // to determine the tensor rank according to the format set.+ // Because cldnn::format requires at least 4 dimensions, scales_layout is treated as a 4D tensor.+ // If scales_layout was promoted from 3D to 4D due to format constraints, revert it back to its original 3D shape.+ if (p.get_engine().get_device_info().supports_immad) {+ auto input_max_rank = std::max({+ mem_input_low->get_layout().get_partial_shape().rank().get_length(),+ mem_input_high->get_layout().get_partial_shape().rank().get_length(),+ mem_output_low->get_layout().get_partial_shape().rank().get_length(),+ mem_output_high->get_layout().get_partial_shape().rank().get_length()+ });++ if (input_max_rank == 3 && scales_layout.get_partial_shape().rank().get_length() == 4) {+ scales_layout.set_partial_shape({scales_layout.batch(), scales_layout.feature(),+ std::max(scales_layout.spatial(0), scales_layout.spatial(1))});+ }+ }+auto mem_input_scale = p.get_engine().allocate_memory(scales_layout, false);auto mem_input_shift = p.get_engine().allocate_memory(scales_layout, false);auto mem_output_scale = p.get_engine().allocate_memory(scales_layout, false);diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cppindex 7101ad01e9c..cb24943c2c2 100644--- a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp@@ -275,11 +275,11 @@ int64_t get_offset(const cldnn::layout& l, dnnl::memory::desc&& desc) {std::tuple<dnnl::memory::desc, dnnl::memory::desc, dnnl::memory::desc>get_conv_memory_descs(cldnn::layout input_layout, cldnn::layout weights_layout, cldnn::layout output_layout, dnnl::memory::format_tag target_fmt) {- mem_flags flags = (input_layout.format.is_blocked() || output_layout.format.is_blocked()) ?- mem_flags::need_blocked : mem_flags::None;- dnnl::memory::desc input_desc = layout_to_memory_desc(input_layout, target_fmt, flags);- dnnl::memory::desc weights_desc = layout_to_memory_desc(weights_layout, dnnl::memory::format_tag::any, flags);- dnnl::memory::desc output_desc = layout_to_memory_desc(output_layout, target_fmt, flags);+ mem_flags flag = (input_layout.format.is_blocked() || output_layout.format.is_blocked()) ? mem_flags::need_blocked : mem_flags::None;+ flag = format::is_grouped(weights_layout.format) ? mem_flags::grouped : flag;+ dnnl::memory::desc input_desc = layout_to_memory_desc(input_layout, target_fmt, flag);+ dnnl::memory::desc weights_desc = layout_to_memory_desc(weights_layout, dnnl::memory::format_tag::any, flag);+ dnnl::memory::desc output_desc = layout_to_memory_desc(output_layout, target_fmt, flag);return {input_desc, weights_desc, output_desc};}@@ -307,6 +307,7 @@ dnnl::memory::desc layout_to_memory_desc(cldnn::layout l, dnnl::memory::format_tbool flatten = has_mem_flag(flags, mem_flags::flatten);bool use_strides = has_mem_flag(flags, mem_flags::use_strides);bool need_blocked = has_mem_flag(flags, mem_flags::need_blocked);+ bool is_grouped = has_mem_flag(flags, mem_flags::grouped);if (target_fmt == dnnl::memory::format_tag::ab && flatten) {dims = flatten_tensor(l.get_tensor());dims.insert(dims.begin(), 1);@@ -349,7 +350,7 @@ dnnl::memory::desc layout_to_memory_desc(cldnn::layout l, dnnl::memory::format_t// However, if the memory::desc to be converted is related to another blocked format, it should be expanded to a 4d tensor.auto shape_rank = l.is_dynamic() ?static_cast<size_t>(l.get_partial_shape().rank().get_length()) : l.get_shape().size();- if (shape_rank == 3 && !need_blocked) {+ if (shape_rank == 3 && !need_blocked && !is_grouped) {dims.push_back(l.batch());dims.push_back(l.feature());// In cldnn::layer, when it is a 3D shape, the values of the XY axes can sometimes be flipped,@@ -734,21 +735,25 @@ bool keep_weights_reorder_shape_consistent(cldnn::layout& layout, const dnnl::mestd::copy_if(desc_dims.begin(), desc_dims.end(), std::back_inserter(filtered_desc_dims),[](ov::Dimension::value_type i) { return i != 1; });- // Check whether they have same values and orders.- if (filtered_target_dims == filtered_desc_dims) {- layout.set_partial_shape(desc_dims);- if (layout.get_rank() != desc_dims.size()) {- if (cldnn::format::is_default_format(layout.format)) {- layout.format = cldnn::format::get_default_format(desc_dims.size());- } else {- // TO-DO: Consider that weight format is not default format- return false;- }- }- return true;+ if (filtered_target_dims != filtered_desc_dims)+ return false; // We cannot keep the shapes consistent++ layout.set_partial_shape(desc_dims);+ if (layout.get_rank() == desc_dims.size()) {+ return true; // Shapes are now consistent} else {- return false;+ auto is_weights = cldnn::format::is_weights_format(layout.format);+ auto is_grouped = cldnn::format::is_grouped(layout.format);+ auto expected_format = cldnn::format::get_default_format(cldnn::format::dimension(layout.format), is_weights, is_grouped);+ if (layout.format == expected_format) {+ // Dimension expansion is only allowed when the input layout is in the default format.+ layout.format = cldnn::format::get_default_format(desc_dims.size(), is_weights, is_grouped);+ } else {+ // The expected format is not default format.+ return false;+ }}+ return true;}size_t get_post_ops_count(const program_node& node) {diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.hpp b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.hppindex 0e83bb6757d..a5cab60c0c8 100644--- a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.hpp+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.hpp@@ -41,6 +41,7 @@ enum class mem_flags : uint32_t {flatten = 1 << 0,use_strides = 1 << 1,need_blocked = 1 << 2,+ grouped = 1 << 3,};dnnl::memory::desc layout_to_memory_desc(cldnn::layout l,diff --git a/src/plugins/intel_gpu/src/graph/reorder.cpp b/src/plugins/intel_gpu/src/graph/reorder.cppindex 20ec0bc9096..a3f76a83629 100644--- a/src/plugins/intel_gpu/src/graph/reorder.cpp+++ b/src/plugins/intel_gpu/src/graph/reorder.cpp@@ -186,6 +186,8 @@ std::vector<layout> reorder_inst::calc_output_layouts(reorder_node const& /*node#ifdef ENABLE_ONEDNN_FOR_GPUauto onednn_weights_params = std::dynamic_pointer_cast<onednn::WeightsReorderParamsOneDNN>(desc->weights_reorder_params);if (onednn_weights_params && input_layout.format != onednn::find_data_format(onednn_weights_params->_in_desc)) {+ auto shape_consistent = onednn::keep_weights_reorder_shape_consistent(input_layout, onednn_weights_params->_out_desc);+ OPENVINO_ASSERT(shape_consistent, "[GPU] Input shape and output shape of weight reorder should be same.");onednn_weights_params->_in_desc = onednn::layout_to_memory_desc(input_layout);}#endif // ENABLE_ONEDNN_FOR_GPUdiff --git a/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cppindex d802debac80..cebb50f1940 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp@@ -11546,3 +11546,148 @@ INSTANTIATE_TEST_SUITE_P(smoke, conv_dyn_3d_test,{ ov::Shape{1, 16, 5, 5, 5}, ov::Shape{2, 16, 3, 3, 3}, ov::Strides{1, 1, 1}, ov::Strides{1, 1, 1}, ov::CoordinateDiff{1, 1, 1}, ov::CoordinateDiff{1, 1, 1}, 1, false },{ ov::Shape{1, 16, 5, 5, 5}, ov::Shape{16, 1, 1, 3, 3, 3}, ov::Strides{1, 1, 1}, ov::Strides{1, 1, 1}, ov::CoordinateDiff{0, 0, 0}, ov::CoordinateDiff{0, 0, 0}, 16, false }}));++TEST(group_convolution_f16_fw_gpu, basic_1d_group_convolution) {+ auto& engine = get_test_engine();+ if (!engine.get_device_info().supports_immad)+ GTEST_SKIP();++ // Input: [batch=1, channels=768, spatial=292]+ auto input = engine.allocate_memory({{ 1, 256, 12 }, data_types::f16, format::bfyx });+ // Weights shape for group convolution: [groups, output_channels_per_group, input_channels_per_group, kernel_size]+ auto weights = engine.allocate_memory({ {16, 16, 16, 7}, data_types::f16, format::bfyx });++ tests::random_generator rg(GET_SUITE_NAME);+ // Generate random input data+ auto input_data = rg.generate_random_1d<ov::float16>(input->count(), -1, 1);+ set_values(input, input_data);++ // Generate random weights data - using smaller range for stability+ auto weights_data = rg.generate_random_1d<ov::float16>(weights->count(), -1, 1);+ set_values(weights, weights_data);++ // Create topology with group convolution + bias add subgraph+ topology topology(input_layout("input", input->get_layout()));+ topology.add(+ data("weights", weights),+ // Group convolution: 16 groups, kernel=7, stride=1, padding=3+ convolution("group_conv", input_info("input"), "weights", "",+ 16, // groups+ { 1 }, // stride+ { 1 }, // dilation+ { 3 }, // pad_begin+ { 3 }, // pad_end+ true),+ activation("relu", input_info("group_conv"), activation_func::relu),+ reorder("output", input_info("relu"), {{ 1, 256, 12 }, data_types::f32, format::bfyx })+ );++ ov::intel_gpu::ImplementationDesc conv_impl_ref = { format::any, "", impl_types::ocl };+ ExecutionConfig cfg_ref = get_test_default_config(engine,+ {ov::intel_gpu::queue_type(QueueTypes::in_order),+ ov::intel_gpu::allow_new_shape_infer(true),+ ov::intel_gpu::optimize_data(true),+ ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ { "group_conv", conv_impl_ref } })+ });++ network net_ref(engine, topology, cfg_ref);+ net_ref.set_input_data("input", input);+ auto out_ref = net_ref.execute();+ auto mem_ref = out_ref.at("output").get_memory();++ ov::intel_gpu::ImplementationDesc conv_impl_opt = { format::any, "", impl_types::onednn };+ ExecutionConfig cfg_opt = get_test_default_config(engine,+ {ov::intel_gpu::queue_type(QueueTypes::in_order),+ ov::intel_gpu::allow_new_shape_infer(true),+ ov::intel_gpu::optimize_data(true),+ ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ { "group_conv", conv_impl_opt } })+ });++ network net_opt(engine, topology, cfg_opt);+ net_opt.set_input_data("input", input);+ auto out_opt = net_opt.execute();+ auto mem_opt = out_opt.at("output").get_memory();++ cldnn::mem_lock<float> output_ptr_ref(mem_ref, get_test_stream());+ cldnn::mem_lock<float> output_ptr_opt(mem_opt, get_test_stream());++ ASSERT_EQ(mem_opt->get_layout(), mem_ref->get_layout());+ for (size_t i = 0; i < output_ptr_opt.size(); i++) {+ ASSERT_FLOAT_EQ(output_ptr_opt[i], output_ptr_ref[i]);+ }+}++TEST(group_convolution_f16_fw_gpu, with_weights_as_input) {+ auto& engine = get_test_engine();+ if (!engine.get_device_info().supports_immad)+ GTEST_SKIP();++ // Input: 1x64x31x31 to get 23x23 output with 9x9 kernel and no padding+ auto input = engine.allocate_memory({{ 1, 64, 31, 31 }, data_types::f16, format::bfyx });++ // Weights input: [64, 1, 9, 9] - 64 groups, 1 output per group, 1 input per group, 9x9 kernel+ auto input_weights = engine.allocate_memory({ {64, 1, 9, 9}, data_types::f32, format::bfyx });++ tests::random_generator rg(GET_SUITE_NAME);+ // Generate random input data+ auto input_data = rg.generate_random_1d<ov::float16>(input->count(), -1, 1);+ set_values(input, input_data);++ // Generate random weights data for input_weights - using smaller range for stability+ auto weights_data = rg.generate_random_1d<float>(input_weights->count(), -1, 1);+ set_values(input_weights, weights_data);++ topology topology(+ input_layout("input", input->get_layout()),+ input_layout("input_weights", input_weights->get_layout())+ );+ topology.add(+ reorder("Convert", input_info("input_weights"), format::bfyx, data_types::f16),+ reorder("Reshape_reorder", input_info("Convert"), format::bfzyx, data_types::f16),+ reshape("Reshape", input_info("Reshape_reorder"), { 64, 1, 9, 9, 1 }),+ // Group convolution: 64 groups, kernel=9x9, stride=1, no padding (to match 31x31 -> 23x23)+ convolution("Conv", input_info("input"), "Reshape", "",+ 64, // groups+ { 1, 1 }, // stride+ { 1, 1 }, // dilation+ { 0, 0 }, // pad_begin (no padding to get 23x23 from 31x31)+ { 0, 0 }, // pad_end+ true), // grouped+ reorder("output", input_info("Conv"), {{ 1, 64, 23, 23 }, data_types::f32, format::bfyx })+ );++ ov::intel_gpu::ImplementationDesc conv_impl_ref = { format::any, "", impl_types::ocl };+ ExecutionConfig cfg_ref = get_test_default_config(engine,+ {ov::intel_gpu::queue_type(QueueTypes::in_order),+ ov::intel_gpu::optimize_data(true),+ ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ { "Conv", conv_impl_ref } })+ });++ network net_ref(engine, topology, cfg_ref);+ net_ref.set_input_data("input", input);+ net_ref.set_input_data("input_weights", input_weights);+ auto out_ref = net_ref.execute();+ auto mem_ref = out_ref.at("output").get_memory();++ ov::intel_gpu::ImplementationDesc conv_impl_opt = { format::any, "", impl_types::onednn };+ ExecutionConfig cfg_opt = get_test_default_config(engine,+ {ov::intel_gpu::queue_type(QueueTypes::in_order),+ ov::intel_gpu::optimize_data(true),+ ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ { "Conv", conv_impl_opt } })+ });++ network net_opt(engine, topology, cfg_opt);+ net_opt.set_input_data("input", input);+ net_opt.set_input_data("input_weights", input_weights);+ auto out_opt = net_opt.execute();+ auto mem_opt = out_opt.at("output").get_memory();++ cldnn::mem_lock<float> output_ptr_ref(mem_ref, get_test_stream());+ cldnn::mem_lock<float> output_ptr_opt(mem_opt, get_test_stream());++ ASSERT_EQ(mem_opt->get_layout(), mem_ref->get_layout());+ for (size_t i = 0; i < output_ptr_opt.size(); i++) {+ ASSERT_FLOAT_EQ(output_ptr_opt[i], output_ptr_ref[i]);+ }+}+