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] updates quantize to use original layout in postop of onednn impl (#30225)
Eddy Kim33be59899ff5
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cppindex bfbd88fc6b8..3cf691f6e24 100644--- a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp@@ -75,6 +75,17 @@ dnnl::memory::dims convert_gemm_dims(const std::vector<int32_t> &sizes, size_t dreturn res;}+dnnl::memory::format_tag get_default_data_format(const cldnn::layout& l) {+ switch (l.get_partial_shape().size()) {+ case 2: return dnnl::memory::format_tag::ab;+ case 3: return dnnl::memory::format_tag::abc;+ case 4: return dnnl::memory::format_tag::abcd;+ case 5: return dnnl::memory::format_tag::abcde;+ case 6: return dnnl::memory::format_tag::abcdef;+ default: OPENVINO_THROW("[GPU] Unsupported conversion from "+ l.to_short_string() + " to onednn format_tag");+ }+}+dnnl::memory::format_tag convert_gemm_data_format(dnnl::memory::dims dims, format target) {if (dims.size() == target.dimension()) {auto tag = convert_data_format(target);diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.hpp b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.hppindex ab62a97c15e..6f75a5ddb2f 100644--- a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.hpp+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.hpp@@ -33,6 +33,7 @@ dnnl::memory::dims get_strides(dnnl::memory::dims dims);dnnl::memory::data_type convert_data_type(cldnn::data_types dt);dnnl::memory::format_tag convert_data_format(cldnn::format fmt);cldnn::format convert_data_format(dnnl::memory::format_tag fmt);+dnnl::memory::format_tag get_default_data_format(const cldnn::layout& l);dnnl::memory::format_tag convert_gemm_data_format(dnnl::memory::dims dims, format target);dnnl::memory::desc layout_to_memory_desc(cldnn::layout l, dnnl::memory::format_tag target_fmt = dnnl::memory::format_tag::undef, bool flatten = false);dnnl::algorithm convert_activation_func(cldnn::activation_func func);diff --git a/src/plugins/intel_gpu/src/graph/program_node.cpp b/src/plugins/intel_gpu/src/graph/program_node.cppindex 3d1b4dde81f..900d10de546 100644--- a/src/plugins/intel_gpu/src/graph/program_node.cpp+++ b/src/plugins/intel_gpu/src/graph/program_node.cpp@@ -1648,9 +1648,9 @@ void program_node::create_onednn_primitive_attributes(update_onednn_post_op_list(onednn_post_op_type::eltwise_linear, empty_mem);} else {auto in_scale = get_input_layout(dep_idx++);- dnnl::memory::desc in_scale_desc = onednn::layout_to_memory_desc(in_scale, dnnl::memory::format_tag::ab, true);+ dnnl::memory::desc in_scale_desc = onednn::layout_to_memory_desc(in_scale, onednn::get_default_data_format(in_scale));post_ops.append_binary(dnnl::algorithm::binary_mul, in_scale_desc);- update_onednn_post_op_list(onednn_post_op_type::binary_mul, dep_idx - 1, dnnl::memory::format_tag::ab, true,+ update_onednn_post_op_list(onednn_post_op_type::binary_mul, dep_idx - 1, onednn::get_default_data_format(in_scale), false,in_scale_desc.get_dims(), in_scale_desc.get_data_type());}@@ -1660,9 +1660,9 @@ void program_node::create_onednn_primitive_attributes(update_onednn_post_op_list(onednn_post_op_type::eltwise_linear, empty_mem);} else {auto in_shift = get_input_layout(dep_idx++);- dnnl::memory::desc in_shift_desc = onednn::layout_to_memory_desc(in_shift, dnnl::memory::format_tag::ab, true);+ dnnl::memory::desc in_shift_desc = onednn::layout_to_memory_desc(in_shift, onednn::get_default_data_format(in_shift));post_ops.append_binary(dnnl::algorithm::binary_add, in_shift_desc);- update_onednn_post_op_list(onednn_post_op_type::binary_add, dep_idx - 1, dnnl::memory::format_tag::ab, true,+ update_onednn_post_op_list(onednn_post_op_type::binary_add, dep_idx - 1, onednn::get_default_data_format(in_shift), false,in_shift_desc.get_dims(), in_shift_desc.get_data_type());}}@@ -1692,9 +1692,9 @@ void program_node::create_onednn_primitive_attributes(update_onednn_post_op_list(onednn_post_op_type::eltwise_linear, empty_mem);} else {auto out_scale = get_input_layout(dep_idx++);- dnnl::memory::desc out_scale_desc = onednn::layout_to_memory_desc(out_scale, dnnl::memory::format_tag::ab, true);+ dnnl::memory::desc out_scale_desc = onednn::layout_to_memory_desc(out_scale, onednn::get_default_data_format(out_scale));post_ops.append_binary(dnnl::algorithm::binary_mul, out_scale_desc);- update_onednn_post_op_list(onednn_post_op_type::binary_mul, dep_idx - 1, dnnl::memory::format_tag::ab, true,+ update_onednn_post_op_list(onednn_post_op_type::binary_mul, dep_idx - 1, onednn::get_default_data_format(out_scale), false,out_scale_desc.get_dims(), out_scale_desc.get_data_type());}}@@ -1705,9 +1705,9 @@ void program_node::create_onednn_primitive_attributes(update_onednn_post_op_list(onednn_post_op_type::eltwise_linear, empty_mem);} else {auto out_shift = get_input_layout(dep_idx++);- dnnl::memory::desc out_shift_desc = onednn::layout_to_memory_desc(out_shift, dnnl::memory::format_tag::ab, true);+ dnnl::memory::desc out_shift_desc = onednn::layout_to_memory_desc(out_shift, onednn::get_default_data_format(out_shift));post_ops.append_binary(dnnl::algorithm::binary_add, out_shift_desc);- update_onednn_post_op_list(onednn_post_op_type::binary_add, dep_idx - 1, dnnl::memory::format_tag::ab, true,+ update_onednn_post_op_list(onednn_post_op_type::binary_add, dep_idx - 1, onednn::get_default_data_format(out_shift), false,out_shift_desc.get_dims(), out_shift_desc.get_data_type());}}@@ -1732,14 +1732,14 @@ void program_node::create_onednn_primitive_attributes(auto in_hi = get_input_layout(dep_idx++);dnnl::algorithm clamp_max = dnnl::algorithm::binary_max;dnnl::algorithm clamp_min = dnnl::algorithm::binary_min;- dnnl::memory::desc in_lo_desc = onednn::layout_to_memory_desc(in_lo, dnnl::memory::format_tag::ab, true);- dnnl::memory::desc in_hi_desc = onednn::layout_to_memory_desc(in_hi, dnnl::memory::format_tag::ab, true);+ dnnl::memory::desc in_lo_desc = onednn::layout_to_memory_desc(in_lo, onednn::get_default_data_format(in_lo));+ dnnl::memory::desc in_hi_desc = onednn::layout_to_memory_desc(in_hi, onednn::get_default_data_format(in_hi));post_ops.append_binary(clamp_max, in_lo_desc);- update_onednn_post_op_list(onednn_post_op_type::binary_max, dep_idx - 2, dnnl::memory::format_tag::ab, true,+ update_onednn_post_op_list(onednn_post_op_type::binary_max, dep_idx - 2, onednn::get_default_data_format(in_lo), false,in_lo_desc.get_dims(), in_lo_desc.get_data_type());post_ops.append_binary(clamp_min, in_hi_desc);- update_onednn_post_op_list(onednn_post_op_type::binary_min, dep_idx - 1, dnnl::memory::format_tag::ab, true,+ update_onednn_post_op_list(onednn_post_op_type::binary_min, dep_idx - 1, onednn::get_default_data_format(in_hi), false,in_hi_desc.get_dims(), in_hi_desc.get_data_type());}}@@ -1755,9 +1755,9 @@ void program_node::create_onednn_primitive_attributes(update_onednn_post_op_list(onednn_post_op_type::eltwise_linear, empty_mem);} else {auto in_scale = get_input_layout(dep_idx++);- dnnl::memory::desc in_scale_desc = onednn::layout_to_memory_desc(in_scale, dnnl::memory::format_tag::ab, true);+ dnnl::memory::desc in_scale_desc = onednn::layout_to_memory_desc(in_scale, onednn::get_default_data_format(in_scale));post_ops.append_binary(dnnl::algorithm::binary_mul, in_scale_desc);- update_onednn_post_op_list(onednn_post_op_type::binary_mul, dep_idx - 1, dnnl::memory::format_tag::ab, true,+ update_onednn_post_op_list(onednn_post_op_type::binary_mul, dep_idx - 1, onednn::get_default_data_format(in_scale), false,in_scale_desc.get_dims(), in_scale_desc.get_data_type());}@@ -1767,9 +1767,9 @@ void program_node::create_onednn_primitive_attributes(update_onednn_post_op_list(onednn_post_op_type::eltwise_linear, empty_mem);} else {auto in_shift = get_input_layout(dep_idx++);- dnnl::memory::desc in_shift_desc = onednn::layout_to_memory_desc(in_shift, dnnl::memory::format_tag::ab, true);+ dnnl::memory::desc in_shift_desc = onednn::layout_to_memory_desc(in_shift, onednn::get_default_data_format(in_shift));post_ops.append_binary(dnnl::algorithm::binary_add, in_shift_desc);- update_onednn_post_op_list(onednn_post_op_type::binary_add, dep_idx - 1, dnnl::memory::format_tag::ab, true,+ update_onednn_post_op_list(onednn_post_op_type::binary_add, dep_idx - 1, onednn::get_default_data_format(in_shift), false,in_shift_desc.get_dims(), in_shift_desc.get_data_type());}}@@ -1795,9 +1795,9 @@ void program_node::create_onednn_primitive_attributes(update_onednn_post_op_list(onednn_post_op_type::eltwise_linear, empty_mem);} else {auto out_scale = get_input_layout(dep_idx++);- dnnl::memory::desc out_scale_desc = onednn::layout_to_memory_desc(out_scale, dnnl::memory::format_tag::ab, true);+ dnnl::memory::desc out_scale_desc = onednn::layout_to_memory_desc(out_scale, onednn::get_default_data_format(out_scale));post_ops.append_binary(dnnl::algorithm::binary_mul, out_scale_desc);- update_onednn_post_op_list(onednn_post_op_type::binary_mul, dep_idx - 1, dnnl::memory::format_tag::ab, true,+ update_onednn_post_op_list(onednn_post_op_type::binary_mul, dep_idx - 1, onednn::get_default_data_format(out_scale), false,out_scale_desc.get_dims(), out_scale_desc.get_data_type());}}@@ -1808,9 +1808,9 @@ void program_node::create_onednn_primitive_attributes(update_onednn_post_op_list(onednn_post_op_type::eltwise_linear, empty_mem);} else {auto out_shift = get_input_layout(dep_idx++);- dnnl::memory::desc out_shift_desc = onednn::layout_to_memory_desc(out_shift, dnnl::memory::format_tag::ab, true);+ dnnl::memory::desc out_shift_desc = onednn::layout_to_memory_desc(out_shift, onednn::get_default_data_format(out_shift));post_ops.append_binary(dnnl::algorithm::binary_add, out_shift_desc);- update_onednn_post_op_list(onednn_post_op_type::binary_add, dep_idx - 1, dnnl::memory::format_tag::ab, true,+ update_onednn_post_op_list(onednn_post_op_type::binary_add, dep_idx - 1, onednn::get_default_data_format(out_shift), false,out_shift_desc.get_dims(), out_shift_desc.get_data_type());}}