Skip to content

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

[GPU] Add optimized universal OpenCL SelectiveSSM reference implementation (#37478)

Nesterov Alexander88427b62cf21
diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp
index e5ec7628baa..339f340ff61 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp
@@ -317,12 +317,14 @@ REGISTER_FACTORY(internal, DynamicQuantize);
REGISTER_FACTORY(internal, PagedAttentionExtension);
REGISTER_FACTORY(internal, PA_KV_Reorder);
REGISTER_FACTORY(internal, PagedGatedDeltaNet);
+REGISTER_FACTORY(internal, PagedSelectiveSSM);
REGISTER_FACTORY(internal, LoraSubgraph);
REGISTER_FACTORY(internal, LoraSubgraphFused);
REGISTER_FACTORY(internal, VLSDPA);
REGISTER_FACTORY(internal, MOECompressed);
REGISTER_FACTORY(internal, MoERouterFused);
REGISTER_FACTORY(internal, GatedDeltaNet);
+REGISTER_FACTORY(internal, SelectiveSSM);
REGISTER_FACTORY(internal, PagedCausalConv1D);
REGISTER_FACTORY(internal, GatherMatmul);
REGISTER_FACTORY(internal, GatherMatmulCompressed);
diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_selective_ssm.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_selective_ssm.hpp
new file mode 100644
index 00000000000..0ebc7a7da4a
--- /dev/null
+++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_selective_ssm.hpp
@@ -0,0 +1,54 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <vector>
+
+#include "intel_gpu/graph/program.hpp"
+#include "intel_gpu/graph/topology.hpp"
+#include "openvino/op/paged_selective_ssm.hpp"
+#include "primitive.hpp"
+
+namespace cldnn {
+
+using PagedSelectiveSSM = ov::op::internal::PagedSelectiveSSM;
+
+struct paged_selective_ssm : public primitive_base<paged_selective_ssm> {
+ CLDNN_DECLARE_PRIMITIVE(paged_selective_ssm)
+
+ enum PagedSelectiveSSMInputIdx {
+ A = 0,
+ DT = 1,
+ B = 2,
+ X = 3,
+ C = 4,
+ RECURRENT_STATE_TABLE = 5,
+ SUBSEQUENCE_BEGINS = 6,
+ BLOCK_INDICES = 7,
+ BLOCK_INDICES_BEGINS = 8,
+ NUM_PROCESSED_TOKENS = 9,
+ CACHE_INTERVAL = 10,
+ };
+
+ paged_selective_ssm() : primitive_base("", {}) {}
+
+ paged_selective_ssm(const primitive_id& id, const std::vector<input_info>& inputs) : primitive_base(id, inputs) {
+ OPENVINO_ASSERT(inputs.size() == 11, "Unexpected inputs number for paged_selective_ssm primitive: ", inputs.size());
+ }
+
+ bool operator==(const primitive& rhs) const override {
+ return compare_common_params(rhs);
+ }
+
+ void save(BinaryOutputBuffer& ob) const override {
+ primitive_base<paged_selective_ssm>::save(ob);
+ }
+
+ void load(BinaryInputBuffer& ib) override {
+ primitive_base<paged_selective_ssm>::load(ib);
+ }
+};
+
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/selective_ssm.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/selective_ssm.hpp
new file mode 100644
index 00000000000..a02fc3c9d26
--- /dev/null
+++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/selective_ssm.hpp
@@ -0,0 +1,41 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <vector>
+
+#include "intel_gpu/graph/program.hpp"
+#include "intel_gpu/graph/topology.hpp"
+#include "openvino/op/selective_ssm.hpp"
+#include "primitive.hpp"
+
+namespace cldnn {
+
+using SelectiveSSM = ov::op::internal::SelectiveSSM;
+
+struct selective_ssm : public primitive_base<selective_ssm> {
+ CLDNN_DECLARE_PRIMITIVE(selective_ssm)
+
+ selective_ssm() : primitive_base("", {}) {}
+
+ selective_ssm(const primitive_id& id, const std::vector<input_info>& inputs) : primitive_base(id, inputs) {
+ OPENVINO_ASSERT(inputs.size() == 6, "Unexpected inputs number for selective_ssm primitive: ", inputs.size());
+ num_outputs = 2;
+ }
+
+ bool operator==(const primitive& rhs) const override {
+ return compare_common_params(rhs);
+ }
+
+ void save(BinaryOutputBuffer& ob) const override {
+ primitive_base<selective_ssm>::save(ob);
+ }
+
+ void load(BinaryInputBuffer& ib) override {
+ primitive_base<selective_ssm>::load(ib);
+ }
+};
+
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm.cpp
new file mode 100644
index 00000000000..9d892f5a9d5
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm.cpp
@@ -0,0 +1,197 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "paged_selective_ssm.hpp"
+
+#include <algorithm>
+#include <array>
+#include <limits>
+
+#include "intel_gpu/primitives/paged_selective_ssm.hpp"
+#include "primitive_ocl_base.hpp"
+#include "selective_ssm_utils.hpp"
+#include "utils/kernel_generator.hpp"
+
+namespace ov::intel_gpu::ocl {
+
+using cldnn::BufferDescriptor;
+using cldnn::paged_selective_ssm;
+using cldnn::primitive_impl;
+using cldnn::program_node;
+
+namespace {
+
+size_t get_scratch_elements(const std::array<size_t, 4>& dimensions) {
+ size_t elements = 1;
+ for (const size_t dimension : dimensions) {
+ OPENVINO_ASSERT(dimension == 0 || elements <= std::numeric_limits<size_t>::max() / dimension,
+ "PagedSelectiveSSM global state scratch size overflows size_t");
+ elements *= dimension;
+ }
+ return std::max<size_t>(elements, 1);
+}
+
+class PagedSelectiveSSMOptGenerator : public KernelGenerator {
+public:
+ PagedSelectiveSSMOptGenerator() : KernelGenerator("paged_selective_ssm_opt") {}
+
+protected:
+ [[nodiscard]] Arguments get_arguments_desc(const RuntimeParams& params) const override {
+ Arguments args;
+ if (params.is_dynamic())
+ args.push_back({ArgumentDescriptor::Types::SHAPE_INFO, 0});
+ for (uint32_t i = 0; i < params.input_layouts.size(); i++) {
+ args.push_back({ArgumentDescriptor::Types::INPUT, i});
+ }
+ args.push_back({ArgumentDescriptor::Types::OUTPUT, 0});
+ args.push_back({ArgumentDescriptor::Types::SCALAR, 0});
+ args.push_back({ArgumentDescriptor::Types::SCALAR, 1});
+ args.push_back({ArgumentDescriptor::Types::LOCAL_MEMORY_SIZE, 0});
+ return args;
+ }
+
+ [[nodiscard]] DispatchDataFunc get_dispatch_data_func() const override {
+ return DispatchDataFunc{[](const RuntimeParams& params, KernelData& kd, ImplRuntimeParams*) {
+ auto& wgs = kd.params.workGroups;
+ if (params.is_dynamic()) {
+ wgs.global = {1, 1, 1};
+ wgs.local = {1, 1, 1};
+ selective_ssm_utils::set_dispatch_scalars(kd, 1, params.get_device_info());
+ kd.params.local_memory_args = {2 * sizeof(float)};
+ return;
+ }
+
+ const auto& x_shape = params.get_input_layout(3).get_partial_shape();
+ const auto& B_shape = params.get_input_layout(2).get_partial_shape();
+ const auto& seq_shape = params.get_input_layout(6).get_partial_shape();
+ const size_t sequences = seq_shape[0].get_length() > 0 ? seq_shape[0].get_length() - 1 : 0;
+ const size_t num_heads = x_shape[1].get_length();
+ const size_t head_dim = x_shape[2].get_length();
+ const size_t state_size = B_shape[2].get_length();
+ const size_t lws = selective_ssm_utils::get_lws(state_size, params.get_device_info());
+ if (selective_ssm_utils::requires_global_state(state_size, lws, params.get_device_info())) {
+ wgs.global = {1, 1, 1};
+ wgs.local = {1, 1, 1};
+ selective_ssm_utils::set_dispatch_scalars(kd, 1, params.get_device_info());
+ kd.params.local_memory_args = {sizeof(float)};
+ return;
+ }
+ const size_t head_dim_block = selective_ssm_utils::get_head_dim_block(head_dim, state_size, lws, params.get_device_info());
+ const size_t head_dim_groups = selective_ssm_utils::get_head_dim_groups(head_dim, head_dim_block);
+ const size_t local_bytes = head_dim_block * (state_size + lws) * sizeof(float);
+
+ wgs.global = {std::max<size_t>(head_dim_groups, 1) * lws, std::max<size_t>(num_heads, 1), std::max<size_t>(sequences, 1)};
+ wgs.local = {lws, 1, 1};
+ selective_ssm_utils::set_dispatch_scalars(kd, head_dim_block, params.get_device_info());
+ kd.params.local_memory_args = {local_bytes};
+ }};
+ }
+};
+
+class PagedSelectiveSSMLargeStateGenerator : public KernelGenerator {
+public:
+ PagedSelectiveSSMLargeStateGenerator() : KernelGenerator("paged_selective_ssm_large_state") {}
+
+protected:
+ [[nodiscard]] Arguments get_arguments_desc(const RuntimeParams& params) const override {
+ Arguments args;
+ if (params.is_dynamic())
+ args.push_back({ArgumentDescriptor::Types::SHAPE_INFO, 0});
+ for (uint32_t i = 0; i < params.input_layouts.size(); i++) {
+ args.push_back({ArgumentDescriptor::Types::INPUT, i});
+ }
+ args.push_back({ArgumentDescriptor::Types::OUTPUT, 0});
+ args.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 0});
+ args.push_back({ArgumentDescriptor::Types::SCALAR, 0});
+ args.push_back({ArgumentDescriptor::Types::SCALAR, 1});
+ args.push_back({ArgumentDescriptor::Types::LOCAL_MEMORY_SIZE, 0});
+ return args;
+ }
+
+ [[nodiscard]] DispatchDataFunc get_dispatch_data_func() const override {
+ return DispatchDataFunc{[](const RuntimeParams& params, KernelData& kd, ImplRuntimeParams*) {
+ auto& wgs = kd.params.workGroups;
+ if (params.is_dynamic()) {
+ wgs.global = {1, 1, 1};
+ wgs.local = {1, 1, 1};
+ selective_ssm_utils::set_dispatch_scalars(kd, 1, params.get_device_info());
+ kd.params.local_memory_args = {sizeof(float)};
+ return;
+ }
+
+ const auto& x_shape = params.get_input_layout(3).get_partial_shape();
+ const auto& B_shape = params.get_input_layout(2).get_partial_shape();
+ const auto& seq_shape = params.get_input_layout(6).get_partial_shape();
+ const size_t sequences = seq_shape[0].get_length() > 0 ? seq_shape[0].get_length() - 1 : 0;
+ const size_t num_heads = x_shape[1].get_length();
+ const size_t head_dim = x_shape[2].get_length();
+ const size_t state_size = B_shape[2].get_length();
+ const size_t lws = selective_ssm_utils::get_lws(state_size, params.get_device_info());
+ const size_t head_dim_block = std::min(std::max<size_t>(head_dim, 1), selective_ssm_utils::max_head_dim_block);
+ const size_t head_dim_groups = selective_ssm_utils::get_head_dim_groups(head_dim, head_dim_block);
+
+ wgs.global = {std::max<size_t>(head_dim_groups, 1) * lws, std::max<size_t>(num_heads, 1), std::max<size_t>(sequences, 1)};
+ wgs.local = {lws, 1, 1};
+ selective_ssm_utils::set_dispatch_scalars(kd, head_dim_block, params.get_device_info());
+ kd.params.local_memory_args = {head_dim_block * lws * sizeof(float)};
+ }};
+ }
+};
+
+class PagedSelectiveSSMOptImpl : public PrimitiveImplOCL {
+public:
+ DECLARE_OBJECT_TYPE_SERIALIZATION(ov::intel_gpu::ocl::PagedSelectiveSSMOptImpl)
+
+ Stage::Ptr paged_selective_ssm = make_stage<PagedSelectiveSSMOptGenerator>();
+ Stage::Ptr paged_selective_ssm_large_state = make_stage<PagedSelectiveSSMLargeStateGenerator>();
+
+ PagedSelectiveSSMOptImpl() : PrimitiveImplOCL(PagedSelectiveSSMOpt::get_type_info_static()) {}
+ PagedSelectiveSSMOptImpl(const program_node&, const RuntimeParams& params) : PagedSelectiveSSMOptImpl() {
+ add_stage(paged_selective_ssm, params);
+ add_stage(paged_selective_ssm_large_state, params);
+ }
+
+ [[nodiscard]] std::unique_ptr<primitive_impl> clone() const override {
+ return make_deep_copy<PagedSelectiveSSMOptImpl>(this);
+ }
+
+ [[nodiscard]] std::vector<BufferDescriptor> get_internal_buffer_descs(const RuntimeParams& params) const override {
+ size_t state_scratch_elements = 1;
+ const auto& B_shape = params.get_input_layout(2).get_partial_shape();
+ const auto& x_shape = params.get_input_layout(3).get_partial_shape();
+ const auto& seq_shape = params.get_input_layout(6).get_partial_shape();
+ if (B_shape.is_static() && x_shape.is_static() && seq_shape.is_static()) {
+ const size_t state_size = B_shape[2].get_length();
+ const size_t lws = selective_ssm_utils::get_lws(state_size, params.get_device_info());
+ if (selective_ssm_utils::requires_global_state(state_size, lws, params.get_device_info())) {
+ const size_t sequences = seq_shape[0].get_length() > 0 ? seq_shape[0].get_length() - 1 : 0;
+ const size_t num_heads = x_shape[1].get_length();
+ const size_t head_dim = x_shape[2].get_length();
+ state_scratch_elements = get_scratch_elements({sequences, num_heads, head_dim, state_size});
+ }
+ }
+ return {BufferDescriptor{state_scratch_elements, ov::element::f32}};
+ }
+
+ [[nodiscard]] std::vector<size_t> get_stages_execution_order(const RuntimeParams& params) const override {
+ const auto& B_shape = params.get_input_layout(2).get_partial_shape();
+ if (!B_shape.is_static())
+ return {0};
+ const size_t state_size = B_shape[2].get_length();
+ const size_t lws = selective_ssm_utils::get_lws(state_size, params.get_device_info());
+ return {selective_ssm_utils::requires_global_state(state_size, lws, params.get_device_info()) ? 1ul : 0ul};
+ }
+};
+
+} // namespace
+
+std::unique_ptr<primitive_impl> PagedSelectiveSSMOpt::create_impl(const program_node& node, const RuntimeParams& params) const {
+ assert(node.is_type<paged_selective_ssm>());
+ return std::make_unique<PagedSelectiveSSMOptImpl>(node, params);
+}
+
+} // namespace ov::intel_gpu::ocl
+
+BIND_BINARY_BUFFER_WITH_TYPE(cldnn::paged_selective_ssm)
+BIND_BINARY_BUFFER_WITH_TYPE(ov::intel_gpu::ocl::PagedSelectiveSSMOptImpl)
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm.hpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm.hpp
new file mode 100644
index 00000000000..89ba4eef41b
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm.hpp
@@ -0,0 +1,58 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <array>
+#include <memory>
+#include <utility>
+
+#include "paged_selective_ssm_inst.h"
+#include "program_node.h"
+#include "registry/implementation_manager.hpp"
+
+namespace ov::intel_gpu::ocl {
+
+struct PagedSelectiveSSMOpt : public cldnn::ImplementationManager {
+ OV_GPU_PRIMITIVE_IMPL("ocl::paged_selective_ssm::opt")
+ explicit PagedSelectiveSSMOpt(cldnn::shape_types shape_type, cldnn::ValidateFunc vf = nullptr)
+ : cldnn::ImplementationManager(cldnn::impl_types::ocl, shape_type, std::move(vf)) {}
+
+ [[nodiscard]] std::unique_ptr<cldnn::primitive_impl> create_impl(const cldnn::program_node& node, const RuntimeParams& params) const override;
+
+ [[nodiscard]] bool validate_impl(const cldnn::program_node& node) const override {
+ assert(node.is_type<cldnn::paged_selective_ssm>());
+ static constexpr std::array supported_fmts = {cldnn::format::bfyx};
+ static constexpr std::array supported_real_types = {ov::element::f16, ov::element::f32, ov::element::bf16};
+ static constexpr std::array supported_index_types = {ov::element::i32, ov::element::i64};
+
+ ov::element::Type real_type = ov::element::dynamic;
+ ov::element::Type index_type = ov::element::dynamic;
+ for (size_t i = 0; i < node.get_dependencies().size(); i++) {
+ const auto& in_layout = node.get_input_layout(i);
+ if (!cldnn::one_of(in_layout.format, supported_fmts))
+ return false;
+ if (i <= cldnn::paged_selective_ssm::RECURRENT_STATE_TABLE) {
+ if (!cldnn::one_of(in_layout.data_type, supported_real_types))
+ return false;
+ if (real_type.is_dynamic())
+ real_type = in_layout.data_type;
+ else if (real_type != in_layout.data_type)
+ return false;
+ } else {
+ if (!cldnn::one_of(in_layout.data_type, supported_index_types))
+ return false;
+ if (index_type.is_dynamic())
+ index_type = in_layout.data_type;
+ else if (index_type != in_layout.data_type)
+ return false;
+ }
+ }
+
+ const auto& out_layout = node.get_output_layout(0);
+ return cldnn::one_of(out_layout.format, supported_fmts) && out_layout.data_type == real_type;
+ }
+};
+
+} // namespace ov::intel_gpu::ocl
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm_large_state.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm_large_state.cl
new file mode 100644
index 00000000000..c38f9daffac
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm_large_state.cl
@@ -0,0 +1,183 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "include/batch_headers/common.cl"
+#include "include/batch_headers/fetch_data.cl"
+#include "include/batch_headers/bf16_utils.cl"
+
+#define SSM_MAX_HEAD_DIM_BLOCK 4
+#if INPUT0_IS_FP
+# define SSM_TO_FLOAT(v) convert_float(v)
+#else
+# define SSM_TO_FLOAT(v) _convert_as_bfloat16_float(v)
+#endif
+#define SSM_STATE_ITERATION_TYPE size_t
+#define SSM_DT_INDEX(token) GET_DATA_INDEX(INPUT1, token, h, 0, 0)
+#define SSM_B_INDEX(token, state_element) GET_DATA_INDEX(INPUT2, token, g, state_element, 0)
+#define SSM_C_INDEX(token, state_element) GET_DATA_INDEX(INPUT4, token, g, state_element, 0)
+#define SSM_X_INDEX(token, p) GET_DATA_INDEX(INPUT3, token, h, p, 0)
+#define SSM_OUTPUT_INDEX(token, p) GET_DATA_INDEX(OUTPUT, token, h, p, 0)
+#define SSM_STATE_INDEX(p_offset, state_element) \
+ (((seq * num_heads + h) * head_dim + p_base + (size_t)(p_offset)) * state_size + (state_element))
+#define SSM_STATE_AT(state_index) state_scratch[state_index]
+
+KERNEL(paged_selective_ssm_large_state)(
+ OPTIONAL_SHAPE_INFO_ARG
+ const __global INPUT0_TYPE* A,
+ const __global INPUT1_TYPE* dt,
+ const __global INPUT2_TYPE* B,
+ const __global INPUT3_TYPE* x,
+ const __global INPUT4_TYPE* C,
+ __global INPUT5_TYPE* recurrent_state_table,
+ const __global INPUT6_TYPE* subsequence_begins,
+ const __global INPUT7_TYPE* block_indices,
+ const __global INPUT8_TYPE* block_indices_begins,
+ const __global INPUT9_TYPE* num_processed_tokens,
+ const __global INPUT10_TYPE* cache_interval,
+ __global OUTPUT_TYPE* output,
+ __global float* state_scratch,
+ int head_dim_block,
+ uint use_subgroup_reduction,
+ __local float* reduction) {
+ const uint lane = get_local_id(0);
+ const uint lws = get_local_size(0);
+ const uint subgroup_lane = get_sub_group_local_id();
+ const uint subgroup_id = get_sub_group_id();
+ const uint subgroup_count = get_num_sub_groups();
+ const size_t h = get_global_id(1);
+ const size_t seq = get_global_id(2);
+
+ const size_t tokens = INPUT3_BATCH_NUM;
+ const size_t num_heads = INPUT3_FEATURE_NUM;
+ const size_t head_dim = INPUT3_SIZE_Y;
+ const size_t num_groups = INPUT2_FEATURE_NUM;
+ const size_t state_size = INPUT2_SIZE_Y;
+ const int block = head_dim_block;
+ const size_t state_iterations = state_size / lws + (size_t)(state_size % lws != 0);
+ const size_t p_base = get_group_id(0) * (size_t)block;
+ const size_t num_state_blocks = INPUT5_BATCH_NUM;
+ const size_t block_indices_count = INPUT7_BATCH_NUM;
+ const size_t sequences = INPUT6_BATCH_NUM > 0 ? INPUT6_BATCH_NUM - 1 : 0;
+
+ if (INPUT0_BATCH_NUM != num_heads ||
+ INPUT1_BATCH_NUM != tokens || INPUT1_FEATURE_NUM != num_heads ||
+ INPUT2_BATCH_NUM != tokens || INPUT4_BATCH_NUM != tokens ||
+ INPUT4_FEATURE_NUM != num_groups || INPUT4_SIZE_Y != state_size ||
+ INPUT5_FEATURE_NUM != num_heads || INPUT5_SIZE_Y != head_dim || INPUT5_SIZE_X != state_size ||
+ INPUT8_BATCH_NUM < sequences + 1 || INPUT9_BATCH_NUM < sequences ||
+ INPUT10_BATCH_NUM < sequences)
+ return;
+
+ if (seq >= sequences || h >= num_heads || p_base >= head_dim || num_groups == 0 ||
+ num_heads % num_groups != 0 || block <= 0 || block > SSM_MAX_HEAD_DIM_BLOCK)
+ return;
+
+ const long token_begin = (long)subsequence_begins[GET_DATA_INDEX(INPUT6, seq, 0, 0, 0)];
+ const long token_end = (long)subsequence_begins[GET_DATA_INDEX(INPUT6, seq + 1, 0, 0, 0)];
+ const long block_begin = (long)block_indices_begins[GET_DATA_INDEX(INPUT8, seq, 0, 0, 0)];
+ const long block_end = (long)block_indices_begins[GET_DATA_INDEX(INPUT8, seq + 1, 0, 0, 0)];
+
+ if (token_begin < 0 || token_end < token_begin || (size_t)token_end > tokens)
+ return;
+ if (token_begin == token_end)
+ return;
+
+ if (block_begin < 0 || block_end <= block_begin || (size_t)block_end > block_indices_count) {
+ if (lane == 0) {
+ for (long token = token_begin; token < token_end; ++token) {
+ for (int p_offset = 0; p_offset < block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ if (p < head_dim)
+ output[GET_DATA_INDEX(OUTPUT, (size_t)token, h, p, 0)] = TO_OUTPUT_TYPE(0.0f);
+ }
+ }
+ }
+ return;
+ }
+
+ const long first_block = (long)block_indices[GET_DATA_INDEX(INPUT7, (size_t)block_begin, 0, 0, 0)];
+ if (first_block < 0 || (size_t)first_block >= num_state_blocks) {
+ if (lane == 0) {
+ for (long token = token_begin; token < token_end; ++token) {
+ for (int p_offset = 0; p_offset < block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ if (p < head_dim)
+ output[GET_DATA_INDEX(OUTPUT, (size_t)token, h, p, 0)] = TO_OUTPUT_TYPE(0.0f);
+ }
+ }
+ }
+ return;
+ }
+
+ const long processed_raw = (long)num_processed_tokens[GET_DATA_INDEX(INPUT9, seq, 0, 0, 0)];
+ const long interval = (long)cache_interval[GET_DATA_INDEX(INPUT10, seq, 0, 0, 0)];
+ const long processed = max(processed_raw, (long)0);
+ const bool cache_enabled = interval > 0;
+ const ulong positive_interval = cache_enabled ? (ulong)interval : 1;
+ const ulong previous_in_interval = cache_enabled ? (ulong)processed % positive_interval : 0;
+ ulong tokens_until_boundary = cache_enabled ? positive_interval - previous_in_interval : 0;
+ ulong write_slot = 1;
+ const size_t heads_per_group = num_heads / num_groups;
+ const size_t g = h / heads_per_group;
+ const float A_value = SSM_TO_FLOAT(A[GET_DATA_INDEX(INPUT0, h, 0, 0, 0)]);
+ const int valid_head_dim_block = p_base + (size_t)block <= head_dim
+ ? block
+ : (int)(head_dim - p_base);
+
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ const size_t scratch_base = ((seq * num_heads + h) * head_dim + p) * state_size;
+ for (size_t step = 0; step < state_iterations; ++step) {
+ const size_t state_element = step * lws + lane;
+ if (state_element >= state_size)
+ break;
+ state_scratch[scratch_base + state_element] =
+ SSM_TO_FLOAT(recurrent_state_table[GET_DATA_INDEX(INPUT5, (size_t)first_block, h, p, state_element)]);
+ }
+ }
+
+ for (long token = token_begin; token < token_end; ++token) {
+ const size_t token_idx = (size_t)token;
+#define SSM_TOKEN_INDEX token_idx
+#include "selective_ssm_recurrence.cl"
+#undef SSM_TOKEN_INDEX
+
+ if (cache_enabled) {
+ const bool at_boundary = --tokens_until_boundary == 0;
+ const bool at_sequence_end = token + 1 == token_end;
+ if (at_boundary || at_sequence_end) {
+ const ulong block_position = (ulong)block_begin + write_slot++;
+ if (block_position < (ulong)block_end && block_position < (ulong)block_indices_count) {
+ const long block_id = (long)block_indices[GET_DATA_INDEX(INPUT7, (size_t)block_position, 0, 0, 0)];
+ if (block_id >= 0 && (size_t)block_id < num_state_blocks) {
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ const size_t scratch_base = ((seq * num_heads + h) * head_dim + p) * state_size;
+ for (size_t step = 0; step < state_iterations; ++step) {
+ const size_t state_element = step * lws + lane;
+ if (state_element >= state_size)
+ break;
+ recurrent_state_table[GET_DATA_INDEX(INPUT5, (size_t)block_id, h, p, state_element)] =
+ TO_INPUT5_TYPE(state_scratch[scratch_base + state_element]);
+ }
+ }
+ }
+ }
+ if (at_boundary)
+ tokens_until_boundary = positive_interval;
+ }
+ }
+ }
+}
+
+#undef SSM_MAX_HEAD_DIM_BLOCK
+#undef SSM_TO_FLOAT
+#undef SSM_STATE_ITERATION_TYPE
+#undef SSM_DT_INDEX
+#undef SSM_B_INDEX
+#undef SSM_C_INDEX
+#undef SSM_X_INDEX
+#undef SSM_OUTPUT_INDEX
+#undef SSM_STATE_INDEX
+#undef SSM_STATE_AT
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm_opt.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm_opt.cl
new file mode 100644
index 00000000000..aecff8148c6
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_selective_ssm_opt.cl
@@ -0,0 +1,186 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "include/batch_headers/common.cl"
+#include "include/batch_headers/fetch_data.cl"
+#include "include/batch_headers/bf16_utils.cl"
+
+#define SSM_MAX_HEAD_DIM_BLOCK 4
+#if INPUT0_IS_FP
+# define SSM_TO_FLOAT(v) convert_float(v)
+#else
+# define SSM_TO_FLOAT(v) _convert_as_bfloat16_float(v)
+#endif
+#define SSM_STATE_ITERATION_TYPE uint
+#define SSM_DT_INDEX(token) GET_DATA_INDEX(INPUT1, token, h, 0, 0)
+#define SSM_B_INDEX(token, state_element) GET_DATA_INDEX(INPUT2, token, g, state_element, 0)
+#define SSM_C_INDEX(token, state_element) GET_DATA_INDEX(INPUT4, token, g, state_element, 0)
+#define SSM_X_INDEX(token, p) GET_DATA_INDEX(INPUT3, token, h, p, 0)
+#define SSM_OUTPUT_INDEX(token, p) GET_DATA_INDEX(OUTPUT, token, h, p, 0)
+#define SSM_STATE_INDEX(p_offset, state_element) ((size_t)(p_offset) * state_size + (state_element))
+#define SSM_STATE_AT(state_index) local_state[state_index]
+
+KERNEL(paged_selective_ssm_opt)(
+ OPTIONAL_SHAPE_INFO_ARG
+ const __global INPUT0_TYPE* A,
+ const __global INPUT1_TYPE* dt,
+ const __global INPUT2_TYPE* B,
+ const __global INPUT3_TYPE* x,
+ const __global INPUT4_TYPE* C,
+ __global INPUT5_TYPE* recurrent_state_table,
+ const __global INPUT6_TYPE* subsequence_begins,
+ const __global INPUT7_TYPE* block_indices,
+ const __global INPUT8_TYPE* block_indices_begins,
+ const __global INPUT9_TYPE* num_processed_tokens,
+ const __global INPUT10_TYPE* cache_interval,
+ __global OUTPUT_TYPE* output,
+ int head_dim_block,
+ uint use_subgroup_reduction,
+ __local float* work) {
+ const uint lane = get_local_id(0);
+ const uint runtime_lws = get_local_size(0);
+ const uint subgroup_lane = get_sub_group_local_id();
+ const uint subgroup_id = get_sub_group_id();
+ const uint subgroup_count = get_num_sub_groups();
+ const size_t h = get_global_id(1);
+ const size_t seq = get_global_id(2);
+
+ const size_t tokens = INPUT3_BATCH_NUM;
+ const size_t num_heads = INPUT3_FEATURE_NUM;
+ const size_t head_dim = INPUT3_SIZE_Y;
+ const size_t num_groups = INPUT2_FEATURE_NUM;
+ const size_t state_size = INPUT2_SIZE_Y;
+ const uint lws = runtime_lws;
+ const int block = head_dim_block;
+ // This kernel is selected only when the full state fits in local memory,
+ // so both the iteration count and state element index fit in uint.
+ const uint state_iterations = (uint)(state_size / lws + (size_t)(state_size % lws != 0));
+ const size_t p_base = get_group_id(0) * (size_t)block;
+ const size_t num_state_blocks = INPUT5_BATCH_NUM;
+ const size_t block_indices_count = INPUT7_BATCH_NUM;
+ const size_t sequences = INPUT6_BATCH_NUM > 0 ? INPUT6_BATCH_NUM - 1 : 0;
+
+ if (INPUT0_BATCH_NUM != num_heads ||
+ INPUT1_BATCH_NUM != tokens || INPUT1_FEATURE_NUM != num_heads ||
+ INPUT2_BATCH_NUM != tokens || INPUT4_BATCH_NUM != tokens ||
+ INPUT4_FEATURE_NUM != num_groups || INPUT4_SIZE_Y != state_size ||
+ INPUT5_FEATURE_NUM != num_heads || INPUT5_SIZE_Y != head_dim || INPUT5_SIZE_X != state_size ||
+ INPUT8_BATCH_NUM < sequences + 1 || INPUT9_BATCH_NUM < sequences ||
+ INPUT10_BATCH_NUM < sequences)
+ return;
+
+ if (seq >= sequences || h >= num_heads || p_base >= head_dim || num_groups == 0 ||
+ num_heads % num_groups != 0 || block <= 0 || block > SSM_MAX_HEAD_DIM_BLOCK)
+ return;
+
+ const long token_begin = (long)subsequence_begins[GET_DATA_INDEX(INPUT6, seq, 0, 0, 0)];
+ const long token_end = (long)subsequence_begins[GET_DATA_INDEX(INPUT6, seq + 1, 0, 0, 0)];
+ const long block_begin = (long)block_indices_begins[GET_DATA_INDEX(INPUT8, seq, 0, 0, 0)];
+ const long block_end = (long)block_indices_begins[GET_DATA_INDEX(INPUT8, seq + 1, 0, 0, 0)];
+
+ if (token_begin < 0 || token_end < token_begin || (size_t)token_end > tokens)
+ return;
+ if (token_begin == token_end)
+ return;
+
+ if (block_begin < 0 || block_end <= block_begin || (size_t)block_end > block_indices_count) {
+ if (lane == 0) {
+ for (long token = token_begin; token < token_end; ++token) {
+ for (int p_offset = 0; p_offset < block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ if (p < head_dim)
+ output[GET_DATA_INDEX(OUTPUT, (size_t)token, h, p, 0)] = TO_OUTPUT_TYPE(0.0f);
+ }
+ }
+ }
+ return;
+ }
+
+ const long first_block = (long)block_indices[GET_DATA_INDEX(INPUT7, (size_t)block_begin, 0, 0, 0)];
+ if (first_block < 0 || (size_t)first_block >= num_state_blocks) {
+ if (lane == 0) {
+ for (long token = token_begin; token < token_end; ++token) {
+ for (int p_offset = 0; p_offset < block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ if (p < head_dim)
+ output[GET_DATA_INDEX(OUTPUT, (size_t)token, h, p, 0)] = TO_OUTPUT_TYPE(0.0f);
+ }
+ }
+ }
+ return;
+ }
+
+ const long processed_raw = (long)num_processed_tokens[GET_DATA_INDEX(INPUT9, seq, 0, 0, 0)];
+ const long interval = (long)cache_interval[GET_DATA_INDEX(INPUT10, seq, 0, 0, 0)];
+ const long processed = max(processed_raw, (long)0);
+ const bool cache_enabled = interval > 0;
+ const ulong positive_interval = cache_enabled ? (ulong)interval : 1;
+ const ulong previous_in_interval = cache_enabled ? (ulong)processed % positive_interval : 0;
+ ulong tokens_until_boundary = cache_enabled ? positive_interval - previous_in_interval : 0;
+ ulong write_slot = 1;
+ const size_t heads_per_group = num_heads / num_groups;
+ const size_t g = h / heads_per_group;
+ const float A_value = SSM_TO_FLOAT(A[GET_DATA_INDEX(INPUT0, h, 0, 0, 0)]);
+ // Keep recurrent state in FP32 across tokens; cast only when writing output.
+ __local float* local_state = work;
+ __local float* reduction = work + (size_t)block * state_size;
+ const int valid_head_dim_block = p_base + (size_t)block <= head_dim
+ ? block
+ : (int)(head_dim - p_base);
+
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ for (uint step = 0; step < state_iterations; ++step) {
+ const uint state_element = step * lws + lane;
+ if (state_element >= state_size)
+ break;
+ const size_t state_idx = GET_DATA_INDEX(INPUT5, (size_t)first_block, h, p, state_element);
+ local_state[(size_t)p_offset * state_size + state_element] = SSM_TO_FLOAT(recurrent_state_table[state_idx]);
+ }
+ }
+
+ for (long token = token_begin; token < token_end; ++token) {
+ const size_t token_idx = (size_t)token;
+#define SSM_TOKEN_INDEX token_idx
+#include "selective_ssm_recurrence.cl"
+#undef SSM_TOKEN_INDEX
+
+ if (cache_enabled) {
+ const bool at_boundary = --tokens_until_boundary == 0;
+ const bool at_sequence_end = token + 1 == token_end;
+ if (at_boundary || at_sequence_end) {
+ const ulong block_position = (ulong)block_begin + write_slot++;
+ if (block_position < (ulong)block_end && block_position < (ulong)block_indices_count) {
+ const long block_id = (long)block_indices[GET_DATA_INDEX(INPUT7, (size_t)block_position, 0, 0, 0)];
+ if (block_id >= 0 && (size_t)block_id < num_state_blocks) {
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ for (uint step = 0; step < state_iterations; ++step) {
+ const uint state_element = step * lws + lane;
+ if (state_element >= state_size)
+ break;
+ const size_t local_idx = (size_t)p_offset * state_size + state_element;
+ const size_t state_idx = GET_DATA_INDEX(INPUT5, (size_t)block_id, h, p, state_element);
+ recurrent_state_table[state_idx] = TO_INPUT5_TYPE(local_state[local_idx]);
+ }
+ }
+ }
+ }
+ if (at_boundary)
+ tokens_until_boundary = positive_interval;
+ }
+ }
+ }
+}
+
+#undef SSM_MAX_HEAD_DIM_BLOCK
+#undef SSM_TO_FLOAT
+#undef SSM_STATE_ITERATION_TYPE
+#undef SSM_DT_INDEX
+#undef SSM_B_INDEX
+#undef SSM_C_INDEX
+#undef SSM_X_INDEX
+#undef SSM_OUTPUT_INDEX
+#undef SSM_STATE_INDEX
+#undef SSM_STATE_AT
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm.cpp
new file mode 100644
index 00000000000..d5803056119
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm.cpp
@@ -0,0 +1,183 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "selective_ssm.hpp"
+
+#include <algorithm>
+
+#include "intel_gpu/primitives/selective_ssm.hpp"
+#include "primitive_ocl_base.hpp"
+#include "selective_ssm_utils.hpp"
+#include "utils/kernel_generator.hpp"
+
+namespace ov::intel_gpu::ocl {
+
+using cldnn::BufferDescriptor;
+using cldnn::primitive_impl;
+using cldnn::program_node;
+using cldnn::selective_ssm;
+
+namespace {
+
+class SelectiveSSMOptGenerator : public KernelGenerator {
+public:
+ SelectiveSSMOptGenerator() : KernelGenerator("selective_ssm_opt") {}
+
+protected:
+ [[nodiscard]] Arguments get_arguments_desc(const RuntimeParams& params) const override {
+ Arguments args;
+ if (params.is_dynamic())
+ args.push_back({ArgumentDescriptor::Types::SHAPE_INFO, 0});
+ for (uint32_t i = 0; i < params.input_layouts.size(); i++) {
+ args.push_back({ArgumentDescriptor::Types::INPUT, i});
+ }
+ for (uint32_t i = 0; i < params.output_layouts.size(); i++) {
+ args.push_back({ArgumentDescriptor::Types::OUTPUT, i});
+ }
+ args.push_back({ArgumentDescriptor::Types::SCALAR, 0});
+ args.push_back({ArgumentDescriptor::Types::SCALAR, 1});
+ args.push_back({ArgumentDescriptor::Types::LOCAL_MEMORY_SIZE, 0});
+ return args;
+ }
+
+ [[nodiscard]] DispatchDataFunc get_dispatch_data_func() const override {
+ return DispatchDataFunc{[](const RuntimeParams& params, KernelData& kd, ImplRuntimeParams*) {
+ auto& wgs = kd.params.workGroups;
+ if (params.is_dynamic()) {
+ wgs.global = {1, 1, 1};
+ wgs.local = {1, 1, 1};
+ selective_ssm_utils::set_dispatch_scalars(kd, 1, params.get_device_info());
+ kd.params.local_memory_args = {2 * sizeof(float)};
+ return;
+ }
+
+ const auto& x_shape = params.get_input_layout(3).get_partial_shape();
+ const auto& B_shape = params.get_input_layout(2).get_partial_shape();
+ const size_t batch = x_shape[0].get_length();
+ const size_t num_heads = x_shape[2].get_length();
+ const size_t head_dim = x_shape[3].get_length();
+ const size_t state_size = B_shape[3].get_length();
+ const size_t lws = selective_ssm_utils::get_lws(state_size, params.get_device_info());
+ if (selective_ssm_utils::requires_global_state(state_size, lws, params.get_device_info())) {
+ wgs.global = {1, 1, 1};
+ wgs.local = {1, 1, 1};
+ selective_ssm_utils::set_dispatch_scalars(kd, 1, params.get_device_info());
+ kd.params.local_memory_args = {sizeof(float)};
+ return;
+ }
+ const size_t head_dim_block = selective_ssm_utils::get_head_dim_block(head_dim, state_size, lws, params.get_device_info());
+ const size_t head_dim_groups = selective_ssm_utils::get_head_dim_groups(head_dim, head_dim_block);
+ const size_t local_bytes = head_dim_block * (state_size + lws) * sizeof(float);
+
+ wgs.global = {std::max<size_t>(head_dim_groups, 1) * lws, std::max<size_t>(num_heads, 1), std::max<size_t>(batch, 1)};
+ wgs.local = {lws, 1, 1};
+ selective_ssm_utils::set_dispatch_scalars(kd, head_dim_block, params.get_device_info());
+ kd.params.local_memory_args = {local_bytes};
+ }};
+ }
+};
+
+class SelectiveSSMLargeStateGenerator : public KernelGenerator {
+public:
+ SelectiveSSMLargeStateGenerator() : KernelGenerator("selective_ssm_large_state") {}
+
+protected:
+ [[nodiscard]] Arguments get_arguments_desc(const RuntimeParams& params) const override {
+ Arguments args;
+ if (params.is_dynamic())
+ args.push_back({ArgumentDescriptor::Types::SHAPE_INFO, 0});
+ for (uint32_t i = 0; i < params.input_layouts.size(); i++) {
+ args.push_back({ArgumentDescriptor::Types::INPUT, i});
+ }
+ for (uint32_t i = 0; i < params.output_layouts.size(); i++) {
+ args.push_back({ArgumentDescriptor::Types::OUTPUT, i});
+ }
+ args.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 0});
+ args.push_back({ArgumentDescriptor::Types::SCALAR, 0});
+ args.push_back({ArgumentDescriptor::Types::SCALAR, 1});
+ args.push_back({ArgumentDescriptor::Types::LOCAL_MEMORY_SIZE, 0});
+ return args;
+ }
+
+ [[nodiscard]] DispatchDataFunc get_dispatch_data_func() const override {
+ return DispatchDataFunc{[](const RuntimeParams& params, KernelData& kd, ImplRuntimeParams*) {
+ auto& wgs = kd.params.workGroups;
+ if (params.is_dynamic()) {
+ wgs.global = {1, 1, 1};
+ wgs.local = {1, 1, 1};
+ selective_ssm_utils::set_dispatch_scalars(kd, 1, params.get_device_info());
+ kd.params.local_memory_args = {sizeof(float)};
+ return;
+ }
+
+ const auto& x_shape = params.get_input_layout(3).get_partial_shape();
+ const auto& B_shape = params.get_input_layout(2).get_partial_shape();
+ const size_t batch = x_shape[0].get_length();
+ const size_t num_heads = x_shape[2].get_length();
+ const size_t head_dim = x_shape[3].get_length();
+ const size_t state_size = B_shape[3].get_length();
+ const size_t lws = selective_ssm_utils::get_lws(state_size, params.get_device_info());
+ const size_t head_dim_block = std::min(std::max<size_t>(head_dim, 1), selective_ssm_utils::max_head_dim_block);
+ const size_t head_dim_groups = selective_ssm_utils::get_head_dim_groups(head_dim, head_dim_block);
+
+ wgs.global = {std::max<size_t>(head_dim_groups, 1) * lws, std::max<size_t>(num_heads, 1), std::max<size_t>(batch, 1)};
+ wgs.local = {lws, 1, 1};
+ selective_ssm_utils::set_dispatch_scalars(kd, head_dim_block, params.get_device_info());
+ kd.params.local_memory_args = {head_dim_block * lws * sizeof(float)};
+ }};
+ }
+};
+
+class SelectiveSSMOptImpl : public PrimitiveImplOCL {
+public:
+ DECLARE_OBJECT_TYPE_SERIALIZATION(ov::intel_gpu::ocl::SelectiveSSMOptImpl)
+
+ Stage::Ptr selective_ssm = make_stage<SelectiveSSMOptGenerator>();
+ Stage::Ptr selective_ssm_large_state = make_stage<SelectiveSSMLargeStateGenerator>();
+
+ SelectiveSSMOptImpl() : PrimitiveImplOCL(SelectiveSSMOpt::get_type_info_static()) {}
+ SelectiveSSMOptImpl(const program_node&, const RuntimeParams& params) : SelectiveSSMOptImpl() {
+ add_stage(selective_ssm, params);
+ add_stage(selective_ssm_large_state, params);
+ }
+
+ [[nodiscard]] std::unique_ptr<primitive_impl> clone() const override {
+ return make_deep_copy<SelectiveSSMOptImpl>(this);
+ }
+
+ [[nodiscard]] std::vector<BufferDescriptor> get_internal_buffer_descs(const RuntimeParams& params) const override {
+ size_t state_scratch_elements = 1;
+ const auto& B_shape = params.get_input_layout(2).get_partial_shape();
+ const auto& state_layout = params.get_input_layout(5);
+ if (B_shape.is_static() && state_layout.is_static()) {
+ const size_t state_size = B_shape[3].get_length();
+ const size_t lws = selective_ssm_utils::get_lws(state_size, params.get_device_info());
+ if (selective_ssm_utils::requires_global_state(state_size, lws, params.get_device_info()))
+ state_scratch_elements = std::max<size_t>(state_layout.count(), 1);
+ }
+
+ return {BufferDescriptor{state_scratch_elements, ov::element::f32}};
+ }
+
+ [[nodiscard]] std::vector<size_t> get_stages_execution_order(const RuntimeParams& params) const override {
+ const auto& B_shape = params.get_input_layout(2).get_partial_shape();
+ if (!B_shape.is_static())
+ return {0};
+ const size_t state_size = B_shape[3].get_length();
+ const size_t lws = selective_ssm_utils::get_lws(state_size, params.get_device_info());
+ return {selective_ssm_utils::requires_global_state(state_size, lws, params.get_device_info()) ? 1ul : 0ul};
+ }
+};
+
+} // namespace
+
+std::unique_ptr<primitive_impl> SelectiveSSMOpt::create_impl(const program_node& node, const RuntimeParams& params) const {
+ assert(node.is_type<selective_ssm>());
+ return std::make_unique<SelectiveSSMOptImpl>(node, params);
+}
+
+} // namespace ov::intel_gpu::ocl
+
+BIND_BINARY_BUFFER_WITH_TYPE(cldnn::selective_ssm)
+BIND_BINARY_BUFFER_WITH_TYPE(ov::intel_gpu::ocl::SelectiveSSMOptImpl)
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm.hpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm.hpp
new file mode 100644
index 00000000000..6112c613a8b
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm.hpp
@@ -0,0 +1,55 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <array>
+#include <memory>
+#include <utility>
+
+#include "program_node.h"
+#include "registry/implementation_manager.hpp"
+#include "selective_ssm_inst.h"
+
+namespace ov::intel_gpu::ocl {
+
+struct SelectiveSSMOpt : public cldnn::ImplementationManager {
+ OV_GPU_PRIMITIVE_IMPL("ocl::selective_ssm::opt")
+ explicit SelectiveSSMOpt(cldnn::shape_types shape_type, cldnn::ValidateFunc vf = nullptr)
+ : cldnn::ImplementationManager(cldnn::impl_types::ocl, shape_type, std::move(vf)) {}
+
+ [[nodiscard]] std::unique_ptr<cldnn::primitive_impl> create_impl(const cldnn::program_node& node, const RuntimeParams& params) const override;
+
+ [[nodiscard]] bool validate_impl(const cldnn::program_node& node) const override {
+ assert(node.is_type<cldnn::selective_ssm>());
+ static constexpr std::array supported_fmts = {cldnn::format::bfyx};
+ static constexpr std::array supported_types = {ov::element::f16, ov::element::f32, ov::element::bf16};
+
+ ov::element::Type common_type = ov::element::dynamic;
+ for (size_t i = 0; i < node.get_dependencies().size(); i++) {
+ const auto& in_layout = node.get_input_layout(i);
+ if (!cldnn::one_of(in_layout.format, supported_fmts) || !cldnn::one_of(in_layout.data_type, supported_types)) {
+ return false;
+ }
+ if (common_type.is_dynamic()) {
+ common_type = in_layout.data_type;
+ } else if (common_type != in_layout.data_type) {
+ return false;
+ }
+ }
+
+ for (size_t i = 0; i < node.get_outputs_count(); i++) {
+ const auto& out_layout = node.get_output_layout(i);
+ if (!cldnn::one_of(out_layout.format, supported_fmts) || !cldnn::one_of(out_layout.data_type, supported_types)) {
+ return false;
+ }
+ if (!common_type.is_dynamic() && out_layout.data_type != common_type) {
+ return false;
+ }
+ }
+ return true;
+ }
+};
+
+} // namespace ov::intel_gpu::ocl
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_large_state.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_large_state.cl
new file mode 100644
index 00000000000..9025574fe15
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_large_state.cl
@@ -0,0 +1,117 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "include/batch_headers/common.cl"
+#include "include/batch_headers/fetch_data.cl"
+#include "include/batch_headers/bf16_utils.cl"
+
+#define SSM_MAX_HEAD_DIM_BLOCK 4
+#if INPUT0_IS_FP
+# define SSM_TO_FLOAT(v) convert_float(v)
+#else
+# define SSM_TO_FLOAT(v) _convert_as_bfloat16_float(v)
+#endif
+#define SSM_STATE_ITERATION_TYPE size_t
+#define SSM_DT_INDEX(token) GET_DATA_INDEX(INPUT1, b, token, h, 0)
+#define SSM_B_INDEX(token, state_element) GET_DATA_INDEX(INPUT2, b, token, g, state_element)
+#define SSM_C_INDEX(token, state_element) GET_DATA_INDEX(INPUT4, b, token, g, state_element)
+#define SSM_X_INDEX(token, p) GET_DATA_INDEX(INPUT3, b, token, h, p)
+#define SSM_OUTPUT_INDEX(token, p) GET_DATA_INDEX(OUTPUT, b, token, h, p)
+#define SSM_STATE_INDEX(p_offset, state_element) \
+ (((b * num_heads + h) * head_dim + p_base + (size_t)(p_offset)) * state_size + (state_element))
+#define SSM_STATE_AT(state_index) state_scratch[state_index]
+
+KERNEL(selective_ssm_large_state)(
+ OPTIONAL_SHAPE_INFO_ARG
+ const __global INPUT0_TYPE* A,
+ const __global INPUT1_TYPE* dt,
+ const __global INPUT2_TYPE* B,
+ const __global INPUT3_TYPE* x,
+ const __global INPUT4_TYPE* C,
+ const __global INPUT5_TYPE* initial_state,
+ __global OUTPUT_TYPE* output,
+ __global OUTPUT1_TYPE* output_state,
+ __global float* state_scratch,
+ int head_dim_block,
+ uint use_subgroup_reduction,
+ __local float* reduction) {
+ const uint lane = get_local_id(0);
+ const uint lws = get_local_size(0);
+ const uint subgroup_lane = get_sub_group_local_id();
+ const uint subgroup_id = get_sub_group_id();
+ const uint subgroup_count = get_num_sub_groups();
+ const size_t h = get_global_id(1);
+ const size_t b = get_global_id(2);
+
+ const size_t batch = INPUT3_BATCH_NUM;
+ const size_t seq_len = INPUT3_FEATURE_NUM;
+ const size_t num_heads = INPUT3_SIZE_Y;
+ const size_t head_dim = INPUT3_SIZE_X;
+ const size_t num_groups = INPUT2_SIZE_Y;
+ const size_t state_size = INPUT2_SIZE_X;
+ const int block = head_dim_block;
+ const size_t state_iterations = state_size / lws + (size_t)(state_size % lws != 0);
+ const size_t p_base = get_group_id(0) * (size_t)block;
+
+ if (INPUT0_BATCH_NUM != num_heads ||
+ INPUT1_BATCH_NUM != batch || INPUT1_FEATURE_NUM != seq_len || INPUT1_SIZE_Y != num_heads ||
+ INPUT2_BATCH_NUM != batch || INPUT2_FEATURE_NUM != seq_len ||
+ INPUT4_BATCH_NUM != batch || INPUT4_FEATURE_NUM != seq_len ||
+ INPUT4_SIZE_Y != num_groups || INPUT4_SIZE_X != state_size ||
+ INPUT5_BATCH_NUM != batch || INPUT5_FEATURE_NUM != num_heads ||
+ INPUT5_SIZE_Y != head_dim || INPUT5_SIZE_X != state_size)
+ return;
+
+ if (b >= batch || h >= num_heads || p_base >= head_dim || num_groups == 0 ||
+ num_heads % num_groups != 0 || block <= 0 || block > SSM_MAX_HEAD_DIM_BLOCK)
+ return;
+
+ const size_t heads_per_group = num_heads / num_groups;
+ const size_t g = h / heads_per_group;
+ const float A_value = SSM_TO_FLOAT(A[GET_DATA_INDEX(INPUT0, h, 0, 0, 0)]);
+ const int valid_head_dim_block = p_base + (size_t)block <= head_dim
+ ? block
+ : (int)(head_dim - p_base);
+
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ const size_t scratch_base = ((b * num_heads + h) * head_dim + p) * state_size;
+ for (size_t step = 0; step < state_iterations; ++step) {
+ const size_t state_element = step * lws + lane;
+ if (state_element >= state_size)
+ break;
+ state_scratch[scratch_base + state_element] =
+ SSM_TO_FLOAT(initial_state[GET_DATA_INDEX(INPUT5, b, h, p, state_element)]);
+ }
+ }
+
+ for (size_t t = 0; t < seq_len; ++t) {
+#define SSM_TOKEN_INDEX t
+#include "selective_ssm_recurrence.cl"
+#undef SSM_TOKEN_INDEX
+ }
+
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ const size_t scratch_base = ((b * num_heads + h) * head_dim + p) * state_size;
+ for (size_t step = 0; step < state_iterations; ++step) {
+ const size_t state_element = step * lws + lane;
+ if (state_element >= state_size)
+ break;
+ output_state[GET_DATA_INDEX(OUTPUT1, b, h, p, state_element)] =
+ TO_OUTPUT1_TYPE(state_scratch[scratch_base + state_element]);
+ }
+ }
+}
+
+#undef SSM_MAX_HEAD_DIM_BLOCK
+#undef SSM_TO_FLOAT
+#undef SSM_STATE_ITERATION_TYPE
+#undef SSM_DT_INDEX
+#undef SSM_B_INDEX
+#undef SSM_C_INDEX
+#undef SSM_X_INDEX
+#undef SSM_OUTPUT_INDEX
+#undef SSM_STATE_INDEX
+#undef SSM_STATE_AT
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_opt.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_opt.cl
new file mode 100644
index 00000000000..fc522c1bc21
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_opt.cl
@@ -0,0 +1,119 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "include/batch_headers/common.cl"
+#include "include/batch_headers/fetch_data.cl"
+#include "include/batch_headers/bf16_utils.cl"
+
+#define SSM_MAX_HEAD_DIM_BLOCK 4
+#if INPUT0_IS_FP
+# define SSM_TO_FLOAT(v) convert_float(v)
+#else
+# define SSM_TO_FLOAT(v) _convert_as_bfloat16_float(v)
+#endif
+#define SSM_STATE_ITERATION_TYPE uint
+#define SSM_DT_INDEX(token) GET_DATA_INDEX(INPUT1, b, token, h, 0)
+#define SSM_B_INDEX(token, state_element) GET_DATA_INDEX(INPUT2, b, token, g, state_element)
+#define SSM_C_INDEX(token, state_element) GET_DATA_INDEX(INPUT4, b, token, g, state_element)
+#define SSM_X_INDEX(token, p) GET_DATA_INDEX(INPUT3, b, token, h, p)
+#define SSM_OUTPUT_INDEX(token, p) GET_DATA_INDEX(OUTPUT, b, token, h, p)
+#define SSM_STATE_INDEX(p_offset, state_element) ((size_t)(p_offset) * state_size + (state_element))
+#define SSM_STATE_AT(state_index) local_state[state_index]
+
+KERNEL(selective_ssm_opt)(
+ OPTIONAL_SHAPE_INFO_ARG
+ const __global INPUT0_TYPE* A,
+ const __global INPUT1_TYPE* dt,
+ const __global INPUT2_TYPE* B,
+ const __global INPUT3_TYPE* x,
+ const __global INPUT4_TYPE* C,
+ const __global INPUT5_TYPE* initial_state,
+ __global OUTPUT_TYPE* output,
+ __global OUTPUT1_TYPE* output_state,
+ int head_dim_block,
+ uint use_subgroup_reduction,
+ __local float* work) {
+ const uint lane = get_local_id(0);
+ const uint runtime_lws = get_local_size(0);
+ const uint subgroup_lane = get_sub_group_local_id();
+ const uint subgroup_id = get_sub_group_id();
+ const uint subgroup_count = get_num_sub_groups();
+ const size_t h = get_global_id(1);
+ const size_t b = get_global_id(2);
+
+ const size_t batch = INPUT3_BATCH_NUM;
+ const size_t seq_len = INPUT3_FEATURE_NUM;
+ const size_t num_heads = INPUT3_SIZE_Y;
+ const size_t head_dim = INPUT3_SIZE_X;
+ const size_t num_groups = INPUT2_SIZE_Y;
+ const size_t state_size = INPUT2_SIZE_X;
+ const uint lws = runtime_lws;
+ const int block = head_dim_block;
+ // This kernel is selected only when the full state fits in local memory,
+ // so both the iteration count and state element index fit in uint.
+ const uint state_iterations = (uint)(state_size / lws + (size_t)(state_size % lws != 0));
+ const size_t p_base = get_group_id(0) * (size_t)block;
+
+ if (INPUT0_BATCH_NUM != num_heads ||
+ INPUT1_BATCH_NUM != batch || INPUT1_FEATURE_NUM != seq_len || INPUT1_SIZE_Y != num_heads ||
+ INPUT2_BATCH_NUM != batch || INPUT2_FEATURE_NUM != seq_len ||
+ INPUT4_BATCH_NUM != batch || INPUT4_FEATURE_NUM != seq_len ||
+ INPUT4_SIZE_Y != num_groups || INPUT4_SIZE_X != state_size ||
+ INPUT5_BATCH_NUM != batch || INPUT5_FEATURE_NUM != num_heads ||
+ INPUT5_SIZE_Y != head_dim || INPUT5_SIZE_X != state_size)
+ return;
+
+ if (b >= batch || h >= num_heads || p_base >= head_dim || num_groups == 0 ||
+ num_heads % num_groups != 0 || block <= 0 || block > SSM_MAX_HEAD_DIM_BLOCK)
+ return;
+
+ const size_t heads_per_group = num_heads / num_groups;
+ const size_t g = h / heads_per_group;
+ const float A_value = SSM_TO_FLOAT(A[GET_DATA_INDEX(INPUT0, h, 0, 0, 0)]);
+ // Keep recurrent state in FP32 across tokens; cast only when writing output.
+ __local float* local_state = work;
+ __local float* reduction = work + (size_t)block * state_size;
+ const int valid_head_dim_block = p_base + (size_t)block <= head_dim
+ ? block
+ : (int)(head_dim - p_base);
+
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ for (uint step = 0; step < state_iterations; ++step) {
+ const uint state_element = step * lws + lane;
+ if (state_element >= state_size)
+ break;
+ const size_t state_idx = GET_DATA_INDEX(INPUT5, b, h, p, state_element);
+ local_state[(size_t)p_offset * state_size + state_element] = SSM_TO_FLOAT(initial_state[state_idx]);
+ }
+ }
+
+ for (size_t t = 0; t < seq_len; ++t) {
+#define SSM_TOKEN_INDEX t
+#include "selective_ssm_recurrence.cl"
+#undef SSM_TOKEN_INDEX
+ }
+
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ for (uint step = 0; step < state_iterations; ++step) {
+ const uint state_element = step * lws + lane;
+ if (state_element >= state_size)
+ break;
+ const size_t local_idx = (size_t)p_offset * state_size + state_element;
+ output_state[GET_DATA_INDEX(OUTPUT1, b, h, p, state_element)] = TO_OUTPUT1_TYPE(local_state[local_idx]);
+ }
+ }
+}
+
+#undef SSM_MAX_HEAD_DIM_BLOCK
+#undef SSM_TO_FLOAT
+#undef SSM_STATE_ITERATION_TYPE
+#undef SSM_DT_INDEX
+#undef SSM_B_INDEX
+#undef SSM_C_INDEX
+#undef SSM_X_INDEX
+#undef SSM_OUTPUT_INDEX
+#undef SSM_STATE_INDEX
+#undef SSM_STATE_AT
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_recurrence.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_recurrence.cl
new file mode 100644
index 00000000000..8c4a49d0a04
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_recurrence.cl
@@ -0,0 +1,78 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+// The including kernel provides the layout-specific SSM_*_INDEX macros,
+// SSM_TOKEN_INDEX, and the state accessors. This file is included directly
+// inside the token loop to preserve the compiler-visible recurrence body.
+const size_t dt_idx = SSM_DT_INDEX(SSM_TOKEN_INDEX);
+const float dt_value = SSM_TO_FLOAT(dt[dt_idx]);
+const float dA = exp(A_value * dt_value);
+float input_scales[SSM_MAX_HEAD_DIM_BLOCK];
+float partial[SSM_MAX_HEAD_DIM_BLOCK];
+
+for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ input_scales[p_offset] = SSM_TO_FLOAT(x[SSM_X_INDEX(SSM_TOKEN_INDEX, p)]) * dt_value;
+ partial[p_offset] = 0.0f;
+}
+
+for (SSM_STATE_ITERATION_TYPE step = 0; step < state_iterations; ++step) {
+ const SSM_STATE_ITERATION_TYPE state_element = step * lws + lane;
+ if (state_element >= state_size)
+ break;
+ const size_t b_idx = SSM_B_INDEX(SSM_TOKEN_INDEX, state_element);
+ const size_t c_idx = SSM_C_INDEX(SSM_TOKEN_INDEX, state_element);
+ const float b_value = SSM_TO_FLOAT(B[b_idx]);
+ const float c_value = SSM_TO_FLOAT(C[c_idx]);
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t recurrence_state_idx = SSM_STATE_INDEX(p_offset, state_element);
+ const float new_state = fma(SSM_STATE_AT(recurrence_state_idx), dA, input_scales[p_offset] * b_value);
+ SSM_STATE_AT(recurrence_state_idx) = new_state;
+ partial[p_offset] = fma(new_state, c_value, partial[p_offset]);
+ }
+}
+
+if (use_subgroup_reduction) {
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const float subgroup_sum = sub_group_reduce_add(partial[p_offset]);
+ if (subgroup_lane == 0)
+ reduction[(size_t)p_offset * lws + subgroup_id] = subgroup_sum;
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+
+ if (subgroup_id == 0) {
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ float total = subgroup_lane < subgroup_count
+ ? reduction[(size_t)p_offset * lws + subgroup_lane]
+ : 0.0f;
+ total = sub_group_reduce_add(total);
+ const size_t p = p_base + (size_t)p_offset;
+ if (subgroup_lane == 0)
+ output[SSM_OUTPUT_INDEX(SSM_TOKEN_INDEX, p)] = TO_OUTPUT_TYPE(total);
+ }
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+} else {
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset)
+ reduction[(size_t)p_offset * lws + lane] = partial[p_offset];
+ barrier(CLK_LOCAL_MEM_FENCE);
+
+ for (uint offset = lws / 2; offset > 0; offset /= 2) {
+ if (lane < offset) {
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t reduction_idx = (size_t)p_offset * lws + lane;
+ reduction[reduction_idx] += reduction[reduction_idx + offset];
+ }
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+
+ if (lane == 0) {
+ for (int p_offset = 0; p_offset < valid_head_dim_block; ++p_offset) {
+ const size_t p = p_base + (size_t)p_offset;
+ output[SSM_OUTPUT_INDEX(SSM_TOKEN_INDEX, p)] = TO_OUTPUT_TYPE(reduction[(size_t)p_offset * lws]);
+ }
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+}
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_utils.hpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_utils.hpp
new file mode 100644
index 00000000000..9f360fcd628
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/selective_ssm_utils.hpp
@@ -0,0 +1,61 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
+#include <limits>
+
+#include "common_utils/kernel_generator_base.hpp"
+#include "intel_gpu/runtime/device_info.hpp"
+#include "intel_gpu/runtime/utils.hpp"
+
+namespace ov::intel_gpu::ocl::selective_ssm_utils {
+
+inline constexpr size_t max_head_dim_block = 4;
+
+inline size_t get_lws(const size_t state_size, const cldnn::device_info& info) {
+ const size_t limit = std::min<size_t>(32, info.max_work_group_size);
+ const size_t target = std::min(std::max<size_t>(state_size, 1), limit);
+ size_t lws = 1;
+ while (lws * 2 <= target)
+ lws *= 2;
+ return lws;
+}
+
+inline bool requires_global_state(const size_t state_size, const size_t lws, const cldnn::device_info& info) {
+ const size_t local_capacity = info.max_local_mem_size / sizeof(float);
+ return state_size > std::numeric_limits<uint32_t>::max() || state_size > local_capacity || lws > local_capacity - state_size;
+}
+
+inline size_t get_head_dim_block(const size_t head_dim, const size_t state_size, const size_t lws, const cldnn::device_info& info) {
+ const size_t local_capacity = info.max_local_mem_size / sizeof(float);
+ const size_t state_and_reduction = state_size + lws;
+ size_t block = std::min(std::max<size_t>(head_dim, 1), max_head_dim_block);
+ while (block > 1 && state_and_reduction > local_capacity / block)
+ --block;
+ return block;
+}
+
+inline size_t get_head_dim_groups(const size_t head_dim, const size_t head_dim_block) {
+ return cldnn::ceil_div(head_dim, head_dim_block);
+}
+
+inline void set_dispatch_scalars(KernelData& kd, const size_t block, const cldnn::device_info& info) {
+ kd.params.scalars.clear();
+ cldnn::scalar_desc block_desc;
+ block_desc.t = cldnn::scalar_desc::Types::INT32;
+ block_desc.v.s32 = static_cast<int32_t>(block);
+ kd.params.scalars.push_back(block_desc);
+
+ const bool use_subgroup_reduction = info.dev_type == cldnn::device_type::integrated_gpu || info.gfx_ver.major >= 20;
+ cldnn::scalar_desc reduction_desc;
+ reduction_desc.t = cldnn::scalar_desc::Types::UINT32;
+ reduction_desc.v.u32 = use_subgroup_reduction ? 1 : 0;
+ kd.params.scalars.push_back(reduction_desc);
+}
+
+} // namespace ov::intel_gpu::ocl::selective_ssm_utils
diff --git a/src/plugins/intel_gpu/src/graph/include/paged_selective_ssm_inst.h b/src/plugins/intel_gpu/src/graph/include/paged_selective_ssm_inst.h
new file mode 100644
index 00000000000..9f4e4f5ba39
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/include/paged_selective_ssm_inst.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "intel_gpu/primitives/paged_selective_ssm.hpp"
+#include "primitive_inst.h"
+
+namespace cldnn {
+
+template <>
+struct typed_program_node<paged_selective_ssm> : public typed_program_node_base<paged_selective_ssm> {
+ using parent = typed_program_node_base<paged_selective_ssm>;
+
+public:
+ using parent::parent;
+
+ program_node& input(size_t index = 0) const {
+ return get_dependency(index);
+ }
+ std::vector<size_t> get_shape_infer_dependencies() const override {
+ return {};
+ }
+};
+using paged_selective_ssm_node = typed_program_node<paged_selective_ssm>;
+
+template <>
+class typed_primitive_inst<paged_selective_ssm> : public typed_primitive_inst_base<paged_selective_ssm> {
+ using parent = typed_primitive_inst_base<paged_selective_ssm>;
+ using parent::parent;
+
+public:
+ template <typename ShapeType>
+ static std::vector<layout> calc_output_layouts(const paged_selective_ssm_node& node, const kernel_impl_params& impl_params);
+ static layout calc_output_layout(const paged_selective_ssm_node& node, const kernel_impl_params& impl_params);
+
+ static std::string to_string(const paged_selective_ssm_node& node);
+ typed_primitive_inst(network& network, const paged_selective_ssm_node& node);
+};
+
+using paged_selective_ssm_inst = typed_primitive_inst<paged_selective_ssm>;
+
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/include/selective_ssm_inst.h b/src/plugins/intel_gpu/src/graph/include/selective_ssm_inst.h
new file mode 100644
index 00000000000..d589592ab9a
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/include/selective_ssm_inst.h
@@ -0,0 +1,52 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "intel_gpu/primitives/selective_ssm.hpp"
+#include "primitive_inst.h"
+
+namespace cldnn {
+
+template <>
+struct typed_program_node<selective_ssm> : public typed_program_node_base<selective_ssm> {
+ using parent = typed_program_node_base<selective_ssm>;
+
+public:
+ using parent::parent;
+
+ program_node& input(size_t index = 0) const {
+ return get_dependency(index);
+ }
+ std::vector<size_t> get_shape_infer_dependencies() const override {
+ return {};
+ }
+};
+using selective_ssm_node = typed_program_node<selective_ssm>;
+
+template <>
+class typed_primitive_inst<selective_ssm> : public typed_primitive_inst_base<selective_ssm> {
+ using parent = typed_primitive_inst_base<selective_ssm>;
+ using parent::parent;
+
+public:
+ template <typename ShapeType>
+ static std::vector<layout> calc_output_layouts(const selective_ssm_node& node, const kernel_impl_params& impl_params);
+ static layout calc_output_layout(const selective_ssm_node& node, const kernel_impl_params& impl_params);
+
+ static std::string to_string(const selective_ssm_node& node);
+
+private:
+ void on_execute() override;
+ void update_shape() override;
+ void update_empty_sequence_output();
+
+ memory::ptr _state_output_memory;
+ size_t _state_output_max_layout_count = 0;
+ bool _state_output_aliased = false;
+};
+
+using selective_ssm_inst = typed_primitive_inst<selective_ssm>;
+
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/paged_selective_ssm.cpp b/src/plugins/intel_gpu/src/graph/paged_selective_ssm.cpp
new file mode 100644
index 00000000000..2960b76e017
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/paged_selective_ssm.cpp
@@ -0,0 +1,66 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/op/paged_selective_ssm.hpp"
+
+#include <string>
+#include <vector>
+
+#include "json_object.h"
+#include "paged_selective_ssm_inst.h"
+#include "paged_selective_ssm_shape_inference.hpp"
+#include "primitive_type_base.h"
+#include "to_string_utils.h"
+
+namespace cldnn {
+GPU_DEFINE_PRIMITIVE_TYPE_ID(paged_selective_ssm)
+
+layout paged_selective_ssm_inst::calc_output_layout(const paged_selective_ssm_node& node, const kernel_impl_params& impl_param) {
+ return calc_output_layouts<ov::PartialShape>(node, impl_param)[0];
+}
+
+template <typename ShapeType>
+std::vector<layout> paged_selective_ssm_inst::calc_output_layouts(const paged_selective_ssm_node& node, const kernel_impl_params& impl_param) {
+ const auto& all_inputs = node.get_input_layouts();
+ OPENVINO_ASSERT(all_inputs.size() == 11, "paged_selective_ssm must have 11 inputs");
+
+ std::vector<ShapeType> input_shapes;
+ input_shapes.reserve(all_inputs.size());
+ for (size_t i = 0; i < all_inputs.size(); i++) {
+ input_shapes.push_back(impl_param.get_input_layout(i).get<ShapeType>());
+ }
+
+ ov::op::internal::PagedSelectiveSSM op;
+ const auto output_shapes = ov::op::internal::shape_infer(&op, input_shapes);
+ const auto x_layout = impl_param.get_input_layout(3);
+ return {layout(output_shapes[0], x_layout.data_type, x_layout.format)};
+}
+
+template std::vector<layout> paged_selective_ssm_inst::calc_output_layouts<ov::PartialShape>(const paged_selective_ssm_node& node,
+ const kernel_impl_params& impl_param);
+
+std::string paged_selective_ssm_inst::to_string(const paged_selective_ssm_node& node) {
+ auto node_info = node.desc_to_json();
+
+ std::stringstream primitive_description;
+ json_composite pssm_info;
+ pssm_info.add("A", node.input(0).id());
+ pssm_info.add("dt", node.input(1).id());
+ pssm_info.add("B", node.input(2).id());
+ pssm_info.add("x", node.input(3).id());
+ pssm_info.add("C", node.input(4).id());
+ pssm_info.add("recurrent_state_table", node.input(5).id());
+ pssm_info.add("subsequence_begins", node.input(6).id());
+ pssm_info.add("block_indices", node.input(7).id());
+ pssm_info.add("block_indices_begins", node.input(8).id());
+ pssm_info.add("num_processed_tokens", node.input(9).id());
+ pssm_info.add("cache_interval", node.input(10).id());
+ node_info->add("paged_selective_ssm_info", pssm_info);
+ node_info->dump(primitive_description);
+ return primitive_description.str();
+}
+
+paged_selective_ssm_inst::typed_primitive_inst(network& network, const paged_selective_ssm_node& node) : parent(network, node) {}
+
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/registry/paged_selective_ssm_impls.cpp b/src/plugins/intel_gpu/src/graph/registry/paged_selective_ssm_impls.cpp
new file mode 100644
index 00000000000..25d0063d2df
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/registry/paged_selective_ssm_impls.cpp
@@ -0,0 +1,27 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "intel_gpu/primitives/paged_selective_ssm.hpp"
+#include "primitive_inst.h"
+#include "registry.hpp"
+
+#if OV_GPU_WITH_OCL
+# include "impls/ocl_v2/paged_selective_ssm.hpp"
+#endif
+
+namespace ov::intel_gpu {
+
+using namespace cldnn;
+
+const std::vector<std::shared_ptr<cldnn::ImplementationManager>>& Registry<paged_selective_ssm>::get_implementations() {
+ static const std::vector<std::shared_ptr<ImplementationManager>> impls = {
+#if OV_GPU_WITH_OCL
+ OV_GPU_CREATE_INSTANCE_OCL(ocl::PagedSelectiveSSMOpt, shape_types::any)
+#endif
+ };
+
+ return impls;
+}
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/graph/registry/registry.hpp b/src/plugins/intel_gpu/src/graph/registry/registry.hpp
index 73361ed6c07..f0f5cd66daa 100644
--- a/src/plugins/intel_gpu/src/graph/registry/registry.hpp
+++ b/src/plugins/intel_gpu/src/graph/registry/registry.hpp
@@ -153,6 +153,7 @@ REGISTER_IMPLS(gated_mlp);
REGISTER_IMPLS(gather);
REGISTER_IMPLS(gather_nd);
REGISTER_IMPLS(gated_delta_net);
+REGISTER_IMPLS(selective_ssm);
REGISTER_IMPLS(gemm);
REGISTER_IMPLS(group_normalization);
REGISTER_IMPLS(loop);
@@ -163,6 +164,7 @@ REGISTER_IMPLS(gru_seq);
REGISTER_IMPLS(non_max_suppression);
REGISTER_IMPLS(paged_attention);
REGISTER_IMPLS(paged_gated_delta_net);
+REGISTER_IMPLS(paged_selective_ssm);
REGISTER_IMPLS(pa_kv_reorder);
REGISTER_IMPLS(paged_causal_conv1d);
REGISTER_IMPLS(pooling);
diff --git a/src/plugins/intel_gpu/src/graph/registry/selective_ssm_impls.cpp b/src/plugins/intel_gpu/src/graph/registry/selective_ssm_impls.cpp
new file mode 100644
index 00000000000..ef1cd39444e
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/registry/selective_ssm_impls.cpp
@@ -0,0 +1,27 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "intel_gpu/primitives/selective_ssm.hpp"
+#include "primitive_inst.h"
+#include "registry.hpp"
+
+#if OV_GPU_WITH_OCL
+# include "impls/ocl_v2/selective_ssm.hpp"
+#endif
+
+namespace ov::intel_gpu {
+
+using namespace cldnn;
+
+const std::vector<std::shared_ptr<cldnn::ImplementationManager>>& Registry<selective_ssm>::get_implementations() {
+ static const std::vector<std::shared_ptr<ImplementationManager>> impls = {
+#if OV_GPU_WITH_OCL
+ OV_GPU_CREATE_INSTANCE_OCL(ocl::SelectiveSSMOpt, shape_types::any)
+#endif
+ };
+
+ return impls;
+}
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/graph/selective_ssm.cpp b/src/plugins/intel_gpu/src/graph/selective_ssm.cpp
new file mode 100644
index 00000000000..8e0be758f88
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/selective_ssm.cpp
@@ -0,0 +1,119 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/op/selective_ssm.hpp"
+
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "json_object.h"
+#include "primitive_type_base.h"
+#include "selective_ssm_inst.h"
+#include "selective_ssm_shape_inference.hpp"
+#include "to_string_utils.h"
+
+namespace cldnn {
+GPU_DEFINE_PRIMITIVE_TYPE_ID(selective_ssm)
+
+layout selective_ssm_inst::calc_output_layout(const selective_ssm_node& node, const kernel_impl_params& impl_param) {
+ return calc_output_layouts<ov::PartialShape>(node, impl_param)[0];
+}
+
+template <typename ShapeType>
+std::vector<layout> selective_ssm_inst::calc_output_layouts(const selective_ssm_node& node, const kernel_impl_params& impl_param) {
+ const auto& desc = impl_param.typed_desc<selective_ssm>();
+ const auto& all_inputs = node.get_input_layouts();
+ OPENVINO_ASSERT(all_inputs.size() == 6, "selective_ssm must have 6 inputs");
+
+ ov::op::internal::SelectiveSSM op;
+ std::vector<ShapeType> input_shapes;
+ input_shapes.reserve(all_inputs.size());
+ for (size_t i = 0; i < all_inputs.size(); i++) {
+ input_shapes.push_back(impl_param.get_input_layout(i).get<ShapeType>());
+ }
+ const auto output_shapes = ov::op::internal::shape_infer(&op, input_shapes);
+
+ const auto x_layout = impl_param.get_input_layout(3);
+ const auto state_layout = impl_param.get_input_layout(5);
+ std::vector<layout> output_layouts;
+ output_layouts.emplace_back(output_shapes[0], x_layout.data_type, x_layout.format);
+ if (desc->output_size() == 2) {
+ output_layouts.emplace_back(output_shapes[1], state_layout.data_type, state_layout.format);
+ }
+ return output_layouts;
+}
+
+template std::vector<layout> selective_ssm_inst::calc_output_layouts<ov::PartialShape>(const selective_ssm_node& node, const kernel_impl_params& impl_param);
+
+std::string selective_ssm_inst::to_string(const selective_ssm_node& node) {
+ auto node_info = node.desc_to_json();
+
+ std::stringstream primitive_description;
+ json_composite ssm_info;
+ ssm_info.add("A", node.input(0).id());
+ ssm_info.add("dt", node.input(1).id());
+ ssm_info.add("B", node.input(2).id());
+ ssm_info.add("x", node.input(3).id());
+ ssm_info.add("C", node.input(4).id());
+ ssm_info.add("recurrent_state", node.input(5).id());
+ node_info->add("selective_ssm_info", ssm_info);
+ node_info->dump(primitive_description);
+ return primitive_description.str();
+}
+
+void selective_ssm_inst::update_shape() {
+ parent::update_shape();
+ update_empty_sequence_output();
+}
+
+void selective_ssm_inst::on_execute() {
+ update_empty_sequence_output();
+}
+
+void selective_ssm_inst::update_empty_sequence_output() {
+ OPENVINO_ASSERT(_outputs.size() == 2, "selective_ssm must have 2 outputs");
+ const auto& sequence_output_layout = get_output_layout(0);
+ const bool empty_sequence = sequence_output_layout.is_static() && sequence_output_layout.count() == 0;
+
+ if (!empty_sequence) {
+ if (_state_output_aliased) {
+ _outputs[1] = std::move(_state_output_memory);
+ _max_output_layout_count[1] = _state_output_max_layout_count;
+ _state_output_max_layout_count = 0;
+ _state_output_aliased = false;
+ set_flag(ExecutionFlags::MEMORY_CHANGED);
+ }
+ return;
+ }
+
+ build_deps();
+ const auto state_input = input_memory_ptr(5);
+ OPENVINO_ASSERT(state_input != nullptr, "selective_ssm recurrent state input is not allocated");
+
+ // Dynamic zero-sized outputs are not allocated by the generic path. Keep a zero-sized view backed
+ // by a dummy allocation so optimized users of output 1 can observe that all outputs are available.
+ if (!_outputs[0]) {
+ auto dummy = _network.get_engine().allocate_memory(layout{{1}, data_types::u8, format::bfyx});
+ _outputs[0] = _network.get_engine().reinterpret_buffer(*dummy, sequence_output_layout);
+ _max_output_layout_count[0] = 0;
+ set_flag(ExecutionFlags::MEMORY_CHANGED);
+ }
+
+ if (!_state_output_aliased) {
+ _state_output_memory = _outputs[1];
+ _state_output_max_layout_count = _max_output_layout_count[1];
+ _state_output_aliased = true;
+ }
+
+ if (!_outputs[1] || !_network.get_engine().is_the_same_buffer(*_outputs[1], *state_input)) {
+ _outputs[1] = state_input;
+ _max_output_layout_count[1] = state_input->get_layout().get_linear_size();
+ set_flag(ExecutionFlags::MEMORY_CHANGED);
+ }
+
+ set_flag(ExecutionFlags::SKIP);
+}
+
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/plugin/graph.cpp b/src/plugins/intel_gpu/src/plugin/graph.cpp
index 6584c69ac6b..c727ff8f154 100644
--- a/src/plugins/intel_gpu/src/plugin/graph.cpp
+++ b/src/plugins/intel_gpu/src/plugin/graph.cpp
@@ -288,6 +288,7 @@ std::shared_ptr<ov::Model> Graph::get_runtime_model(std::vector<cldnn::primitive
{ "fully_connected", "FullyConnected" },
{ "gated_delta_net", "GatedDeltaNet" },
{ "paged_causal_conv1d", "PagedCausalConv1D" },
+ { "paged_selective_ssm", "PagedSelectiveSSM" },
{ "gather", "Gather" },
{ "gemm", "Gemm" },
{ "gru_seq", "GRU_Seq" },
@@ -310,6 +311,7 @@ std::shared_ptr<ov::Model> Graph::get_runtime_model(std::vector<cldnn::primitive
{ "reverse_sequence", "ReverseSequence" },
{ "roi_pooling", "ROIPooling" },
{ "scale", "ScaleShift" },
+ { "selective_ssm", "SelectiveSSM" },
{ "shuffle_channels", "ShuffleChannels" },
{ "softmax", "SoftMax" },
{ "strided_slice", "StridedSlice" },
diff --git a/src/plugins/intel_gpu/src/plugin/ops/paged_selective_ssm.cpp b/src/plugins/intel_gpu/src/plugin/ops/paged_selective_ssm.cpp
new file mode 100644
index 00000000000..e064a896219
--- /dev/null
+++ b/src/plugins/intel_gpu/src/plugin/ops/paged_selective_ssm.cpp
@@ -0,0 +1,26 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/op/paged_selective_ssm.hpp"
+
+#include <intel_gpu/primitives/paged_selective_ssm.hpp>
+
+#include "intel_gpu/plugin/common_utils.hpp"
+#include "intel_gpu/plugin/program_builder.hpp"
+
+namespace ov::intel_gpu {
+
+static void CreatePagedSelectiveSSMOp(ProgramBuilder& p, const std::shared_ptr<ov::op::internal::PagedSelectiveSSM>& op) {
+ validate_inputs_count(op, {11});
+ auto inputs = p.GetInputInfo(op);
+
+ const std::string layer_name = layer_type_name_ID(op);
+ cldnn::paged_selective_ssm prim(layer_name, inputs);
+ prim.num_outputs = 1;
+ p.add_primitive(*op, prim);
+}
+
+REGISTER_FACTORY_IMPL(internal, PagedSelectiveSSM);
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/plugin/ops/selective_ssm.cpp b/src/plugins/intel_gpu/src/plugin/ops/selective_ssm.cpp
new file mode 100644
index 00000000000..338a1efa030
--- /dev/null
+++ b/src/plugins/intel_gpu/src/plugin/ops/selective_ssm.cpp
@@ -0,0 +1,26 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/op/selective_ssm.hpp"
+
+#include <intel_gpu/primitives/selective_ssm.hpp>
+
+#include "intel_gpu/plugin/common_utils.hpp"
+#include "intel_gpu/plugin/program_builder.hpp"
+
+namespace ov::intel_gpu {
+
+static void CreateSelectiveSSMOp(ProgramBuilder& p, const std::shared_ptr<ov::op::internal::SelectiveSSM>& op) {
+ validate_inputs_count(op, {6});
+ auto inputs = p.GetInputInfo(op);
+
+ const std::string layer_name = layer_type_name_ID(op);
+ cldnn::selective_ssm prim(layer_name, inputs);
+ prim.num_outputs = op->get_output_size();
+ p.add_primitive(*op, prim);
+}
+
+REGISTER_FACTORY_IMPL(internal, SelectiveSSM);
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/preserve_selective_ssm_precision.cpp b/src/plugins/intel_gpu/src/plugin/transformations/preserve_selective_ssm_precision.cpp
new file mode 100644
index 00000000000..d0e3268a5fb
--- /dev/null
+++ b/src/plugins/intel_gpu/src/plugin/transformations/preserve_selective_ssm_precision.cpp
@@ -0,0 +1,86 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "preserve_selective_ssm_precision.hpp"
+
+#include <string>
+
+#include "openvino/core/rt_info.hpp"
+#include "openvino/op/paged_selective_ssm.hpp"
+#include "openvino/op/reshape.hpp"
+#include "openvino/op/selective_ssm.hpp"
+#include "openvino/op/shape_of.hpp"
+#include "transformations/rt_info/disable_precision_conversion.hpp"
+
+namespace ov::intel_gpu {
+
+bool EliminateEmptySelectiveSSM::run_on_model(const std::shared_ptr<ov::Model>& model) {
+ bool changed = false;
+ for (const auto& node : model->get_ordered_ops()) {
+ const auto selective_ssm = ov::as_type_ptr<ov::op::internal::SelectiveSSM>(node);
+ if (!selective_ssm) {
+ continue;
+ }
+
+ const auto& x_shape = selective_ssm->get_input_partial_shape(3);
+ if (x_shape.rank().is_dynamic() || x_shape.size() < 2 || x_shape[1].is_dynamic() || x_shape[1].get_length() != 0) {
+ continue;
+ }
+
+ selective_ssm->output(0).replace(selective_ssm->input_value(3));
+ selective_ssm->output(1).replace(selective_ssm->input_value(5));
+ changed = true;
+ }
+ return changed;
+}
+
+bool PreserveSingleSelectiveSSMOutput::run_on_model(const std::shared_ptr<ov::Model>& model) {
+ bool changed = false;
+ for (const auto& node : model->get_ordered_ops()) {
+ const auto selective_ssm = ov::as_type_ptr<ov::op::internal::SelectiveSSM>(node);
+ if (!selective_ssm) {
+ continue;
+ }
+
+ const bool output0_used = !selective_ssm->output(0).get_target_inputs().empty();
+ const bool output1_used = !selective_ssm->output(1).get_target_inputs().empty();
+ if (output0_used == output1_used) {
+ continue;
+ }
+
+ const size_t output_index = output1_used ? 1 : 0;
+ if (!selective_ssm->is_dynamic() && output_index == 0) {
+ continue;
+ }
+
+ auto output = selective_ssm->output(output_index);
+ const auto target_inputs = output.get_target_inputs();
+ const auto output_shape = std::make_shared<ov::op::v3::ShapeOf>(output, ov::element::i64);
+ const auto output_view = std::make_shared<ov::op::v1::Reshape>(output, output_shape, false);
+ output_view->set_friendly_name(selective_ssm->get_friendly_name() + "/output_view_" + std::to_string(output_index));
+ output_view->output(0).get_tensor().set_names(output.get_names());
+ ov::copy_runtime_info(selective_ssm, {output_shape, output_view});
+ for (const auto& input : target_inputs) {
+ input.replace_source_output(output_view);
+ }
+ changed = true;
+ }
+ return changed;
+}
+
+bool PreserveSelectiveSSMPrecision::run_on_model(const std::shared_ptr<ov::Model>& model) {
+ for (const auto& node : model->get_ordered_ops()) {
+ if (!ov::is_type<ov::op::internal::SelectiveSSM>(node) && !ov::is_type<ov::op::internal::PagedSelectiveSSM>(node)) {
+ continue;
+ }
+
+ ov::disable_conversion(node, ov::element::dynamic, ov::element::dynamic);
+ for (size_t input = 0; input < node->get_input_size(); ++input) {
+ ov::disable_conversion(node->get_input_node_shared_ptr(input), ov::element::dynamic, ov::element::dynamic);
+ }
+ }
+ return false;
+}
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/preserve_selective_ssm_precision.hpp b/src/plugins/intel_gpu/src/plugin/transformations/preserve_selective_ssm_precision.hpp
new file mode 100644
index 00000000000..c458019f20b
--- /dev/null
+++ b/src/plugins/intel_gpu/src/plugin/transformations/preserve_selective_ssm_precision.hpp
@@ -0,0 +1,38 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "openvino/pass/pass.hpp"
+
+namespace ov::intel_gpu {
+
+// Replaces a SelectiveSSM with its inputs when the sequence length is statically zero:
+// sequence output is empty x, while recurrent state remains unchanged.
+class EliminateEmptySelectiveSSM final : public ov::pass::ModelPass {
+public:
+ OPENVINO_MODEL_PASS_RTTI("EliminateEmptySelectiveSSM");
+
+ bool run_on_model(const std::shared_ptr<ov::Model>& model) override;
+};
+
+// Adds a zero-copy view for a lone SelectiveSSM output so clDNN does not apply
+// single-output optimizations directly to a multi-output primitive.
+class PreserveSingleSelectiveSSMOutput final : public ov::pass::ModelPass {
+public:
+ OPENVINO_MODEL_PASS_RTTI("PreserveSingleSelectiveSSMOutput");
+
+ bool run_on_model(const std::shared_ptr<ov::Model>& model) override;
+};
+
+// Prevents generic precision conversion from changing SelectiveSSM and PagedSelectiveSSM
+// operations or any of their inputs, preserving the precision required by the GPU kernels.
+class PreserveSelectiveSSMPrecision final : public ov::pass::ModelPass {
+public:
+ OPENVINO_MODEL_PASS_RTTI("PreserveSelectiveSSMPrecision");
+
+ bool run_on_model(const std::shared_ptr<ov::Model>& model) override;
+};
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
index a6cb836326a..8b9860a54ee 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
@@ -104,6 +104,7 @@
#include "plugin/transformations/keep_gqa_kv_scale_precision.hpp"
#include "plugin/transformations/keep_moe_3gemm_const_precision.hpp"
#include "plugin/transformations/keep_xattention_threshold_precision.hpp"
+#include "plugin/transformations/preserve_selective_ssm_precision.hpp"
#include "plugin/transformations/kv_cache_compression.hpp"
#include "plugin/transformations/kv_cache_fusion.hpp"
#include "plugin/transformations/lora_horizontal_fusion.hpp"
@@ -768,6 +769,8 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
// Keep GroupQueryAttention quantized-KV scales fp32 through the ConvertPrecision below
// (the intact op requires fp32 scales; it is decomposed later in CommonOptimizations).
manager.register_pass<ov::intel_gpu::KeepGQAKVScalePrecision>();
+ manager.register_pass<ov::intel_gpu::EliminateEmptySelectiveSSM>();
+ manager.register_pass<ov::intel_gpu::PreserveSelectiveSSMPrecision>();
manager.register_pass<ov::pass::ConvertPrecision>(fp_convert_precision_map,
empty_fuse_map,
@@ -1790,6 +1793,8 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
manager.register_pass<ov::pass::ConstantsReduce>();
+ manager.register_pass<ov::intel_gpu::PreserveSingleSelectiveSSMOutput>();
+
// This is supposed to be the last pass to ensure that we don't have name collisions until
// GPU plugin stops using friendly names for program creation
manager.register_pass<ov::pass::ResolveNameCollisions>(true);
diff --git a/src/plugins/intel_gpu/src/runtime/execution_config.cpp b/src/plugins/intel_gpu/src/runtime/execution_config.cpp
index 62c74b2c2aa..39efa623660 100644
--- a/src/plugins/intel_gpu/src/runtime/execution_config.cpp
+++ b/src/plugins/intel_gpu/src/runtime/execution_config.cpp
@@ -21,8 +21,10 @@
#include "openvino/op/lstm_sequence.hpp"
#include "openvino/op/matmul.hpp"
#include "openvino/op/paged_attention.hpp"
+#include "openvino/op/paged_selective_ssm.hpp"
#include "openvino/op/scaled_dot_product_attention.hpp"
#include "openvino/op/search_sorted.hpp"
+#include "openvino/op/selective_ssm.hpp"
#include "openvino/op/sparse_fill_empty_rows.hpp"
#include "openvino/op/stft.hpp"
#include "openvino/runtime/internal_properties.hpp"
@@ -68,7 +70,8 @@ bool requires_new_shape_infer(const std::shared_ptr<ov::Node>& op) {
if (ov::is_type<ov::op::internal::DynamicQuantize>(op) || ov::is_type<ov::op::internal::RMS>(op))
return true;
- if (ov::is_type<ov::op::internal::GatedDeltaNet>(op))
+ if (ov::is_type<ov::op::internal::GatedDeltaNet>(op) || ov::is_type<ov::op::internal::SelectiveSSM>(op) ||
+ ov::is_type<ov::op::internal::PagedSelectiveSSM>(op))
return true;
if (ov::is_type<ov::op::v5::Loop>(op)) {
diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/selective_ssm.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/selective_ssm.cpp
new file mode 100644
index 00000000000..3274e29d0da
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/selective_ssm.cpp
@@ -0,0 +1,579 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/op/selective_ssm.hpp"
+
+#include <gtest/gtest.h>
+
+#include <algorithm>
+#include <array>
+#include <cmath>
+#include <cstdint>
+#include <sstream>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <vector>
+
+#include "openvino/op/paged_selective_ssm.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/result.hpp"
+#include "openvino/runtime/core.hpp"
+
+namespace {
+
+constexpr size_t large_state_size = 32 * 1024 + 1;
+
+template <typename T>
+ov::Tensor make_tensor(const ov::element::Type& type, const ov::Shape& shape, const std::vector<T>& values) {
+ ov::Tensor tensor(type, shape);
+ OPENVINO_ASSERT(tensor.get_size() == values.size());
+ std::copy(values.begin(), values.end(), tensor.data<T>());
+ return tensor;
+}
+
+std::vector<float> make_values(size_t count, float scale, float shift = 0.f) {
+ std::vector<float> values(count);
+ for (size_t i = 0; i < count; i++)
+ values[i] = (static_cast<int32_t>(i % 11) - 5) * scale + shift;
+ return values;
+}
+
+void expect_tensor_near(const ov::Tensor& actual, const std::vector<float>& expected, float tolerance = 2e-4f) {
+ ASSERT_EQ(actual.get_size(), expected.size());
+ const auto* data = actual.data<const float>();
+ for (size_t i = 0; i < expected.size(); i++)
+ ASSERT_NEAR(data[i], expected[i], tolerance) << "index=" << i;
+}
+
+std::vector<std::string> get_gpu_devices(ov::Core& core) {
+ std::vector<std::string> devices;
+ for (const auto& device : core.get_available_devices()) {
+ if (device.rfind("GPU.", 0) == 0)
+ devices.push_back(device);
+ }
+ if (devices.empty())
+ devices.emplace_back("GPU");
+ return devices;
+}
+
+std::pair<std::vector<float>, std::vector<float>> selective_reference(const std::vector<float>& A,
+ const std::vector<float>& dt,
+ const std::vector<float>& B,
+ const std::vector<float>& x,
+ const std::vector<float>& C,
+ std::vector<float> state,
+ int32_t batch,
+ int32_t seq_len,
+ int32_t num_heads,
+ int32_t num_groups,
+ int32_t head_dim,
+ int32_t state_size) {
+ const int32_t heads_per_group = num_heads / num_groups;
+ std::vector<float> output(static_cast<size_t>(batch) * seq_len * num_heads * head_dim);
+ for (int32_t b = 0; b < batch; b++) {
+ for (int32_t h = 0; h < num_heads; h++) {
+ const int32_t g = h / heads_per_group;
+ for (int32_t t = 0; t < seq_len; t++) {
+ const float dt_value = dt[(b * seq_len + t) * num_heads + h];
+ const float dA = std::exp(A[h] * dt_value);
+ for (int32_t p = 0; p < head_dim; p++) {
+ const float x_value = x[((b * seq_len + t) * num_heads + h) * head_dim + p];
+ float sum = 0.f;
+ for (int32_t n = 0; n < state_size; n++) {
+ auto& current = state[((b * num_heads + h) * head_dim + p) * state_size + n];
+ current = current * dA + x_value * dt_value * B[((b * seq_len + t) * num_groups + g) * state_size + n];
+ sum += current * C[((b * seq_len + t) * num_groups + g) * state_size + n];
+ }
+ output[((b * seq_len + t) * num_heads + h) * head_dim + p] = sum;
+ }
+ }
+ }
+ }
+ return {output, state};
+}
+
+std::pair<std::vector<float>, std::vector<float>> paged_reference(const std::vector<float>& A,
+ const std::vector<float>& dt,
+ const std::vector<float>& B,
+ const std::vector<float>& x,
+ const std::vector<float>& C,
+ std::vector<float> state,
+ const std::vector<int64_t>& subsequence_begins,
+ const std::vector<int64_t>& block_indices,
+ const std::vector<int64_t>& block_indices_begins,
+ const std::vector<int64_t>& processed_tokens,
+ const std::vector<int64_t>& cache_intervals,
+ int32_t num_heads,
+ int32_t num_groups,
+ int32_t head_dim,
+ int32_t state_size) {
+ const int32_t heads_per_group = num_heads / num_groups;
+ const int64_t tokens = subsequence_begins.back();
+ std::vector<float> output(static_cast<size_t>(tokens) * num_heads * head_dim);
+ const auto state_offset = [=](int64_t block, int32_t h, int32_t p, int32_t n) {
+ return ((block * num_heads + h) * head_dim + p) * state_size + n;
+ };
+
+ for (size_t seq = 0; seq + 1 < subsequence_begins.size(); seq++) {
+ const int64_t token_begin = subsequence_begins[seq];
+ const int64_t token_end = subsequence_begins[seq + 1];
+ if (token_begin == token_end)
+ continue;
+ const int64_t block_begin = block_indices_begins[seq];
+ const int64_t first_block = block_indices[block_begin];
+ const int64_t interval = cache_intervals[seq];
+ const int64_t previous = interval > 0 ? std::max<int64_t>(processed_tokens[seq], 0) % interval : 0;
+ for (int32_t h = 0; h < num_heads; h++) {
+ const int32_t g = h / heads_per_group;
+ for (int32_t p = 0; p < head_dim; p++) {
+ std::vector<float> local_state(state_size);
+ for (int32_t n = 0; n < state_size; n++)
+ local_state[n] = state[state_offset(first_block, h, p, n)];
+ for (int64_t token = token_begin; token < token_end; token++) {
+ const float dt_value = dt[token * num_heads + h];
+ const float dA = std::exp(A[h] * dt_value);
+ const float x_value = x[(token * num_heads + h) * head_dim + p];
+ float sum = 0.f;
+ for (int32_t n = 0; n < state_size; n++) {
+ local_state[n] = local_state[n] * dA + x_value * dt_value * B[(token * num_groups + g) * state_size + n];
+ sum += local_state[n] * C[(token * num_groups + g) * state_size + n];
+ }
+ output[(token * num_heads + h) * head_dim + p] = sum;
+
+ const int64_t cached_tokens = previous + token - token_begin + 1;
+ if (interval > 0 && (cached_tokens % interval == 0 || token + 1 == token_end)) {
+ const int64_t slot = 1 + (cached_tokens - 1) / interval;
+ if (block_begin + slot < block_indices_begins[seq + 1]) {
+ const int64_t block = block_indices[block_begin + slot];
+ for (int32_t n = 0; n < state_size; n++)
+ state[state_offset(block, h, p, n)] = local_state[n];
+ }
+ }
+ }
+ }
+ }
+ }
+ return {output, state};
+}
+
+TEST(smoke_GPUSelectiveSSMIntegration, SelectiveSSMDynamicModel) {
+ struct SelectiveCase {
+ size_t batch;
+ size_t seq_len;
+ size_t num_heads;
+ size_t num_groups;
+ size_t head_dim;
+ size_t state_size;
+ };
+
+ auto A_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1});
+ auto dt_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1});
+ auto B_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1, -1});
+ auto x_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1, -1});
+ auto C_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1, -1});
+ auto state_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1, -1});
+ auto ssm = std::make_shared<ov::op::internal::SelectiveSSM>(A_param, dt_param, B_param, x_param, C_param, state_param);
+ auto model = std::make_shared<ov::Model>(
+ ov::ResultVector{std::make_shared<ov::op::v0::Result>(ssm->output(0)), std::make_shared<ov::op::v0::Result>(ssm->output(1))},
+ ov::ParameterVector{A_param, dt_param, B_param, x_param, C_param, state_param});
+
+ const std::vector<SelectiveCase> cases{{2, 3, 4, 2, 3, 5},
+ {1, 7, 6, 3, 5, 33},
+ {1, 0, 2, 1, 4, 9},
+ {1, 0, 1, 1, 1, large_state_size},
+ {3, 1, 8, 4, 1, 513},
+ {2, 3, 4, 2, 3, 5}};
+
+ ov::Core core;
+ for (const auto& device : get_gpu_devices(core)) {
+ SCOPED_TRACE(device);
+ auto request = core.compile_model(model, device).create_infer_request();
+ for (const auto& test_case : cases) {
+ const auto [batch, seq_len, num_heads, num_groups, head_dim, state_size] = test_case;
+ SCOPED_TRACE(testing::Message() << "batch=" << batch << ", seq_len=" << seq_len << ", heads=" << num_heads << ", groups=" << num_groups
+ << ", head_dim=" << head_dim << ", state_size=" << state_size);
+ auto A = make_values(num_heads, -0.03f, -0.25f);
+ auto dt = make_values(batch * seq_len * num_heads, 0.007f, 0.08f);
+ auto B = make_values(batch * seq_len * num_groups * state_size, 0.01f);
+ auto x = make_values(batch * seq_len * num_heads * head_dim, 0.015f);
+ auto C = make_values(batch * seq_len * num_groups * state_size, 0.012f);
+ auto state = make_values(batch * num_heads * head_dim * state_size, 0.008f);
+ const auto [expected_output, expected_state] =
+ selective_reference(A, dt, B, x, C, state, batch, seq_len, num_heads, num_groups, head_dim, state_size);
+
+ request.set_input_tensor(0, make_tensor<float>(ov::element::f32, {num_heads}, A));
+ request.set_input_tensor(1, make_tensor<float>(ov::element::f32, {batch, seq_len, num_heads}, dt));
+ request.set_input_tensor(2, make_tensor<float>(ov::element::f32, {batch, seq_len, num_groups, state_size}, B));
+ request.set_input_tensor(3, make_tensor<float>(ov::element::f32, {batch, seq_len, num_heads, head_dim}, x));
+ request.set_input_tensor(4, make_tensor<float>(ov::element::f32, {batch, seq_len, num_groups, state_size}, C));
+ request.set_input_tensor(5, make_tensor<float>(ov::element::f32, {batch, num_heads, head_dim, state_size}, state));
+ request.infer();
+
+ expect_tensor_near(request.get_output_tensor(0), expected_output);
+ expect_tensor_near(request.get_output_tensor(1), expected_state);
+ }
+ }
+}
+
+TEST(smoke_GPUSelectiveSSMIntegration, SelectiveSSMIndividualOutputs) {
+ constexpr size_t batch = 1;
+ constexpr size_t num_heads = 4;
+ constexpr size_t num_groups = 2;
+ constexpr size_t head_dim = 3;
+ constexpr size_t state_size = 5;
+
+ const auto make_model = [batch, num_heads, num_groups, head_dim, state_size](size_t seq_len, size_t output_index, bool dynamic) {
+ const auto shape = [dynamic](const ov::Shape& static_shape) {
+ return dynamic ? ov::PartialShape::dynamic(static_shape.size()) : ov::PartialShape{static_shape};
+ };
+ auto A = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, shape({num_heads}));
+ auto dt = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, shape({batch, seq_len, num_heads}));
+ auto B = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, shape({batch, seq_len, num_groups, state_size}));
+ auto x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, shape({batch, seq_len, num_heads, head_dim}));
+ auto C = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, shape({batch, seq_len, num_groups, state_size}));
+ auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, shape({batch, num_heads, head_dim, state_size}));
+ auto ssm = std::make_shared<ov::op::internal::SelectiveSSM>(A, dt, B, x, C, state);
+ return std::make_shared<ov::Model>(ov::OutputVector{ssm->output(output_index)}, ov::ParameterVector{A, dt, B, x, C, state});
+ };
+
+ const auto A = make_values(num_heads, -0.03f, -0.25f);
+ const auto state = make_values(batch * num_heads * head_dim * state_size, 0.008f);
+ const auto check = [&](ov::InferRequest& request, size_t seq_len, size_t output_index) {
+ SCOPED_TRACE(testing::Message() << "seq_len=" << seq_len << ", output_index=" << output_index);
+ const auto dt = make_values(batch * seq_len * num_heads, 0.007f, 0.08f);
+ const auto B = make_values(batch * seq_len * num_groups * state_size, 0.01f);
+ const auto x = make_values(batch * seq_len * num_heads * head_dim, 0.015f);
+ const auto C = make_values(batch * seq_len * num_groups * state_size, 0.012f);
+ const auto expected = selective_reference(A, dt, B, x, C, state, batch, seq_len, num_heads, num_groups, head_dim, state_size);
+
+ request.set_input_tensor(0, make_tensor<float>(ov::element::f32, {num_heads}, A));
+ request.set_input_tensor(1, make_tensor<float>(ov::element::f32, {batch, seq_len, num_heads}, dt));
+ request.set_input_tensor(2, make_tensor<float>(ov::element::f32, {batch, seq_len, num_groups, state_size}, B));
+ request.set_input_tensor(3, make_tensor<float>(ov::element::f32, {batch, seq_len, num_heads, head_dim}, x));
+ request.set_input_tensor(4, make_tensor<float>(ov::element::f32, {batch, seq_len, num_groups, state_size}, C));
+ request.set_input_tensor(5, make_tensor<float>(ov::element::f32, {batch, num_heads, head_dim, state_size}, state));
+ request.infer();
+ expect_tensor_near(request.get_output_tensor(0), output_index == 0 ? expected.first : expected.second);
+ };
+
+ const auto run = [&](ov::Core& core, const std::string& device, size_t seq_len, size_t output_index, bool dynamic) {
+ auto compiled_model = core.compile_model(make_model(seq_len, output_index, dynamic), device);
+ auto request = compiled_model.create_infer_request();
+ check(request, seq_len, output_index);
+ std::stringstream blob;
+ compiled_model.export_model(blob);
+ auto imported_request = core.import_model(blob, device).create_infer_request();
+ check(imported_request, seq_len, output_index);
+ };
+
+ const auto run_dynamic_sequence = [&](ov::Core& core, const std::string& device, size_t output_index) {
+ static constexpr std::array<size_t, 5> sequence_lengths{0, 1, 9, 0, 3};
+ auto compiled_model = core.compile_model(make_model(sequence_lengths.front(), output_index, true), device);
+ auto request = compiled_model.create_infer_request();
+ for (const auto seq_len : sequence_lengths) {
+ check(request, seq_len, output_index);
+ }
+
+ std::stringstream blob;
+ compiled_model.export_model(blob);
+ auto imported_request = core.import_model(blob, device).create_infer_request();
+ for (const auto seq_len : sequence_lengths) {
+ check(imported_request, seq_len, output_index);
+ }
+ };
+
+ ov::Core core;
+ for (const auto& device : get_gpu_devices(core)) {
+ SCOPED_TRACE(device);
+ run(core, device, 3, 0, false);
+ run(core, device, 1, 1, false);
+ run(core, device, 0, 1, false);
+ run_dynamic_sequence(core, device, 0);
+ run_dynamic_sequence(core, device, 1);
+ }
+}
+
+TEST(smoke_GPUSelectiveSSMIntegration, PagedSelectiveSSMDynamicModel) {
+ struct PagedCase {
+ std::vector<int64_t> subsequences;
+ std::vector<int64_t> blocks;
+ std::vector<int64_t> block_begins;
+ std::vector<int64_t> processed;
+ std::vector<int64_t> intervals;
+ size_t state_blocks;
+ size_t num_heads;
+ size_t num_groups;
+ size_t head_dim;
+ size_t state_size;
+ };
+
+ auto A_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1});
+ auto dt_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1});
+ auto B_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1});
+ auto x_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1});
+ auto C_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1});
+ auto state_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1, -1});
+ const auto index_param = [] {
+ return std::make_shared<ov::op::v0::Parameter>(ov::element::i64, ov::PartialShape{-1});
+ };
+ auto subsequence_param = index_param();
+ auto blocks_param = index_param();
+ auto block_begins_param = index_param();
+ auto processed_param = index_param();
+ auto interval_param = index_param();
+ auto ssm = std::make_shared<ov::op::internal::PagedSelectiveSSM>(A_param,
+ dt_param,
+ B_param,
+ x_param,
+ C_param,
+ state_param,
+ subsequence_param,
+ blocks_param,
+ block_begins_param,
+ processed_param,
+ interval_param);
+ auto model = std::make_shared<ov::Model>(ov::OutputVector{ssm},
+ ov::ParameterVector{A_param,
+ dt_param,
+ B_param,
+ x_param,
+ C_param,
+ state_param,
+ subsequence_param,
+ blocks_param,
+ block_begins_param,
+ processed_param,
+ interval_param});
+
+ const std::vector<PagedCase> cases{
+ {{0, 3, 5}, {0, 1, 2, 3, 4, 5}, {0, 3, 6}, {0, 1}, {2, 2}, 6, 4, 2, 3, 5},
+ {{0, 1}, {1, 1}, {0, 2}, {4}, {2}, 2, 4, 2, 3, 5},
+ {{0, 2, 7}, {5, 2, 1, 4, 0, 3}, {0, 2, 6}, {1, 7}, {3, 2}, 6, 6, 3, 5, 33},
+ {{0, 2}, {0, 1}, {0, 2}, {4294967297}, {4294967296}, 2, 2, 1, 1, 513},
+ {{0, 0}, {}, {0, 0}, {0}, {2}, 1, 2, 1, 4, 9},
+ {{0, 1}, {0, 1}, {0, 2}, {0}, {1}, 2, 1, 1, 1, 8192},
+ {{0, 3, 5}, {0, 1, 2, 3, 4, 5}, {0, 3, 6}, {0, 1}, {2, 2}, 6, 4, 2, 3, 5},
+ };
+
+ ov::Core core;
+ for (const auto& device : get_gpu_devices(core)) {
+ SCOPED_TRACE(device);
+ auto compiled_model = core.compile_model(model, device);
+ auto request = compiled_model.create_infer_request();
+ const auto set_index_input = [&request](size_t index, const std::vector<int64_t>& values) {
+ request.set_input_tensor(index, make_tensor<int64_t>(ov::element::i64, {values.size()}, values));
+ };
+ for (const auto& test_case : cases) {
+ const auto tokens = static_cast<size_t>(test_case.subsequences.back());
+ const auto [num_heads, num_groups, head_dim, state_size] =
+ std::tie(test_case.num_heads, test_case.num_groups, test_case.head_dim, test_case.state_size);
+ SCOPED_TRACE(testing::Message() << "tokens=" << tokens << ", sequences=" << test_case.subsequences.size() - 1 << ", heads=" << num_heads
+ << ", groups=" << num_groups << ", head_dim=" << head_dim << ", state_size=" << state_size);
+ auto A = make_values(num_heads, -0.03f, -0.2f);
+ auto dt = make_values(tokens * num_heads, 0.006f, 0.07f);
+ auto B = make_values(tokens * num_groups * state_size, 0.009f);
+ auto x = make_values(tokens * num_heads * head_dim, 0.013f);
+ auto C = make_values(tokens * num_groups * state_size, 0.011f);
+ auto state = make_values(test_case.state_blocks * num_heads * head_dim * state_size, 0.007f);
+ const auto expected = paged_reference(A,
+ dt,
+ B,
+ x,
+ C,
+ state,
+ test_case.subsequences,
+ test_case.blocks,
+ test_case.block_begins,
+ test_case.processed,
+ test_case.intervals,
+ num_heads,
+ num_groups,
+ head_dim,
+ state_size);
+
+ auto state_tensor = compiled_model.get_context().create_tensor(ov::element::f32, {test_case.state_blocks, num_heads, head_dim, state_size});
+ state_tensor.copy_from(make_tensor<float>(ov::element::f32, {test_case.state_blocks, num_heads, head_dim, state_size}, state));
+ request.set_input_tensor(0, make_tensor<float>(ov::element::f32, {num_heads}, A));
+ request.set_input_tensor(1, make_tensor<float>(ov::element::f32, {tokens, num_heads}, dt));
+ request.set_input_tensor(2, make_tensor<float>(ov::element::f32, {tokens, num_groups, state_size}, B));
+ request.set_input_tensor(3, make_tensor<float>(ov::element::f32, {tokens, num_heads, head_dim}, x));
+ request.set_input_tensor(4, make_tensor<float>(ov::element::f32, {tokens, num_groups, state_size}, C));
+ request.set_input_tensor(5, state_tensor);
+ set_index_input(6, test_case.subsequences);
+ set_index_input(7, test_case.blocks);
+ set_index_input(8, test_case.block_begins);
+ set_index_input(9, test_case.processed);
+ set_index_input(10, test_case.intervals);
+ request.infer();
+
+ expect_tensor_near(request.get_output_tensor(0), expected.first);
+ ov::Tensor actual_state(ov::element::f32, {test_case.state_blocks, num_heads, head_dim, state_size});
+ request.get_tensor(state_param).copy_to(actual_state);
+ expect_tensor_near(actual_state, expected.second);
+ }
+ }
+}
+
+TEST(smoke_GPUSelectiveSSMIntegration, SelectiveSSMChainedState) {
+ constexpr int32_t batch = 1;
+ constexpr int32_t seq_len = 5;
+ constexpr int32_t num_heads = 4;
+ constexpr int32_t num_groups = 2;
+ constexpr int32_t head_dim = 5;
+ constexpr int32_t state_size = 17;
+
+ auto A_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{num_heads});
+ auto dt_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, num_heads});
+ auto B_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, num_groups, state_size});
+ auto x_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, num_heads, head_dim});
+ auto C_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, num_groups, state_size});
+ auto state_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, num_heads, head_dim, state_size});
+ auto first = std::make_shared<ov::op::internal::SelectiveSSM>(A_param, dt_param, B_param, x_param, C_param, state_param);
+ auto second = std::make_shared<ov::op::internal::SelectiveSSM>(A_param, dt_param, B_param, first->output(0), C_param, first->output(1));
+ auto model = std::make_shared<ov::Model>(
+ ov::ResultVector{std::make_shared<ov::op::v0::Result>(second->output(0)), std::make_shared<ov::op::v0::Result>(second->output(1))},
+ ov::ParameterVector{A_param, dt_param, B_param, x_param, C_param, state_param});
+
+ auto A = make_values(num_heads, -0.03f, -0.25f);
+ auto dt = make_values(batch * seq_len * num_heads, 0.007f, 0.08f);
+ auto B = make_values(batch * seq_len * num_groups * state_size, 0.01f);
+ auto x = make_values(batch * seq_len * num_heads * head_dim, 0.015f);
+ auto C = make_values(batch * seq_len * num_groups * state_size, 0.012f);
+ auto state = make_values(batch * num_heads * head_dim * state_size, 0.008f);
+ const auto first_expected = selective_reference(A, dt, B, x, C, state, batch, seq_len, num_heads, num_groups, head_dim, state_size);
+ const auto second_expected =
+ selective_reference(A, dt, B, first_expected.first, C, first_expected.second, batch, seq_len, num_heads, num_groups, head_dim, state_size);
+
+ ov::Core core;
+ for (const auto& device : get_gpu_devices(core)) {
+ SCOPED_TRACE(device);
+ auto request = core.compile_model(model, device).create_infer_request();
+ request.set_input_tensor(0, make_tensor<float>(ov::element::f32, {num_heads}, A));
+ request.set_input_tensor(1, make_tensor<float>(ov::element::f32, {batch, seq_len, num_heads}, dt));
+ request.set_input_tensor(2, make_tensor<float>(ov::element::f32, {batch, seq_len, num_groups, state_size}, B));
+ request.set_input_tensor(3, make_tensor<float>(ov::element::f32, {batch, seq_len, num_heads, head_dim}, x));
+ request.set_input_tensor(4, make_tensor<float>(ov::element::f32, {batch, seq_len, num_groups, state_size}, C));
+ request.set_input_tensor(5, make_tensor<float>(ov::element::f32, {batch, num_heads, head_dim, state_size}, state));
+ request.infer();
+
+ expect_tensor_near(request.get_output_tensor(0), second_expected.first);
+ expect_tensor_near(request.get_output_tensor(1), second_expected.second);
+ }
+}
+
+TEST(smoke_GPUSelectiveSSMIntegration, PagedSelectiveSSMChainedStateMutation) {
+ constexpr int32_t tokens = 2;
+ constexpr int32_t num_heads = 4;
+ constexpr int32_t num_groups = 2;
+ constexpr int32_t head_dim = 3;
+ constexpr int32_t state_size = 5;
+ constexpr int32_t state_blocks = 2;
+
+ auto A_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{num_heads});
+ auto dt_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{tokens, num_heads});
+ auto B_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{tokens, num_groups, state_size});
+ auto x_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{tokens, num_heads, head_dim});
+ auto C_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{tokens, num_groups, state_size});
+ auto state_param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{state_blocks, num_heads, head_dim, state_size});
+ const auto index_param = [](size_t size) {
+ return std::make_shared<ov::op::v0::Parameter>(ov::element::i64, ov::Shape{size});
+ };
+ auto subsequence_param = index_param(2);
+ auto blocks_param = index_param(2);
+ auto block_begins_param = index_param(2);
+ auto processed_param = index_param(1);
+ auto interval_param = index_param(1);
+ auto first = std::make_shared<ov::op::internal::PagedSelectiveSSM>(A_param,
+ dt_param,
+ B_param,
+ x_param,
+ C_param,
+ state_param,
+ subsequence_param,
+ blocks_param,
+ block_begins_param,
+ processed_param,
+ interval_param);
+ auto second = std::make_shared<ov::op::internal::PagedSelectiveSSM>(A_param,
+ dt_param,
+ B_param,
+ first->output(0),
+ C_param,
+ state_param,
+ subsequence_param,
+ blocks_param,
+ block_begins_param,
+ processed_param,
+ interval_param);
+ auto model = std::make_shared<ov::Model>(ov::OutputVector{second},
+ ov::ParameterVector{A_param,
+ dt_param,
+ B_param,
+ x_param,
+ C_param,
+ state_param,
+ subsequence_param,
+ blocks_param,
+ block_begins_param,
+ processed_param,
+ interval_param});
+
+ auto A = make_values(num_heads, -0.03f, -0.2f);
+ auto dt = make_values(tokens * num_heads, 0.006f, 0.07f);
+ auto B = make_values(tokens * num_groups * state_size, 0.009f);
+ auto x = make_values(tokens * num_heads * head_dim, 0.013f);
+ auto C = make_values(tokens * num_groups * state_size, 0.011f);
+ auto state = make_values(state_blocks * num_heads * head_dim * state_size, 0.007f);
+ const std::vector<int64_t> subsequences{0, tokens};
+ const std::vector<int64_t> blocks{0, 0};
+ const std::vector<int64_t> block_begins{0, 2};
+ const std::vector<int64_t> processed{0};
+ const std::vector<int64_t> intervals{tokens};
+ const auto first_expected =
+ paged_reference(A, dt, B, x, C, state, subsequences, blocks, block_begins, processed, intervals, num_heads, num_groups, head_dim, state_size);
+ const auto second_expected = paged_reference(A,
+ dt,
+ B,
+ first_expected.first,
+ C,
+ first_expected.second,
+ subsequences,
+ blocks,
+ block_begins,
+ processed,
+ intervals,
+ num_heads,
+ num_groups,
+ head_dim,
+ state_size);
+
+ ov::Core core;
+ for (const auto& device : get_gpu_devices(core)) {
+ SCOPED_TRACE(device);
+ auto compiled_model = core.compile_model(model, device);
+ auto state_tensor = compiled_model.get_context().create_tensor(ov::element::f32, {state_blocks, num_heads, head_dim, state_size});
+ state_tensor.copy_from(make_tensor<float>(ov::element::f32, {state_blocks, num_heads, head_dim, state_size}, state));
+ auto request = compiled_model.create_infer_request();
+ request.set_input_tensor(0, make_tensor<float>(ov::element::f32, {num_heads}, A));
+ request.set_input_tensor(1, make_tensor<float>(ov::element::f32, {tokens, num_heads}, dt));
+ request.set_input_tensor(2, make_tensor<float>(ov::element::f32, {tokens, num_groups, state_size}, B));
+ request.set_input_tensor(3, make_tensor<float>(ov::element::f32, {tokens, num_heads, head_dim}, x));
+ request.set_input_tensor(4, make_tensor<float>(ov::element::f32, {tokens, num_groups, state_size}, C));
+ request.set_input_tensor(5, state_tensor);
+ request.set_input_tensor(6, make_tensor<int64_t>(ov::element::i64, {subsequences.size()}, subsequences));
+ request.set_input_tensor(7, make_tensor<int64_t>(ov::element::i64, {blocks.size()}, blocks));
+ request.set_input_tensor(8, make_tensor<int64_t>(ov::element::i64, {block_begins.size()}, block_begins));
+ request.set_input_tensor(9, make_tensor<int64_t>(ov::element::i64, {processed.size()}, processed));
+ request.set_input_tensor(10, make_tensor<int64_t>(ov::element::i64, {intervals.size()}, intervals));
+ request.infer();
+
+ expect_tensor_near(request.get_output_tensor(0), second_expected.first);
+ ov::Tensor actual_state(ov::element::f32, {state_blocks, num_heads, head_dim, state_size});
+ request.get_tensor(state_param).copy_to(actual_state);
+ expect_tensor_near(actual_state, second_expected.second);
+ }
+}
+
+} // namespace
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/paged_selective_ssm.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/paged_selective_ssm.cpp
new file mode 100644
index 00000000000..18e1ec7d010
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/paged_selective_ssm.cpp
@@ -0,0 +1,479 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <algorithm>
+#include <cmath>
+#include <cstddef>
+#include <intel_gpu/primitives/input_layout.hpp>
+#include <intel_gpu/primitives/paged_selective_ssm.hpp>
+#include <intel_gpu/primitives/reorder.hpp>
+#include <numeric>
+#include <vector>
+
+#include "paged_selective_ssm_inst.h"
+#include "test_utils.h"
+
+using namespace cldnn;
+using namespace ::tests;
+
+namespace {
+
+constexpr int32_t large_state_size = 32 * 1024 + 1;
+
+template <typename T>
+std::vector<T> make_test_values(size_t count, float scale, float shift = 0.f) {
+ std::vector<T> values(count);
+ for (size_t i = 0; i < count; ++i)
+ values[i] = static_cast<T>((static_cast<int32_t>(i % 11) - 5) * scale + shift);
+ return values;
+}
+
+struct paged_selective_ssm_test_params {
+ std::vector<int32_t> seq_tokens;
+ std::vector<int32_t> processed_tokens;
+ std::vector<int32_t> cache_intervals;
+ int32_t num_heads;
+ int32_t num_groups;
+ int32_t head_dim;
+ int32_t state_size;
+ ov::element::Type precision;
+ ov::element::Type index_precision;
+ bool dynamic_shapes;
+ std::vector<bool> alias_first_write = {};
+ bool reverse_blocks = false;
+ bool caching_test = false;
+ bool padded_layouts = false;
+ int32_t iterations = 1;
+ int32_t invalid_metadata = 0;
+ bool accumulation_test = false;
+ float relative_output_tolerance = 5e-5f;
+};
+
+struct paged_selective_ssm_gpu_test : public ::testing::TestWithParam<paged_selective_ssm_test_params> {
+ template <typename T>
+ static void run_reference(const std::vector<T>& A,
+ const std::vector<T>& dt,
+ const std::vector<T>& B,
+ const std::vector<T>& x,
+ const std::vector<T>& C,
+ std::vector<T>& state,
+ const std::vector<int32_t>& subsequence_begins,
+ const std::vector<int32_t>& block_indices,
+ const std::vector<int32_t>& block_indices_begins,
+ const std::vector<int32_t>& num_processed_tokens,
+ const std::vector<int32_t>& cache_interval,
+ int32_t num_heads,
+ int32_t num_groups,
+ int32_t head_dim,
+ int32_t state_size,
+ std::vector<T>& output) {
+ const int32_t heads_per_group = num_heads / num_groups;
+ const int32_t num_sequences = static_cast<int32_t>(subsequence_begins.size()) - 1;
+ const int32_t tokens = static_cast<int32_t>(x.size()) / (num_heads * head_dim);
+ output.resize(static_cast<size_t>(tokens) * num_heads * head_dim);
+ const auto state_off = [=](int32_t block, int32_t h, int32_t p, int32_t n) {
+ return ((block * num_heads + h) * head_dim + p) * state_size + n;
+ };
+
+ for (int32_t seq = 0; seq < num_sequences; seq++) {
+ const int32_t token_begin = subsequence_begins[seq];
+ const int32_t token_end = subsequence_begins[seq + 1];
+ const int32_t block_begin = block_indices_begins[seq];
+ const int32_t block_end = block_indices_begins[seq + 1];
+ const int32_t seq_blocks = std::max(block_end - block_begin, 0);
+ const int32_t processed = std::max(num_processed_tokens[seq], 0);
+ const int32_t interval = cache_interval[seq];
+ const int32_t prev_nums = interval > 0 ? (processed % interval) : 0;
+ const int32_t first_block = block_indices[block_begin];
+
+ for (int32_t h = 0; h < num_heads; h++) {
+ const int32_t g = h / heads_per_group;
+ for (int32_t p = 0; p < head_dim; p++) {
+ std::vector<float> local_state(static_cast<size_t>(state_size), 0.f);
+ for (int32_t n = 0; n < state_size; n++) {
+ local_state[n] = static_cast<float>(state[state_off(first_block, h, p, n)]);
+ }
+
+ for (int32_t token = token_begin; token < token_end; token++) {
+ const float dt_val = static_cast<float>(dt[token * num_heads + h]);
+ const float dA = std::exp(static_cast<float>(A[h]) * dt_val);
+ const float x_val = static_cast<float>(x[(token * num_heads + h) * head_dim + p]);
+ float acc = 0.f;
+ for (int32_t n = 0; n < state_size; n++) {
+ const float new_state = local_state[n] * dA + x_val * dt_val * static_cast<float>(B[(token * num_groups + g) * state_size + n]);
+ local_state[n] = new_state;
+ acc += local_state[n] * static_cast<float>(C[(token * num_groups + g) * state_size + n]);
+ }
+ output[(token * num_heads + h) * head_dim + p] = static_cast<T>(acc);
+
+ const int32_t processed_now = (token - token_begin) + 1;
+ const int32_t cached_tokens = prev_nums + processed_now;
+ const bool reached_interval_boundary = interval > 0 && ((cached_tokens % interval) == 0);
+ const bool reached_sequence_end = token == token_end - 1;
+ if (interval > 0 && (reached_interval_boundary || reached_sequence_end)) {
+ const int32_t slot = 1 + (cached_tokens - 1) / interval;
+ if (slot < seq_blocks) {
+ const int32_t block_id = block_indices[block_begin + slot];
+ for (int32_t n = 0; n < state_size; n++) {
+ state[state_off(block_id, h, p, n)] = static_cast<T>(local_state[n]);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ template <typename T>
+ void execute_t(const paged_selective_ssm_test_params& p) {
+ auto& engine = get_test_engine();
+ const auto data_type = cldnn::element_type_to_data_type(p.precision);
+ const auto index_data_type = cldnn::element_type_to_data_type(p.index_precision);
+ const int32_t num_sequences = static_cast<int32_t>(p.seq_tokens.size());
+ const int32_t tokens = static_cast<int32_t>(std::accumulate(p.seq_tokens.begin(), p.seq_tokens.end(), 0));
+
+ std::vector<int32_t> subsequence_begins{0};
+ std::vector<int32_t> block_indices;
+ std::vector<int32_t> block_indices_begins{0};
+ int32_t total_blocks = 0;
+ for (int32_t seq = 0; seq < num_sequences; seq++) {
+ subsequence_begins.push_back(subsequence_begins.back() + p.seq_tokens[seq]);
+ int32_t required_slots = 1;
+ if (p.cache_intervals[seq] > 0) {
+ const int32_t processed = std::max(p.processed_tokens[seq], 0);
+ const int32_t prev_nums = processed % p.cache_intervals[seq];
+ const int32_t write_blocks = (prev_nums + p.seq_tokens[seq] + p.cache_intervals[seq] - 1) / p.cache_intervals[seq];
+ required_slots = 1 + write_blocks;
+ }
+ std::vector<int32_t> sequence_block_indices(static_cast<size_t>(required_slots));
+ for (int32_t i = 0; i < required_slots; i++) {
+ sequence_block_indices[i] = total_blocks + (p.reverse_blocks ? required_slots - i - 1 : i);
+ }
+ if (required_slots > 1 && seq < static_cast<int32_t>(p.alias_first_write.size()) && p.alias_first_write[seq]) {
+ sequence_block_indices[1] = sequence_block_indices[0];
+ }
+ block_indices.insert(block_indices.end(), sequence_block_indices.begin(), sequence_block_indices.end());
+ total_blocks += required_slots;
+ block_indices_begins.push_back(static_cast<int32_t>(block_indices.size()));
+ }
+ if (p.invalid_metadata != 0) {
+ OPENVINO_ASSERT(num_sequences == 1, "Invalid-metadata tests require one sequence");
+ if (p.invalid_metadata == 1) {
+ block_indices[0] = total_blocks + 3;
+ } else if (p.invalid_metadata == 2) {
+ block_indices_begins[1] = static_cast<int32_t>(block_indices.size()) + 1;
+ } else {
+ OPENVINO_THROW("Unknown invalid metadata mode");
+ }
+ }
+
+ layout A_layout({p.num_heads}, data_type, format::bfyx);
+ layout dt_layout({tokens, p.num_heads}, data_type, format::bfyx);
+ layout BC_layout({tokens, p.num_groups, p.state_size}, data_type, format::bfyx);
+ layout x_layout({tokens, p.num_heads, p.head_dim}, data_type, format::bfyx);
+ layout state_layout({total_blocks, p.num_heads, p.head_dim, p.state_size}, data_type, format::bfyx);
+ const auto state_memory_layout = p.padded_layouts ? state_layout.with_padding(padding({1, 2, 1, 3}, {2, 1, 2, 1})) : state_layout;
+ const auto state_pitches = state_memory_layout.get_pitches();
+ const auto state_offset = [&](int32_t block, int32_t h, int32_t dim, int32_t n) {
+ return state_memory_layout.get_linear_offset() + static_cast<size_t>(block) * state_pitches[0] + static_cast<size_t>(h) * state_pitches[1] +
+ static_cast<size_t>(dim) * state_pitches[2] + static_cast<size_t>(n) * state_pitches[3];
+ };
+ layout index_vec_layout({static_cast<int32_t>(subsequence_begins.size())}, index_data_type, format::bfyx);
+ layout block_indices_layout({static_cast<int32_t>(block_indices.size())}, index_data_type, format::bfyx);
+ layout processed_layout({num_sequences}, index_data_type, format::bfyx);
+
+ // Empty tensors use the runtime's supported dummy-memory representation instead of a zero-byte OpenCL buffer.
+ const auto allocate = [&](const layout& requested_layout) {
+ if (requested_layout.count() != 0)
+ return engine.allocate_memory(requested_layout);
+ auto dummy = engine.allocate_memory(layout{{1}, data_types::u8, format::bfyx});
+ return engine.reinterpret_buffer(*dummy, requested_layout);
+ };
+
+ auto A_mem = allocate(A_layout);
+ auto dt_mem = allocate(dt_layout);
+ auto B_mem = allocate(BC_layout);
+ auto x_mem = allocate(x_layout);
+ auto C_mem = allocate(BC_layout);
+ auto state_mem = allocate(state_memory_layout);
+ auto subseq_mem = allocate(index_vec_layout);
+ auto blocks_mem = allocate(block_indices_layout);
+ auto block_begins_mem = allocate(index_vec_layout);
+ auto processed_mem = allocate(processed_layout);
+ auto interval_mem = allocate(processed_layout);
+
+ auto A_data = make_test_values<T>(A_mem->count(), -0.03f, -0.2f);
+ auto dt_data = make_test_values<T>(dt_mem->count(), 0.006f, 0.07f);
+ auto B_data = make_test_values<T>(B_mem->count(), 0.009f);
+ auto x_data = make_test_values<T>(x_mem->count(), 0.013f);
+ auto C_data = make_test_values<T>(C_mem->count(), 0.011f);
+ auto state_data = make_test_values<T>(state_layout.count(), 0.007f);
+
+ if (p.accumulation_test) {
+ A_data.assign(A_data.size(), static_cast<T>(0.f));
+ dt_data.assign(dt_data.size(), static_cast<T>(1.f));
+ B_data.assign(B_data.size(), static_cast<T>(1.f));
+ const float increment = p.precision == ov::element::bf16 ? 0.0546875f : 0.195068359375f;
+ x_data.assign(x_data.size(), static_cast<T>(increment));
+ C_data.assign(C_data.size(), static_cast<T>(1.f));
+ state_data.assign(state_data.size(), static_cast<T>(0.f));
+ }
+
+ const auto set_non_empty = [](const memory::ptr& mem, const auto& values) {
+ if (!values.empty())
+ set_values(mem, values);
+ };
+ set_non_empty(A_mem, A_data);
+ set_non_empty(dt_mem, dt_data);
+ set_non_empty(B_mem, B_data);
+ set_non_empty(x_mem, x_data);
+ set_non_empty(C_mem, C_data);
+ if (p.padded_layouts && !state_data.empty()) {
+ cldnn::mem_lock<T, mem_lock_type::write> state_ptr(state_mem, get_test_stream());
+ for (size_t i = 0; i < state_ptr.size(); i++)
+ state_ptr[i] = T{};
+ for (int32_t block = 0; block < total_blocks; block++) {
+ for (int32_t h = 0; h < p.num_heads; h++) {
+ for (int32_t dim = 0; dim < p.head_dim; dim++) {
+ for (int32_t n = 0; n < p.state_size; n++) {
+ const auto logical_idx = ((block * p.num_heads + h) * p.head_dim + dim) * p.state_size + n;
+ const auto physical_idx = state_offset(block, h, dim, n);
+ state_ptr[physical_idx] = state_data[logical_idx];
+ }
+ }
+ }
+ }
+ } else {
+ set_non_empty(state_mem, state_data);
+ }
+ if (p.index_precision == ov::element::i64) {
+ const std::vector<int64_t> subsequence_begins_i64(subsequence_begins.begin(), subsequence_begins.end());
+ const std::vector<int64_t> block_indices_i64(block_indices.begin(), block_indices.end());
+ const std::vector<int64_t> block_indices_begins_i64(block_indices_begins.begin(), block_indices_begins.end());
+ const std::vector<int64_t> processed_i64(p.processed_tokens.begin(), p.processed_tokens.end());
+ const std::vector<int64_t> intervals_i64(p.cache_intervals.begin(), p.cache_intervals.end());
+ set_non_empty(subseq_mem, subsequence_begins_i64);
+ set_non_empty(blocks_mem, block_indices_i64);
+ set_non_empty(block_begins_mem, block_indices_begins_i64);
+ set_non_empty(processed_mem, processed_i64);
+ set_non_empty(interval_mem, intervals_i64);
+ } else {
+ set_non_empty(subseq_mem, subsequence_begins);
+ set_non_empty(blocks_mem, block_indices);
+ set_non_empty(block_begins_mem, block_indices_begins);
+ set_non_empty(processed_mem, p.processed_tokens);
+ set_non_empty(interval_mem, p.cache_intervals);
+ }
+
+ const auto dt_input_layout = p.dynamic_shapes ? layout{ov::PartialShape{-1, p.num_heads}, data_type, format::bfyx} : dt_layout;
+ const auto BC_input_layout = p.dynamic_shapes ? layout{ov::PartialShape{-1, p.num_groups, p.state_size}, data_type, format::bfyx} : BC_layout;
+ const auto x_input_layout = p.dynamic_shapes ? layout{ov::PartialShape{-1, p.num_heads, p.head_dim}, data_type, format::bfyx} : x_layout;
+ const auto state_input_layout =
+ p.dynamic_shapes ? layout{ov::PartialShape{-1, p.num_heads, p.head_dim, p.state_size}, data_type, format::bfyx} : state_memory_layout;
+ const auto dynamic_index_layout = layout{ov::PartialShape{-1}, index_data_type, format::bfyx};
+ const auto index_vec_input_layout = p.dynamic_shapes ? dynamic_index_layout : index_vec_layout;
+ const auto block_indices_input_layout = p.dynamic_shapes ? dynamic_index_layout : block_indices_layout;
+ const auto processed_input_layout = p.dynamic_shapes ? dynamic_index_layout : processed_layout;
+
+ topology topo;
+ topo.add(input_layout("A", A_layout));
+ topo.add(input_layout("dt", dt_input_layout));
+ topo.add(input_layout("B", BC_input_layout));
+ topo.add(input_layout("x", x_input_layout));
+ topo.add(input_layout("C", BC_input_layout));
+ topo.add(input_layout("state", state_input_layout));
+ topo.add(input_layout("subsequence_begins", index_vec_input_layout));
+ topo.add(input_layout("block_indices", block_indices_input_layout));
+ topo.add(input_layout("block_indices_begins", index_vec_input_layout));
+ topo.add(input_layout("num_processed_tokens", processed_input_layout));
+ topo.add(input_layout("cache_interval", processed_input_layout));
+ std::vector<input_info> ssm_inputs{input_info("A"),
+ input_info("dt"),
+ input_info("B"),
+ input_info("x"),
+ input_info("C"),
+ input_info("state"),
+ input_info("subsequence_begins"),
+ input_info("block_indices"),
+ input_info("block_indices_begins"),
+ input_info("num_processed_tokens"),
+ input_info("cache_interval")};
+ if (p.padded_layouts) {
+ OPENVINO_ASSERT(!p.dynamic_shapes, "Padded-layout test requires static input layouts");
+ const auto A_padding = padding(std::vector<ov::Dimension::value_type>{1}, std::vector<ov::Dimension::value_type>{2});
+ const auto metadata_padding = padding(std::vector<ov::Dimension::value_type>{2}, std::vector<ov::Dimension::value_type>{1});
+ topo.add(reorder("A_padded", input_info("A"), A_layout.with_padding(A_padding)));
+ topo.add(reorder("dt_padded", input_info("dt"), dt_layout.with_padding(padding({1, 2}, {2, 1}))));
+ topo.add(reorder("B_padded", input_info("B"), BC_layout.with_padding(padding({1, 2, 3}, {2, 1, 2}))));
+ topo.add(reorder("x_padded", input_info("x"), x_layout.with_padding(padding({1, 2, 3}, {2, 1, 2}))));
+ topo.add(reorder("C_padded", input_info("C"), BC_layout.with_padding(padding({1, 2, 3}, {2, 1, 2}))));
+ topo.add(reorder("subsequence_begins_padded", input_info("subsequence_begins"), index_vec_layout.with_padding(metadata_padding)));
+ topo.add(reorder("block_indices_padded", input_info("block_indices"), block_indices_layout.with_padding(metadata_padding)));
+ topo.add(reorder("block_indices_begins_padded", input_info("block_indices_begins"), index_vec_layout.with_padding(metadata_padding)));
+ topo.add(reorder("num_processed_tokens_padded", input_info("num_processed_tokens"), processed_layout.with_padding(metadata_padding)));
+ topo.add(reorder("cache_interval_padded", input_info("cache_interval"), processed_layout.with_padding(metadata_padding)));
+ ssm_inputs = {input_info("A_padded"),
+ input_info("dt_padded"),
+ input_info("B_padded"),
+ input_info("x_padded"),
+ input_info("C_padded"),
+ input_info("state"),
+ input_info("subsequence_begins_padded"),
+ input_info("block_indices_padded"),
+ input_info("block_indices_begins_padded"),
+ input_info("num_processed_tokens_padded"),
+ input_info("cache_interval_padded")};
+ }
+ auto ssm_prim = paged_selective_ssm("paged_selective_ssm", ssm_inputs);
+ if (p.padded_layouts)
+ ssm_prim.output_paddings = {padding({1, 2, 3}, {2, 1, 2})};
+ topo.add(ssm_prim);
+ topo.add(reorder("output", input_info("paged_selective_ssm"), format::bfyx, data_type));
+
+ ExecutionConfig config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ auto network = get_network(engine, topo, config, get_test_stream_ptr(), p.caching_test);
+ network->set_input_data("A", A_mem);
+ network->set_input_data("dt", dt_mem);
+ network->set_input_data("B", B_mem);
+ network->set_input_data("x", x_mem);
+ network->set_input_data("C", C_mem);
+ network->set_input_data("state", state_mem);
+ network->set_input_data("subsequence_begins", subseq_mem);
+ network->set_input_data("block_indices", blocks_mem);
+ network->set_input_data("block_indices_begins", block_begins_mem);
+ network->set_input_data("num_processed_tokens", processed_mem);
+ network->set_input_data("cache_interval", interval_mem);
+
+ std::vector<T> ref_output;
+ auto ref_state = state_data;
+ const float tol = p.precision == ov::element::f32 ? 2e-4f : (p.precision == ov::element::bf16 ? 0.08f : 0.03f);
+ for (int32_t iteration = 0; iteration < p.iterations; iteration++) {
+ auto outputs = network->execute();
+ if (p.invalid_metadata != 0) {
+ ref_output.assign(static_cast<size_t>(tokens) * p.num_heads * p.head_dim, T{});
+ } else {
+ run_reference(A_data,
+ dt_data,
+ B_data,
+ x_data,
+ C_data,
+ ref_state,
+ subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ p.processed_tokens,
+ p.cache_intervals,
+ p.num_heads,
+ p.num_groups,
+ p.head_dim,
+ p.state_size,
+ ref_output);
+ }
+
+ if (!ref_output.empty()) {
+ auto out_mem = outputs.at("output").get_memory();
+ ASSERT_NE(out_mem, nullptr);
+ cldnn::mem_lock<T, mem_lock_type::read> out_ptr(out_mem, get_test_stream());
+ for (size_t i = 0; i < ref_output.size(); i++) {
+ const float reference = static_cast<float>(ref_output[i]);
+ const float output_tol = p.precision == ov::element::f32 ? std::max(tol, std::abs(reference) * p.relative_output_tolerance) : tol;
+ ASSERT_NEAR(static_cast<float>(out_ptr[i]), reference, output_tol) << "iteration=" << iteration << ", output idx=" << i;
+ }
+ }
+
+ if (!ref_state.empty()) {
+ cldnn::mem_lock<T, mem_lock_type::read> state_ptr(state_mem, get_test_stream());
+ for (int32_t block = 0; block < total_blocks; block++) {
+ for (int32_t h = 0; h < p.num_heads; h++) {
+ for (int32_t dim = 0; dim < p.head_dim; dim++) {
+ for (int32_t n = 0; n < p.state_size; n++) {
+ const auto logical_idx = ((block * p.num_heads + h) * p.head_dim + dim) * p.state_size + n;
+ const auto physical_idx = state_offset(block, h, dim, n);
+ ASSERT_NEAR(static_cast<float>(state_ptr[physical_idx]), static_cast<float>(ref_state[logical_idx]), tol)
+ << "iteration=" << iteration << ", state idx=" << logical_idx;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ void execute(const paged_selective_ssm_test_params& p) {
+ if (p.precision == ov::element::f16) {
+ execute_t<ov::float16>(p);
+ } else if (p.precision == ov::element::bf16) {
+ execute_t<ov::bfloat16>(p);
+ } else {
+ execute_t<float>(p);
+ }
+ }
+};
+
+TEST_P(paged_selective_ssm_gpu_test, basic) {
+ execute(GetParam());
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ smoke_paged_selective_ssm_gpu_test,
+ paged_selective_ssm_gpu_test,
+ ::testing::Values(
+ paged_selective_ssm_test_params{{3, 2}, {1, 2}, {2, 0}, 4, 2, 8, 8, ov::element::f32, ov::element::i32, false},
+ paged_selective_ssm_test_params{{2, 4, 1}, {1, 2, 3}, {1, 3, 2}, 4, 1, 8, 16, ov::element::f32, ov::element::i32, false},
+ paged_selective_ssm_test_params{{3, 2}, {1, 2}, {2, 0}, 4, 2, 8, 8, ov::element::f16, ov::element::i32, false},
+ paged_selective_ssm_test_params{{2, 1}, {0, 3}, {2, 1}, 2, 1, 4, 16, ov::element::f32, ov::element::i64, false},
+ paged_selective_ssm_test_params{{2}, {0}, {2}, 2, 1, 4, 16, ov::element::bf16, ov::element::i32, false},
+ paged_selective_ssm_test_params{{2}, {0}, {2}, 2, 1, 2, 513, ov::element::f32, ov::element::i32, false},
+ paged_selective_ssm_test_params{{2, 3}, {1, 0}, {2, 3}, 4, 2, 4, 16, ov::element::f32, ov::element::i64, true},
+ // Five page-aliasing cases from the published specification.
+ paged_selective_ssm_test_params{{5}, {0}, {2}, 4, 2, 5, 17, ov::element::f32, ov::element::i32, false, {true}, true},
+ paged_selective_ssm_test_params{{5}, {4}, {2}, 4, 2, 5, 17, ov::element::f32, ov::element::i32, false, {false}, true},
+ paged_selective_ssm_test_params{{5}, {3}, {2}, 4, 2, 5, 17, ov::element::f16, ov::element::i32, false, {true}, true},
+ paged_selective_ssm_test_params{{1}, {4}, {2}, 4, 2, 5, 17, ov::element::f32, ov::element::i64, false, {false}, true},
+ paged_selective_ssm_test_params{{1}, {3}, {2}, 4, 2, 5, 17, ov::element::bf16, ov::element::i64, false, {true}, true},
+ // Disabled cache must leave every state block unchanged.
+ paged_selective_ssm_test_params{{4, 3}, {9, 2}, {0, -3}, 4, 2, 4, 31, ov::element::f32, ov::element::i64, false, {}, true},
+ // Empty sequences and completely empty token batches are legal no-ops.
+ paged_selective_ssm_test_params{{0, 3, 0}, {0, 1, 7}, {2, 2, 0}, 4, 2, 4, 16, ov::element::f32, ov::element::i32, false, {true, false, false}, true},
+ paged_selective_ssm_test_params{{0}, {0}, {2}, 2, 1, 2, 8, ov::element::f32, ov::element::i32, true, {true}, false},
+ // Exercise binary serialization of the optimized implementation.
+ paged_selective_ssm_test_params{{3, 2}, {1, 0}, {2, 2}, 4, 2, 4, 16, ov::element::f16, ov::element::i64, true, {true, true}, true, true},
+ paged_selective_ssm_test_params{{4, 2}, {3, 7}, {2, 3}, 4, 2, 3, 19, ov::element::f32, ov::element::i64, false, {true, false}, true, false, true},
+ paged_selective_ssm_test_params{{3, 2}, {1, 0}, {2, 2}, 4, 2, 4, 16, ov::element::f16, ov::element::i32, true, {true, true}, true, false, false, 3},
+ paged_selective_ssm_test_params{{32, 17, 5}, {3, 7, 1}, {4, 3, 2}, 8, 4, 16, 64, ov::element::f16, ov::element::i64, true},
+ paged_selective_ssm_test_params{{128}, {0}, {32}, 4, 2, 8, 32, ov::element::f16, ov::element::i32, false},
+ paged_selective_ssm_test_params{{128}, {0}, {32}, 4, 2, 8, 32, ov::element::bf16, ov::element::i32, false},
+ paged_selective_ssm_test_params{{128}, {0}, {128}, 1, 1, 1, 1, ov::element::f16, ov::element::i32, false, {}, false, false, false, 1, 0, true},
+ paged_selective_ssm_test_params{{128}, {0}, {128}, 1, 1, 1, 1, ov::element::bf16, ov::element::i32, false, {}, false, false, false, 1, 0, true},
+ paged_selective_ssm_test_params{{3}, {-7}, {2}, 2, 1, 4, 8, ov::element::f32, ov::element::i32, false},
+ paged_selective_ssm_test_params{{3}, {0}, {2}, 2, 1, 4, 8, ov::element::f32, ov::element::i32, false, {}, false, false, false, 1, 1},
+ paged_selective_ssm_test_params{{3}, {0}, {2}, 2, 1, 4, 8, ov::element::f16, ov::element::i64, false, {}, false, false, false, 1, 2},
+ // Exercise local-memory-driven 4 -> 3 -> 2 -> 1 blocking and tails.
+ paged_selective_ssm_test_params{{2}, {0}, {2}, 2, 1, 4, 5000, ov::element::f32, ov::element::i32, false},
+ paged_selective_ssm_test_params{{2}, {0}, {2}, 2, 1, 3, 6000, ov::element::f32, ov::element::i32, false},
+ paged_selective_ssm_test_params{{2}, {0}, {2}, 2, 1, 4, 8192, ov::element::f32, ov::element::i32, false},
+ // Exceed 128 KiB of FP32 state and exercise the universal global-state fallback.
+ paged_selective_ssm_test_params{{2},
+ {0},
+ {2},
+ 1,
+ 1,
+ 1,
+ large_state_size,
+ ov::element::f32,
+ ov::element::i32,
+ false,
+ {},
+ false,
+ false,
+ true,
+ 1,
+ 0,
+ false,
+ 2e-4f},
+ paged_selective_ssm_test_params{{2}, {0}, {2}, 1, 1, 1, large_state_size, ov::element::f16, ov::element::i32, true, {}, false, true}));
+
+} // namespace
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/selective_ssm.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/selective_ssm.cpp
new file mode 100644
index 00000000000..70e7f04216d
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/selective_ssm.cpp
@@ -0,0 +1,276 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <cmath>
+#include <cstddef>
+#include <intel_gpu/primitives/input_layout.hpp>
+#include <intel_gpu/primitives/reorder.hpp>
+#include <intel_gpu/primitives/selective_ssm.hpp>
+#include <vector>
+
+#include "selective_ssm_inst.h"
+#include "test_utils.h"
+
+using namespace cldnn;
+using namespace ::tests;
+
+namespace {
+
+constexpr int32_t large_state_size = 32 * 1024 + 1;
+
+template <typename T>
+std::vector<T> make_test_values(size_t count, float scale, float shift = 0.f) {
+ std::vector<T> values(count);
+ for (size_t i = 0; i < count; ++i)
+ values[i] = static_cast<T>((static_cast<int32_t>(i % 11) - 5) * scale + shift);
+ return values;
+}
+
+struct selective_ssm_test_params {
+ int32_t batch;
+ int32_t seq_len;
+ int32_t num_heads;
+ int32_t num_groups;
+ int32_t head_dim;
+ int32_t state_size;
+ ov::element::Type precision;
+ bool dynamic_shapes;
+ bool caching_test = false;
+ bool padded_layouts = false;
+ int32_t iterations = 1;
+ bool accumulation_test = false;
+ float relative_output_tolerance = 5e-5f;
+};
+
+struct selective_ssm_gpu_test : public ::testing::TestWithParam<selective_ssm_test_params> {
+ template <typename T>
+ static void run_reference(const std::vector<T>& A,
+ const std::vector<T>& dt,
+ const std::vector<T>& B,
+ const std::vector<T>& x,
+ const std::vector<T>& C,
+ std::vector<T>& state,
+ int32_t batch,
+ int32_t seq_len,
+ int32_t num_heads,
+ int32_t num_groups,
+ int32_t head_dim,
+ int32_t state_size,
+ std::vector<T>& output) {
+ const int32_t heads_per_group = num_heads / num_groups;
+ std::vector<float> state_fp32(state.size());
+ for (size_t i = 0; i < state.size(); ++i)
+ state_fp32[i] = static_cast<float>(state[i]);
+
+ output.resize(static_cast<size_t>(batch) * seq_len * num_heads * head_dim);
+ for (int32_t b = 0; b < batch; b++) {
+ for (int32_t h = 0; h < num_heads; h++) {
+ const int32_t g = h / heads_per_group;
+ for (int32_t t = 0; t < seq_len; t++) {
+ const float dt_val = static_cast<float>(dt[(b * seq_len + t) * num_heads + h]);
+ const float dA = std::exp(static_cast<float>(A[h]) * dt_val);
+ for (int32_t p = 0; p < head_dim; p++) {
+ const float x_val = static_cast<float>(x[((b * seq_len + t) * num_heads + h) * head_dim + p]);
+ float acc = 0.f;
+ for (int32_t n = 0; n < state_size; n++) {
+ auto& s = state_fp32[((b * num_heads + h) * head_dim + p) * state_size + n];
+ const float new_state = s * dA + x_val * dt_val * static_cast<float>(B[((b * seq_len + t) * num_groups + g) * state_size + n]);
+ s = new_state;
+ acc += s * static_cast<float>(C[((b * seq_len + t) * num_groups + g) * state_size + n]);
+ }
+ output[((b * seq_len + t) * num_heads + h) * head_dim + p] = static_cast<T>(acc);
+ }
+ }
+ }
+ }
+ for (size_t i = 0; i < state.size(); ++i)
+ state[i] = static_cast<T>(state_fp32[i]);
+ }
+
+ template <typename T>
+ void execute_t(const selective_ssm_test_params& p) {
+ auto& engine = get_test_engine();
+ const auto data_type = cldnn::element_type_to_data_type(p.precision);
+
+ layout A_layout({p.num_heads}, data_type, format::bfyx);
+ layout dt_layout({p.batch, p.seq_len, p.num_heads}, data_type, format::bfyx);
+ layout BC_layout({p.batch, p.seq_len, p.num_groups, p.state_size}, data_type, format::bfyx);
+ layout x_layout({p.batch, p.seq_len, p.num_heads, p.head_dim}, data_type, format::bfyx);
+ layout state_layout({p.batch, p.num_heads, p.head_dim, p.state_size}, data_type, format::bfyx);
+
+ const auto allocate = [&](const layout& requested_layout) {
+ if (requested_layout.count() != 0)
+ return engine.allocate_memory(requested_layout);
+ auto dummy = engine.allocate_memory(layout{{1}, data_types::u8, format::bfyx});
+ return engine.reinterpret_buffer(*dummy, requested_layout);
+ };
+
+ auto A_mem = allocate(A_layout);
+ auto dt_mem = allocate(dt_layout);
+ auto B_mem = allocate(BC_layout);
+ auto x_mem = allocate(x_layout);
+ auto C_mem = allocate(BC_layout);
+ auto state_mem = allocate(state_layout);
+
+ auto A_data = make_test_values<T>(A_mem->count(), -0.03f, -0.25f);
+ auto dt_data = make_test_values<T>(dt_mem->count(), 0.007f, 0.08f);
+ auto B_data = make_test_values<T>(B_mem->count(), 0.01f);
+ auto x_data = make_test_values<T>(x_mem->count(), 0.015f);
+ auto C_data = make_test_values<T>(C_mem->count(), 0.012f);
+ auto state_data = make_test_values<T>(state_mem->count(), 0.008f);
+
+ if (p.accumulation_test) {
+ A_data.assign(A_data.size(), static_cast<T>(0.f));
+ dt_data.assign(dt_data.size(), static_cast<T>(1.f));
+ B_data.assign(B_data.size(), static_cast<T>(1.f));
+ const float increment = p.precision == ov::element::bf16 ? 0.0546875f : 0.195068359375f;
+ x_data.assign(x_data.size(), static_cast<T>(increment));
+ C_data.assign(C_data.size(), static_cast<T>(1.f));
+ state_data.assign(state_data.size(), static_cast<T>(0.f));
+ }
+
+ const auto set_non_empty = [](const memory::ptr& mem, const auto& values) {
+ if (!values.empty())
+ set_values(mem, values);
+ };
+ set_non_empty(A_mem, A_data);
+ set_non_empty(dt_mem, dt_data);
+ set_non_empty(B_mem, B_data);
+ set_non_empty(x_mem, x_data);
+ set_non_empty(C_mem, C_data);
+ set_non_empty(state_mem, state_data);
+
+ const auto dt_input_layout = p.dynamic_shapes ? layout{ov::PartialShape{-1, -1, p.num_heads}, data_type, format::bfyx} : dt_layout;
+ const auto BC_input_layout = p.dynamic_shapes ? layout{ov::PartialShape{-1, -1, p.num_groups, p.state_size}, data_type, format::bfyx} : BC_layout;
+ const auto x_input_layout = p.dynamic_shapes ? layout{ov::PartialShape{-1, -1, p.num_heads, p.head_dim}, data_type, format::bfyx} : x_layout;
+ const auto state_input_layout =
+ p.dynamic_shapes ? layout{ov::PartialShape{-1, p.num_heads, p.head_dim, p.state_size}, data_type, format::bfyx} : state_layout;
+
+ topology topo;
+ topo.add(input_layout("A", A_layout));
+ topo.add(input_layout("dt", dt_input_layout));
+ topo.add(input_layout("B", BC_input_layout));
+ topo.add(input_layout("x", x_input_layout));
+ topo.add(input_layout("C", BC_input_layout));
+ topo.add(input_layout("state", state_input_layout));
+ std::vector<input_info> ssm_inputs{input_info("A"), input_info("dt"), input_info("B"), input_info("x"), input_info("C"), input_info("state")};
+ if (p.padded_layouts) {
+ OPENVINO_ASSERT(!p.dynamic_shapes, "Padded-layout test requires static input layouts");
+ const auto A_padding = padding(std::vector<ov::Dimension::value_type>{1}, std::vector<ov::Dimension::value_type>{2});
+ topo.add(reorder("A_padded", input_info("A"), A_layout.with_padding(A_padding)));
+ topo.add(reorder("dt_padded", input_info("dt"), dt_layout.with_padding(padding({1, 2, 1}, {2, 1, 3}))));
+ topo.add(reorder("B_padded", input_info("B"), BC_layout.with_padding(padding({1, 2, 1, 3}, {2, 1, 2, 1}))));
+ topo.add(reorder("x_padded", input_info("x"), x_layout.with_padding(padding({1, 2, 1, 3}, {2, 1, 2, 1}))));
+ topo.add(reorder("C_padded", input_info("C"), BC_layout.with_padding(padding({1, 2, 1, 3}, {2, 1, 2, 1}))));
+ topo.add(reorder("state_padded", input_info("state"), state_layout.with_padding(padding({1, 2, 1, 3}, {2, 1, 2, 1}))));
+ ssm_inputs = {input_info("A_padded"),
+ input_info("dt_padded"),
+ input_info("B_padded"),
+ input_info("x_padded"),
+ input_info("C_padded"),
+ input_info("state_padded")};
+ }
+ auto ssm_prim = selective_ssm("selective_ssm", ssm_inputs);
+ if (p.padded_layouts) {
+ ssm_prim.output_paddings = {padding({1, 2, 1, 3}, {2, 1, 2, 1}), padding({1, 2, 1, 3}, {2, 1, 2, 1})};
+ }
+ topo.add(ssm_prim);
+ topo.add(reorder("output", input_info("selective_ssm", 0), format::bfyx, data_type));
+ topo.add(reorder("state_output", input_info("selective_ssm", 1), format::bfyx, data_type));
+
+ ExecutionConfig config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ auto network = get_network(engine, topo, config, get_test_stream_ptr(), p.caching_test);
+ network->set_input_data("A", A_mem);
+ network->set_input_data("dt", dt_mem);
+ network->set_input_data("B", B_mem);
+ network->set_input_data("x", x_mem);
+ network->set_input_data("C", C_mem);
+ network->set_input_data("state", state_mem);
+
+ const float tol = p.precision == ov::element::f32 ? 2e-4f : (p.precision == ov::element::bf16 ? 0.08f : 0.03f);
+ for (int32_t iteration = 0; iteration < p.iterations; iteration++) {
+ auto outputs = network->execute();
+ std::vector<T> ref_output;
+ auto ref_state = state_data;
+ run_reference(A_data,
+ dt_data,
+ B_data,
+ x_data,
+ C_data,
+ ref_state,
+ p.batch,
+ p.seq_len,
+ p.num_heads,
+ p.num_groups,
+ p.head_dim,
+ p.state_size,
+ ref_output);
+
+ if (!ref_output.empty()) {
+ auto out_mem = outputs.at("output").get_memory();
+ ASSERT_NE(out_mem, nullptr);
+ cldnn::mem_lock<T, mem_lock_type::read> out_ptr(out_mem, get_test_stream());
+ for (size_t i = 0; i < ref_output.size(); i++) {
+ const float reference = static_cast<float>(ref_output[i]);
+ const float output_tol = p.precision == ov::element::f32 ? std::max(tol, std::abs(reference) * p.relative_output_tolerance) : tol;
+ ASSERT_NEAR(static_cast<float>(out_ptr[i]), reference, output_tol) << "iteration=" << iteration << ", output idx=" << i;
+ }
+ }
+ if (!ref_state.empty()) {
+ auto state_out_mem = outputs.at("state_output").get_memory();
+ ASSERT_NE(state_out_mem, nullptr);
+ cldnn::mem_lock<T, mem_lock_type::read> state_ptr(state_out_mem, get_test_stream());
+ for (size_t i = 0; i < ref_state.size(); i++) {
+ ASSERT_NEAR(static_cast<float>(state_ptr[i]), static_cast<float>(ref_state[i]), tol) << "iteration=" << iteration << ", state idx=" << i;
+ }
+ }
+ }
+ }
+
+ void execute(const selective_ssm_test_params& p) {
+ if (p.precision == ov::element::f16) {
+ execute_t<ov::float16>(p);
+ } else if (p.precision == ov::element::bf16) {
+ execute_t<ov::bfloat16>(p);
+ } else {
+ execute_t<float>(p);
+ }
+ }
+};
+
+TEST_P(selective_ssm_gpu_test, basic) {
+ execute(GetParam());
+}
+
+INSTANTIATE_TEST_SUITE_P(smoke_selective_ssm_gpu_test,
+ selective_ssm_gpu_test,
+ ::testing::Values(selective_ssm_test_params{1, 4, 4, 2, 8, 8, ov::element::f32, false},
+ selective_ssm_test_params{2, 3, 4, 1, 8, 16, ov::element::f32, false},
+ selective_ssm_test_params{1, 4, 4, 2, 8, 8, ov::element::f16, false},
+ selective_ssm_test_params{1, 3, 2, 1, 4, 16, ov::element::bf16, false},
+ selective_ssm_test_params{1, 8, 64, 1, 64, 128, ov::element::f32, false},
+ selective_ssm_test_params{1, 8, 64, 1, 64, 128, ov::element::f16, false},
+ selective_ssm_test_params{1, 2, 2, 1, 2, 513, ov::element::f32, false},
+ selective_ssm_test_params{2, 3, 4, 2, 4, 16, ov::element::f32, true},
+ selective_ssm_test_params{1, 7, 4, 2, 5, 31, ov::element::f16, true},
+ selective_ssm_test_params{1, 5, 4, 2, 8, 17, ov::element::f32, false, true},
+ selective_ssm_test_params{1, 5, 4, 2, 3, 19, ov::element::f32, false, false, true},
+ selective_ssm_test_params{2, 0, 4, 2, 3, 17, ov::element::f16, true},
+ selective_ssm_test_params{1, 0, 2, 1, 4, 9, ov::element::bf16, false},
+ selective_ssm_test_params{2, 4, 4, 2, 3, 15, ov::element::f32, true, false, false, 3},
+ selective_ssm_test_params{2, 32, 8, 4, 16, 64, ov::element::f16, false},
+ selective_ssm_test_params{1, 128, 4, 2, 8, 32, ov::element::f16, false},
+ selective_ssm_test_params{1, 128, 4, 2, 8, 32, ov::element::bf16, false},
+ selective_ssm_test_params{1, 128, 1, 1, 1, 1, ov::element::f16, false, false, false, 1, true},
+ selective_ssm_test_params{1, 128, 1, 1, 1, 1, ov::element::bf16, false, false, false, 1, true},
+ // Exercise local-memory-driven 4 -> 3 -> 2 -> 1 blocking and tails.
+ selective_ssm_test_params{1, 2, 2, 1, 4, 5000, ov::element::f32, false},
+ selective_ssm_test_params{1, 2, 2, 1, 3, 6000, ov::element::f32, false},
+ selective_ssm_test_params{1, 2, 2, 1, 4, 8192, ov::element::f32, false},
+ // Exceed 128 KiB of FP32 state and exercise the universal global-state fallback.
+ selective_ssm_test_params{1, 2, 1, 1, 1, large_state_size, ov::element::f32, false, false, true, 1, false, 2e-4f},
+ selective_ssm_test_params{1, 2, 1, 1, 1, large_state_size, ov::element::f16, true, true}));
+
+} // namespace
diff --git a/src/plugins/intel_gpu/tests/unit/transformations/preserve_selective_ssm_precision_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/preserve_selective_ssm_precision_test.cpp
new file mode 100644
index 00000000000..7e246611527
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/unit/transformations/preserve_selective_ssm_precision_test.cpp
@@ -0,0 +1,165 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "plugin/transformations/preserve_selective_ssm_precision.hpp"
+
+#include <gtest/gtest.h>
+
+#include "openvino/op/paged_selective_ssm.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/reshape.hpp"
+#include "openvino/op/selective_ssm.hpp"
+#include "openvino/op/shape_of.hpp"
+#include "transformations/rt_info/disable_precision_conversion.hpp"
+
+namespace ov::intel_gpu::test {
+namespace {
+
+void expect_conversion_disabled(const std::shared_ptr<ov::Node>& node) {
+ EXPECT_TRUE(ov::is_conversion_disabled(node, ov::element::dynamic, ov::element::dynamic));
+}
+
+TEST(PreserveSelectiveSSMPrecisionTest, MarksSelectiveSSMAndDataInputs) {
+ const auto A = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{4});
+ const auto dt = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 2, 4});
+ const auto B = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 2, 2, 3});
+ const auto x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 2, 4, 5});
+ const auto C = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 2, 2, 3});
+ const auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 4, 5, 3});
+ const ov::ParameterVector parameters{A, dt, B, x, C, state};
+ const auto ssm = std::make_shared<ov::op::internal::SelectiveSSM>(A, dt, B, x, C, state);
+ const auto model = std::make_shared<ov::Model>(ssm->outputs(), parameters);
+
+ PreserveSelectiveSSMPrecision pass;
+ EXPECT_FALSE(pass.run_on_model(model));
+
+ expect_conversion_disabled(ssm);
+ for (const auto& parameter : parameters) {
+ expect_conversion_disabled(parameter);
+ }
+}
+
+TEST(PreserveSelectiveSSMPrecisionTest, MarksPagedOperationAndAllInputs) {
+ const auto A = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{4});
+ const auto dt = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{2, 4});
+ const auto B = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{2, 2, 3});
+ const auto x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{2, 4, 5});
+ const auto C = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{2, 2, 3});
+ const auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{2, 4, 5, 3});
+ const auto subsequences = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{2});
+ const auto blocks = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{2});
+ const auto block_begins = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{2});
+ const auto processed = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{1});
+ const auto intervals = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{1});
+ const ov::ParameterVector data_parameters{A, dt, B, x, C, state};
+ const ov::ParameterVector metadata_parameters{subsequences, blocks, block_begins, processed, intervals};
+ ov::ParameterVector parameters = data_parameters;
+ parameters.insert(parameters.end(), metadata_parameters.begin(), metadata_parameters.end());
+ const auto ssm = std::make_shared<ov::op::internal::PagedSelectiveSSM>(A, dt, B, x, C, state, subsequences, blocks, block_begins, processed, intervals);
+ const auto model = std::make_shared<ov::Model>(ssm->outputs(), parameters);
+
+ PreserveSelectiveSSMPrecision pass;
+ EXPECT_FALSE(pass.run_on_model(model));
+
+ expect_conversion_disabled(ssm);
+ for (const auto& parameter : data_parameters) {
+ expect_conversion_disabled(parameter);
+ }
+ for (const auto& parameter : metadata_parameters) {
+ expect_conversion_disabled(parameter);
+ }
+}
+
+TEST(PreserveSelectiveSSMPrecisionTest, EliminatesStaticallyEmptySelectiveSSM) {
+ const auto A = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{4});
+ const auto dt = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 0, 4});
+ const auto B = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 0, 2, 3});
+ const auto x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 0, 4, 5});
+ const auto C = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 0, 2, 3});
+ const auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 4, 5, 3});
+ const ov::ParameterVector parameters{A, dt, B, x, C, state};
+ const auto ssm = std::make_shared<ov::op::internal::SelectiveSSM>(A, dt, B, x, C, state);
+ const auto model = std::make_shared<ov::Model>(ssm->outputs(), parameters);
+
+ EliminateEmptySelectiveSSM pass;
+ EXPECT_TRUE(pass.run_on_model(model));
+ EXPECT_EQ(model->get_results()[0]->input_value(0), x->output(0));
+ EXPECT_EQ(model->get_results()[1]->input_value(0), state->output(0));
+}
+
+TEST(PreserveSelectiveSSMPrecisionTest, AddsZeroCopyViewsForSingleDynamicOutputs) {
+ const auto dynamic_1d = ov::PartialShape::dynamic(1);
+ const auto dynamic_3d = ov::PartialShape::dynamic(3);
+ const auto dynamic_4d = ov::PartialShape::dynamic(4);
+ const auto A = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, dynamic_1d);
+ const auto dt = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, dynamic_3d);
+ const auto B = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, dynamic_4d);
+ const auto x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, dynamic_4d);
+ const auto C = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, dynamic_4d);
+ const auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, dynamic_4d);
+ const ov::ParameterVector parameters{A, dt, B, x, C, state};
+ for (size_t output_index : {0, 1}) {
+ const auto ssm = std::make_shared<ov::op::internal::SelectiveSSM>(A, dt, B, x, C, state);
+ const auto model = std::make_shared<ov::Model>(ov::OutputVector{ssm->output(output_index)}, parameters);
+
+ PreserveSingleSelectiveSSMOutput pass;
+ EXPECT_TRUE(pass.run_on_model(model));
+ const auto output_view = ov::as_type_ptr<ov::op::v1::Reshape>(model->get_results()[0]->get_input_node_shared_ptr(0));
+ ASSERT_NE(output_view, nullptr);
+ EXPECT_EQ(output_view->input_value(0), ssm->output(output_index));
+ const auto output_shape = ov::as_type_ptr<ov::op::v3::ShapeOf>(output_view->get_input_node_shared_ptr(1));
+ ASSERT_NE(output_shape, nullptr);
+ EXPECT_EQ(output_shape->input_value(0), ssm->output(output_index));
+ EXPECT_EQ(ssm->output(output_index).get_target_inputs().size(), 2);
+ }
+}
+
+TEST(PreserveSelectiveSSMPrecisionTest, HandlesSingleStaticOutputs) {
+ const auto A = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{4});
+ const auto dt = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 4});
+ const auto B = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 2, 5});
+ const auto x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 4, 6});
+ const auto C = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 2, 5});
+ const auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 4, 6, 5});
+ const ov::ParameterVector parameters{A, dt, B, x, C, state};
+ for (size_t output_index : {0, 1}) {
+ const auto ssm = std::make_shared<ov::op::internal::SelectiveSSM>(A, dt, B, x, C, state);
+ const auto model = std::make_shared<ov::Model>(ov::OutputVector{ssm->output(output_index)}, parameters);
+
+ PreserveSingleSelectiveSSMOutput pass;
+ EXPECT_EQ(pass.run_on_model(model), output_index == 1);
+ if (output_index == 0) {
+ EXPECT_EQ(model->get_results()[0]->input_value(0), ssm->output(0));
+ continue;
+ }
+
+ const auto output_view = ov::as_type_ptr<ov::op::v1::Reshape>(model->get_results()[0]->get_input_node_shared_ptr(0));
+ ASSERT_NE(output_view, nullptr);
+ EXPECT_EQ(output_view->input_value(0), ssm->output(1));
+ const auto output_shape = ov::as_type_ptr<ov::op::v3::ShapeOf>(output_view->get_input_node_shared_ptr(1));
+ ASSERT_NE(output_shape, nullptr);
+ EXPECT_EQ(output_shape->input_value(0), ssm->output(1));
+ EXPECT_EQ(ssm->output(1).get_target_inputs().size(), 2);
+ }
+}
+
+TEST(PreserveSelectiveSSMPrecisionTest, DoesNotAddViewsWhenBothOutputsAreUsed) {
+ const auto A = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(1));
+ const auto dt = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(3));
+ const auto B = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(4));
+ const auto x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(4));
+ const auto C = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(4));
+ const auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(4));
+ const ov::ParameterVector parameters{A, dt, B, x, C, state};
+ const auto ssm = std::make_shared<ov::op::internal::SelectiveSSM>(A, dt, B, x, C, state);
+ const auto model = std::make_shared<ov::Model>(ssm->outputs(), parameters);
+
+ PreserveSingleSelectiveSSMOutput pass;
+ EXPECT_FALSE(pass.run_on_model(model));
+ EXPECT_EQ(model->get_results()[0]->input_value(0), ssm->output(0));
+ EXPECT_EQ(model->get_results()[1]->input_value(0), ssm->output(1));
+}
+
+} // namespace
+} // namespace ov::intel_gpu::test