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] Enforce oneDNN post-op cap for FC in validate_impl (#38035)
Zhaoliangb0104bc403f0
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp b/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hppindex 96c5b45aa64..cdd1788a975 100644--- a/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp@@ -102,7 +102,7 @@ struct FullyConnectedImplementationManager : public ImplementationManager {}}- return true;+ return is_supported_post_ops(node);}in_out_fmts_t query_formats(const program_node& node) const override {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 919f85b2c05..75e971ec4f9 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@@ -1494,3 +1494,102 @@ TEST_P(fc_fp16_fuse_bias_and_find_eltwise_4d, basic) {INSTANTIATE_TEST_SUITE_P(fusings_gpu, fc_fp16_fuse_bias_and_find_eltwise_4d, ::testing::ValuesIn(std::vector<fully_connected_test_params>{fully_connected_test_params{ DYN_CASE_FC_FP16_4D_1, 2, 4 },}));++// Verify that a chain exceeding the oneDNN post-op cap still produces numerically+// identical output. With the check moved to validate_impl, ALL post-ops fuse into+// the node, but validate_impl rejects the oneDNN impl when > 32 post-ops are present,+// causing the node to fall back to OCL which handles them all correctly.+#ifdef ENABLE_ONEDNN_FOR_GPU+class fc_fp16_eltwise_sum_post_op_cap : public FullyConnectedFusingTestOneDNN {+public:+ void run_test(int num_activations) {+ auto p = GetParam();++ if (!engine.get_device_info().supports_immad)+ GTEST_SKIP();++ static constexpr int num_post_ops = 33;+ const int num_sums = num_post_ops - num_activations;++ auto w_mem = get_mem(get_weights_layout(p), -1, 1);+ auto b_mem = get_mem(get_bias_layout(p), -2, 2);++ for (auto* topo : {&topology_fused, &topology_non_fused}) {+ topo->add(input_layout("input", get_input_layout(p)));+ topo->add(data("weights", w_mem));+ topo->add(data("bias", b_mem));+ topo->add(fully_connected("fc_prim", input_info("input"), "weights", "bias", get_output_dim_size(p)));+ }++ std::string prev = "fc_prim";+ for (int i = 0; i < num_activations; i++) {+ auto name = "activation_" + std::to_string(i);+ for (auto* topo : {&topology_fused, &topology_non_fused})+ topo->add(activation(name, input_info(prev), activation_func::relu));+ prev = name;+ }++ for (int i = 0; i < num_sums; i++) {+ auto dname = "sum_data_" + std::to_string(i);+ auto ename = "sum_" + std::to_string(i);+ auto d_mem = get_mem(get_per_channel_layout(p), 1, 9);+ for (auto* topo : {&topology_fused, &topology_non_fused}) {+ topo->add(data(dname, d_mem));+ topo->add(eltwise(ename, {input_info(prev), input_info(dname)}, eltwise_mode::sum));+ }+ prev = ename;+ }++ for (auto* topo : {&topology_fused, &topology_non_fused})+ topo->add(reorder("reorder_bfyx", input_info(prev), p.default_format, data_types::f32));++ auto input_prim = get_mem(get_input_layout(p), -1, 1);+ network network_not_fused(engine, topology_non_fused, cfg_not_fused);+ network network_fused(engine, topology_fused, cfg_fused);+ network_fused.set_input_data("input", input_prim);+ network_not_fused.set_input_data("input", input_prim);++ // All post-ops fuse into fc_prim. When the count exceeds the oneDNN cap,+ // validate_impl rejects the oneDNN impl so fc_prim runs on OCL, which still+ // produces the correct result (verified against the non-fused reference below).+ auto primitives_info = network_fused.get_primitives_info();+ auto fc_info = std::find_if(primitives_info.begin(), primitives_info.end(), [](const primitive_info& info) {+ return info.original_id == "fc_prim";+ });+ ASSERT_NE(fc_info, primitives_info.end());+ ASSERT_EQ(fc_info->c_fused_ids.size(), size_t(num_post_ops));+ for (int i = 0; i < num_activations; i++) {+ auto name = "activation_" + std::to_string(i);+ ASSERT_NE(std::find(fc_info->c_fused_ids.begin(), fc_info->c_fused_ids.end(), name), fc_info->c_fused_ids.end());+ }+ for (int i = 0; i < num_sums; i++) {+ auto name = "sum_" + std::to_string(i);+ ASSERT_NE(std::find(fc_info->c_fused_ids.begin(), fc_info->c_fused_ids.end(), name), fc_info->c_fused_ids.end());+ }++ auto outputs_ref = network_not_fused.execute();+ auto outputs_opt = network_fused.execute();++ ASSERT_EQ(outputs_ref.size(), size_t(1));+ ASSERT_EQ(outputs_opt.size(), size_t(1));+ auto val_ref = get_output_values_to_float(network_not_fused, outputs_ref.begin()->second);+ std::vector<float> val_opt;+ ASSERT_NO_THROW(val_opt = get_output_values_to_float(network_fused, outputs_opt.begin()->second));+ ASSERT_EQ(val_ref.size(), val_opt.size());+ for (size_t i = 0; i < val_ref.size(); i++)+ ASSERT_NEAR(val_ref[i], val_opt[i], 0.5f);+ }+};++TEST_P(fc_fp16_eltwise_sum_post_op_cap, basic) {+ run_test(0);+}++TEST_P(fc_fp16_eltwise_sum_post_op_cap, activation_chain) {+ run_test(4);+}++INSTANTIATE_TEST_SUITE_P(fusings_gpu, fc_fp16_eltwise_sum_post_op_cap, ::testing::ValuesIn(std::vector<fully_connected_test_params>{+ fully_connected_test_params{ CASE_FC_FP16_1, 0, 0 },+}));+#endif // ENABLE_ONEDNN_FOR_GPU