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] adding sdpa_micro_gqa_single_token (#33204)
Eddy Kim41839d2408aa
diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_attention.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_attention.hppindex ca5b8dbbe22..62e0f7986ca 100644--- a/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_attention.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_attention.hpp@@ -58,6 +58,26 @@ struct paged_attention : public primitive_base<paged_attention> {return num_outputs >= 2;}+ size_t hash() const override {+ size_t seed = primitive::hash();+ seed = hash_combine(seed, k_head_size);+ seed = hash_combine(seed, v_head_size);+ seed = hash_combine(seed, heads_num);+ seed = hash_combine(seed, kv_heads_num);+ seed = hash_combine(seed, has_alibi);+ seed = hash_combine(seed, has_rotated_blocks);+ seed = hash_combine(seed, sliding_window);+ seed = hash_combine(seed, has_score_aggregation);+ seed = hash_combine(seed, has_xattention);+ seed = hash_combine(seed, has_sink_input);+ if (scale_val.has_value()) {+ seed = hash_combine(seed, scale_val.value());+ }+ seed = hash_combine(seed, is_key_by_channel);++ return seed;+ }+bool operator==(const primitive& rhs) const override {if (!compare_common_params(rhs))return false;@@ -82,7 +102,6 @@ struct paged_attention : public primitive_base<paged_attention> {ob << heads_num;ob << kv_heads_num;ob << has_alibi;- ob << has_score_aggregation;ob << has_rotated_blocks;ob << sliding_window;ob << has_score_aggregation;@@ -106,7 +125,6 @@ struct paged_attention : public primitive_base<paged_attention> {ib >> heads_num;ib >> kv_heads_num;ib >> has_alibi;- ib >> has_score_aggregation;ib >> has_rotated_blocks;ib >> sliding_window;ib >> has_score_aggregation;diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.cppindex b07cc4ffdf3..4fa80e1457d 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.cpp@@ -15,7 +15,6 @@#include <utility>#include "../primitive_ocl_base.hpp"-#include "../utils/kernel_generator.hpp"#include "common_utils/jitter.hpp"#include "intel_gpu/graph/kernel_impl_params.hpp"#include "intel_gpu/primitives/paged_attention.hpp"@@ -27,27 +26,12 @@#include "sdpa_gen_opt.hpp"namespace ov::intel_gpu::ocl {namespace {-enum class PagedAttentionStage : uint8_t { GENERATE = 0, PREFILL = 1, MIXED = 2, UNKNOWN = 3 };constexpr ov::element::Type softmax_accumulator_type = ov::element::f32;constexpr size_t paged_attention_block_size = 16;constexpr size_t seq_len_partition_size = 256;constexpr size_t subgroup_size = 16;-struct PagedAttentionRuntimeParams : public ImplRuntimeParams {- PagedAttentionStage stage;- size_t num_of_partitions;- size_t partition_size;- size_t max_context_len;- size_t paged_attention_aligned_seq_len;- size_t sdpa_opt_seq_len_partition_size;-- size_t paged_attention_snap_kv_tokens;- bool use_micro_sdpa = false;- bool use_gqa_kernel = false;- size_t query_block_size = 16;-};-inline bool get_kv_compressed(const RuntimeParams& params) {auto key_cache_layout = params.input_layouts[PagedAttentionInputIdx::KEY_CACHE];if (data_type_traits::is_i8_u8(key_cache_layout.data_type)) {@@ -1104,6 +1088,7 @@ public:#ifdef ENABLE_ONEDNN_FOR_GPUStage::Ptr pa_sdpa_micro = make_stage<SDPAMicroGenerator>(true);Stage::Ptr pa_sdpa_micro_mixed = make_stage<SDPAMicroGenerator>(false);+ Stage::Ptr pa_sdpa_micro_gqa_single_token = make_stage<SDPAMicroGenerator>(false, true);#endifPagedAttentionOptImpl() : SDPAImplBase(PagedAttentionOpt::get_type_info_static()) {}@@ -1117,6 +1102,7 @@ public:if (use_micro_sdpa) {add_stage(pa_sdpa_micro, params);add_stage(pa_sdpa_micro_mixed, params);+ add_stage(pa_sdpa_micro_gqa_single_token, params);}#endif@@ -1188,7 +1174,10 @@ public:size_t get_query_block_size(const PagedAttentionStage& stage, const bool use_micro_sdpa) const {const auto default_block_size = 16;if (use_micro_sdpa) {- return (stage == PagedAttentionStage::PREFILL) ? get_micro_tile_qsize(pa_sdpa_micro->kd) : get_micro_tile_qsize(pa_sdpa_micro_mixed->kd);+ if (stage == PagedAttentionStage::PREFILL)+ return get_micro_tile_qsize(pa_sdpa_micro->kd);+ else if (stage == PagedAttentionStage::MIXED)+ return get_micro_tile_qsize(pa_sdpa_micro_mixed->kd);}return default_block_size;}@@ -1233,14 +1222,20 @@ public:}#ifdef ENABLE_ONEDNN_FOR_GPU- rt_params->use_micro_sdpa = supports_micro_sdpa(params) && rt_params->stage != PagedAttentionStage::GENERATE;+ rt_params->use_micro_sdpa = supports_micro_sdpa(params);#elsert_params->use_micro_sdpa = false;#endifrt_params->query_block_size = get_query_block_size(rt_params->stage, rt_params->use_micro_sdpa);- if (rt_params->stage == PagedAttentionStage::GENERATE && !rt_params->use_micro_sdpa) {- rt_params->use_gqa_kernel = can_use_gqa_kernel(params, PagedAttentionStage::GENERATE, rt_params->max_context_len);+ if (rt_params->stage == PagedAttentionStage::GENERATE) {+ if (rt_params->use_micro_sdpa) {+ size_t kv_group_size = desc->heads_num / desc->kv_heads_num;+ rt_params->use_gqa_kernel = (kv_group_size == 8 && desc->k_head_size == 64);+ rt_params->use_micro_sdpa = rt_params->use_gqa_kernel;+ } else {+ rt_params->use_gqa_kernel = can_use_gqa_kernel(params, PagedAttentionStage::GENERATE, rt_params->max_context_len);+ }} else {rt_params->use_gqa_kernel = false;}@@ -1274,23 +1269,22 @@ public:if (rt_params->stage == PagedAttentionStage::PREFILL) {#ifdef ENABLE_ONEDNN_FOR_GPU- if (rt_params->use_micro_sdpa) {+ if (rt_params->use_micro_sdpa)res_event = {execute_stage(res_event, instance, pa_sdpa_micro)};- } else {- res_event = {execute_stage(res_event, instance, pa_sdpa_opt)};- }-#else- res_event = {execute_stage(res_event, instance, pa_sdpa_opt)};+ else#endif+ res_event = {execute_stage(res_event, instance, pa_sdpa_opt)};} else if (rt_params->stage == PagedAttentionStage::GENERATE || rt_params->stage == PagedAttentionStage::MIXED) {const auto multi_tokens_mode = rt_params->stage == PagedAttentionStage::MIXED;auto num_of_partitions = rt_params->num_of_partitions;- if (rt_params->use_gqa_kernel) {+ if (rt_params->use_gqa_kernel && !rt_params->use_micro_sdpa) {res_event = {execute_stage(res_event, instance, multi_tokens_mode ? pa_multi_token : pa_gqa_single_token)};} else {#ifdef ENABLE_ONEDNN_FOR_GPUif (multi_tokens_mode && rt_params->use_micro_sdpa)res_event = {execute_stage(res_event, instance, pa_sdpa_micro_mixed)};+ else if (!multi_tokens_mode && rt_params->use_micro_sdpa && rt_params->use_gqa_kernel)+ res_event = {execute_stage(res_event, instance, pa_sdpa_micro_gqa_single_token)};else#endifres_event = {execute_stage(res_event, instance, multi_tokens_mode ? pa_multi_token : pa_single_token)};@@ -1385,7 +1379,9 @@ public:}bool can_use_micro_sdpa = false;#ifdef ENABLE_ONEDNN_FOR_GPU- can_use_micro_sdpa = has_stage(pa_sdpa_micro) && stage != PagedAttentionStage::GENERATE;+ can_use_micro_sdpa = has_stage(pa_sdpa_micro);+ if (stage == PagedAttentionStage::GENERATE && rt_params->use_gqa_kernel == false)+ can_use_micro_sdpa = false;#endifGPU_DEBUG_TRACE_DETAIL << "get_internal_buffer_descs: stage = " << static_cast<size_t>(stage) << std::endl;int64_t paged_attention_aligned_seq_len = -1;@@ -1580,13 +1576,13 @@ public:OPENVINO_ASSERT(intermediates_memories.size() > sequential_gws_subseq_mapping_idx,"[GPU] Unexpected number of intermediates buffers for Paged Attention for mixed stage");- auto sequential_gws_subseq_mapping_mem = intermediates_memories[sequential_gws_subseq_mapping_idx];+ auto& sequential_gws_subseq_mapping_mem = intermediates_memories[sequential_gws_subseq_mapping_idx];sequential_gws_subseq_mapping_lock.reset(new mem_lock<int32_t, mem_lock_type::write>(sequential_gws_subseq_mapping_mem, stream));}if (use_micro_sdpa) {const auto memory_idx = 3; // intermediate_idx for micro kernel- auto memory = intermediates_memories[memory_idx];+ auto& memory = intermediates_memories[memory_idx];micro_sdpa_block_starts_and_gws_mapping_lock.reset(new mem_lock<int32_t, mem_lock_type::write>(memory, stream));}diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.hpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.hppindex d3c3c92f6f5..9aaeb506b39 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.hpp+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.hpp@@ -8,6 +8,7 @@#include <memory>#include <utility>+#include "../utils/kernel_generator.hpp"#include "paged_attention_inst.h"#include "program_node.h"#include "registry/implementation_manager.hpp"@@ -16,6 +17,22 @@ using namespace cldnn; // TODO: Remove once namespaces are alignednamespace ov::intel_gpu::ocl {+enum class PagedAttentionStage : uint8_t { GENERATE = 0, PREFILL = 1, MIXED = 2, UNKNOWN = 3 };++struct PagedAttentionRuntimeParams : public ImplRuntimeParams {+ PagedAttentionStage stage;+ size_t num_of_partitions;+ size_t partition_size;+ size_t max_context_len;+ size_t paged_attention_aligned_seq_len;+ size_t sdpa_opt_seq_len_partition_size;++ size_t paged_attention_snap_kv_tokens;+ bool use_micro_sdpa = false;+ bool use_gqa_kernel = false;+ size_t query_block_size = 16;+};+struct PagedAttentionOpt : public ImplementationManager {OV_GPU_PRIMITIVE_IMPL("ocl::paged_attention::opt")explicit PagedAttentionOpt(shape_types shape_type, ValidateFunc vf = nullptr) : ImplementationManager(impl_types::ocl, shape_type, std::move(vf)) {}diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.cppindex 3807efad77f..648793acdf8 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.cpp@@ -7,6 +7,7 @@// Put this file at first to avoid incorrect header files includes order.// For example, intel_gpu/runtime/utils.hpp will causes compiling error in hash<dnnl::impl::primitive_hashing::key_t>#include "sdpa_gen_micro.hpp"+#include "paged_attention_opt.hpp"#include "intel_gpu/graph/kernel_impl_params.hpp"#include "intel_gpu/primitives/scaled_dot_product_attention.hpp"@@ -335,6 +336,7 @@ sdpa_config_t xehpc_h32_s32 = {16, 16, 16, 16, 2, 4, 2, 4};sdpa_config_t xehpc_h32_2nd = {16, 64, 16, 16, 8, 1, 2, 4};sdpa_config_t xehpc_h64_pa = {16, 16, 16, 16, 4, 4, 4, 4};+sdpa_config_t xehpc_h64_pa_2nd = {16, 16, 16, 16, 16, 2, 16, 2};sdpa_config_t xehpc_h64 = {16, 64, 32, 16, 8, 2, 2, 8};sdpa_config_t xehpc_h64_s64 = {32, 32, 32, 16, 4, 2, 2, 4};sdpa_config_t xehpc_h64_s32 = {16, 16, 16, 16, 4, 2, 4, 2};@@ -568,7 +570,7 @@ sdpa_config_t* choose_config_xehpc(int head_size, int seq, bool thin_q, bool quareturn &xehpc_h32;} else if (head_size <= 64) {if (seq <= 0 && is_pa)- return is_prefill ? &xehpc_h64 : &xehpc_h64_pa;+ return is_prefill ? &xehpc_h64 : (thin_q ? &xehpc_h64_pa_2nd : &xehpc_h64_pa);if (thin_q) {if (quantized) {if (seq <= 96)@@ -871,7 +873,7 @@ KernelData SDPAMicroGenerator::get_kernel_data(const kernel_impl_params& params)std::vector<micro::Package> gemms(2); // KQ and VSsdpa_configuration sdpa_config;init_sdpa_configuration(params, sdpa_config);- init_microkernels(params, sdpa_config, gemms[kq_id], gemms[vs_id], m_is_prefill);+ init_microkernels(params, sdpa_config, gemms[kq_id], gemms[vs_id], m_is_prefill, m_is_gqa_single_token);const auto& device_info = params.get_device_info();auto jit = get_jit_constants(params, gemms[kq_id], gemms[vs_id]);@@ -1029,10 +1031,11 @@ JitConstants SDPAMicroGenerator::get_jit_constants(const kernel_impl_params& parjit.make("A_ALIGN", micro::alignment_for_ld(static_cast<int>(lda)));jit.make("IS_PREFILL", m_is_prefill);+ jit.make("IS_GQA_SINGLE_TOKEN", m_is_gqa_single_token);jit.make("TRANSPOSE_K", false);jit.make("IS_PAGED_ATTENTION", config.is_paged_attention ? 1 : 0);jit.make("KV_HEADS_NUM", config.kv_heads_num);- jit.make("HEADS_NUM", config.heads_num);+ jit.make("HEADS_NUM", m_is_gqa_single_token ? config.kv_heads_num : config.heads_num);jit.make("QRY_DATA_T", to_ocl_type(Q.data_type));jit.make("KEY_DATA_T", to_ocl_type(K.data_type));@@ -1319,7 +1322,13 @@ DispatchDataFunc SDPAMicroGenerator::get_dispatch_data_func() const {const auto& out_ps = out.get_partial_shape();const auto v_head_size = micro_get_head_size(params, 2);- const auto head_num = micro_get_num_heads(params, 0);+ auto head_num = micro_get_num_heads(params, 0);++ if (params.is_type<paged_attention>()) {+ auto pa_rt_params = static_cast<PagedAttentionRuntimeParams*>(rt_params);+ if (pa_rt_params->stage == PagedAttentionStage::GENERATE)+ head_num = micro_get_num_heads(params, 1);+ }auto wg_tile_q = gemm_kq.getSetting("wg_tile_n");auto sg_per_wg = gemm_kq.getSetting("sg_per_wg_m") * gemm_kq.getSetting("sg_per_wg_n");@@ -1374,7 +1383,8 @@ void SDPAMicroGenerator::init_microkernels(const kernel_impl_params& params,const sdpa_configuration& configuration,micro::Package& gemm_kq,micro::Package& gemm_vs,- bool is_prefill) {+ bool is_prefill,+ bool is_gqa_single_token) {// TODO: Remove once micro API is thread safestd::lock_guard<std::mutex> l(m);@@ -1403,6 +1413,8 @@ void SDPAMicroGenerator::init_microkernels(const kernel_impl_params& params,/* Retrieve pre-tuned kernel configuration */sdpa_config_t* config = nullptr;bool thin_q = (!n_queries.is_dynamic() && n_queries.get_length() <= 16) || !is_prefill;+ if (is_paged_attention && !is_prefill)+ thin_q = is_gqa_single_token;bool is_integrated = device_info.dev_type == device_type::integrated_gpu;bool is_quantized =diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.hpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.hppindex b8969097fc6..dfea7bbff13 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.hpp+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.hpp@@ -22,7 +22,17 @@ namespace ov::intel_gpu::ocl {#ifdef ENABLE_ONEDNN_FOR_GPUclass SDPAMicroGenerator : public SDPABase {public:- explicit SDPAMicroGenerator(bool prefill) : SDPABase("sdpa_micro", prefill ? "_prefill" : "_generate", false), m_is_prefill(prefill) {}+ explicit SDPAMicroGenerator(bool prefill, bool gqa_single_token = false)+ : SDPABase("sdpa_micro",+ prefill ? "_prefill"+ : gqa_single_token ? "_gqa_single_token"+ : "_generate",+ false),+ m_is_prefill(prefill),+ m_is_gqa_single_token(gqa_single_token) {+ if (gqa_single_token)+ OPENVINO_ASSERT(prefill == false, "prefill should be false when gqa_single_token is true");+ }[[nodiscard]] std::string get_build_options(const kernel_impl_params& params) const override;[[nodiscard]] KernelData get_kernel_data(const kernel_impl_params& params) const override;@@ -43,10 +53,12 @@ private:const sdpa_configuration& sdpa_config,micro::Package& gemm_kq,micro::Package& gemm_vs,- bool is_prefill);+ bool is_prefill,+ bool is_gqa_single_token);static void init_sdpa_configuration(const kernel_impl_params& params, sdpa_configuration& config);bool m_is_prefill;+ bool m_is_gqa_single_token;static std::mutex m;static constexpr size_t kq_id = 0;diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_micro.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_micro.clindex 1097aab40f3..ba0d67e80d9 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_micro.cl+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_micro.cl@@ -179,18 +179,25 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARGconst uint subsequence_begin = subsequence_begins[gws_mapping];const uint subsequence_end = subsequence_begins[gws_mapping + 1];const uint subsequence_query_block_idx = block_start_pos - subsequence_begin;- const int q = subsequence_end - subsequence_begin;+ int q = subsequence_end - subsequence_begin;#if IS_PREFILLconst int k = q;#elseconst int k = q + past_lens[gws_mapping];#endifconst int d = HEAD_SIZE;+#if IS_GQA_SINGLE_TOKEN+ q *= KV_GROUP_SIZE;+#endif#endifuint sg_ij = sub_group_broadcast(get_local_id(1), 0);uint b0 = get_group_id(1);uint b1 = get_group_id(2);+#if IS_GQA_SINGLE_TOKEN+ uint b0_kv = b0;+#elseuint b0_kv = b0 / KV_GROUP_SIZE;+#endif#if IS_PAGED_ATTENTIONuint wg_j0 = subsequence_query_block_idx;@@ -199,8 +206,13 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG#endif/* Leading dimension for matrices */#if IS_PAGED_ATTENTION- uint ldq = HEAD_SIZE * HEADS_NUM + INPUT0_PAD_BEFORE_FEATURE_NUM + INPUT0_PAD_AFTER_FEATURE_NUM;- uint lda = HEAD_SIZE * HEADS_NUM;+ #if IS_GQA_SINGLE_TOKEN+ uint ldq = HEAD_SIZE + INPUT0_PAD_BEFORE_FEATURE_NUM + INPUT0_PAD_AFTER_FEATURE_NUM;+ uint lda = HEAD_SIZE;+ #else+ uint ldq = HEAD_SIZE * HEADS_NUM + INPUT0_PAD_BEFORE_FEATURE_NUM + INPUT0_PAD_AFTER_FEATURE_NUM;+ uint lda = HEAD_SIZE * HEADS_NUM;+ #endif#if IS_PREFILLuint ldk = HEAD_SIZE * KV_HEADS_NUM + INPUT1_PAD_BEFORE_FEATURE_NUM + INPUT1_PAD_AFTER_FEATURE_NUM;uint ldv = HEAD_SIZE * KV_HEADS_NUM + INPUT2_PAD_BEFORE_FEATURE_NUM + INPUT2_PAD_AFTER_FEATURE_NUM;@@ -262,10 +274,17 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG/* Locate K/Q/V/A matrices within batch */#if IS_PAGED_ATTENTION- Q += subsequence_begin * ldq- + b0 * HEAD_SIZE + INPUT0_PAD_BEFORE_FEATURE_NUM;- A += subsequence_begin * lda- + b0 * HEAD_SIZE;+ #if IS_GQA_SINGLE_TOKEN+ Q += subsequence_begin * ldq+ + b0 * HEAD_SIZE * KV_GROUP_SIZE + INPUT0_PAD_BEFORE_FEATURE_NUM;+ A += subsequence_begin * lda+ + b0 * HEAD_SIZE * KV_GROUP_SIZE;+ #else+ Q += subsequence_begin * ldq+ + b0 * HEAD_SIZE + INPUT0_PAD_BEFORE_FEATURE_NUM;+ A += subsequence_begin * lda+ + b0 * HEAD_SIZE;+ #endif#if IS_PREFILLK += subsequence_begin * ldk+ b0_kv * HEAD_SIZE + INPUT1_PAD_BEFORE_FEATURE_NUM;@@ -357,7 +376,12 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARGfloat masked_scale = iscale * STATIC_SCALAR_ATTN_MASK_VALUE;#endif#ifdef HAS_SINK_INPUT- const float sink_val = convert_float(sink_ptr[b0]);+ #if IS_GQA_SINGLE_TOKEN+ int sink_idx = b0 * KV_GROUP_SIZE + get_sub_group_local_id();+ const float sink_val = convert_float(sink_ptr[sink_idx]);+ #else+ const float sink_val = convert_float(sink_ptr[b0]);+ #endif#define MULTI_TOKENS_PER_WI ((ugemm_kq_sg_tile_n/SUBGROUP_SIZE) > 1)#if MULTI_TOKENS_PER_WI#define VEC_SIZE (ugemm_kq_sg_tile_n / SUBGROUP_SIZE)@@ -549,7 +573,11 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARGint col_offset = wg_j0 + sg_j0_kq;#if IS_PAGED_ATTENTION && IS_PREFILL == 0- col_offset += k - q;+ #if IS_GQA_SINGLE_TOKEN+ col_offset += k - 1 - get_sub_group_local_id();+ #else+ col_offset += k - q;+ #endif#endif/* Apply causal mask */diff --git a/src/plugins/intel_gpu/src/graph/include/paged_attention_inst.h b/src/plugins/intel_gpu/src/graph/include/paged_attention_inst.hindex 5f5cd4f4333..aa682b2a4f9 100644--- a/src/plugins/intel_gpu/src/graph/include/paged_attention_inst.h+++ b/src/plugins/intel_gpu/src/graph/include/paged_attention_inst.h@@ -17,7 +17,7 @@ private:using parent = typed_program_node_base<paged_attention>;public:- using parent::parent;+ typed_program_node(const std::shared_ptr<paged_attention> prim, program& prog);std::set<size_t> get_lockable_input_ids() const override {std::set<size_t> input_ports = { PagedAttentionInputIdx::PAST_LENS,diff --git a/src/plugins/intel_gpu/src/graph/include/primitive_inst.h b/src/plugins/intel_gpu/src/graph/include/primitive_inst.hindex 1ad1a8cbeff..aeba6039824 100644--- a/src/plugins/intel_gpu/src/graph/include/primitive_inst.h+++ b/src/plugins/intel_gpu/src/graph/include/primitive_inst.h@@ -320,6 +320,7 @@ public:bool mem_allocated() const { return _mem_allocated; }bool is_dynamic() const { return _is_dynamic; }bool can_share_buffer() const { return _can_share_buffer; }+ bool can_share_internal_buffer() const { return _can_share_internal_buffer; }bool is_constant() const { return _is_constant; }bool needs_completion_event() const { return _needs_completion_event; }bool has_unfused_subgraph() const { return (_unfused_subgraph != nullptr); }@@ -437,6 +438,7 @@ protected:size_t _fused_mem_offset = 0;bool _can_be_optimized = false;bool _can_share_buffer = true;+ bool _can_share_internal_buffer = true;bool _is_constant = false;bool _needs_completion_event = false;diff --git a/src/plugins/intel_gpu/src/graph/include/program_node.h b/src/plugins/intel_gpu/src/graph/include/program_node.hindex 2fcc9fce53a..69cc67c96f6 100644--- a/src/plugins/intel_gpu/src/graph/include/program_node.h+++ b/src/plugins/intel_gpu/src/graph/include/program_node.h@@ -321,6 +321,10 @@ public:bool can_share_buffer() const { return share_buffer; }void can_share_buffer(bool share) { share_buffer = share; }+ // check/set if the node's internal buffer can be shared+ bool can_share_internal_buffer() const { return share_internal_buffer; }+ void can_share_internal_buffer(bool share) { share_internal_buffer = share; }+// Sets padding support for all axisvoid support_padding_all(bool support);// Sets padding support for specified axis@@ -519,6 +523,7 @@ protected:uint8_t user_mark = 0;bool optimized = false;bool share_buffer = true;+ bool share_internal_buffer = true;std::array<bool, tensor_dim_max> _support_padding_in_axis;mutable bool has_reused_memory = false;diff --git a/src/plugins/intel_gpu/src/graph/paged_attention.cpp b/src/plugins/intel_gpu/src/graph/paged_attention.cppindex ba9742f3e64..7e567d7eca3 100644--- a/src/plugins/intel_gpu/src/graph/paged_attention.cpp+++ b/src/plugins/intel_gpu/src/graph/paged_attention.cpp@@ -11,6 +11,11 @@namespace cldnn {GPU_DEFINE_PRIMITIVE_TYPE_ID(paged_attention)+paged_attention_node::typed_program_node(const std::shared_ptr<paged_attention> prim, program& prog)+ : parent(prim, prog) {+ can_share_internal_buffer(false);+}+layout paged_attention_inst::calc_output_layout(const paged_attention_node& /*node*/, kernel_impl_params const& impl_param) {auto out_layout = impl_param.get_input_layout(0);diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cppindex c521f390f7a..d7e4eefcc40 100644--- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp+++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp@@ -2259,6 +2259,7 @@ primitive_inst::primitive_inst(network & network, program_node const& node, bool, _fused_mem_offset((_fused_mem_count > 0 && node.get_first_fused_dep_idx() > 0) ? static_cast<uint64_t>(node.get_first_fused_dep_idx()) : 0), _can_be_optimized(node.can_be_optimized()), _can_share_buffer(node.can_share_buffer())+ , _can_share_internal_buffer(node.can_share_internal_buffer()), _is_constant(node.is_constant()), _needs_completion_event(is_any_user_cpu(node.get_users()) || node.is_output()) {// When dynamic shape node has huge upper boundary which causes bigger mem size than system max allocable mem size, do not allocate in build time.@@ -2387,8 +2388,6 @@ memory::ptr primitive_inst::allocate_internal_buffer(const layout& layout, size_}GPU_DEBUG_LOG << "=> allocate to " << alloc_type << std::endl;- // Reuse intermediate buffer like output buffer.- bool reuse_internal_buf = true;auto ret_mem =get_memory_from_pool(get_network().get_engine(),get_network_id(),@@ -2396,7 +2395,7 @@ memory::ptr primitive_inst::allocate_internal_buffer(const layout& layout, size_*_node,layout,alloc_type,- reuse_internal_buf,+ can_share_internal_buffer(),_runtime_memory_dependencies,reset,_intermediates_memory.size() > idx ? _intermediates_memory[idx].get() : nullptr);diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cppindex 052619f02bf..94ff27f6eb1 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cpp@@ -1759,7 +1759,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_paged_attention, paged_attention_test, ::testing:paged_attention_test_params{ {{34, 0}}, 2, 2, 32, 32, 16, {100.0}, 2, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_CHANNEL, STATIC_INPUT_PAD, DISABLE_SCORES, PER_TOKEN_ROTATION, DISABLE_FA_V2 }, // 1st tokenpaged_attention_test_params{ {{1, 1008}}, 32, 32, 128, 128, 16, {100.0}, 6, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_CHANNEL, STATIC_INPUT_PAD, DISABLE_SCORES, PER_TOKEN_ROTATION, DISABLE_FA_V2 }, // 2nd tokenpaged_attention_test_params{ {{6, 20}}, 2, 2, 128, 128, 16, {100.0}, 8, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_CHANNEL, STATIC_INPUT_PAD, DISABLE_SCORES, PER_TOKEN_ROTATION, DISABLE_FA_V2 }, // mixed: prefix caching- paged_attention_test_params{ {{254, 10}}, 32, 8, 128, 128, 16, {100.0}, 10, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_CHANNEL, STATIC_INPUT_PAD, DISABLE_SCORES, PER_TOKEN_ROTATION, DISABLE_FA_V2 }, // mixed: prefix caching, GQA+ paged_attention_test_params{ {{1, 288}}, 64, 8, 64, 64, 16, {100.0}, 128, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_CHANNEL, STATIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2 }, // mixed: prefix caching, GQApaged_attention_test_params{ {{84, 2}}, 32, 32, 128, 128, 16, {100.0}, 16, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_CHANNEL, STATIC_INPUT_PAD, DISABLE_SCORES, PER_TOKEN_ROTATION, DISABLE_FA_V2 }, // mixed: prefix cachingpaged_attention_test_params{ {{1008, 492}}, 32, 32, 32, 32, 16, {100.0}, 32, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_TOKEN, STATIC_INPUT_PAD, DISABLE_SCORES, PER_TOKEN_ROTATION, DISABLE_FA_V2 }, // mixed: prefix cachingpaged_attention_test_params{ {{1008, 492}}, 16, 16, 64, 64, 16, {100.0}, 64, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_TOKEN, STATIC_INPUT_PAD, DISABLE_SCORES, PER_TOKEN_ROTATION, DISABLE_FA_V2 }, // mixed: prefix caching