Skip to content

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

[GPU] XAttention performance optimization. (#34431)

cecilia pengfbb6ac7956c4
diff --git a/src/plugins/intel_gpu/src/graph/impls/cm/include/cm_pa_common.hpp b/src/plugins/intel_gpu/src/graph/impls/cm/include/cm_pa_xe1.hpp
similarity index 79%
rename from src/plugins/intel_gpu/src/graph/impls/cm/include/cm_pa_common.hpp
rename to src/plugins/intel_gpu/src/graph/impls/cm/include/cm_pa_xe1.hpp
index c6b889b3036..2748f1aefc3 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cm/include/cm_pa_common.hpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cm/include/cm_pa_xe1.hpp
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include "cm_attention_common.hpp"
+#ifndef CM_HAS_LSC_UNTYPED_2D
#if CMPA_KVCACHE_U8
template<bool use_causal_mask, int num_heads, int num_kv_heads, int head_size, int is_q_fused = 0>
@@ -15,23 +15,14 @@ void pa_lsc_u8(
int kv_stop,
int q_len,
int kv_len,
-#ifdef CM_HAS_LSC_UNTYPED_2D
- svmptr_t q_base [[type("svmptr_t")]],
-#else
SurfaceIndex q_gather,
uint32_t q_gather_offset_bytes,
-#endif
svmptr_t k_cache_base [[type("svmptr_t")]],
-#ifdef CM_HAS_LSC_UNTYPED_2D
- svmptr_t v_cache_base [[type("svmptr_t")]],
-#else
SurfaceIndex v_cache_stateful [[type("buffer_t")]],
uint32_t v_cache_stateful_offset_bytes,
-#endif
-#if IS_BLOCK_SPARSE
+#if SPARSE_BLOCK_SIZE > 1
svmptr_t sparse_mask_base [[type("svmptr_t")]],
svmptr_t wg_sparse_mask_base [[type("svmptr_t")]],
- int SPARSE_BLOCK_SIZE,
#endif
svmptr_t o_base [[type("svmptr_t")]],
int32_t past_lens,
@@ -50,6 +41,7 @@ void pa_lsc_u8(
constexpr int num_P_tiles = REG_N / REG_M;
matrix<half, head_size/REG_K, REG_K*REG_N> rQ;
matrix <float, head_size/REG_N*num_P_tiles, REG_M*REG_N> rO;
+ bool first_active = true;
auto q_tokens_left = q_len;
static_assert(q_step == REG_N);
@@ -59,14 +51,6 @@ void pa_lsc_u8(
if (q_tokens_left < 0) q_tokens_left = 0;
if (q_tokens_left > q_step) q_tokens_left = q_step;
if (q_tokens_left > 0) {
- #ifdef CM_HAS_LSC_UNTYPED_2D
- lsc::block_2d_desc<uint, 1, REG_N, REG_K/2> b2dQ(reinterpret_cast<uint*>(q_base), q_tokens_left - 1, head_size*sizeof(half) - 1, q_pitch - 1, 0, 0);
- #pragma unroll
- for(int k = 0, ri = 0; k < head_size/2; k += REG_K/2, ri++) {
- cm_load<lsc::Transpose>(rQ[ri].format<uint>(), b2dQ.set_block_x(k));
- rQ[ri].format<half>() = cm_mul<half>(rQ[ri].format<half>(), (half)scale_factor);
- }
- #else
constexpr int q_tile_uints = REG_K / 2;
constexpr int q_tile_elems = q_tile_uints * REG_N;
vector<ushort, q_tile_elems> gather_pred;
@@ -99,12 +83,7 @@ void pa_lsc_u8(
rQ[ri].format<uint>() = gathered;
rQ[ri].format<half>() = cm_mul<half>(rQ[ri].format<half>(), (half)scale_factor);
}
- #endif
}
- #ifdef CM_HAS_LSC_UNTYPED_2D
- lsc::block_2d_desc<uint8_t, 1, kv_step, REG_K> b2dK(k_cache_base, CMPA_BLOCK_SZ - 1, head_size*sizeof(uint8_t) - 1, kv_pitch - 1, 0, 0);
- lsc::block_2d_desc<uint8_t, 1, REG_K, REG_N> b2dV(v_cache_base, CMPA_BLOCK_SZ - 1, head_size*sizeof(uint8_t) - 1, kv_pitch - 1, 0, 0);
- #endif
constexpr int quan_blk_stride = CMFLA_NUM_KV_HEADS * (CMFLA_HEAD_SIZE+4) * CMPA_BLOCK_SZ * sizeof(uint8_t);
int causal_left = q_start + past_lens;
@@ -112,7 +91,7 @@ void pa_lsc_u8(
int slm_buff_id_write = 0;
int slm_buff_id_read = 0;
-#if IS_BLOCK_SPARSE
+#if SPARSE_BLOCK_SIZE > 1
const int sb_shift = (SPARSE_BLOCK_SIZE == 128) ? 7 : (SPARSE_BLOCK_SIZE == 256) ? 8 : -1;
auto skip_by = [&](const bool* base, int kv_pos) -> bool {
@@ -126,8 +105,8 @@ void pa_lsc_u8(
auto load_slm_KV = [&](int kv_pos) {
if (kv_pos < kv_stop) {
-#if IS_BLOCK_SPARSE
- if (SPARSE_BLOCK_SIZE > 1 && skip_load(kv_pos)) {
+#if SPARSE_BLOCK_SIZE > 1
+ if (skip_load(kv_pos)) {
slm_buff_id_write++;
return;
}
@@ -148,20 +127,12 @@ void pa_lsc_u8(
matrix<half, kv_step, REG_K> kmat;
auto quanKmat = kmat.format<half, 2, kv_step * REG_K/2>()[1].format<uint8_t, kv_step, REG_K>();
- #ifdef CM_HAS_LSC_UNTYPED_2D
- b2dK.set_base_ptr(reinterpret_cast<uint8_t*>(k_cache_base+cur_block_id*quan_blk_stride));
- b2dK.set_block_y(kv_pos%CMPA_BLOCK_SZ);
- #endif
for(int k = REG_K*wg_local_id; k < head_size; k += REG_K*(local_size/2)) {
- #ifdef CM_HAS_LSC_UNTYPED_2D
- cm_load<lsc::Normal>(quanKmat.format<uint8_t>(), b2dK.set_block_x(k));
- #else
auto k_base = reinterpret_cast<svmptr_t>((int8_t*)k_cache_base + cur_block_id * quan_blk_stride + (kv_pos % CMPA_BLOCK_SZ) * kv_pitch + k);
#pragma unroll
for(int r = 0; r < kv_step; r++) {
cm_svm_block_read(k_base + r * kv_pitch, quanKmat.row(r));
}
- #endif
/*@bug: cm compiler in the tail process.
: loop combined with type convert.
for(int r = 0; r < kv_left; r++) {
@@ -181,10 +152,6 @@ void pa_lsc_u8(
cm_slm_block_write(slm_K, slm_offset + k * kv_step * sizeof(half), kmat.format<half>());
}
} else {
-#ifdef CM_HAS_LSC_UNTYPED_2D
- cm_svm_block_read(reinterpret_cast<svmptr_t>(v_cache_base + dscale_offset), dscale);
- cm_svm_block_read(reinterpret_cast<svmptr_t>(v_cache_base + dscale_offset + CMPA_BLOCK_SZ*sizeof(half)), zp);
-#else
// dscale/zp are half[kv_step] => 32 bytes each when kv_step=16
constexpr int half16_bytes = 16 * sizeof(half); // 32
constexpr int u32_per_half16 = half16_bytes / sizeof(uint); // 8
@@ -194,20 +161,12 @@ void pa_lsc_u8(
auto zp_u32 = cm_load<uint, u32_per_half16>(v_cache_stateful, zp_off);
dscale.format<uint>() = ds_u32;
zp.format<uint>() = zp_u32;
-#endif
matrix<half, REG_K/2, REG_N*2> VmatVNNI;
matrix<half, REG_K, REG_N> Vmat;
auto quanVmat = Vmat.format<half, 2, REG_K*REG_N/2>().row(1).format<uint8_t, REG_K, REG_N>();
- #ifdef CM_HAS_LSC_UNTYPED_2D
- b2dV.set_base_ptr(reinterpret_cast<uint8_t*>(v_cache_base+cur_block_id*quan_blk_stride));
- b2dV.set_block_y(kv_pos%CMPA_BLOCK_SZ);
- #endif
#pragma unroll
for(int k = REG_N*(wg_local_id-(local_size/2)); k < head_size; k += REG_N*(local_size/2)) {
- #ifdef CM_HAS_LSC_UNTYPED_2D
- cm_load<lsc::Normal>(quanVmat.format<uint8_t>(), b2dV.set_block_x(k));
- #else
// Each row loads REG_N bytes (REG_N=16) => 4 dwords
constexpr int v_row_u32 = REG_N / 4; // 4
#pragma unroll
@@ -221,7 +180,6 @@ void pa_lsc_u8(
auto row_u32 = cm_load<uint, v_row_u32>(v_cache_stateful, cur_off);
quanVmat.row(r).format<uint>() = row_u32;
}
- #endif
/*@bug: cm compiler in the tail process.
: loop combined with type convert.
for(int r = 0; r < kv_left; r++) {
@@ -272,8 +230,8 @@ void pa_lsc_u8(
load_slm_KV(kv_pos + kv_step*2);
-#if IS_BLOCK_SPARSE
- if (SPARSE_BLOCK_SIZE > 1 && skip_compute(kv_pos)) {
+#if SPARSE_BLOCK_SIZE > 1
+ if (skip_compute(kv_pos)) {
if constexpr (use_causal_mask)
causal_left -= kv_step;
continue;
@@ -320,27 +278,29 @@ void pa_lsc_u8(
matrix<half, REG_N, REG_K> P;
Transpose2DMatrix(St, P);
- if (kv_pos == 0)
+ if (first_active) {
ugemm_PV0(slm_V, P, rO, slm_offset);
- else
+ first_active = false;
+ } else {
ugemm_PV1(slm_V, P, max_comp, rO, slm_offset);
+ }
}
}
// cm_sbarrier(0);
if (q_tokens_left == 0) return;
+#ifdef CMPA_DEBUG_ALL_MASKED
+ if (first_active) {
+ cm_printf("CMPA error: all blocks masked out, q_start=%d\n", q_start);
+ }
+#endif
+
//# save cur_O/cur_sum.transpose(0, 1)
matrix<half, num_P_tiles*REG_M, REG_N> cur_O_f16;
cur_sum = cm_inv(cur_sum);
- #ifdef CM_HAS_LSC_UNTYPED_2D
- lsc::block_2d_desc<half, 1, REG_M, REG_N> b2dO(o_base, q_tokens_left - 1, head_size*sizeof(half) - 1, o_pitch - 1, 0, 0);
- #endif
#pragma unroll
for(int k = 0, ri=0; k < head_size; k += REG_N, ri += num_P_tiles) {
- #ifdef CM_HAS_LSC_UNTYPED_2D
- b2dO.set_block_x(k);
- #endif
#pragma unroll
for(int p = 0; p < num_P_tiles; p++) {
auto cO = rO[ri + p].format<float, REG_M, REG_N>();
@@ -348,9 +308,6 @@ void pa_lsc_u8(
for(int r = 0; r < cO.n_rows(); r++) {
cur_O_f16[r + p*REG_M] = cm_mul<float>(cO.row(r), cur_sum[r + p*REG_M]);
}
- #ifdef CM_HAS_LSC_UNTYPED_2D
- cm_store(b2dO.set_block_y(p * REG_M), cur_O_f16.format<half, num_P_tiles, REG_M * REG_N>().row(p));
- #else
int o_stride_elems = o_pitch / sizeof(half);
half* output_ptr = (half*)o_base + p * REG_M * o_stride_elems + k;
auto cur_O_ref = cur_O_f16.format<half, num_P_tiles, REG_M * REG_N>().row(p).format<half, REG_M, REG_N>();
@@ -358,7 +315,6 @@ void pa_lsc_u8(
for (int r = 0; r < REG_M; r++) {
cm_svm_block_write<half, REG_N>((svmptr_t)(output_ptr + r * o_stride_elems), cur_O_ref.row(r).format<half>());
}
- #endif
}
}
}
@@ -372,23 +328,14 @@ void pa_kernel_lsc_prefetch_f16(
int kv_stop, //
int q_len, //q_step
int kv_len, //not used for now
-#ifdef CM_HAS_LSC_UNTYPED_2D
- svmptr_t q_base [[type("svmptr_t")]],
-#else
SurfaceIndex q_gather,
uint32_t q_gather_offset_bytes,
-#endif
svmptr_t k_cache_base [[type("svmptr_t")]],
-#ifdef CM_HAS_LSC_UNTYPED_2D
- svmptr_t v_cache_base [[type("svmptr_t")]],
- #else
SurfaceIndex v_cache_stateful,
uint32_t v_cache_stateful_offset_bytes,
-#endif
-#if IS_BLOCK_SPARSE
+#if SPARSE_BLOCK_SIZE > 1
svmptr_t sparse_mask_base [[type("svmptr_t")]],
svmptr_t wg_sparse_mask_base [[type("svmptr_t")]],
- int SPARSE_BLOCK_SIZE,
#endif
svmptr_t o_base [[type("svmptr_t")]],
int32_t past_lens,
@@ -407,13 +354,20 @@ void pa_kernel_lsc_prefetch_f16(
cur_max = -3e38f;
cur_sum = 0;
constexpr int num_P_tiles = REG_N / REG_M;
-#ifdef CM_HAS_LSC_UNTYPED_2D
- constexpr int VALUE_TILE_NUM = 1;
-#else
constexpr int VALUE_TILE_NUM = 2;
-#endif
matrix<half, head_size/REG_K, REG_K*REG_N> rQ;
matrix <float, head_size/REG_M, REG_M*REG_N> rO;
+ bool first_active = true;
+
+#if SPARSE_BLOCK_SIZE > 1
+ const int sb_shift = (SPARSE_BLOCK_SIZE == 128) ? 7 : (SPARSE_BLOCK_SIZE == 256) ? 8 : -1;
+ auto skip_by = [&](const bool* base, int kv_pos) -> bool {
+ if (sb_shift < 0) return false;
+ return !base[(uint)kv_pos >> sb_shift];
+ };
+
+ auto skip_compute = [&](int kv_pos) { return skip_by((const bool*)sparse_mask_base, kv_pos); };
+#endif
auto q_tokens_left = q_len;// - q_start;
static_assert(q_step == REG_N);
@@ -423,19 +377,9 @@ void pa_kernel_lsc_prefetch_f16(
if (q_tokens_left < 0) q_tokens_left = 0;
if (q_tokens_left > q_step) q_tokens_left = q_step;
- #ifndef CM_HAS_LSC_UNTYPED_2D
if (q_tokens_left == 0) return;
- #endif
if (q_tokens_left > 0) {
- #ifdef CM_HAS_LSC_UNTYPED_2D
- lsc::block_2d_desc<uint, 1, REG_N, REG_K/2> b2dQ(reinterpret_cast<uint*>(q_base), q_tokens_left - 1, head_size*sizeof(half) - 1, q_pitch - 1, 0, 0);
- #pragma unroll
- for(int k = 0, ri = 0; k < head_size/2; k += REG_K/2, ri++) {
- cm_load<lsc::Transpose>(rQ[ri].format<uint>(), b2dQ.set_block_x(k));
- rQ[ri].format<half>() = cm_mul<half>(rQ[ri].format<half>(), (half)scale_factor);
- }
- #else
constexpr int q_tile_uints = REG_K / 2;
constexpr int q_tile_elems = q_tile_uints * REG_N;
vector<ushort, q_tile_elems> gather_pred;
@@ -465,16 +409,7 @@ void pa_kernel_lsc_prefetch_f16(
rQ[ri].format<uint>() = gathered;
rQ[ri].format<half>() = cm_mul<half>(rQ[ri].format<half>(), (half)scale_factor);
}
- #endif
}
-
- #ifdef CM_HAS_LSC_UNTYPED_2D
- lsc::block_2d_desc<half, 1, kv_step, REG_K> b2dK(k_cache_base, CMPA_BLOCK_SZ - 1, head_size*sizeof(half) - 1, k_pitch - 1, 0, 0);
- lsc::block_2d_desc<half, 1, REG_K, REG_N> b2dV(v_cache_base, CMPA_BLOCK_SZ - 1, head_size*sizeof(half) - 1, v_pitch - 1, 0, 0);
- static_assert(wg_local_size == 16);
- lsc::block_2d_desc<half, 1, kv_step/wg_local_size, REG_K> prefetch_K(k_cache_base, CMPA_BLOCK_SZ - 1, head_size*sizeof(half) - 1, k_pitch - 1, 0, 0);
- lsc::block_2d_desc<half, 1, REG_K/wg_local_size, REG_N> prefetch_V(v_cache_base, CMPA_BLOCK_SZ - 1, head_size*sizeof(half) - 1, v_pitch - 1, 0, 0);
- #endif
constexpr int blk_stride = CMFLA_NUM_KV_HEADS * CMFLA_HEAD_SIZE*CMPA_BLOCK_SZ;
int causal_left = q_start+past_lens;
@@ -491,16 +426,10 @@ void pa_kernel_lsc_prefetch_f16(
matrix<half, num_K, REG_M * REG_K> Kmat;
- #ifdef CM_HAS_LSC_UNTYPED_2D
- prefetch_K.set_base_ptr((reinterpret_cast<half*>(k_cache_base)+prefetch_block_id * blk_stride));
- prefetch_K.set_block_y((prefetch_kv_pos + wg_local_id) % CMPA_BLOCK_SZ);
- cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_K.set_block_x(0));
- #else
half* prefetch_k_pos = (half*)k_cache_base + prefetch_block_id * blk_stride + ((prefetch_kv_pos + wg_local_id) % CMPA_BLOCK_SZ) * head_size;
cm_ptr_prefetch<REG_K/2, DataSize::U32, CacheHint::Cached, CacheHint::Cached>((const unsigned int *const)prefetch_k_pos, 0);
- #endif
-#if IS_BLOCK_SPARSE
+#if SPARSE_BLOCK_SIZE > 1
const int sb_shift = (SPARSE_BLOCK_SIZE == 128) ? 7 :
(SPARSE_BLOCK_SIZE == 256) ? 8 : -1;
@@ -509,24 +438,18 @@ void pa_kernel_lsc_prefetch_f16(
return !*(reinterpret_cast<bool*>(sparse_mask_base) + ((uint)pos >> sb_shift));
};
- if (SPARSE_BLOCK_SIZE > 1 && skip_compute(kv_pos)) {
+ if (skip_compute(kv_pos)) {
if constexpr (use_causal_mask)
causal_left -= kv_step;
continue;
}
#endif
- #ifdef CM_HAS_LSC_UNTYPED_2D
- b2dK.set_base_ptr((reinterpret_cast<half*>(k_cache_base)+cur_block_id*blk_stride));
- b2dK.set_block_y(kv_pos % CMPA_BLOCK_SZ);
- cm_load<lsc::Normal>(Kmat.format<half>(), b2dK.set_block_x(0));
- #else
half* base_k_cache_ptr = (half*)k_cache_base + cur_block_id*blk_stride + (kv_pos % CMPA_BLOCK_SZ)*head_size;
auto kmatref = Kmat.format<half, kv_step, REG_K>();
#pragma unroll
for(int kr = 0; kr < kv_step; kr++){
cm_svm_block_read<half, REG_K>((svmptr_t)((half*)base_k_cache_ptr + kr * head_size), kmatref.row(kr));
}
- #endif
// somtimes KV cache would be filled with random Nan, so need to clean up the unused key data.
if ((kv_pos + kv_step) > kv_stop) {
auto valid_rows = kv_stop - kv_pos;
@@ -542,16 +465,11 @@ void pa_kernel_lsc_prefetch_f16(
#pragma unroll
for(int ri = 1; ri < head_size/REG_K; ri++) {
- #ifdef CM_HAS_LSC_UNTYPED_2D
- cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_K.set_block_x(ri*REG_K));
- cm_load<lsc::Normal>(Kmat.format<half>(), b2dK.set_block_x(ri*REG_K));
- #else
cm_ptr_prefetch<REG_K/2, DataSize::U32, CacheHint::Cached, CacheHint::Cached>((const unsigned int *const)prefetch_k_pos, ri*REG_K/2);
#pragma unroll
for(int kr = 0; kr < kv_step; kr++){
cm_svm_block_read<half, REG_K>((svmptr_t)((half*)base_k_cache_ptr + kr * head_size + ri * REG_K), kmatref.row(kr));
}
- #endif
// somtimes KV cache would be filled with random Nan, so need to clean up the unused key data.
if ((kv_pos + kv_step) > kv_stop) {
auto valid_rows = kv_stop - kv_pos;
@@ -604,21 +522,10 @@ void pa_kernel_lsc_prefetch_f16(
matrix<half, REG_N, REG_K> P;
Transpose2DMatrix(St, P);
- #ifdef CM_HAS_LSC_UNTYPED_2D
- prefetch_V.set_base_ptr((reinterpret_cast<half*>(v_cache_base)+prefetch_block_id*blk_stride));
- prefetch_V.set_block_y((prefetch_kv_pos + wg_local_id) % CMPA_BLOCK_SZ);
-
- b2dV.set_base_ptr((reinterpret_cast<half*>(v_cache_base)+cur_block_id*blk_stride));
- b2dV.set_block_y(kv_pos%CMPA_BLOCK_SZ);
- #endif
auto P2 = P.format<half, num_P_tiles, REG_M * REG_K>();
matrix<half, REG_K/2, REG_N*2*VALUE_TILE_NUM> Vmat;
#pragma unroll
for(int k = 0, ri=0; k < head_size; k += REG_N * VALUE_TILE_NUM, ri += num_P_tiles * VALUE_TILE_NUM) {
- #ifdef CM_HAS_LSC_UNTYPED_2D
- cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_V.set_block_x(k));
- cm_load<lsc::VNNI>(Vmat.format<half>(), b2dV.set_block_x(k));
- #else
matrix<half, REG_K, REG_N*VALUE_TILE_NUM> Vmat_tmp;
constexpr uint elem_size = sizeof(half);
constexpr int value_row_u32 = (REG_N * VALUE_TILE_NUM * sizeof(half)) / sizeof(uint);
@@ -642,20 +549,8 @@ void pa_kernel_lsc_prefetch_f16(
Vmat.row(r).select<REG_N*VALUE_TILE_NUM, 2>(0) = Vmat_tmp.row(r*2);
Vmat.row(r).select<REG_N*VALUE_TILE_NUM, 2>(1) = Vmat_tmp.row(r*2+1);
}
- #endif
- #ifdef CM_HAS_LSC_UNTYPED_2D
- // somtimes KV cache would be filled with random Nan, so need to clean up the unused value data.
- if ((kv_pos + kv_step) > kv_stop) {
- uint valid_rows = kv_stop - kv_pos;
- uint valid_rows_vnni = (valid_rows+1)/2;
- for (int r = valid_rows_vnni; r < REG_K/2; r++)
- Vmat.row(r) = 0.f;
- if (valid_rows % 2 == 1)
- Vmat.row(valid_rows_vnni-1).select<REG_N, 2>(1) = 0.f;
- }
- #endif
- if (kv_pos == 0) {
+ if (first_active) {
#pragma unroll
for (int tile = 0; tile < VALUE_TILE_NUM; tile++) {
int rO_base = ri + tile * num_P_tiles;
@@ -668,6 +563,7 @@ void pa_kernel_lsc_prefetch_f16(
P2.row(p).format<int32_t>());
}
}
+ first_active = false;
} else {
#pragma unroll
for (int tile = 0; tile < VALUE_TILE_NUM; tile++) {
@@ -698,22 +594,18 @@ void pa_kernel_lsc_prefetch_f16(
}
}
}
- #ifdef CM_HAS_LSC_UNTYPED_2D
- if (q_tokens_left == 0) return;
- #endif
+
+#ifdef CMPA_DEBUG_ALL_MASKED
+ if (first_active) {
+ cm_printf("CMPA error: all blocks masked out, q_start=%d\n", q_start);
+ }
+#endif
//# save cur_O/cur_sum.transpose(0, 1)
matrix<half, num_P_tiles * REG_M, REG_N> cur_O_f16;
cur_sum = cm_inv(cur_sum);
-
- #ifdef CM_HAS_LSC_UNTYPED_2D
- lsc::block_2d_desc<half, 1, REG_M, REG_N> b2dO(o_base, q_tokens_left - 1, head_size*sizeof(half) - 1, o_pitch - 1, 0, 0);
- #endif
#pragma unroll
for(int k = 0, ri=0; k < head_size; k += REG_N, ri += num_P_tiles) {
- #ifdef CM_HAS_LSC_UNTYPED_2D
- b2dO.set_block_x(k);
- #endif
#pragma unroll
for(int p = 0; p < num_P_tiles; p++) {
auto cO = rO[ri + p].format<float, REG_M, REG_N>();
@@ -721,9 +613,6 @@ void pa_kernel_lsc_prefetch_f16(
for(int r = 0; r < cO.n_rows(); r++) {
cur_O_f16[r + p*REG_M] = cm_mul<float>(cO.row(r), cur_sum[r + p*REG_M]);
}
- #ifdef CM_HAS_LSC_UNTYPED_2D
- cm_store(b2dO.set_block_y(p * REG_M), cur_O_f16.format<half, num_P_tiles, REG_M * REG_N>().row(p));
- #else
int o_stride_elems = o_pitch / sizeof(half);
half* output_ptr = (half*)o_base + p * REG_M * o_stride_elems + k;
auto cur_O_ref = cur_O_f16.format<half, num_P_tiles, REG_M * REG_N>().row(p).format<half, REG_M, REG_N>();
@@ -731,9 +620,9 @@ void pa_kernel_lsc_prefetch_f16(
for (int r = 0; r < REG_M; r++) {
cm_svm_block_write<half, REG_N>((svmptr_t)(output_ptr + r * o_stride_elems), cur_O_ref.row(r).format<half>());
}
- #endif
}
}
}
#endif
+#endif // !CM_HAS_LSC_UNTYPED_2D
\ No newline at end of file
diff --git a/src/plugins/intel_gpu/src/graph/impls/cm/include/cm_pa_xe2.hpp b/src/plugins/intel_gpu/src/graph/impls/cm/include/cm_pa_xe2.hpp
new file mode 100644
index 00000000000..e7531c2d53e
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/cm/include/cm_pa_xe2.hpp
@@ -0,0 +1,957 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#ifdef CM_HAS_LSC_UNTYPED_2D
+
+#ifndef CMPA_WG_SEQ_LEN
+#error "CMPA_WG_SEQ_LEN must be defined"
+#endif
+
+#ifndef SPARSE_BLOCK_SIZE
+#error "SPARSE_BLOCK_SIZE must be defined"
+#endif
+
+#ifndef CMPA_KVCACHE_U8
+#error "CMPA_KVCACHE_U8 must be defined"
+#endif
+
+#if CMPA_KVCACHE_U8
+#define OPTIMIZED_SPARSE_PIPELINE ( \
+ (SPARSE_BLOCK_SIZE == CMPA_WG_SEQ_LEN) && \
+ (SPARSE_BLOCK_SIZE == 128 || SPARSE_BLOCK_SIZE == 256) && \
+ ((CMPA_BLOCK_SZ % SPARSE_BLOCK_SIZE) == 0) \
+ )
+#else
+#define OPTIMIZED_SPARSE_PIPELINE ( \
+ (SPARSE_BLOCK_SIZE == CMPA_WG_SEQ_LEN) && \
+ (SPARSE_BLOCK_SIZE == 128 || SPARSE_BLOCK_SIZE == 256) \
+ )
+#endif
+
+#if OPTIMIZED_SPARSE_PIPELINE == 1
+ static_assert(SPARSE_BLOCK_SIZE == CMPA_WG_SEQ_LEN,
+ "This optimized pipeline requires SPARSE_BLOCK_SIZE to be the same as CMPA_WG_SEQ_LEN");
+ static_assert(SPARSE_BLOCK_SIZE == 128 || SPARSE_BLOCK_SIZE == 256,
+ "This optimized pipeline assumes SPARSE_BLOCK_SIZE is 128 or 256 to efficiently index sparse blocks");
+#if CMPA_KVCACHE_U8
+ static_assert((CMPA_BLOCK_SZ % SPARSE_BLOCK_SIZE) == 0,
+ "U8 optimized sparse pipeline assumes CMPA_BLOCK_SZ is divisible by SPARSE_BLOCK_SIZE to efficiently index kvcache blocks");
+#endif
+#endif
+
+#if CMPA_KVCACHE_U8
+template<bool use_causal_mask, int num_heads, int num_kv_heads, int head_size, int is_q_fused = 0>
+void pa_lsc_u8(
+ uint slm_K,
+ uint slm_V,
+ int wg_local_id,
+ int local_size,
+ int q_start,
+ int kv_stop,
+ int q_len,
+ int kv_len,
+ svmptr_t q_base [[type("svmptr_t")]],
+ svmptr_t k_cache_base [[type("svmptr_t")]],
+ svmptr_t v_cache_base [[type("svmptr_t")]],
+#if SPARSE_BLOCK_SIZE > 1
+ svmptr_t sparse_mask_base [[type("svmptr_t")]],
+ svmptr_t wg_sparse_mask_base [[type("svmptr_t")]],
+#endif
+ svmptr_t o_base [[type("svmptr_t")]],
+ int32_t past_lens,
+ int32_t* block_indices [[type("svmptr_t")]]) {
+
+ constexpr uint o_pitch = (num_heads * head_size * sizeof(half));
+ constexpr uint q_pitch = is_q_fused
+ ? ((num_heads + num_kv_heads * 2) * head_size * sizeof(half))
+ : o_pitch;
+
+ constexpr uint kv_pitch = head_size * sizeof(uint8_t);
+
+ vector<float, q_step> cur_max;
+ vector<float, q_step> cur_sum;
+
+ cur_max = -3e38f;
+ cur_sum = 0;
+
+ constexpr int num_P_tiles = REG_N / REG_M;
+ matrix<half, head_size / REG_K, REG_K * REG_N> rQ;
+ matrix<float, head_size / REG_N * num_P_tiles, REG_M * REG_N> rO;
+ bool first_active = true;
+
+ auto q_tokens_left = q_len;
+ static_assert(q_step == REG_N);
+ static_assert(kv_step == REG_K);
+
+ if (q_tokens_left < 0) q_tokens_left = 0;
+ if (q_tokens_left > q_step) q_tokens_left = q_step;
+
+ // ---- Load Q (unchanged) ----
+ if (q_tokens_left > 0) {
+ lsc::block_2d_desc<uint, 1, REG_N, REG_K / 2> b2dQ(
+ reinterpret_cast<uint*>(q_base),
+ q_tokens_left - 1,
+ head_size * sizeof(half) - 1,
+ q_pitch - 1,
+ 0, 0);
+
+ #pragma unroll
+ for (int k = 0, ri = 0; k < head_size / 2; k += REG_K / 2, ri++) {
+ cm_load<lsc::Transpose>(rQ[ri].format<uint>(), b2dQ.set_block_x(k));
+ rQ[ri].format<half>() = cm_mul<half>(rQ[ri].format<half>(), (half)scale_factor);
+ }
+ }
+
+ lsc::block_2d_desc<uint8_t, 1, kv_step, REG_K> b2dK(
+ k_cache_base, CMPA_BLOCK_SZ - 1, head_size * sizeof(uint8_t) - 1, kv_pitch - 1, 0, 0);
+ lsc::block_2d_desc<uint8_t, 1, REG_K, REG_N> b2dV(
+ v_cache_base, CMPA_BLOCK_SZ - 1, head_size * sizeof(uint8_t) - 1, kv_pitch - 1, 0, 0);
+
+ constexpr int quan_blk_stride =
+ CMFLA_NUM_KV_HEADS * (CMFLA_HEAD_SIZE + 4) * CMPA_BLOCK_SZ * sizeof(uint8_t);
+
+ int causal_left = q_start + past_lens;
+
+ constexpr uint slm_buff_size = kv_step * head_size * sizeof(half);
+ int slm_buff_id_write = 0;
+ int slm_buff_id_read = 0;
+
+#if OPTIMIZED_SPARSE_PIPELINE == 1
+ // ==================================================================================
+ // Optimized block-granular sparse pipeline when SPARSE_BLOCK_SIZE == WG_SEQ_LEN
+ // ==================================================================================
+ constexpr int cmpa_shift = (CMPA_BLOCK_SZ == 256) ? 8 : (CMPA_BLOCK_SZ == 128) ? 7 : -1;
+ constexpr int cmpa_mask = CMPA_BLOCK_SZ - 1;
+ constexpr int sb_shift = (SPARSE_BLOCK_SIZE == 128) ? 7 : (SPARSE_BLOCK_SIZE == 256) ? 8 : -1;
+
+ auto skip_by = [&](const bool* base, int kv_pos) -> bool {
+ if constexpr (sb_shift < 0) {
+ return false;
+ } else {
+ return !base[(uint)kv_pos >> sb_shift];
+ }
+ };
+
+ auto get_mask_base = [&](bool for_load) -> const bool* {
+ (void)for_load;
+ return (const bool*)sparse_mask_base;
+ };
+
+ auto skip_load = [&](int kv_pos) -> bool {
+ return skip_by(get_mask_base(true), kv_pos);
+ };
+
+ auto skip_compute = [&](int kv_pos) -> bool {
+ return skip_by(get_mask_base(false), kv_pos);
+ };
+
+ // ============================================================
+ // Maskless SLM loader for ACTIVE blocks (per-step skip removed)
+ // ============================================================
+ auto load_slm_KV_active = [&](int kv_pos, int blk_end, int kv_pos_in_block, int cur_block_id) {
+
+ // Only load KV that will be consumed inside this active block.
+ if (kv_pos >= blk_end) return;
+ if (kv_pos >= kv_stop) return;
+
+ // Ring slot for this load
+ uint slm_offset = (slm_buff_id_write & 3) * slm_buff_size;
+
+ // kv_left for tail within kv_stop
+ int kv_left = kv_step;
+ if (kv_pos + kv_step > kv_stop) kv_left = kv_stop - kv_pos;
+
+ uint32_t dscale_offset =
+ cur_block_id * quan_blk_stride +
+ CMPA_BLOCK_SZ * head_size * sizeof(uint8_t) +
+ kv_pos_in_block * sizeof(half);
+
+ // Advance write id exactly when we actually stage data
+ slm_buff_id_write++;
+
+ vector<half, kv_step> dscale;
+ vector<half, kv_step> zp;
+
+ if (wg_local_id < local_size / 2) {
+ // ---- Load K scales / zps ----
+ cm_svm_block_read(reinterpret_cast<svmptr_t>(k_cache_base + dscale_offset), dscale);
+ cm_svm_block_read(reinterpret_cast<svmptr_t>(k_cache_base + dscale_offset + CMPA_BLOCK_SZ * sizeof(half)), zp);
+
+ matrix<half, kv_step, REG_K> kmat;
+ auto quanKmat =
+ kmat.format<half, 2, kv_step * REG_K / 2>()[1].format<uint8_t, kv_step, REG_K>();
+
+ b2dK.set_base_ptr(reinterpret_cast<uint8_t*>(k_cache_base + cur_block_id * quan_blk_stride));
+ b2dK.set_block_y(kv_pos_in_block);
+
+ for (int k = REG_K * wg_local_id; k < head_size; k += REG_K * (local_size / 2)) {
+ cm_load<lsc::Normal>(quanKmat.format<uint8_t>(), b2dK.set_block_x(k));
+
+ #pragma unroll
+ for (int r = 0; r < kv_step; r++) {
+ kmat[r] = quanKmat[r] - zp[r];
+ kmat[r] = cm_mul<half>(kmat[r], dscale[r]);
+ }
+
+ if (kv_left < kv_step) {
+ for (int r = kv_step - 1; r >= kv_left; r--) kmat[r] = 0;
+ }
+
+ cm_slm_block_write(slm_K, slm_offset + k * kv_step * sizeof(half), kmat.format<half>());
+ }
+ } else {
+ // ---- Load V scales / zps ----
+ cm_svm_block_read(reinterpret_cast<svmptr_t>(v_cache_base + dscale_offset), dscale);
+ cm_svm_block_read(reinterpret_cast<svmptr_t>(v_cache_base + dscale_offset + CMPA_BLOCK_SZ * sizeof(half)), zp);
+
+ matrix<half, REG_K / 2, REG_N * 2> VmatVNNI;
+ matrix<half, REG_K, REG_N> Vmat;
+ auto quanVmat =
+ Vmat.format<half, 2, REG_K * REG_N / 2>().row(1).format<uint8_t, REG_K, REG_N>();
+
+ b2dV.set_base_ptr(reinterpret_cast<uint8_t*>(v_cache_base + cur_block_id * quan_blk_stride));
+ b2dV.set_block_y(kv_pos_in_block);
+
+ #pragma unroll
+ for (int k = REG_N * (wg_local_id - (local_size / 2));
+ k < head_size;
+ k += REG_N * (local_size / 2)) {
+
+ cm_load<lsc::Normal>(quanVmat.format<uint8_t>(), b2dV.set_block_x(k));
+
+ #pragma unroll
+ for (int r = 0; r < kv_step; r++) {
+ Vmat[r] = quanVmat[r] - zp[r];
+ Vmat[r] = cm_mul<half>(Vmat[r], dscale[r]);
+ }
+
+ if (kv_left < kv_step) {
+ for (int r = kv_step - 1; r >= kv_left; r--) Vmat[r] = 0;
+ }
+
+ prepackAsVNNIWidth2(Vmat, VmatVNNI);
+ cm_slm_block_write(slm_V, slm_offset + k * REG_K * sizeof(half), VmatVNNI.format<half>());
+ }
+ }
+ };
+
+ // ============================================================
+ // Block-granular sparse gating + block-local pipeline
+ // ============================================================
+ constexpr int KV_BLOCK = SPARSE_BLOCK_SIZE;
+ constexpr int STEPS_PER_BLOCK = KV_BLOCK / kv_step;
+
+ for (int kv_blk = 0; kv_blk < kv_stop; kv_blk += KV_BLOCK) {
+
+ int blk_end = kv_blk + KV_BLOCK;
+ if (blk_end > kv_stop) blk_end = kv_stop;
+
+ int blk_len = blk_end - kv_blk;
+ if (blk_len <= 0) break;
+
+ int steps_in_block = (blk_len + kv_step - 1) / kv_step; // <= 16
+
+ // Per-block skip (mask constant within SPARSE_BLOCK_SIZE tokens)
+ const bool block_sparse = skip_load(kv_blk);
+
+ if (block_sparse) {
+ if constexpr (use_causal_mask) {
+ causal_left -= steps_in_block * kv_step;
+ }
+ continue;
+ }
+
+ {
+ // Reset ring counters per active block
+ slm_buff_id_write = 0;
+ slm_buff_id_read = 0;
+
+ auto kv_blk_block_id = block_indices[kv_blk >> cmpa_shift];
+ auto kv_blk_pos_in_block = kv_blk & cmpa_mask;
+
+ // Prime pipeline (avoid 2nd prime if block too short)
+ load_slm_KV_active(kv_blk, blk_end, kv_blk_pos_in_block, kv_blk_block_id);
+ if (kv_blk + kv_step < blk_end)
+ load_slm_KV_active(kv_blk + kv_step, blk_end, (kv_blk + kv_step) & cmpa_mask,
+ block_indices[(kv_blk + kv_step) >> cmpa_shift]);
+
+ cm_slm_fence(CM_LOCAL_BARRIER);
+ cm_sbarrier(1);
+
+ for (int kv_pos = kv_blk; kv_pos < blk_end; kv_pos += kv_step, slm_buff_id_read++) {
+
+ cm_fence(CM_LOCAL_BARRIER);
+ cm_sbarrier(0);
+
+ // Prefetch 2 steps ahead only if it stays within this block
+ if (kv_pos + 2 * kv_step < blk_end) {
+ int prefetch_kv_pos = kv_pos + 2 * kv_step;
+ load_slm_KV_active(prefetch_kv_pos, blk_end, prefetch_kv_pos & cmpa_mask,
+ block_indices[prefetch_kv_pos >> cmpa_shift]);
+ cm_slm_fence(CM_LOCAL_BARRIER);
+ }
+
+ if (kv_pos + kv_step < blk_end)
+ cm_sbarrier(1);
+
+ {
+ uint slm_offset = (slm_buff_id_read & 3) * slm_buff_size;
+
+ matrix<float, kv_step, q_step> St = ugemm_KQ(slm_K, rQ, slm_offset);
+
+ if constexpr (use_causal_mask) {
+ if (causal_left == 0) {
+ apply_causal_mask<1>(St);
+ } else if (causal_left < 0) {
+ St = -3.4e38f;
+ }
+ causal_left -= kv_step;
+ } else {
+ int kv_tokens = kv_stop - kv_pos;
+ for (int p = kv_tokens; p < kv_step; p++) St[p] = -3.4e38f;
+ }
+
+ auto max_comp = online_softmax_update(St, cur_max, cur_sum);
+
+ matrix<half, REG_N, REG_K> P;
+ Transpose2DMatrix(St, P);
+
+ if (first_active) {
+ ugemm_PV0(slm_V, P, rO, slm_offset);
+ first_active = false;
+ } else {
+ ugemm_PV1(slm_V, P, max_comp, rO, slm_offset);
+ }
+ }
+ }
+ }
+ }
+
+#else
+ // ========================================================================
+ // Legacy per-step pipeline for any SPARSE_BLOCK_SIZE (including 1)
+ // ======================================================================
+#if SPARSE_BLOCK_SIZE > 1
+ constexpr int sb_shift = (SPARSE_BLOCK_SIZE == 128) ? 7 : (SPARSE_BLOCK_SIZE == 256) ? 8 : -1;
+ auto skip_by = [&](const bool* base, int kv_pos) -> bool {
+ if constexpr (sb_shift < 0) {
+ return false;
+ } else {
+ return !base[(uint)kv_pos >> sb_shift];
+ }
+ };
+
+ auto skip_compute = [&](int kv_pos) -> bool {
+ return skip_by((const bool*)sparse_mask_base, kv_pos);
+ };
+
+ auto skip_load = [&](int kv_pos) -> bool {
+ return skip_by((const bool*)wg_sparse_mask_base, kv_pos);
+ };
+#endif
+ auto load_slm_KV = [&](int kv_pos) {
+ if (kv_pos >= kv_stop) return;
+
+#if SPARSE_BLOCK_SIZE > 1
+ if (skip_load(kv_pos)) {
+ slm_buff_id_write++;
+ return;
+ }
+#endif
+ int cur_block_id = block_indices[kv_pos / CMPA_BLOCK_SZ];
+ int kv_pos_in_block = kv_pos - (kv_pos / CMPA_BLOCK_SZ) * CMPA_BLOCK_SZ;
+ uint32_t dscale_offset =
+ cur_block_id * quan_blk_stride +
+ CMPA_BLOCK_SZ * head_size * sizeof(uint8_t) +
+ kv_pos_in_block * sizeof(half);
+
+ uint slm_offset = (slm_buff_id_write & 3) * slm_buff_size;
+ vector<half, kv_step> dscale;
+ vector<half, kv_step> zp;
+ int kv_left = (kv_stop - kv_pos) > kv_step ? kv_step : (kv_stop - kv_pos);
+
+ slm_buff_id_write++;
+
+ if (wg_local_id < local_size / 2) {
+ cm_svm_block_read(reinterpret_cast<svmptr_t>(k_cache_base + dscale_offset), dscale);
+ cm_svm_block_read(reinterpret_cast<svmptr_t>(k_cache_base + dscale_offset + CMPA_BLOCK_SZ * sizeof(half)), zp);
+
+ matrix<half, kv_step, REG_K> kmat;
+ auto quanKmat =
+ kmat.format<half, 2, kv_step * REG_K / 2>()[1].format<uint8_t, kv_step, REG_K>();
+ b2dK.set_base_ptr(reinterpret_cast<uint8_t*>(k_cache_base + cur_block_id * quan_blk_stride));
+ b2dK.set_block_y(kv_pos_in_block);
+
+ for (int k = REG_K * wg_local_id; k < head_size; k += REG_K * (local_size / 2)) {
+ cm_load<lsc::Normal>(quanKmat.format<uint8_t>(), b2dK.set_block_x(k));
+
+ #pragma unroll
+ for (int r = 0; r < kv_step; r++) {
+ kmat[r] = quanKmat[r] - zp[r];
+ kmat[r] = cm_mul<half>(kmat[r], dscale[r]);
+ }
+
+ for (int r = kv_step - 1; r >= kv_left; r--) kmat[r] = 0;
+
+ cm_slm_block_write(slm_K, slm_offset + k * kv_step * sizeof(half), kmat.format<half>());
+ }
+ } else {
+ cm_svm_block_read(reinterpret_cast<svmptr_t>(v_cache_base + dscale_offset), dscale);
+ cm_svm_block_read(reinterpret_cast<svmptr_t>(v_cache_base + dscale_offset + CMPA_BLOCK_SZ * sizeof(half)), zp);
+
+ matrix<half, REG_K / 2, REG_N * 2> VmatVNNI;
+ matrix<half, REG_K, REG_N> Vmat;
+ auto quanVmat =
+ Vmat.format<half, 2, REG_K * REG_N / 2>().row(1).format<uint8_t, REG_K, REG_N>();
+ b2dV.set_base_ptr(reinterpret_cast<uint8_t*>(v_cache_base + cur_block_id * quan_blk_stride));
+ b2dV.set_block_y(kv_pos_in_block);
+
+ #pragma unroll
+ for (int k = REG_N * (wg_local_id - (local_size / 2));
+ k < head_size;
+ k += REG_N * (local_size / 2)) {
+
+ cm_load<lsc::Normal>(quanVmat.format<uint8_t>(), b2dV.set_block_x(k));
+
+ #pragma unroll
+ for (int r = 0; r < kv_step; r++) {
+ Vmat[r] = quanVmat[r] - zp[r];
+ Vmat[r] = cm_mul<half>(Vmat[r], dscale[r]);
+ }
+
+ for (int r = kv_step - 1; r >= kv_left; r--) Vmat[r] = 0;
+
+ prepackAsVNNIWidth2(Vmat, VmatVNNI);
+ cm_slm_block_write(slm_V, slm_offset + k * REG_K * sizeof(half), VmatVNNI.format<half>());
+ }
+ }
+ };
+
+ load_slm_KV(0);
+ load_slm_KV(kv_step);
+ cm_slm_fence(CM_LOCAL_BARRIER);
+ cm_sbarrier(1);
+
+ for (int kv_pos = 0; kv_pos < kv_stop; kv_pos += kv_step, slm_buff_id_read++) {
+ // load0, load1, signal1,
+ // [wait1, signal2, load2, read0, compute0]
+ // [wait2, signal3, load3, read1, compute1]
+ // [wait3, signal4, load4, read2, compute2]
+ // [wait4, signal5, load5, read3, compute3]
+ //
+ // after wait3, all workers have reached signal3, so:
+ // - all workers have finished load2 & read0.
+ // - we can start to load 4 into SLM slot 0 (i & 3) safely
+ // - we can start to read 2 ((i-2) & 3) safely
+
+ cm_fence(CM_LOCAL_BARRIER);
+ cm_sbarrier(0);
+
+ if (kv_pos + kv_step < kv_stop)
+ cm_sbarrier(1);
+ load_slm_KV(kv_pos + kv_step * 2);
+
+#if SPARSE_BLOCK_SIZE > 1
+ if (skip_compute(kv_pos)) {
+ if constexpr (use_causal_mask) {
+ causal_left -= kv_step;
+ }
+ continue;
+ }
+#endif
+
+ {
+ uint slm_offset = (slm_buff_id_read & 3) * slm_buff_size;
+
+ matrix<float, kv_step, q_step> St = ugemm_KQ(slm_K, rQ, slm_offset);
+
+ if constexpr (use_causal_mask) {
+ if (causal_left == 0) {
+ apply_causal_mask<1>(St);
+ } else if (causal_left < 0) {
+ St = -3.4e38f;
+ }
+ causal_left -= kv_step;
+ } else {
+ int kv_tokens = kv_stop - kv_pos;
+ for (int p = kv_tokens; p < kv_step; p++) St[p] = -3.4e38f;
+ }
+
+ auto max_comp = online_softmax_update(St, cur_max, cur_sum);
+
+ matrix<half, REG_N, REG_K> P;
+ Transpose2DMatrix(St, P);
+
+ if (first_active) {
+ ugemm_PV0(slm_V, P, rO, slm_offset);
+ first_active = false;
+ } else {
+ ugemm_PV1(slm_V, P, max_comp, rO, slm_offset);
+ }
+ }
+ }
+#endif
+
+ // ============================================================
+ // Store O (unchanged)
+ // ============================================================
+ if (q_tokens_left == 0) return;
+
+#ifdef CMPA_DEBUG_ALL_MASKED
+ if (first_active) {
+ cm_printf("CMPA error: all blocks masked out, q_start=%d\n", q_start);
+ }
+#endif
+
+ matrix<half, num_P_tiles * REG_M, REG_N> cur_O_f16;
+ cur_sum = cm_inv(cur_sum);
+
+ lsc::block_2d_desc<half, 1, REG_M, REG_N> b2dO(
+ o_base,
+ q_tokens_left - 1,
+ head_size * sizeof(half) - 1,
+ o_pitch - 1,
+ 0, 0);
+
+ #pragma unroll
+ for (int k = 0, ri = 0; k < head_size; k += REG_N, ri += num_P_tiles) {
+
+ #pragma unroll
+ for (int p = 0; p < num_P_tiles; p++) {
+ auto cO = rO[ri + p].format<float, REG_M, REG_N>();
+
+ #pragma unroll
+ for (int r = 0; r < cO.n_rows(); r++) {
+ cur_O_f16[r + p * REG_M] = cm_mul<float>(cO.row(r), cur_sum[r + p * REG_M]);
+ }
+ }
+
+ b2dO.set_block_x(k);
+ cm_store(b2dO.set_block_y(0),
+ cur_O_f16.format<half, num_P_tiles, REG_M * REG_N>().row(0));
+ cm_store(b2dO.set_block_y(REG_M),
+ cur_O_f16.format<half, num_P_tiles, REG_M * REG_N>().row(1));
+ }
+}
+
+#else
+
+template<bool use_causal_mask, int num_heads, int num_kv_heads, int head_size, int is_qkv_fused, int wg_local_size>
+void pa_kernel_lsc_prefetch_f16(
+ int wg_local_id,
+ int q_start,
+ int kv_stop, //
+ int q_len, //q_step
+ int kv_len, //not used for now
+ svmptr_t q_base [[type("svmptr_t")]],
+ svmptr_t k_cache_base [[type("svmptr_t")]],
+ svmptr_t v_cache_base [[type("svmptr_t")]],
+#if SPARSE_BLOCK_SIZE > 1
+ svmptr_t sparse_mask_base [[type("svmptr_t")]],
+ svmptr_t wg_sparse_mask_base [[type("svmptr_t")]],
+#endif
+ svmptr_t o_base [[type("svmptr_t")]],
+ int32_t past_lens,
+ int32_t* block_indices [[type("svmptr_t")]]) {
+ constexpr uint o_pitch = (num_heads * head_size * sizeof(half));
+ constexpr uint q_pitch = is_qkv_fused ? ((num_heads + num_kv_heads*2) * head_size * sizeof(half)) : o_pitch;
+ // constexpr uint k_pitch = is_qkv_fused ? q_pitch : (num_kv_heads * head_size * sizeof(half));
+ // constexpr uint v_pitch = is_qkv_fused ? q_pitch : (num_kv_heads * head_size * sizeof(half));
+ //[block_num, kv_heads, block_size, head_size]
+ constexpr uint k_pitch = head_size * sizeof(half);
+ constexpr uint v_pitch = k_pitch;
+
+ vector<float, q_step> cur_max;
+ vector<float, q_step> cur_sum;
+
+ cur_max = -3e38f;
+ cur_sum = 0;
+ constexpr int num_P_tiles = REG_N / REG_M;
+ matrix<half, head_size/REG_K, REG_K*REG_N> rQ;
+ matrix <float, head_size/REG_N*num_P_tiles, REG_M*REG_N> rO;
+ bool first_active = true;
+
+#if SPARSE_BLOCK_SIZE > 1
+ constexpr int sb_shift = (SPARSE_BLOCK_SIZE == 128) ? 7 : (SPARSE_BLOCK_SIZE == 256) ? 8 : -1;
+ auto skip_by = [&](const bool* base, int kv_pos) -> bool {
+ if constexpr (sb_shift < 0) {
+ return false;
+ } else {
+ return !base[(uint)kv_pos >> sb_shift];
+ }
+ };
+
+ auto skip_compute = [&](int kv_pos) {
+ return skip_by((const bool*)sparse_mask_base, kv_pos);
+ };
+#endif
+
+ auto q_tokens_left = q_len;
+ static_assert(q_step == REG_N);
+ static_assert(kv_step == REG_K);
+
+ if (q_tokens_left < 0) q_tokens_left = 0;
+ if (q_tokens_left > q_step) q_tokens_left = q_step;
+
+ if (q_tokens_left > 0) {
+ lsc::block_2d_desc<uint, 1, REG_N, REG_K/2> b2dQ(reinterpret_cast<uint*>(q_base), q_tokens_left - 1, head_size*sizeof(half) - 1, q_pitch - 1, 0, 0);
+ #pragma unroll
+ for(int k = 0, ri = 0; k < head_size/2; k += REG_K/2, ri++) {
+ cm_load<lsc::Transpose>(rQ[ri].format<uint>(), b2dQ.set_block_x(k));
+ rQ[ri].format<half>() = cm_mul<half>(rQ[ri].format<half>(), (half)scale_factor);
+ }
+ }
+
+ lsc::block_2d_desc<half, 1, kv_step, REG_K> b2dK(k_cache_base, CMPA_BLOCK_SZ - 1, head_size*sizeof(half) - 1, k_pitch - 1, 0, 0);
+ lsc::block_2d_desc<half, 1, REG_K, REG_N> b2dV(v_cache_base, CMPA_BLOCK_SZ - 1, head_size*sizeof(half) - 1, v_pitch - 1, 0, 0);
+
+ static_assert(wg_local_size == 16);
+ lsc::block_2d_desc<half, 1, kv_step/wg_local_size, REG_K> prefetch_K(k_cache_base, CMPA_BLOCK_SZ - 1, head_size*sizeof(half) - 1, k_pitch - 1, 0, 0);
+ lsc::block_2d_desc<half, 1, REG_K/wg_local_size, REG_N> prefetch_V(v_cache_base, CMPA_BLOCK_SZ - 1, head_size*sizeof(half) - 1, v_pitch - 1, 0, 0);
+ constexpr int blk_stride = CMFLA_NUM_KV_HEADS*CMFLA_HEAD_SIZE*CMPA_BLOCK_SZ;
+ int causal_left = q_start+past_lens;
+
+#if OPTIMIZED_SPARSE_PIPELINE == 1
+ // ====================================================================================
+ // Optimized block-granular sparse pipeline when SPARSE_BLOCK_SIZE == WG_SEQ_LEN
+ // ====================================================================================
+ constexpr int kv_block = SPARSE_BLOCK_SIZE;
+ for (int kv_blk = 0; kv_blk < kv_stop; kv_blk += kv_block) {
+ int blk_end = kv_blk + kv_block;
+ if (blk_end > kv_stop) blk_end = kv_stop;
+ int blk_len = blk_end - kv_blk;
+ if (blk_len <= 0) break;
+ int steps_in_block = (blk_len + kv_step - 1) / kv_step;
+
+ if (skip_compute(kv_blk)) {
+ if constexpr (use_causal_mask) {
+ causal_left -= steps_in_block * kv_step;
+ }
+ continue;
+ }
+
+ for (int kv_pos = kv_blk; kv_pos < blk_end; kv_pos += kv_step) {
+ auto cur_block_id = block_indices[kv_pos / CMPA_BLOCK_SZ];
+ //For the last step, duplicate prefetch here.
+ uint32_t prefetch_kv_pos = (kv_pos+kv_step) >= kv_stop ? kv_pos : (kv_pos+kv_step);
+ auto prefetch_block_id = block_indices[prefetch_kv_pos / CMPA_BLOCK_SZ];
+ //# St = k @ Qt
+ matrix<float, kv_step, q_step> St;
+ {
+ constexpr int num_K = kv_step/REG_M;
+ auto St2 = St.format<float, num_K, REG_M*REG_N>();
+
+ matrix<half, num_K, REG_M * REG_K> Kmat;
+
+ prefetch_K.set_base_ptr((reinterpret_cast<half*>(k_cache_base)+prefetch_block_id*blk_stride));
+ prefetch_K.set_block_y((prefetch_kv_pos + wg_local_id) % CMPA_BLOCK_SZ);
+ cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_K.set_block_x(0));
+
+ if (skip_compute(kv_pos)) {
+ if constexpr (use_causal_mask)
+ causal_left -= kv_step;
+ continue;
+ }
+ b2dK.set_base_ptr((reinterpret_cast<half*>(k_cache_base)+cur_block_id*blk_stride));
+ b2dK.set_block_y(kv_pos%CMPA_BLOCK_SZ);
+ cm_load<lsc::Normal>(Kmat.format<half>(), b2dK.set_block_x(0));
+ // sometimes KV cache would be filled with random Nan, so need to clean up the unused key data.
+ if ((kv_pos + kv_step) > kv_stop) {
+ auto valid_rows = kv_stop - kv_pos;
+ for (int r = valid_rows; r < kv_step; r++)
+ Kmat.format<half, num_K*REG_M, REG_N>().row(r) = 0.f;
+ }
+ #pragma unroll
+ for(int k = 0; k < num_K; k++)
+ St2.row(k) = cm_dpas<CM_PRECISION_HF, CM_PRECISION_HF, SystolicDepth, RepeatCount, float>(
+ 0,
+ rQ[0].format<int32_t>(),
+ Kmat[k].format<int32_t>());
+
+ #pragma unroll
+ for(int ri = 1; ri < head_size/REG_K; ri++) {
+ cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_K.set_block_x(ri*REG_K));
+ cm_load<lsc::Normal>(Kmat.format<half>(), b2dK.set_block_x(ri*REG_K));
+ #pragma unroll
+ for(int k = 0; k < num_K; k++) {
+ St2.row(k) = cm_dpas<CM_PRECISION_HF, CM_PRECISION_HF, SystolicDepth, RepeatCount, float>(
+ St2.row(k),
+ rQ[ri].format<int32_t>(),
+ Kmat[k].format<int32_t>());
+ }
+ }
+ }
+ if constexpr (use_causal_mask) {
+ // since kv_step == q_step == 16, causal_left is n*kv_step
+ if (causal_left == 0) {
+ apply_causal_mask<1>(St);
+ } else if (causal_left < 0) {
+ St = -3.4e38f;
+ }
+ causal_left -= kv_step;
+ } else {
+ int kv_tokens = kv_stop - kv_pos;
+ // LSC ensures no overflow-access, but mask off k-tails attn-score is still required
+ for(int p = kv_tokens; p < kv_step; p++) St[p] = -3.4e38f;
+ }
+
+ //show(St);
+ auto max_comp = online_softmax_update(St, cur_max, cur_sum);
+
+ matrix<half, REG_N, REG_K> P;
+ Transpose2DMatrix(St, P);
+
+ prefetch_V.set_base_ptr((reinterpret_cast<half*>(v_cache_base)+prefetch_block_id*blk_stride));
+ prefetch_V.set_block_y((prefetch_kv_pos + wg_local_id) % CMPA_BLOCK_SZ);
+
+ b2dV.set_base_ptr((reinterpret_cast<half*>(v_cache_base)+cur_block_id*blk_stride));
+ b2dV.set_block_y(kv_pos%CMPA_BLOCK_SZ);
+ if (first_active) {
+ // ugemm_PV0(slm_V, P, rO, slm_offset);
+ auto P2 = P.format<half, num_P_tiles, REG_M * REG_K>();
+ #pragma unroll
+ for(int k = 0, ri = 0; k < head_size; k += REG_N, ri += num_P_tiles) {
+ matrix<half, REG_K/2, REG_N*2> Vmat;
+ cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_V.set_block_x(k));
+ cm_load<lsc::VNNI>(Vmat.format<half>(), b2dV.set_block_x(k));
+ // sometimes KV cache would be filled with random Nan, so need to clean up the unused value data.
+ if ((kv_pos + kv_step) > kv_stop) {
+ uint valid_rows = kv_stop - kv_pos;
+ uint valid_rows_vnni = (valid_rows+1)/2;
+ for (int r = valid_rows_vnni; r < kv_step / 2; r++)
+ Vmat.row(r) = 0.f;
+ if (valid_rows % 2 == 1)
+ Vmat.row(valid_rows_vnni-1).select<REG_N,2>(1) = 0.f;
+ }
+ #pragma unroll
+ for(int p = 0; p < num_P_tiles; p++) {
+ rO[ri + p] = cm_dpas<CM_PRECISION_HF, CM_PRECISION_HF, SystolicDepth, RepeatCount, float>(
+ 0,
+ Vmat.format<int32_t>(),
+ P2.row(p).format<int32_t>());
+ }
+ }
+ first_active = false;
+ }
+ else {
+ //ugemm_PV1(slm_V, P, max_comp, rO, slm_offset);
+ auto P2 = P.format<half, num_P_tiles, REG_M * REG_K>();
+ #pragma unroll
+ for(int k = 0, ri=0; k < head_size; k += REG_N, ri += num_P_tiles) {
+ matrix<half, REG_K/2, REG_N*2> Vmat;
+
+ cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_V.set_block_x(k));
+ cm_load<lsc::VNNI>(Vmat.format<half>(), b2dV.set_block_x(k));
+ // sometimes KV cache would be filled with random Nan, so need to clean up the unused value data.
+ if ((kv_pos + kv_step) > kv_stop) {
+ uint valid_rows = kv_stop - kv_pos;
+ uint valid_rows_vnni = (valid_rows+1)/2;
+ for (int r = valid_rows_vnni; r < kv_step / 2; r++)
+ Vmat.row(r) = 0.f;
+ if (valid_rows % 2 == 1)
+ Vmat.row(valid_rows_vnni-1).select<REG_N,2>(1) = 0.f;
+ }
+ //# compensate cur_O
+ // matrix <float, head_size/REG_K*2, REG_M*REG_N> rO;
+ #pragma unroll
+ for(int p = 0; p < num_P_tiles; p++) {
+ auto cO = rO[ri + p].format<float, REG_M, REG_N>();
+ #pragma unroll
+ for(int r = 0; r < REG_M; r++)
+ cO.row(r) = cm_mul<float>(cO.row(r), max_comp[r + p*REG_M]);
+ }
+
+ #pragma unroll
+ for(int p = 0; p < num_P_tiles; p++) {
+ rO[ri + p] = cm_dpas<CM_PRECISION_HF, CM_PRECISION_HF, SystolicDepth, RepeatCount>(
+ rO[ri + p].format<float>(),
+ Vmat.format<int32_t>(),
+ P2.row(p).format<int32_t>());
+ }
+ }
+ }
+ }
+ }
+#else
+ // ========================================================================
+ // Legacy per-step pipeline for any SPARSE_BLOCK_SIZE (including 1)
+ // ======================================================================
+ for(int kv_pos = 0; kv_pos < kv_stop; kv_pos += kv_step) {
+ auto cur_block_id = block_indices[kv_pos / CMPA_BLOCK_SZ];
+ //For the last step, duplicate prefetch here.
+ uint32_t prefetch_kv_pos = (kv_pos+kv_step) >= kv_stop ? kv_pos : (kv_pos+kv_step);
+ auto prefetch_block_id = block_indices[prefetch_kv_pos / CMPA_BLOCK_SZ];
+ //# St = k @ Qt
+ matrix<float, kv_step, q_step> St;
+ {
+ constexpr int num_K = kv_step/REG_M;
+ auto St2 = St.format<float, num_K, REG_M*REG_N>();
+
+ matrix<half, num_K, REG_M * REG_K> Kmat;
+
+ prefetch_K.set_base_ptr((reinterpret_cast<half*>(k_cache_base)+prefetch_block_id*blk_stride));
+ prefetch_K.set_block_y((prefetch_kv_pos + wg_local_id) % CMPA_BLOCK_SZ);
+ cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_K.set_block_x(0));
+
+#if SPARSE_BLOCK_SIZE > 1
+ if (skip_compute(kv_pos)) {
+ if constexpr (use_causal_mask)
+ causal_left -= kv_step;
+ continue;
+ }
+#endif
+ b2dK.set_base_ptr((reinterpret_cast<half*>(k_cache_base)+cur_block_id*blk_stride));
+ b2dK.set_block_y(kv_pos%CMPA_BLOCK_SZ);
+ cm_load<lsc::Normal>(Kmat.format<half>(), b2dK.set_block_x(0));
+ // sometimes KV cache would be filled with random Nan, so need to clean up the unused key data.
+ if ((kv_pos + kv_step) > kv_stop) {
+ auto valid_rows = kv_stop - kv_pos;
+ for (int r = valid_rows; r < kv_step; r++)
+ Kmat.format<half, num_K*REG_M, REG_N>().row(r) = 0.f;
+ }
+ #pragma unroll
+ for(int k = 0; k < num_K; k++)
+ St2.row(k) = cm_dpas<CM_PRECISION_HF, CM_PRECISION_HF, SystolicDepth, RepeatCount, float>(
+ 0,
+ rQ[0].format<int32_t>(),
+ Kmat[k].format<int32_t>());
+
+ #pragma unroll
+ for(int ri = 1; ri < head_size/REG_K; ri++) {
+ cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_K.set_block_x(ri*REG_K));
+ cm_load<lsc::Normal>(Kmat.format<half>(), b2dK.set_block_x(ri*REG_K));
+ #pragma unroll
+ for(int k = 0; k < num_K; k++) {
+ St2.row(k) = cm_dpas<CM_PRECISION_HF, CM_PRECISION_HF, SystolicDepth, RepeatCount, float>(
+ St2.row(k),
+ rQ[ri].format<int32_t>(),
+ Kmat[k].format<int32_t>());
+ }
+ }
+ }
+ if constexpr (use_causal_mask) {
+ // since kv_step == q_step == 16, causal_left is n*kv_step
+ if (causal_left == 0) {
+ apply_causal_mask<1>(St);
+ } else if (causal_left < 0) {
+ St = -3.4e38f;
+ }
+ causal_left -= kv_step;
+ } else {
+ int kv_tokens = kv_stop - kv_pos;
+ // LSC ensures no overflow-access, but mask off k-tails attn-score is still required
+ for(int p = kv_tokens; p < kv_step; p++) St[p] = -3.4e38f;
+ }
+
+ //show(St);
+ auto max_comp = online_softmax_update(St, cur_max, cur_sum);
+
+ matrix<half, REG_N, REG_K> P;
+ Transpose2DMatrix(St, P);
+
+ prefetch_V.set_base_ptr((reinterpret_cast<half*>(v_cache_base)+prefetch_block_id*blk_stride));
+ prefetch_V.set_block_y((prefetch_kv_pos + wg_local_id) % CMPA_BLOCK_SZ);
+
+ b2dV.set_base_ptr((reinterpret_cast<half*>(v_cache_base)+cur_block_id*blk_stride));
+ b2dV.set_block_y(kv_pos%CMPA_BLOCK_SZ);
+ if (first_active) {
+ // ugemm_PV0(slm_V, P, rO, slm_offset);
+ auto P2 = P.format<half, num_P_tiles, REG_M * REG_K>();
+ #pragma unroll
+ for(int k = 0, ri = 0; k < head_size; k += REG_N, ri += num_P_tiles) {
+ matrix<half, REG_K/2, REG_N*2> Vmat;
+ cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_V.set_block_x(k));
+ cm_load<lsc::VNNI>(Vmat.format<half>(), b2dV.set_block_x(k));
+ // sometimes KV cache would be filled with random Nan, so need to clean up the unused value data.
+ if ((kv_pos + kv_step) > kv_stop) {
+ uint valid_rows = kv_stop - kv_pos;
+ uint valid_rows_vnni = (valid_rows+1)/2;
+ for (int r = valid_rows_vnni; r < kv_step / 2; r++)
+ Vmat.row(r) = 0.f;
+ if (valid_rows % 2 == 1)
+ Vmat.row(valid_rows_vnni-1).select<REG_N,2>(1) = 0.f;
+ }
+ #pragma unroll
+ for(int p = 0; p < num_P_tiles; p++) {
+ rO[ri + p] = cm_dpas<CM_PRECISION_HF, CM_PRECISION_HF, SystolicDepth, RepeatCount, float>(
+ 0,
+ Vmat.format<int32_t>(),
+ P2.row(p).format<int32_t>());
+ }
+ }
+ first_active = false;
+ }
+ else {
+ //ugemm_PV1(slm_V, P, max_comp, rO, slm_offset);
+ auto P2 = P.format<half, num_P_tiles, REG_M * REG_K>();
+ #pragma unroll
+ for(int k = 0, ri=0; k < head_size; k += REG_N, ri += num_P_tiles) {
+ matrix<half, REG_K/2, REG_N*2> Vmat;
+
+ cm_prefetch<CacheHint::Cached, CacheHint::Cached>(prefetch_V.set_block_x(k));
+ cm_load<lsc::VNNI>(Vmat.format<half>(), b2dV.set_block_x(k));
+ // sometimes KV cache would be filled with random Nan, so need to clean up the unused value data.
+ if ((kv_pos + kv_step) > kv_stop) {
+ uint valid_rows = kv_stop - kv_pos;
+ uint valid_rows_vnni = (valid_rows+1)/2;
+ for (int r = valid_rows_vnni; r < kv_step / 2; r++)
+ Vmat.row(r) = 0.f;
+ if (valid_rows % 2 == 1)
+ Vmat.row(valid_rows_vnni-1).select<REG_N,2>(1) = 0.f;
+ }
+ //# compensate cur_O
+ // matrix <float, head_size/REG_K*2, REG_M*REG_N> rO;
+ #pragma unroll
+ for(int p = 0; p < num_P_tiles; p++) {
+ auto cO = rO[ri + p].format<float, REG_M, REG_N>();
+ #pragma unroll
+ for(int r = 0; r < REG_M; r++)
+ cO.row(r) = cm_mul<float>(cO.row(r), max_comp[r + p*REG_M]);
+ }
+
+ #pragma unroll
+ for(int p = 0; p < num_P_tiles; p++) {
+ rO[ri + p] = cm_dpas<CM_PRECISION_HF, CM_PRECISION_HF, SystolicDepth, RepeatCount>(
+ rO[ri + p].format<float>(),
+ Vmat.format<int32_t>(),
+ P2.row(p).format<int32_t>());
+ }
+ }
+ }
+ }
+#endif
+
+#ifdef CMPA_DEBUG_ALL_MASKED
+ if (first_active) {
+ cm_printf("CMPA error: all blocks masked out, q_start=%d\n", q_start);
+ }
+#endif
+
+ if (q_tokens_left == 0) return;
+
+ //# save cur_O/cur_sum.transpose(0, 1)
+ matrix<half, num_P_tiles*REG_M, REG_N> cur_O_f16;
+ cur_sum = cm_inv(cur_sum);
+
+ lsc::block_2d_desc<half, 1, REG_M, REG_N> b2dO(o_base, q_tokens_left - 1, head_size*sizeof(half) - 1, o_pitch - 1, 0, 0);
+
+ #pragma unroll
+ for(int k = 0, ri=0; k < head_size; k += REG_N, ri += num_P_tiles) {
+ #pragma unroll
+ for(int p = 0; p < num_P_tiles; p++) {
+ auto cO = rO[ri + p].format<float, REG_M, REG_N>();
+ #pragma unroll
+ for(int r = 0; r < cO.n_rows(); r++) {
+ cur_O_f16[r + p*REG_M] = cm_mul<float>(cO.row(r), cur_sum[r + p*REG_M]);
+
+ }
+ }
+ b2dO.set_block_x(k);
+ cm_store(b2dO.set_block_y(0), cur_O_f16.format<half, num_P_tiles, REG_M * REG_N>().row(0));
+ cm_store(b2dO.set_block_y(REG_M), cur_O_f16.format<half, num_P_tiles, REG_M * REG_N>().row(1));
+ }
+}
+
+#endif
+#endif // CM_HAS_LSC_UNTYPED_2D
diff --git a/src/plugins/intel_gpu/src/graph/impls/cm/pa_multi_token.cm b/src/plugins/intel_gpu/src/graph/impls/cm/pa_multi_token.cm
index 09b3162238a..f8bd173df53 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cm/pa_multi_token.cm
+++ b/src/plugins/intel_gpu/src/graph/impls/cm/pa_multi_token.cm
@@ -1,27 +1,14 @@
-
-/*******************************************************************************
- * Copyright (c) 2018-2026 Intel Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *******************************************************************************/
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
namespace KERNEL_NAME {
-#include "cm_pa_common.hpp"
+#include "cm_attention_common.hpp"
#ifdef CM_HAS_LSC_UNTYPED_2D
-#define USE_LSC 1
+#include "cm_pa_xe2.hpp"
#else
-#define USE_LSC 0
+#include "cm_pa_xe1.hpp"
#endif
extern "C" _GENX_MAIN_ void KERNEL_NAME(
@@ -53,16 +40,14 @@ extern "C" _GENX_MAIN_ void KERNEL_NAME(
int32_t* block_indices_begins [[type("svmptr_t")]],
int32_t* subsequence_begins [[type("svmptr_t")]],
half* output [[type("svmptr_t")]],
-#if IS_BLOCK_SPARSE
- bool* sparse_block_mask [[type("svmptr_t")]],
+ int q_len
+#if SPARSE_BLOCK_SIZE > 1
+ , bool* sparse_block_mask [[type("svmptr_t")]],
bool* sparse_block_mask_wg [[type("svmptr_t")]],
- int q_len,
int num_q_blocks,
- int num_k_blocks,
- int SPARSE_BLOCK_SIZE) {
-#else
- int q_len) {
+ int num_k_blocks
#endif
+ ) {
constexpr int is_causal = CMFLA_IS_CAUSAL;
constexpr int num_heads = CMFLA_NUM_HEADS;
constexpr int head_size = CMFLA_HEAD_SIZE;
@@ -93,7 +78,11 @@ extern "C" _GENX_MAIN_ void KERNEL_NAME(
// multiple work-groups are required to split a sequence,
// need to figure out which part of query-tokens to process
+#if defined(CMPA_WG_SEQ_LEN)
+ constexpr int wg_seq_len = CMPA_WG_SEQ_LEN;
+#else
int wg_seq_len = local_size * q_step;
+#endif
int past_q_lens = past_lens[0];
kv_start = 0;
kv_seq_len = q_len + past_q_lens;
@@ -138,7 +127,7 @@ extern "C" _GENX_MAIN_ void KERNEL_NAME(
uint q_offset = (q_start_sg*num_heads + h)*head_size;
uint q_offset_bytes = q_offset * sizeof(half);
-#if IS_BLOCK_SPARSE
+#if SPARSE_BLOCK_SIZE > 1
bool *block_mask_base, *wg_block_mask_base;
//# sparse_block_mask [num_heads, num_q_blocks, num_k_blocks]
//# sparse_block_mask_wg [num_heads, wg_count_along_query, num_k_blocks]
@@ -172,10 +161,9 @@ extern "C" _GENX_MAIN_ void KERNEL_NAME(
v_cache_stateful,
kv_offset_bytes,
#endif
-#if IS_BLOCK_SPARSE
+#if SPARSE_BLOCK_SIZE > 1
reinterpret_cast<svmptr_t>(block_mask_base),
reinterpret_cast<svmptr_t>(wg_block_mask_base),
- SPARSE_BLOCK_SIZE,
#endif
reinterpret_cast<svmptr_t>(output + q_offset),
past_q_lens,
@@ -202,10 +190,9 @@ extern "C" _GENX_MAIN_ void KERNEL_NAME(
v_cache_stateful,
kv_offset_bytes,
#endif
-#if IS_BLOCK_SPARSE
+#if SPARSE_BLOCK_SIZE > 1
reinterpret_cast<svmptr_t>(block_mask_base),
reinterpret_cast<svmptr_t>(wg_block_mask_base),
- SPARSE_BLOCK_SIZE,
#endif
reinterpret_cast<svmptr_t>(output + q_offset),
past_q_lens,
diff --git a/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention.cpp b/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention.cpp
index 4ef3206a6a3..bcbc9964e4b 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention.cpp
@@ -37,7 +37,9 @@ public:
Stage::Ptr kv_cache_update = make_stage<PagedAttentionGeneratorKVCacheUpdate>();
Stage::Ptr pa_single_token = make_stage<PagedAttentionGeneratorSingleToken>();
Stage::Ptr pa_single_token_finalization = make_stage<PagedAttentionGeneratorSingleTokenFinalization>();
- Stage::Ptr pa_multi_token = make_stage<PagedAttentionGeneratorMultiToken>();
+ Stage::Ptr pa_multi_token_1 = make_stage<PagedAttentionGeneratorMultiToken>(1);
+ Stage::Ptr pa_multi_token_128 = make_stage<PagedAttentionGeneratorMultiToken>(128);
+ Stage::Ptr pa_multi_token_256 = make_stage<PagedAttentionGeneratorMultiToken>(256);
Stage::Ptr xattn_estimate_gemmqk = make_stage<XAttentionEstimateGEMMQK>(128);
Stage::Ptr xattn_estimate_find_block = make_stage<XAttentionEstimateFindBlock>(128);
Stage::Ptr xattn_estimate_post_proc = make_stage<XAttentionEstimatePostProc>(128);
@@ -55,15 +57,22 @@ public:
add_stage(kv_cache_update, params);
add_stage(pa_single_token, params);
add_stage(pa_single_token_finalization, params);
- add_stage(pa_multi_token, params);
+ add_stage(pa_multi_token_1, params);
if (desc->has_xattention) {
+ add_stage(pa_multi_token_128, params);
+ if (params.get_device_info().arch >= gpu_arch::xe2) {
+ add_stage(pa_multi_token_256, params);
+ }
+
add_stage(xattn_estimate_gemmqk, params);
add_stage(xattn_estimate_find_block, params);
add_stage(xattn_estimate_post_proc, params);
- add_stage(xattn_estimate_gemmqk_256, params);
- add_stage(xattn_estimate_find_block_256, params);
- add_stage(xattn_estimate_post_proc_256, params);
+ if (params.get_device_info().arch >= gpu_arch::xe2) {
+ add_stage(xattn_estimate_gemmqk_256, params);
+ add_stage(xattn_estimate_find_block_256, params);
+ add_stage(xattn_estimate_post_proc_256, params);
+ }
}
}
@@ -126,7 +135,7 @@ public:
<< std::endl;
if (rt_params->stage == PagedAttentionStage::GENERATE) {
- auto partition_size = get_partition_size(desc->has_xattention);
+ auto partition_size = PagedAttentionGeneratorSingleToken::get_partition_size(desc->has_xattention);
rt_params->num_of_partitions = ceil_div(max_context_len, partition_size);
rt_params->q_chunking = get_single_token_q_chunking(params, *desc, partition_size);
GPU_DEBUG_TRACE_DETAIL << " partition_size: " << partition_size << " num_of_partitions: " << rt_params->num_of_partitions << std::endl;
@@ -158,28 +167,37 @@ public:
res_event = {execute_stage(res_event, instance, kv_cache_update)};
if (rt_params->stage == PagedAttentionStage::PREFILL || rt_params->stage == PagedAttentionStage::MIXED) {
- if (!bypass_xattn(params)) {
- if (rt_params->xattn_block_size == 128) {
- res_event = {execute_stage(res_event, instance, xattn_estimate_gemmqk)};
- XATTN_DUMP(instance, PagedAttentionInternBuffIdx::XATTN_GEMMQK_MAX); // 2: kq_max_wg
- XATTN_DUMP(instance,
- PagedAttentionInternBuffIdx::XATTN_GEMMQK_EXPSUMS); // idx 3: kq_exp_partial_sum is subject to change in find_block kernel.
- res_event = {execute_stage(res_event, instance, xattn_estimate_find_block)};
- res_event = {execute_stage(res_event, instance, xattn_estimate_post_proc)};
- } else {
- res_event = {execute_stage(res_event, instance, xattn_estimate_gemmqk_256)};
- XATTN_DUMP(instance, PagedAttentionInternBuffIdx::XATTN_GEMMQK_MAX);
- XATTN_DUMP(instance, PagedAttentionInternBuffIdx::XATTN_GEMMQK_EXPSUMS);
- res_event = {execute_stage(res_event, instance, xattn_estimate_find_block_256)};
- XATTN_DUMP(instance, PagedAttentionInternBuffIdx::XATTN_BLOCKMASK); // 4: sparse_block_mask
- res_event = {execute_stage(res_event, instance, xattn_estimate_post_proc_256)};
- }
+ const bool is_xattn_bypassed = bypass_xattn(params);
+ if (is_xattn_bypassed || desc->has_xattention == false) {
+ GPU_DEBUG_TRACE_DETAIL << "Execute multi-token stage w/o XAttention estimation stages." << std::endl;
+
+ res_event = {execute_stage(res_event, instance, *pa_multi_token_1)};
+ } else {
+ GPU_DEBUG_TRACE_DETAIL << "Execute multi-token stage w/ XAttention estimation stages." << std::endl;
+
+ OPENVINO_ASSERT(rt_params->xattn_block_size == 128 || rt_params->xattn_block_size == 256,
+ "Unsupported xattention block size for multi token stage: ",
+ rt_params->xattn_block_size);
+
+ const bool use_256 = rt_params->xattn_block_size == 256;
+ Stage::Ptr& xattn_gemmqk = use_256 ? xattn_estimate_gemmqk_256 : xattn_estimate_gemmqk;
+ Stage::Ptr& xattn_find_block = use_256 ? xattn_estimate_find_block_256 : xattn_estimate_find_block;
+ Stage::Ptr& xattn_post_proc = use_256 ? xattn_estimate_post_proc_256 : xattn_estimate_post_proc;
+ Stage::Ptr& pa_multi_token = use_256 ? pa_multi_token_256 : pa_multi_token_128;
+
+ res_event = {execute_stage(res_event, instance, xattn_gemmqk)};
+ XATTN_DUMP(instance, PagedAttentionInternBuffIdx::XATTN_GEMMQK_MAX); // 2: kq_max_wg
+ XATTN_DUMP(instance,
+ PagedAttentionInternBuffIdx::XATTN_GEMMQK_EXPSUMS); // idx 3: kq_exp_partial_sum is subject to change in find_block kernel.
+ res_event = {execute_stage(res_event, instance, xattn_find_block)};
+ XATTN_DUMP(instance, PagedAttentionInternBuffIdx::XATTN_BLOCKMASK); // 4: sparse_block_mask
#if FIND_DEBUG_ACC
XATTN_DUMP(instance, PagedAttentionInternBuffIdx::XATTN_FIND_DEBUG_ACC); // 6: kq_sum for debug purpose only
#endif
+ res_event = {execute_stage(res_event, instance, xattn_post_proc)};
+ res_event = {execute_stage(res_event, instance, pa_multi_token)};
}
- res_event = {execute_stage(res_event, instance, pa_multi_token)};
- } else if (rt_params->stage == PagedAttentionStage::GENERATE) {
+ } else {
res_event = {execute_stage(res_event, instance, pa_single_token)};
res_event = {execute_stage(res_event, instance, pa_single_token_finalization)};
}
@@ -262,8 +280,9 @@ private:
const auto blocksize_mem = input_mem.at(PagedAttentionInputIdx::XATTENTION_BLOCK_SIZE);
mem_lock<int32_t, mem_lock_type::read> lock(blocksize_mem, *params.strm); // converted
auto xattn_block_size = static_cast<int32_t>(lock[seq_idx]);
+ GPU_DEBUG_TRACE_DETAIL << "XAttention block size from input: " << xattn_block_size << std::endl;
if (xattn_block_size != 128 && xattn_block_size != 256) {
- xattn_block_size = 128; // default
+ xattn_block_size = 256; // default
}
if (xattn_block_size == 256 && params.get_device_info().arch < gpu_arch::xe2) {
xattn_block_size = 128; // on pre-XE2, only support 128
diff --git a/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention_gen.cpp b/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention_gen.cpp
index 3a7d6711c82..e71dd19d584 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention_gen.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention_gen.cpp
@@ -57,14 +57,6 @@ inline bool get_kv_compressed(const RuntimeParams& params) {
}
}
-size_t get_partition_size(const bool has_xattention) {
- if (!has_xattention && PA_KV_CACHE_BLOCK_SIZE < 128) {
- return 128;
- } else {
- return PA_KV_CACHE_BLOCK_SIZE_XATTN;
- }
-}
-
// max_context_len = max(past_lens + prompt_lens)
size_t get_max_context_len(const kernel_impl_params& params) {
const auto& input_mem = params.memory_deps;
@@ -163,7 +155,7 @@ JitConstants PagedAttentionGeneratorKVCacheUpdate::get_jit_constants(const kerne
if (desc->has_xattention) {
jit.make("PAGED_ATTENTION_BLOCK_SIZE", PA_KV_CACHE_BLOCK_SIZE_XATTN);
} else {
- jit.make("PAGED_ATTENTION_BLOCK_SIZE", PA_KV_CACHE_BLOCK_SIZE);
+ jit.make("PAGED_ATTENTION_BLOCK_SIZE", PA_KV_CACHE_BLOCK_SIZE_LEGACY);
}
if (get_kv_compressed(params)) {
@@ -282,17 +274,14 @@ Arguments PagedAttentionGeneratorMultiToken::get_arguments_desc(const kernel_imp
args.push_back({ArgumentDescriptor::Types::INPUT, PagedAttentionInputIdx::SUBSEQUENCE_BEGINS}); // subsequence_begins
args.push_back({ArgumentDescriptor::Types::OUTPUT, 0});
+ args.push_back({ArgumentDescriptor::Types::SCALAR, 0}); // q_len
- if (desc->has_xattention) {
+ if (_xattn_block_size > 1 && desc->has_xattention) {
args.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, PagedAttentionInternBuffIdx::XATTN_BLOCKMASK}); // sparse_block_mask
args.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, PagedAttentionInternBuffIdx::XATTN_BLOCKMASK_MERGED}); // sparse_block_mask_wg
- }
- args.push_back({ArgumentDescriptor::Types::SCALAR, 0}); // q_len
- if (desc->has_xattention) {
args.push_back({ArgumentDescriptor::Types::SCALAR, 1}); // q_block_pad
args.push_back({ArgumentDescriptor::Types::SCALAR, 2}); // k_block_pad
- args.push_back({ArgumentDescriptor::Types::SCALAR, 3}); // SPARSE_BLOCK_SIZE
}
return args;
}
@@ -301,18 +290,25 @@ JitConstants PagedAttentionGeneratorMultiToken::get_jit_constants(const kernel_i
auto jit = PagedAttentionGeneratorBase::get_jit_constants(params);
const auto desc = params.typed_desc<paged_attention>();
const float scale_factor = 1.0 / std::sqrt(static_cast<double>(desc->k_head_size));
+ OPENVINO_ASSERT(_xattn_block_size == 1 || _xattn_block_size == 128 || _xattn_block_size == 256,
+ "Unsupported xattention block size for multi token kernel: ",
+ _xattn_block_size);
jit.make("CMFLA_NUM_HEADS", desc->heads_num);
jit.make("CMFLA_NUM_KV_HEADS", desc->kv_heads_num);
jit.make("CMFLA_HEAD_SIZE", desc->k_head_size);
jit.add(make_jit_constant("CMFLA_SCALE_FACTOR", scale_factor));
jit.make("CMFLA_IS_CAUSAL", 1);
+ if (_xattn_block_size > 1) {
+ jit.make("SPARSE_BLOCK_SIZE", _xattn_block_size);
+ } else {
+ jit.make("SPARSE_BLOCK_SIZE", 1);
+ }
+
if (desc->has_xattention) {
jit.make("CMPA_BLOCK_SZ", PA_KV_CACHE_BLOCK_SIZE_XATTN);
- jit.make("IS_BLOCK_SPARSE", 1);
} else {
- jit.make("CMPA_BLOCK_SZ", PA_KV_CACHE_BLOCK_SIZE);
- jit.make("IS_BLOCK_SPARSE", 0);
+ jit.make("CMPA_BLOCK_SZ", PA_KV_CACHE_BLOCK_SIZE_LEGACY);
}
if (get_kv_compressed(params)) {
@@ -320,11 +316,15 @@ JitConstants PagedAttentionGeneratorMultiToken::get_jit_constants(const kernel_i
} else {
jit.make("CMPA_KVCACHE_U8", 0);
}
+
+ jit.make("CMPA_WG_SEQ_LEN", get_wg_seq_len(params));
+
return jit;
}
DispatchDataFunc PagedAttentionGeneratorMultiToken::get_dispatch_data_func() const {
- return DispatchDataFunc{[](const RuntimeParams& params, KernelData& kd, ImplRuntimeParams* rt_params) {
+ const size_t xattn_block_size = _xattn_block_size;
+ return DispatchDataFunc{[xattn_block_size](const RuntimeParams& params, KernelData& kd, ImplRuntimeParams* rt_params) {
auto& wgs = kd.params.workGroups;
auto& scalars = kd.params.scalars;
auto desc = params.typed_desc<paged_attention>();
@@ -350,7 +350,7 @@ DispatchDataFunc PagedAttentionGeneratorMultiToken::get_dispatch_data_func() con
<< ", wg_seq_len: " << wg_seq_len << ", wg_count: " << wg_count << ", gws: [" << wgs.global[0] << ", " << wgs.global[1] << ", "
<< wgs.global[2] << "]" << ", lws: [" << wgs.local[0] << ", " << wgs.local[1] << ", " << wgs.local[2] << "]" << std::endl;
}
- auto num_scalers = desc->has_xattention ? 4 : 1;
+ auto num_scalers = xattn_block_size > 1 && desc->has_xattention ? 3 : 1;
scalars.resize(num_scalers);
scalars[0].t = ScalarDescriptor::Types::INT32;
scalars[0].v.s32 = static_cast<int32_t>(q_len);
@@ -360,10 +360,6 @@ DispatchDataFunc PagedAttentionGeneratorMultiToken::get_dispatch_data_func() con
scalars[2].t = ScalarDescriptor::Types::INT32;
scalars[2].v.s32 = static_cast<int32_t>(rtp->k_block_pad);
-
- scalars[3].t = ScalarDescriptor::Types::INT32;
- const bool validate = !bypass_xattn(params);
- scalars[3].v.s32 = static_cast<int32_t>(validate ? rtp->xattn_block_size : 1);
}
}};
}
@@ -381,7 +377,7 @@ JitConstants PagedAttentionGeneratorSingleToken::get_jit_constants(const kernel_
if (desc->has_xattention) {
jit.make("KV_BLOCK_SIZE", PA_KV_CACHE_BLOCK_SIZE_XATTN);
} else {
- jit.make("KV_BLOCK_SIZE", PA_KV_CACHE_BLOCK_SIZE);
+ jit.make("KV_BLOCK_SIZE", PA_KV_CACHE_BLOCK_SIZE_LEGACY);
}
jit.add(make_jit_constant("SCALE_FACTOR", scale_factor));
jit.make("HEAD_SIZE", desc->k_head_size);
diff --git a/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention_gen.hpp b/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention_gen.hpp
index 8a263597a55..4af94eadaff 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention_gen.hpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cm/paged_attention_gen.hpp
@@ -85,9 +85,10 @@ inline std::string get_pa_build_options() {
}
#define FIND_DEBUG_ACC 0
-// BLOCK_SIZE can be 16/256 for legacy and xattn cases respectively
-#define PA_KV_CACHE_BLOCK_SIZE 16
-#define PA_KV_CACHE_BLOCK_SIZE_XATTN 256
+// The block size for KV cache is set to 256 for xattn to achieve better performance.
+// For non-xattn case, it can be set to 16 for compatibility to legacy implementations.
+#define PA_KV_CACHE_BLOCK_SIZE_LEGACY 16
+#define PA_KV_CACHE_BLOCK_SIZE_XATTN 256
constexpr uint32_t SG_M = 4;
constexpr uint32_t SG_N = 8;
@@ -136,7 +137,6 @@ int64_t get_aligned_seq_len(const kernel_impl_params& impl_param, const PagedAtt
PagedAttentionStage get_paged_attention_stage(const kernel_impl_params& impl_param);
size_t get_max_context_len(const kernel_impl_params& params);
size_t get_past_len(const kernel_impl_params& params, const size_t seq_idx);
-size_t get_partition_size(const bool has_xattention);
float get_xattn_thresh(const kernel_impl_params& impl_param, const size_t seq_idx = 0);
bool bypass_xattn(const kernel_impl_params& impl_param);
@@ -160,7 +160,9 @@ public:
class PagedAttentionGeneratorMultiToken : public PagedAttentionGeneratorBase {
public:
- PagedAttentionGeneratorMultiToken() : PagedAttentionGeneratorBase("pa_multi_token") {}
+ explicit PagedAttentionGeneratorMultiToken(size_t xattn_block_size = 1)
+ : PagedAttentionGeneratorBase("pa_multi_token", "_cm_bs" + std::to_string(xattn_block_size)),
+ _xattn_block_size(xattn_block_size) {}
static size_t get_q_step(const kernel_impl_params& params) {
const auto xe_arch = params.get_device_info().arch < gpu_arch::xe2 ? 1 : 2;
@@ -178,6 +180,9 @@ public:
[[nodiscard]] Arguments get_arguments_desc(const kernel_impl_params& params) const override;
[[nodiscard]] JitConstants get_jit_constants(const kernel_impl_params& params) const override;
[[nodiscard]] DispatchDataFunc get_dispatch_data_func() const override;
+
+private:
+ size_t _xattn_block_size;
};
class PagedAttentionGeneratorSingleToken : public PagedAttentionGeneratorBase {
@@ -186,6 +191,16 @@ public:
[[nodiscard]] JitConstants get_jit_constants(const kernel_impl_params& params) const override;
[[nodiscard]] Arguments get_arguments_desc(const kernel_impl_params& params) const override;
[[nodiscard]] DispatchDataFunc get_dispatch_data_func() const override;
+
+ static size_t get_partition_size(const bool has_xattention = false) {
+ // inheristic setting for single token to ensure the best performance, which is also verified by
+ // internal testing. We can consider to make it configurable if needed in the future.
+ if (!has_xattention && PA_KV_CACHE_BLOCK_SIZE_LEGACY < 128) {
+ return 128;
+ } else {
+ return PA_KV_CACHE_BLOCK_SIZE_XATTN;
+ }
+ }
};
class PagedAttentionGeneratorSingleTokenFinalization : public PagedAttentionGeneratorBase {
@@ -201,10 +216,9 @@ public:
//-----------------------------------------------------------------------------------------------------------------
class XAttentionEstimateGeneratorBase : public KernelGenerator {
public:
- explicit XAttentionEstimateGeneratorBase(std::string_view kernel_name, size_t xattn_block_size, std::string_view stage_suffix = "_cm")
- : KernelGenerator(kernel_name, stage_suffix),
+ explicit XAttentionEstimateGeneratorBase(std::string_view kernel_name, size_t xattn_block_size)
+ : KernelGenerator(kernel_name, "_cm_bs" + std::to_string(xattn_block_size)),
_xattn_block_size(xattn_block_size) {}
-
static uint32_t get_block_sg_m(const kernel_impl_params& params) {
return is_xe2_or_xe3(params) ? 64u : 32u;
}
diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
index 2cc094a70ac..53499882b4b 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
@@ -433,7 +433,7 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
[&](const_node_ptr &) -> bool {
auto& engine = m_context->get_engine();
const auto& info = engine.get_device_info();
- if (!(info.supports_immad)) { // CM optimized for systolic-array architectures
+ if (!info.supports_immad) { // CM optimized for systolic-array architectures
return true;
}
@@ -599,7 +599,7 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
auto check_xattn_gpu_compatibility = [&](void) -> bool {
auto& engine = m_context->get_engine();
const auto& info = engine.get_device_info();
- if (!(info.supports_immad)) { // CM optimized for systolic-array architectures
+ if (!info.supports_immad) { // CM optimized for systolic-array architectures
return false;
}