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] binary_mul_inplace integration for Gated_MLP (#38615)
hyunback kim521ffc4d5a7d
diff --git a/src/plugins/intel_gpu/include/intel_gpu/graph/fused_primitive_desc.hpp b/src/plugins/intel_gpu/include/intel_gpu/graph/fused_primitive_desc.hppindex 70453fcc2e6..7bb34114a6e 100644--- a/src/plugins/intel_gpu/include/intel_gpu/graph/fused_primitive_desc.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/graph/fused_primitive_desc.hpp@@ -132,6 +132,7 @@ enum class onednn_post_op_type : uint32_t {eltwise_round,eltwise_hardsigmoid,binary_mul,+ binary_mul_inplace,binary_add,binary_sub,binary_max,@@ -156,6 +157,7 @@ static inline std::ostream& operator<< (std::ostream& os, onednn_post_op_type& tcase onednn_post_op_type::eltwise_round: os << "eltwise_round"; break;case onednn_post_op_type::eltwise_hardsigmoid: os << "eltwise_hardsigmoid"; break;case onednn_post_op_type::binary_mul: os << "binary_mul"; break;+ case onednn_post_op_type::binary_mul_inplace: os << "binary_mul_inplace"; break;case onednn_post_op_type::binary_add: os << "binary_add"; break;case onednn_post_op_type::binary_sub: os << "binary_sub"; break;case onednn_post_op_type::binary_max: os << "binary_max"; break;diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/basic_memory_dependencies.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/basic_memory_dependencies.cppindex 188ed77a4e1..c24d856f62e 100644--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/basic_memory_dependencies.cpp+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/basic_memory_dependencies.cpp@@ -37,6 +37,12 @@ void basic_memory_dependencies::run(program& p) {}add_memory_dependency(node, deps[i].first);add_memory_dependency(deps[i].first, node);++ if (auto alias_idx = onednn_eltwise_fusing_helpers::get_reused_eltwmem_idx(*deps[i].first); alias_idx != -1) {+ auto& alias = deps[i].first->get_dependency(alias_idx);+ node->add_memory_dependency(alias);+ alias.add_memory_dependency(*node);+ }}if (inplace_kv) {@@ -63,7 +69,7 @@ void basic_memory_dependencies::run(program& p) {for (auto& fused_op : node->get_fused_primitives()) {if (fused_op.is_type<eltwise>() && fused_op.deps.size() == 1) {// If it is first sum, reuse the buffer- auto fusing_type = onednn_add_fusing_helpers::get_add_fusing_type(*node, fused_op);+ auto fusing_type = onednn_eltwise_fusing_helpers::get_add_fusing_type(*node, fused_op);if (fusing_type != add_fusing_type::sum || eltw_dep != 0) {continue;}diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_buffer_fusing.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_buffer_fusing.cppindex ccefe338eca..34932fe292d 100644--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_buffer_fusing.cpp+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_buffer_fusing.cpp@@ -211,7 +211,7 @@ bool concat_in_place_optimization::match(const program_node& concat_node,}for (const auto& fused_op : pred_params[idx].fused_desc) {- auto add_type = onednn_add_fusing_helpers::get_add_fusing_type(*pred.first, fused_op);+ auto add_type = onednn_eltwise_fusing_helpers::get_add_fusing_type(*pred.first, fused_op);if (add_type == add_fusing_type::sum)return false;}diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/remove_redundant_reorders.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/remove_redundant_reorders.cppindex c47182fb236..d3affc7408d 100644--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/remove_redundant_reorders.cpp+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/remove_redundant_reorders.cpp@@ -307,7 +307,7 @@ void remove_redundant_reorders::run(program& p) {if (dep_node.get_preferred_impl_type() == impl_types::onednn && !no_output_optimization) {for (auto& fused_op : dep_node.get_fused_primitives()) {if (fused_op.is_type<eltwise>() && fused_op.deps.size() == 1) {- auto fusing_type = onednn_add_fusing_helpers::get_add_fusing_type(dep_node, fused_op);+ auto fusing_type = onednn_eltwise_fusing_helpers::get_add_fusing_type(dep_node, fused_op);if (fusing_type == add_fusing_type::sum) {no_output_optimization |= true;break;diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/reorder_inputs.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/reorder_inputs.cppindex ce16c9a990d..73cf0374869 100644--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/reorder_inputs.cpp+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/reorder_inputs.cpp@@ -690,9 +690,9 @@ void reorder_inputs::run(program& p, reorder_factory& rf) {// When the conv node is of onednn impl type and eltwise sum with full tensor is fused,// changes the input format of eltwise sum post-op to use binary add.if (conv_node.get_preferred_impl_type() == impl_types::onednn) {- onednn_add_fusing_helpers::for_eltwise(conv_node, eltwise_mode::sum,+ onednn_eltwise_fusing_helpers::for_eltwise(conv_node, eltwise_mode::sum,[&](const program_node& p_node, const fused_primitive_desc& desc) {- auto fusing_type = onednn_add_fusing_helpers::get_add_fusing_type(p_node, desc);+ auto fusing_type = onednn_eltwise_fusing_helpers::get_add_fusing_type(p_node, desc);if (fusing_type == add_fusing_type::binary_per_tensor && desc.has_outer_dep()) {auto& dep_node = p_node.get_dependency(desc.outer_dep_start_idx);auto d_layout = dep_node.get_output_layout();diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.hindex 52018d06af0..f714ffded0f 100644--- a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h@@ -443,6 +443,7 @@ protected:case onednn_post_op_type::binary_add:case onednn_post_op_type::binary_sub:case onednn_post_op_type::binary_mul:+ case onednn_post_op_type::binary_mul_inplace:case onednn_post_op_type::binary_max:case onednn_post_op_type::binary_min:case onednn_post_op_type::binary_div:diff --git a/src/plugins/intel_gpu/src/graph/include/program_helpers.h b/src/plugins/intel_gpu/src/graph/include/program_helpers.hindex 3373cde690c..35169570389 100644--- a/src/plugins/intel_gpu/src/graph/include/program_helpers.h+++ b/src/plugins/intel_gpu/src/graph/include/program_helpers.h@@ -119,7 +119,7 @@ struct program_helpers {}};-struct onednn_add_fusing_helpers {+struct onednn_eltwise_fusing_helpers {enum class add_fusing_type {sum,binary_per_tensor,@@ -127,15 +127,14 @@ struct onednn_add_fusing_helpers {not_supported,};- static bool is_full_tensor(const layout& layout);- static std::vector<fused_primitive_desc> get_fused_eltwise_primitives();static void for_eltwise(const program_node& conv_node, eltwise_mode mode,std::function<void(const program_node&, const fused_primitive_desc&)> func);static add_fusing_type get_add_fusing_type(const program_node& node, const fused_primitive_desc& desc);static int32_t get_reused_eltwmem_idx(const program_node& node);+ static bool can_use_mul_inplace(const program_node& node, const fused_primitive_desc& desc);};-using add_fusing_type = onednn_add_fusing_helpers::add_fusing_type;+using add_fusing_type = onednn_eltwise_fusing_helpers::add_fusing_type;static inline std::ostream& operator<< (std::ostream& os, add_fusing_type& t) {switch (t) {diff --git a/src/plugins/intel_gpu/src/graph/include/to_string_utils.h b/src/plugins/intel_gpu/src/graph/include/to_string_utils.hindex 70939306d74..7a5da581593 100644--- a/src/plugins/intel_gpu/src/graph/include/to_string_utils.h+++ b/src/plugins/intel_gpu/src/graph/include/to_string_utils.h@@ -93,6 +93,7 @@ inline std::string onednn_post_op_type_to_str(onednn_post_op_type type) {case onednn_post_op_type::eltwise_round: return "eltwise_round";case onednn_post_op_type::eltwise_hardsigmoid: return "eltwise_hardsigmoid";case onednn_post_op_type::binary_mul: return "binary_mul";+ case onednn_post_op_type::binary_mul_inplace: return "binary_mul_inplace";case onednn_post_op_type::binary_add: return "binary_add";case onednn_post_op_type::binary_sub: return "binary_add";case onednn_post_op_type::binary_max: return "binary_max";diff --git a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp b/src/plugins/intel_gpu/src/graph/layout_optimizer.cppindex 68fb721d7e3..f01cba1f143 100644--- a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp+++ b/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp@@ -209,7 +209,7 @@ bool layout_optimizer::can_fuse_reorder(program_node& prev, program_node& next,for (auto& fused_op : next.get_fused_primitives()) {if (fused_op.is_type<eltwise>()) {auto out_layout = next.get_output_layout();- auto add_type = onednn_add_fusing_helpers::get_add_fusing_type(next, fused_op);+ auto add_type = onednn_eltwise_fusing_helpers::get_add_fusing_type(next, fused_op);if (add_type == add_fusing_type::sum && prev.get_output_layout().format != out_layout.format)return false;}diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cppindex 152b6122ca6..90428e2babb 100644--- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp+++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp@@ -1303,6 +1303,25 @@ void primitive_inst::realloc_outputs(bool prev_execution_skipped) {return;}+ // binary_mul_inplace lets this FC's dst share the fused eltwise dep buffer (the post-op src1).+ // A static node binds that alias when its output is allocated; a dynamic node has to bind it here.+ if (actual_layouts.size() == 1 && get_node().get_preferred_impl_type() == impl_types::onednn) {+ auto reused_eltwmem_idx = onednn_eltwise_fusing_helpers::get_reused_eltwmem_idx(get_node());+ if (reused_eltwmem_idx != -1) {+ const auto& eltw_inst = get_network().get_primitive(get_node().get_dependency(reused_eltwmem_idx).id());+ auto eltw_mem = eltw_inst->output_memory_ptr();+ if (eltw_mem && eltw_mem->get_mem_tracker() &&+ eltw_mem->get_mem_tracker()->size() >= updated_layouts[0].get_linear_size() * dt_sizes_in_B[0]) {+ if (_outputs[0]) {+ get_network().get_memory_pool().release_memory(_outputs[0].get(), get_node().get_unique_id(), id(), get_network_id());+ }+ _outputs[0] = eltw_mem->get_engine()->reinterpret_buffer(*eltw_mem, updated_layouts[0]);+ _max_output_layout_count[0] = eltw_mem->get_mem_tracker()->size() / dt_sizes_in_B[0];+ return;+ }+ }+ }+for (size_t i = 0; i < actual_layouts.size(); ++i) {bool can_reuse_buffer = (_outputs[i] && updated_layouts[i].get_linear_size() <= _max_output_layout_count[i]);std::pair<bool, ov::Shape> prealloc_info;@@ -2755,7 +2774,7 @@ primitive_inst::primitive_inst(network& network, const program_node& node, bool}}- if (auto reused_eltwmem_idx = onednn_add_fusing_helpers::get_reused_eltwmem_idx(node); reused_eltwmem_idx != -1) {+ if (auto reused_eltwmem_idx = onednn_eltwise_fusing_helpers::get_reused_eltwmem_idx(node); reused_eltwmem_idx != -1) {// sum post-op can use the input buffer as the output bufferauto& eltw_node = node.get_dependency(reused_eltwmem_idx);const auto& eltw_inst = _network.get_primitive(eltw_node.id());diff --git a/src/plugins/intel_gpu/src/graph/program_helpers.cpp b/src/plugins/intel_gpu/src/graph/program_helpers.cppindex 234087e97bb..cc63448ba62 100644--- a/src/plugins/intel_gpu/src/graph/program_helpers.cpp+++ b/src/plugins/intel_gpu/src/graph/program_helpers.cpp@@ -6,6 +6,8 @@#include "intel_gpu/graph/program.hpp"#include "data_inst.h"#include "pooling_inst.h"+#include "fully_connected_inst.h"+#include "transformations/symbolic_transformations/utils.hpp"#include <algorithm>#include <utility>#include <vector>@@ -73,12 +75,12 @@ void program_helpers::reshape_deconvolution_weights(const std::vector<float> &de}}-bool onednn_add_fusing_helpers::is_full_tensor(const layout& l) {+static bool is_full_tensor(const layout& l) {return l.spatial(0) > 1 || l.spatial(1) > 1 || (l.get_spatial_rank() == 3 && l.spatial(2) > 1)|| l.batch() > 1;}-void onednn_add_fusing_helpers::for_eltwise(+void onednn_eltwise_fusing_helpers::for_eltwise(const program_node& node, eltwise_mode mode,std::function<void(const program_node& p_node,const fused_primitive_desc& desc)> func) {@@ -147,7 +149,7 @@ static bool is_direct_ancestor(const program_node& child, const program_node& tareturn false;}-add_fusing_type onednn_add_fusing_helpers::get_add_fusing_type(+add_fusing_type onednn_eltwise_fusing_helpers::get_add_fusing_type(const program_node& p_node, const fused_primitive_desc& desc) {if (!desc.is_type<eltwise>()) {return add_fusing_type::not_supported;@@ -185,13 +187,49 @@ add_fusing_type onednn_add_fusing_helpers::get_add_fusing_type(return add_fusing_type::binary_per_oc;}-int32_t onednn_add_fusing_helpers::get_reused_eltwmem_idx(const program_node& node) {+// binary_mul_inplace: oneDNN matmul post-op whose src1 may alias dst. Unlike sum the alias is+// optional (plain binary_mul otherwise), so this only checks the buffers are interchangeable:+// FC only, dynamic via ov::Symbol, exact layout match, single user.+bool onednn_eltwise_fusing_helpers::can_use_mul_inplace(const program_node& p_node, const fused_primitive_desc& desc) {+ if (!desc.is_type<eltwise>() || desc.typed_desc<eltwise>()->mode != eltwise_mode::prod || !desc.has_outer_dep()+ || !p_node.is_type<fully_connected>()) {+ return false;+ }++ auto& dep_node = p_node.get_dependency(desc.outer_dep_start_idx);+ auto p_layout = p_node.get_output_layout();+ auto d_layout = dep_node.get_output_layout();++ if (p_layout.is_dynamic() || d_layout.is_dynamic()) {+ if (p_layout.data_type != d_layout.data_type || p_layout.format != d_layout.format+ || p_layout.data_padding != d_layout.data_padding) {+ return false;+ }+ const auto& p_pshape = p_layout.get_partial_shape();+ const auto& d_pshape = d_layout.get_partial_shape();+ if (p_pshape.rank().is_dynamic() || d_pshape.rank().is_dynamic() || p_pshape.size() != d_pshape.size()) {+ return false;+ }+ for (size_t i = 0; i < p_pshape.size(); ++i) {+ if (!ov::symbol::util::dims_are_equal(p_pshape[i], d_pshape[i])) {+ return false;+ }+ }+ } else if (p_layout != d_layout || !is_full_tensor(p_layout)) {+ return false;+ }++ return dep_node.get_users().size() == 1 && !dep_node.is_constant() && !p_node.is_output();+}++int32_t onednn_eltwise_fusing_helpers::get_reused_eltwmem_idx(const program_node& node) {if (node.get_preferred_impl_type() == impl_types::onednn) {for (const auto& fused_op : node.get_fused_primitives()) {if (fused_op.is_type<eltwise>() && fused_op.deps.size() == 1) {- // If it is first sum, reuse the buffer- auto fusing_type = get_add_fusing_type(node, fused_op);- if (fusing_type != add_fusing_type::sum)+ auto mode = fused_op.typed_desc<eltwise>()->mode;+ bool reuse_eligible = (mode == eltwise_mode::sum && get_add_fusing_type(node, fused_op) == add_fusing_type::sum) ||+ (mode == eltwise_mode::prod && can_use_mul_inplace(node, fused_op));+ if (!reuse_eligible)continue;if (!fused_op.has_outer_dep())continue;diff --git a/src/plugins/intel_gpu/src/graph/program_node.cpp b/src/plugins/intel_gpu/src/graph/program_node.cppindex fa927e6ee69..f184ab2b3e0 100644--- a/src/plugins/intel_gpu/src/graph/program_node.cpp+++ b/src/plugins/intel_gpu/src/graph/program_node.cpp@@ -1243,6 +1243,7 @@ dnnl::post_ops program_node::try_optimize_post_ops(std::vector<fused_primitive_dcase onednn_post_op_type::binary_add:case onednn_post_op_type::binary_sub:case onednn_post_op_type::binary_mul:+ case onednn_post_op_type::binary_mul_inplace:case onednn_post_op_type::binary_max:case onednn_post_op_type::binary_min:case onednn_post_op_type::binary_div: {@@ -1710,7 +1711,8 @@ void program_node::create_onednn_primitive_attributes(const std::vector<fused_prfused_ops.push_back(cur_op_desc);auto has_memory_buffers = type == onednn_post_op_type::binary_add || type == onednn_post_op_type::binary_sub ||- type == onednn_post_op_type::binary_mul || type == onednn_post_op_type::binary_max ||+ type == onednn_post_op_type::binary_mul || type == onednn_post_op_type::binary_mul_inplace ||+ type == onednn_post_op_type::binary_max ||type == onednn_post_op_type::binary_min || type == onednn_post_op_type::binary_relu ||type == onednn_post_op_type::binary_div || type == onednn_post_op_type::scale || type == onednn_post_op_type::sum;@@ -1728,7 +1730,7 @@ void program_node::create_onednn_primitive_attributes(const std::vector<fused_pr}};- int32_t num_sum_post_ops = 0;+ int32_t num_inplace_post_ops = 0;for (size_t idx = 0; idx < cldnn_post_ops.size(); idx++) {const auto& desc = cldnn_post_ops[idx];if (desc.is_type<activation>()) {@@ -1823,22 +1825,27 @@ void program_node::create_onednn_primitive_attributes(const std::vector<fused_pr};if (desc.typed_desc<eltwise>()->mode == eltwise_mode::sum) {- auto fusing_type = onednn_add_fusing_helpers::get_add_fusing_type(*this, cldnn_post_ops[idx]);- if (fusing_type == add_fusing_type::sum && num_sum_post_ops == 0) {+ auto fusing_type = onednn_eltwise_fusing_helpers::get_add_fusing_type(*this, cldnn_post_ops[idx]);+ if (fusing_type == add_fusing_type::sum && num_inplace_post_ops == 0) {if (is_type<convolution>()) {post_ops.append_sum(1.0f, 0 /*zero-point*/, onednn::convert_data_type(in.data_type));} else {post_ops.append_sum(1.0f);}update_onednn_post_op_list(onednn_post_op_type::sum, dep_idx);- num_sum_post_ops++;+ num_inplace_post_ops++;} else {set_binary_op(dnnl::algorithm::binary_add, onednn_post_op_type::binary_add);}} else if (desc.typed_desc<eltwise>()->mode == eltwise_mode::sub) {set_binary_op(dnnl::algorithm::binary_sub, onednn_post_op_type::binary_sub);} else if (desc.typed_desc<eltwise>()->mode == eltwise_mode::prod) {- set_binary_op(dnnl::algorithm::binary_mul, onednn_post_op_type::binary_mul);+ if (onednn_eltwise_fusing_helpers::can_use_mul_inplace(*this, desc) && num_inplace_post_ops == 0) {+ set_binary_op(dnnl::algorithm::binary_mul_inplace, onednn_post_op_type::binary_mul_inplace);+ num_inplace_post_ops++;+ } else {+ set_binary_op(dnnl::algorithm::binary_mul, onednn_post_op_type::binary_mul);+ }} else if (desc.typed_desc<eltwise>()->mode == eltwise_mode::div) {set_binary_op(dnnl::algorithm::binary_div, onednn_post_op_type::binary_div);} else {diff --git a/src/plugins/intel_gpu/src/graph/resample.cpp b/src/plugins/intel_gpu/src/graph/resample.cppindex dad81a8c04f..a45020eab7c 100644--- a/src/plugins/intel_gpu/src/graph/resample.cpp+++ b/src/plugins/intel_gpu/src/graph/resample.cpp@@ -23,7 +23,7 @@ void rebind_onednn_reuse_optimized_dst_if_needed(primitive_inst& inst) {auto& engine = inst.get_network().get_engine();for (auto* user_inst : inst.get_user_insts()) {- auto reused_eltwmem_idx = onednn_add_fusing_helpers::get_reused_eltwmem_idx(user_inst->get_node());+ auto reused_eltwmem_idx = onednn_eltwise_fusing_helpers::get_reused_eltwmem_idx(user_inst->get_node());if (reused_eltwmem_idx < 0) {continue;}diff --git a/src/plugins/intel_gpu/src/plugin/program_builder.cpp b/src/plugins/intel_gpu/src/plugin/program_builder.cppindex aa57411afde..835306e2a86 100644--- a/src/plugins/intel_gpu/src/plugin/program_builder.cpp+++ b/src/plugins/intel_gpu/src/plugin/program_builder.cpp@@ -22,6 +22,7 @@#include "intel_gpu/op/fully_connected_compressed.hpp"#include "intel_gpu/op/placeholder.hpp"#include "openvino/util/pp.hpp"+#include "transformations/symbolic_transformations/symbolic_optimizations.hpp"#if defined(__linux__) || defined(__APPLE__)# include <dlfcn.h>@@ -110,6 +111,9 @@ ProgramBuilder::ProgramBuilder(std::shared_ptr<ov::Model> model, cldnn::engine&auto custom_layers_config = m_config.get_config_file();CustomLayer::LoadFromFile(custom_layers_config, m_custom_layers, custom_layers_config.empty());+ // Run symbolic shape propagation because GPU plugin relies on this information. (currently, for binary_mul_inplace)+ ov::pass::SymbolicPropagation().run_on_model(model);+auto ops = model->get_ordered_ops();GPU_DEBUG_LOG << "Build model name: " << m_model->get_name() << " friendly name: " << m_model->get_friendly_name() << std::endl;diff --git a/src/plugins/intel_gpu/tests/unit/fusions/fully_connected_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/fully_connected_fusion_test.cppindex 2d82a19adfa..919f85b2c05 100644--- a/src/plugins/intel_gpu/tests/unit/fusions/fully_connected_fusion_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/fusions/fully_connected_fusion_test.cpp@@ -197,6 +197,9 @@ public:#define CASE_FC_U8S8_3D_3 { 2, 3, 1 }, { 2, 3, 15 }, { 15, 1 }, data_types::u8, format::bfyx, data_types::i8, format::oiyx, data_types::f32, format::bfyx#define CASE_FC_U8S8_3D_4 { 1, 512, 1024 }, { 1, 384, 1024 }, { 1024, 1024 }, data_types::u8, format::bfyx, data_types::i8, format::oiyx, data_types::f32, format::bfyx+#define CASE_FC_S8U8_FP16_1 { 2, 32 }, { 2, 16 }, { 16, 32 }, data_types::i8, format::bfyx, data_types::u8, format::oiyx, data_types::f16, format::bfyx+#define CASE_FC_S8U8_FP16_2 { 2, 32, 3 }, { 2, 32, 16 }, { 16, 3 }, data_types::i8, format::bfyx, data_types::u8, format::oiyx, data_types::f16, format::bfyx+#define CASE_FC_FP16_1 { 1, 3 }, { 1, 4 }, { 4, 3 }, data_types::f16, format::bfyx, data_types::f16, format::oiyx, data_types::f32, format::bfyx#define CASE_FC_FP16_2 { 2, 3 }, { 2, 4 }, { 4, 3 }, data_types::f16, format::bfyx, data_types::f16, format::oiyx, data_types::f32, format::bfyx#define CASE_FC_FP16_3 { 2, 32 }, { 2, 16 }, { 16, 32 }, data_types::f16, format::bfyx, data_types::f16, format::oiyx, data_types::f32, format::bfyx@@ -1215,6 +1218,77 @@ TEST_P(fc_fp32_activation_relu, basic) {INSTANTIATE_TEST_SUITE_P(fusings_gpu, fc_fp32_activation_relu, ::testing::ValuesIn(std::vector<fully_connected_test_params>{fully_connected_test_params{ CASE_FC_FP32_1, 2, 3 }}));++class fc_fp16_eltwise_prod_mul_inplace_basic : public FullyConnectedFusingTestOneDNN {};+TEST_P(fc_fp16_eltwise_prod_mul_inplace_basic, matches_unfused_reference) {+ auto p = GetParam();+ create_topologies(+ input_layout("input", get_input_layout(p)),+ input_layout("extra_mul", get_output_layout(p)),+ data("weights", get_mem(get_weights_layout(p))),+ fully_connected("fc_prim", input_info("input"), "weights", "", get_output_dim_size(p)),+ eltwise("mul", {input_info("fc_prim"), input_info("extra_mul")}, eltwise_mode::prod),+ reorder("reorder_bfyx", input_info("mul"), p.default_format, data_types::f16));++ extra_inputs["extra_mul"] = get_output_layout(p);+ tolerance = 1e-2f;+ execute(p);+}++INSTANTIATE_TEST_SUITE_P(fusings_gpu, fc_fp16_eltwise_prod_mul_inplace_basic, ::testing::ValuesIn(std::vector<fully_connected_test_params>{+ fully_connected_test_params{ CASE_FC_FP16_2, 3, 4 },+ fully_connected_test_params{ CASE_FC_FP16_3, 3, 4 },+ fully_connected_test_params{ CASE_FC_FP16_3D_1, 3, 4 },+}));++class fc_s8_u8_fp16_eltwise_prod_mul_inplace : public FullyConnectedFusingTestOneDNN {+public:+ layout get_output_layout(fully_connected_test_params& p) {+ return layout{ p.out_shape, p.default_type, p.default_format };+ }+};++TEST_P(fc_s8_u8_fp16_eltwise_prod_mul_inplace, matches_unfused_reference) {+ auto p = GetParam();+ create_topologies(+ input_layout("input", get_input_layout(p)),+ input_layout("extra_mul", get_output_layout(p)),+ data("weights", get_mem(get_weights_layout(p))),+ fully_connected("fc_prim", input_info("input"), "weights", "", data_types::f16, get_output_dim_size(p), get_input_weights_rank(p)),+ eltwise("mul", {input_info("fc_prim"), input_info("extra_mul")}, eltwise_mode::prod),+ reorder("reorder_bfyx", input_info("mul"), p.default_format, data_types::f16));+ extra_inputs["extra_mul"] = get_output_layout(p);+ tolerance = 1e-2f;+ execute(p);+}++INSTANTIATE_TEST_SUITE_P(fusings_gpu, fc_s8_u8_fp16_eltwise_prod_mul_inplace, ::testing::ValuesIn(std::vector<fully_connected_test_params>{+ fully_connected_test_params{ CASE_FC_S8U8_FP16_1, 3, 4 },+ fully_connected_test_params{ CASE_FC_S8U8_FP16_2, 3, 4 },+}));++class fc_fp16_eltwise_prod_mul_mul_inplace : public FullyConnectedFusingTestOneDNN {};+TEST_P(fc_fp16_eltwise_prod_mul_mul_inplace, matches_unfused_reference) {+ auto p = GetParam();+ create_topologies(+ input_layout("input", get_input_layout(p)),+ input_layout("extra_mul1", get_output_layout(p)),+ input_layout("extra_mul2", get_output_layout(p)),+ data("weights", get_mem(get_weights_layout(p))),+ fully_connected("fc_prim", input_info("input"), "weights", "", get_output_dim_size(p)),+ eltwise("mul1", {input_info("fc_prim"), input_info("extra_mul1")}, eltwise_mode::prod),+ eltwise("mul2", {input_info("mul1"), input_info("extra_mul2")}, eltwise_mode::prod),+ reorder("reorder_bfyx", input_info("mul2"), p.default_format, data_types::f16));++ extra_inputs["extra_mul1"] = get_output_layout(p);+ extra_inputs["extra_mul2"] = get_output_layout(p);+ tolerance = 1e-2f;+ execute(p);+}++INSTANTIATE_TEST_SUITE_P(fusings_gpu, fc_fp16_eltwise_prod_mul_mul_inplace, ::testing::ValuesIn(std::vector<fully_connected_test_params>{+ fully_connected_test_params{ CASE_FC_FP16_3, 4, 6 },+}));#endifclass fc_fp16_eltwise_add_ocl_dynamic : public FullyConnectedFusingTest {diff --git a/src/plugins/intel_gpu/tests/unit/passes/add_onednn_optimization_attributes_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/add_onednn_optimization_attributes_test.cppindex 38ab671582a..5c1d18f5dd2 100644--- a/src/plugins/intel_gpu/tests/unit/passes/add_onednn_optimization_attributes_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/passes/add_onednn_optimization_attributes_test.cpp@@ -93,7 +93,7 @@ TEST(add_onednn_optimization_attributes, sum_post_op_for_residual_connection) {auto &conv3 = prog->get_node("conv3");auto &cldnn_post_ops = conv3.get_fused_primitives();ASSERT_EQ(cldnn_post_ops.size(), 1);- auto fusing_type = onednn_add_fusing_helpers::get_add_fusing_type(conv3, cldnn_post_ops[0]);+ auto fusing_type = onednn_eltwise_fusing_helpers::get_add_fusing_type(conv3, cldnn_post_ops[0]);// Check whether fusing_type is properly selected as sum for residual connection patternASSERT_EQ(fusing_type, add_fusing_type::sum);@@ -137,7 +137,7 @@ TEST(add_onednn_optimization_attributes, fc_sum_u8_single_user_input_uses_sum) {auto& fused = fc_node.get_fused_primitives();ASSERT_EQ(fused.size(), 1);- auto fusing_type = onednn_add_fusing_helpers::get_add_fusing_type(fc_node, fused[0]);+ auto fusing_type = onednn_eltwise_fusing_helpers::get_add_fusing_type(fc_node, fused[0]);ASSERT_EQ(fusing_type, add_fusing_type::sum);}@@ -177,7 +177,7 @@ TEST(add_onednn_optimization_attributes, fc_sum_u8_residual_input_uses_binary) {auto& fused = fc_node.get_fused_primitives();ASSERT_EQ(fused.size(), 1);- auto fusing_type = onednn_add_fusing_helpers::get_add_fusing_type(fc_node, fused[0]);+ auto fusing_type = onednn_eltwise_fusing_helpers::get_add_fusing_type(fc_node, fused[0]);ASSERT_EQ(fusing_type, add_fusing_type::binary_per_tensor);}@@ -215,7 +215,7 @@ static add_fusing_type residual_chain_fusing_type(cldnn::engine& engine, size_t// conv1 feeds both conv2 and the fused eltwise, which is what puts get_add_fusing_type on the// is_direct_ancestor path rather than the single-user shortcut.EXPECT_EQ(prog->get_node("conv1").get_users().size(), 2u);- return onednn_add_fusing_helpers::get_add_fusing_type(last_node, cldnn_post_ops[0]);+ return onednn_eltwise_fusing_helpers::get_add_fusing_type(last_node, cldnn_post_ops[0]);}// An attention residual reaches six hops back -- projection, reshape, attention, reshape, QKVdiff --git a/src/plugins/intel_gpu/tests/unit/passes/basic_memory_dependencies_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/basic_memory_dependencies_test.cppindex ea67d532acd..99987fae909 100644--- a/src/plugins/intel_gpu/tests/unit/passes/basic_memory_dependencies_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/passes/basic_memory_dependencies_test.cpp@@ -183,8 +183,8 @@ TEST(basic_memory_dependencies, optimized_resample_to_onednn_sum_reuse_correctnefor (const auto& fused_desc : conv3_node.get_fused_primitives()) {if (!fused_desc.is_type<eltwise>() || !fused_desc.has_outer_dep())continue;- const auto add_fusing_type = onednn_add_fusing_helpers::get_add_fusing_type(conv3_node, fused_desc);- if (add_fusing_type != onednn_add_fusing_helpers::add_fusing_type::sum)+ const auto add_fusing_type = onednn_eltwise_fusing_helpers::get_add_fusing_type(conv3_node, fused_desc);+ if (add_fusing_type != onednn_eltwise_fusing_helpers::add_fusing_type::sum)continue;const auto outer_dep_idx = static_cast<size_t>(fused_desc.outer_dep_start_idx);if (outer_dep_idx >= conv3_node.get_dependencies().size())@@ -198,7 +198,7 @@ TEST(basic_memory_dependencies, optimized_resample_to_onednn_sum_reuse_correctne<< "ICNet pattern requires eltwise(sum) fused INTO conv3 with resample as outer dep";// conv3 should expose a valid reused eltwise mem idx pointing to resample.- int conv3_reused_idx = onednn_add_fusing_helpers::get_reused_eltwmem_idx(conv3_node);+ int conv3_reused_idx = onednn_eltwise_fusing_helpers::get_reused_eltwmem_idx(conv3_node);ASSERT_GE(conv3_reused_idx, 0);auto conv3_inst = net.get_primitive("conv3");ASSERT_LT(static_cast<size_t>(conv3_reused_idx), conv3_inst->dependencies().size());