Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Resolve perf regression of sdpa_opt usage with systolic arch (#33679)

Min, Byungil7b43dd7e9cc6
diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
index 4199b5d3f06..2c5e03355fd 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
@@ -40,6 +40,8 @@
#include "openvino/core/deprecated.hpp"
#include "openvino/core/type/element_type.hpp"
#include "openvino/core/validation_util.hpp"
+#include "openvino/core/partial_shape.hpp"
+#include "openvino/core/shape.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convolution.hpp"
#include "openvino/op/gather.hpp"
@@ -298,6 +300,31 @@ static bool is_decompression_multiply(const std::shared_ptr<const ov::Node> node
}
} // namespace
+static bool should_decompose_sdpa_for_memory_size(size_t max_size,
+ std::shared_ptr<const ov::op::v13::ScaledDotProductAttention> sdpa) {
+ const auto& q = sdpa->get_input_partial_shape(0);
+ const auto& k = sdpa->get_input_partial_shape(1);
+ const auto& v = sdpa->get_input_partial_shape(2);
+ const auto& sdpa_out = sdpa->get_output_partial_shape(0);
+ const auto dt_size = sdpa->get_element_type().size();
+
+ // Expected sdpa_opt usage : 3D SDPA
+ if (q.size() == 3 && k.size() == 3 && v.size() == 3 && sdpa_out.size() == 3) {
+ if (q.is_dynamic() || k.is_dynamic() || sdpa_out.is_dynamic())
+ return false;
+
+ // Calculate mem size of gemm for Q*K
+ // Gemm layer decomposed from sdpa could exceed max size of memory allocation.
+ size_t sdpa_intermediate_buffer_size = q.get_shape().at(0) * q.get_shape().at(1) * k.get_shape().at(1) * dt_size;
+ if (sdpa_intermediate_buffer_size > max_size * 0.5)
+ return false;
+
+ return true;
+ }
+
+ return false;
+}
+
namespace cldnn {
extern bool query_microkernels_supported(cldnn::engine& e, const cldnn::ExecutionConfig& config);
extern bool check_cm_jit_support(cldnn::engine& e, const cldnn::ExecutionConfig& config);
@@ -703,6 +730,16 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
return false;
}
+ // sdpa_opt will be selected for 3d-tensor sdpa.
+ // sdpa_opt has performance issue on GPUs with XMX. If memory size allows, it is preferrable to decompose sdpa.
+ // If intermediate buffer is expected to be very large, we need to use sdpa_opt to be functional.
+ const auto max_size = m_context->get_engine().get_max_memory_size();
+ if (device_info.supports_immad && should_decompose_sdpa_for_memory_size(max_size, sdpa)) {
+ GPU_DEBUG_TRACE << " Expect sdpa_usage with systolic-arry architectures. mem size is decomposable. Q*K size : query " << query_ps
+ << " key " << key_ps << " dt " << sdpa->get_element_type().size() << std::endl;
+ return false;
+ }
+
const auto head_size = query_ps[query_ps.size() - 1].get_length();
if (device_info.supports_immad && cldnn::query_microkernels_supported(m_context->get_engine(), config) && head_size <= 256)
return true;