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] Disable crop buffer fusing for better perf (#31044)
Kelvin Choifb911f51a58a
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 124d61db911..65a2a338b4f 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@@ -374,6 +374,24 @@ static bool is_optimizable_padding_for_crop(const crop_node& node,input_layout.data_padding._lower_size[3] != 0 || input_layout.data_padding._upper_size[3] != 0)return false;+ // For static shape, gemm ref kernel is selected if there is padding on the feature, x, or y axes.+ // In such cases, do not optimize out this crop to use the opt kernel.+ // TODO: Modify gemm_tiled_opt kernel to support padding even in static shape.+ auto output_layout = node.get_output_layout();+ bool is_input_lower_pad = offsets.feature[0] != 0 || offsets.spatial[0] != 0 || offsets.spatial[1] != 0;+ bool is_input_upper_pad = (output_layout.is_static() &&+ ((input_layout.feature() - offsets.feature[0] - output_layout.get_tensor().feature[0]) != 0 ||+ (input_layout.spatial(0) - offsets.spatial[0] - output_layout.get_tensor().spatial[0]) != 0 ||+ (input_layout.spatial(1) - offsets.spatial[1] - output_layout.get_tensor().spatial[1]) != 0));++ if (is_input_lower_pad || is_input_upper_pad) {+ for (auto user : node.get_users()) {+ if (user->is_type<gemm>() && user->get_dependency_index(node) < 2) {+ return false;+ }+ }+ }+auto opt_lower_pad = offsets.feature[0];auto opt_upper_pad = input_layout.feature() - offsets.feature[0] - crop_layout.get_tensor().feature[0];@@ -488,17 +506,6 @@ bool crop_in_place_optimization::match(const program_node& node,// TODO: Need to allow optimization for gemm userif (node.is_dynamic() && (user->is_type<convolution>() || user->is_type<gemm>()))return false;- // For static shape, gemm ref kernel is selected if there is padding on the feature, x, or y axes.- // In such cases, do not optimize out this crop to use the opt kernel.- // TODO: Modify gemm_tiled_opt kernel to support padding even in static shape.- if ((!node.is_dynamic() || is_runtime) && user->is_type<gemm>() &&- (user->get_dependency_index(node) == 0 || user->get_dependency_index(node) == 1)) {- if (crop_params.input_offsets[0].feature[0] != 0 ||- crop_params.input_offsets[0].spatial[0] != 0 ||- crop_params.input_offsets[0].spatial[1] != 0) {- return false;- }- }if (user->is_type<reshape>()) {// runtime buffer fusing is only handled when there is only one reshape userif (node.is_dynamic() && node.get_users().size() != 1)diff --git a/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cppindex 303cad0aa45..fb743d8346c 100644--- a/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/passes/prepare_buffer_fusing_test.cpp@@ -709,7 +709,7 @@ TEST(prepare_buffer_fusing, in_place_crop_static) {ASSERT_EQ(output_ptr_2[i], out2[i]);}-TEST(prepare_buffer_fusing, in_place_crop_static_padding_and_gemm) {+TEST(prepare_buffer_fusing, disable_crop_buffer_fusing_with_shift_right_padding) {auto& engine = get_test_engine();auto gemm_input_mem = engine.allocate_memory({ {1, 4, 4, 2}, data_types::f32, format::bfyx });@@ -747,7 +747,7 @@ TEST(prepare_buffer_fusing, in_place_crop_static_padding_and_gemm) {auto outputs = network.execute();auto crop_prim = network.get_primitive("crop");- ASSERT_EQ(crop_prim->can_be_optimized(), true);+ ASSERT_EQ(crop_prim->can_be_optimized(), false); // Not opt out because the user, gemm node, has paddings at spatial dimensionsauto output = outputs.at("output").get_memory();cldnn::mem_lock<float> output_ptr(output, get_test_stream());