From c640aa5b48b7280f4ce612d71dd6f7b6b7dc2623 Mon Sep 17 00:00:00 2001 From: Steve Yoo Date: Fri, 13 Sep 2024 12:23:09 +0000 Subject: [PATCH] [GPU] Fix to enable fc 5d --- .../intel_gpu/src/graph/fully_connected.cpp | 24 +++++++------------ .../test_cases/fully_connected_gpu_test.cpp | 20 ++++++++-------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/plugins/intel_gpu/src/graph/fully_connected.cpp b/src/plugins/intel_gpu/src/graph/fully_connected.cpp index e04541683a0c93..78ae0386c7b115 100644 --- a/src/plugins/intel_gpu/src/graph/fully_connected.cpp +++ b/src/plugins/intel_gpu/src/graph/fully_connected.cpp @@ -115,38 +115,32 @@ layout fully_connected_inst::calc_output_layout(fully_connected_node const& node }; int64_t feature = input_pshape[std::min(desc->input_size, static_cast(4)) - 1].get_length(); + + if (desc->input_size == 3) { + feature = std::max({input_layout.spatial(0), input_layout.spatial(1), input_layout.spatial(2)}); + } + + if (weights_pshape.size() != 2) { + weights_layout.set_partial_shape(reshape_to_2d(weights_pshape, feature)); + } + auto output_size = tensor(); // If immad is supported, spatial dimensions are reshaped to 2d in order to select oneDnn impl, // because oneDnn doesn't support spatial dimensions for output. if (supports_immad) { - if (desc->input_size == 3) { - feature = std::max({input_layout.spatial(0), input_layout.spatial(1), input_layout.spatial(2)}); - } - if (desc->input_size > 3) { input_layout.set_partial_shape(reshape_to_2d(input_pshape, feature)); } - if (weights_pshape.size() != 2) { - weights_layout.set_partial_shape(reshape_to_2d(weights_pshape, feature)); - } output_size = tensor(input_layout.batch(), weights_layout.batch(), 1, 1); if (desc->input_size == 3) { output_size = tensor(input_layout.batch(), input_layout.feature(), 1, weights_layout.batch()); } } else { - feature = input_pshape[std::min(desc->input_size, static_cast(5)) - 1].get_length(); - if (desc->input_size == 3) { - feature = std::max({input_layout.spatial(0), input_layout.spatial(1), input_layout.spatial(2)}); - } - if (desc->input_size > 5) { input_layout.set_partial_shape(reshape_to_2d(input_pshape, feature)); } - if (weights_pshape.size() != 2) { - weights_layout.set_partial_shape(reshape_to_2d(weights_pshape, feature)); - } output_size = tensor(input_layout.batch(), weights_layout.batch(), 1, 1); if (desc->input_size == 3) { 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.cpp index 30c680501af5b0..06191d615e0850 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 @@ -461,17 +461,17 @@ TEST(fully_connected_gpu, no_biases_5d_input) { return; // Input : 1x8x8x8x12 - // Weights: 48x12x1x1 + // Weights: 48x12 // Output : 1x8x8x8x48 const int32_t input_b = 1, input_f = 8, input_z = 8, input_y = 8, input_x = 12, // size of the whole input buffer - weight_b = 48, weight_f = 12, weight_y = 1, weight_x = 1; // size of the whole weights buffer + weight_b = 48, weight_f = 12; // size of the whole weights buffer auto input_prim = engine.allocate_memory({ data_types::f32, format::bfzyx, { input_b, input_f, input_x, input_y, input_z } }); - auto weights_prim = engine.allocate_memory({ data_types::f32, format::bfyx, { weight_b, weight_f, weight_x, weight_y } }); + auto weights_prim = engine.allocate_memory({ { weight_b, weight_f }, data_types::f32, format::bfyx }); std::vector input_data(input_b * input_f * input_z * input_y * input_x, 0); - std::vector weights_data(weight_b * weight_f * weight_y * weight_x, 0); + std::vector weights_data(weight_b * weight_f, 0); set_values(input_prim, std::move(input_data)); set_values(weights_prim, std::move(weights_data)); @@ -501,17 +501,17 @@ TEST(fully_connected_gpu, no_biases_5d_input_immad) { return; // Input : 1x8x8x8x12 - // Weights: 48x12x1x1 + // Weights: 48x12 // Output : 512x48x1x1 const int32_t input_b = 1, input_f = 8, input_z = 8, input_y = 8, input_x = 12, // size of the whole input buffer - weight_b = 48, weight_f = 12, weight_y = 1, weight_x = 1; // size of the whole weights buffer + weight_b = 48, weight_f = 12; // size of the whole weights buffer auto input_prim = engine.allocate_memory({ data_types::f32, format::bfzyx, { input_b, input_f, input_x, input_y, input_z } }); - auto weights_prim = engine.allocate_memory({ data_types::f32, format::bfyx, { weight_b, weight_f, weight_x, weight_y } }); + auto weights_prim = engine.allocate_memory({ { weight_b, weight_f }, data_types::f32, format::bfyx }); std::vector input_data(input_b * input_f * input_z * input_y * input_x, 0); - std::vector weights_data(weight_b * weight_f * weight_y * weight_x, 0); + std::vector weights_data(weight_b * weight_f, 0); set_values(input_prim, std::move(input_data)); set_values(weights_prim, std::move(weights_data)); @@ -536,8 +536,8 @@ TEST(fully_connected_gpu, no_biases_5d_input_immad) { auto outputs = network.execute(); ASSERT_EQ(outputs.begin()->second.get_layout().batch(), input_f*input_z*input_y); ASSERT_EQ(outputs.begin()->second.get_layout().feature(), weight_b); - ASSERT_EQ(outputs.begin()->second.get_layout().spatial(1), weight_y); - ASSERT_EQ(outputs.begin()->second.get_layout().spatial(0), weight_x); + ASSERT_EQ(outputs.begin()->second.get_layout().spatial(1), 1); + ASSERT_EQ(outputs.begin()->second.get_layout().spatial(0), 1); } TEST(fully_connected_gpu, xb_f32_batch_1) {