Skip to content

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

[CPU] Add optimized universal SelectiveSSM reference implementation (#37476)

Nesterov Alexander4965a5f67595
diff --git a/src/common/transformations/tests/common_optimizations/paged_selective_ssm_fusion.cpp b/src/common/transformations/tests/common_optimizations/paged_selective_ssm_fusion.cpp
index 24038ece481..20661d75bd3 100644
--- a/src/common/transformations/tests/common_optimizations/paged_selective_ssm_fusion.cpp
+++ b/src/common/transformations/tests/common_optimizations/paged_selective_ssm_fusion.cpp
@@ -6,6 +6,7 @@
#include <gtest/gtest.h>
+#include <algorithm>
#include <string>
#include <unordered_set>
#include <vector>
@@ -26,6 +27,7 @@
#include "openvino/pass/constant_folding.hpp"
#include "openvino/pass/manager.hpp"
#include "openvino/pass/sdpa_to_paged_attention.hpp"
+#include "transformations/rt_info/keep_const_precision.hpp"
namespace {
@@ -235,6 +237,15 @@ TEST_F(PagedSelectiveSSMFusionTest, FusePagedSSM) {
const auto var_ids_to_remove = run_paged_selective_ssm_fusion(model);
EXPECT_EQ(var_ids_to_remove.count("ssm_var_0"), 1u);
+
+ const auto& parameters = model->get_parameters();
+ const auto state_table =
+ std::find_if(parameters.begin(), parameters.end(), [](const std::shared_ptr<v0::Parameter>& parameter) {
+ return parameter->get_friendly_name() == "selective_ssm_state_table.0";
+ });
+ ASSERT_NE(state_table, parameters.end());
+ EXPECT_TRUE(ov::is_keep_const_precision(*state_table));
+ EXPECT_EQ((*state_table)->get_output_element_type(0), ov::element::dynamic);
}
TEST(PagedSelectiveSSMFusionCount, ReportsConvertedCount) {
@@ -248,4 +259,4 @@ TEST(PagedSelectiveSSMFusionCount, ReportsConvertedCount) {
manager.run_passes(model);
EXPECT_EQ(pass->get_fused_count(), 1u);
-}
\ No newline at end of file
+}
diff --git a/src/plugins/intel_cpu/src/cpu_types.cpp b/src/plugins/intel_cpu/src/cpu_types.cpp
index 87869b397bc..e2888123a73 100644
--- a/src/plugins/intel_cpu/src/cpu_types.cpp
+++ b/src/plugins/intel_cpu/src/cpu_types.cpp
@@ -267,6 +267,8 @@ static const TypeToNameMap& get_type_to_name_tbl() {
{"GatherMatmulCompressed", Type::GatherMatmul},
{"GatedDeltaNet", Type::GatedDeltaNet},
{"PagedGatedDeltaNet", Type::PagedGatedDeltaNet},
+ {"SelectiveSSM", Type::SelectiveSSM},
+ {"PagedSelectiveSSM", Type::PagedSelectiveSSM},
{"PagedCausalConv1D", Type::PagedCausalConv1D}};
return type_to_name_tbl;
}
@@ -406,6 +408,8 @@ std::string NameFromType(const Type type) {
CASE(GatherMatmul);
CASE(GatedDeltaNet);
CASE(PagedGatedDeltaNet);
+ CASE(SelectiveSSM);
+ CASE(PagedSelectiveSSM);
CASE(PagedCausalConv1D);
CASE(Unknown);
}
diff --git a/src/plugins/intel_cpu/src/cpu_types.h b/src/plugins/intel_cpu/src/cpu_types.h
index c8c62da0f07..7127cca5c6d 100644
--- a/src/plugins/intel_cpu/src/cpu_types.h
+++ b/src/plugins/intel_cpu/src/cpu_types.h
@@ -142,6 +142,8 @@ enum class Type : uint8_t {
GatherMatmul,
GatedDeltaNet,
PagedGatedDeltaNet,
+ SelectiveSSM,
+ PagedSelectiveSSM,
PagedCausalConv1D
};
diff --git a/src/plugins/intel_cpu/src/extension.cpp b/src/plugins/intel_cpu/src/extension.cpp
index 88705d388ad..381d3f114c9 100644
--- a/src/plugins/intel_cpu/src/extension.cpp
+++ b/src/plugins/intel_cpu/src/extension.cpp
@@ -46,6 +46,7 @@
#include "openvino/op/paged_attention.hpp"
#include "openvino/op/paged_causal_conv1d.hpp"
#include "openvino/op/paged_gated_delta_net.hpp"
+#include "openvino/op/paged_selective_ssm.hpp"
#include "openvino/op/prelu.hpp"
#include "openvino/op/prior_box.hpp"
#include "openvino/op/prior_box_clustered.hpp"
@@ -58,6 +59,7 @@
#include "openvino/op/relu.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/select.hpp"
+#include "openvino/op/selective_ssm.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/shuffle_channels.hpp"
#include "openvino/op/squeeze.hpp"
@@ -210,6 +212,8 @@ OPENVINO_CREATE_EXTENSIONS(std::vector<ov::Extension::Ptr>({
std::make_shared<ov::OpExtension<ov::op::PagedAttentionExtension>>(),
std::make_shared<ov::OpExtension<ov::op::internal::GatedDeltaNet>>(),
std::make_shared<ov::OpExtension<ov::op::internal::PagedGatedDeltaNet>>(),
+ std::make_shared<ov::OpExtension<ov::op::internal::SelectiveSSM>>(),
+ std::make_shared<ov::OpExtension<ov::op::internal::PagedSelectiveSSM>>(),
std::make_shared<ov::OpExtension<ov::op::internal::PagedCausalConv1D>>(),
// clang-format off
OP_EXTENSION_X64(std::make_shared<ov::OpExtension<ov::intel_cpu::InteractionNode>>())
diff --git a/src/plugins/intel_cpu/src/nodes/executors/common/paged_selective_ssm_executor.cpp b/src/plugins/intel_cpu/src/nodes/executors/common/paged_selective_ssm_executor.cpp
new file mode 100644
index 00000000000..c5e4e7e1f97
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/common/paged_selective_ssm_executor.cpp
@@ -0,0 +1,238 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "paged_selective_ssm_executor.hpp"
+
+#include <algorithm>
+#include <array>
+#include <cstddef>
+#include <cstdint>
+#include <memory>
+#include <utility>
+
+#include "memory_desc/cpu_blocked_memory_desc.h"
+#include "nodes/common/cpu_convert.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/memory_arguments.hpp"
+#include "nodes/executors/paged_selective_ssm_config.hpp"
+#include "nodes/kernels/selective_ssm.hpp"
+#include "onednn/iml_type_mapper.h"
+#include "openvino/core/except.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "utils/general_utils.h"
+
+namespace ov::intel_cpu {
+namespace {
+
+static_assert(sizeof(float) == sizeof(int32_t));
+
+bool is_supported_data_precision(const ov::element::Type& precision) {
+ return any_of(precision, ov::element::f32, ov::element::f16, ov::element::bf16);
+}
+
+bool is_supported_index_precision(const ov::element::Type& precision) {
+ return any_of(precision, ov::element::i32, ov::element::i64);
+}
+
+} // namespace
+
+bool PagedSelectiveSSMExecutor::supports(const PagedSelectiveSSMConfig& config) {
+ const auto data_precision = config.descs.at(ARG_PAGED_SSM_A)->getPrecision();
+ if (!is_supported_data_precision(data_precision)) {
+ return false;
+ }
+ constexpr std::array data_args{
+ ARG_PAGED_SSM_DT,
+ ARG_PAGED_SSM_B,
+ ARG_PAGED_SSM_X,
+ ARG_PAGED_SSM_C,
+ ARG_PAGED_SSM_STATE,
+ ARG_PAGED_SSM_OUT,
+ };
+ if (!std::all_of(data_args.begin(), data_args.end(), [&](const auto arg) {
+ return config.descs.at(arg)->getPrecision() == data_precision;
+ })) {
+ return false;
+ }
+
+ const auto index_precision = config.descs.at(ARG_PAGED_SSM_SUBSEQUENCE_BEGINS)->getPrecision();
+ if (!is_supported_index_precision(index_precision)) {
+ return false;
+ }
+ constexpr std::array index_args{
+ ARG_PAGED_SSM_BLOCK_INDICES,
+ ARG_PAGED_SSM_BLOCK_INDICES_BEGINS,
+ ARG_PAGED_SSM_NUM_PROCESSED_TOKENS,
+ ARG_PAGED_SSM_CACHE_INTERVAL,
+ };
+ return std::all_of(index_args.begin(), index_args.end(), [&](const auto arg) {
+ return config.descs.at(arg)->getPrecision() == index_precision;
+ });
+}
+
+PagedSelectiveSSMExecutor::PagedSelectiveSSMExecutor(const PagedSelectiveSSMAttrs& /*attrs*/,
+ const MemoryArgs& memory,
+ ExecutorContext::CPtr context)
+ : m_context(std::move(context)) {
+ update(memory);
+}
+
+bool PagedSelectiveSSMExecutor::update_scratchpad(const MemoryArgs& memory) {
+ const auto& x_shape = memory.at(ARG_PAGED_SSM_X)->getDescPtr()->getShape();
+ const auto& B_shape = memory.at(ARG_PAGED_SSM_B)->getDescPtr()->getShape();
+ const auto& state_shape = memory.at(ARG_PAGED_SSM_STATE)->getDescPtr()->getShape();
+ const auto& subsequence_shape = memory.at(ARG_PAGED_SSM_SUBSEQUENCE_BEGINS)->getDescPtr()->getShape();
+ if (x_shape.isDynamic() || B_shape.isDynamic() || state_shape.isDynamic() || subsequence_shape.isDynamic()) {
+ return true;
+ }
+ const auto& x_dims = x_shape.getStaticDims();
+ const auto& B_dims = B_shape.getStaticDims();
+ const auto& state_dims = state_shape.getStaticDims();
+ const auto& subsequence_dims = subsequence_shape.getStaticDims();
+ const auto precision = memory.at(ARG_PAGED_SSM_X)->getDescPtr()->getPrecision();
+ OPENVINO_ASSERT(x_dims.size() == 3 && B_dims.size() == 3 && state_dims.size() == 4 &&
+ subsequence_dims.size() == 1 && subsequence_dims[0] >= 1);
+ const auto head_dim = x_dims[2];
+ const auto state_size = state_dims[3];
+ const auto thread_count = static_cast<size_t>(m_context->getCpuParallel()->get_num_worker_threads());
+ const auto sequence_count = subsequence_dims[0] - 1;
+ const auto outer_work = node::kernel::checked_size_product({sequence_count, x_dims[1]}, "outer work items");
+ const auto scratch_head_dim = node::kernel::get_scratch_head_dim(head_dim, state_size, outer_work, thread_count);
+ const auto scratch_elements =
+ node::kernel::checked_size_product({scratch_head_dim, state_size}, "state scratch per worker");
+ const auto state_scratch_elements =
+ node::kernel::checked_size_product({thread_count, scratch_elements}, "state scratch");
+ const auto projection_elements =
+ node::kernel::checked_size_product({B_dims[0], B_dims[1], B_dims[2]}, "B/C projection");
+ const auto projection_scratch_elements =
+ precision == ov::element::f32
+ ? size_t{0}
+ : node::kernel::checked_size_product({size_t{2}, projection_elements}, "B/C projection scratch");
+ const auto metadata_scratch_elements = state_dims[0];
+ if (m_scratch && m_scratch_head_dim == scratch_head_dim && m_scratch_state_size == state_size &&
+ m_state_scratch_elements == state_scratch_elements &&
+ m_projection_scratch_elements == projection_scratch_elements &&
+ m_metadata_scratch_elements == metadata_scratch_elements &&
+ m_cached_projection_elements == projection_elements) {
+ return true;
+ }
+
+ const auto total_scratch_elements =
+ node::kernel::checked_size_sum({state_scratch_elements, projection_scratch_elements, metadata_scratch_elements},
+ "combined state, projection, and metadata scratch");
+ const auto scratch_desc =
+ std::make_shared<CpuBlockedMemoryDesc>(ov::element::f32,
+ ov::intel_cpu::Shape{std::max(size_t{1}, total_scratch_elements)});
+ m_scratch = m_context->getScratchPad()->createScratchPadMem(scratch_desc);
+ m_scratch_head_dim = scratch_head_dim;
+ m_scratch_state_size = state_size;
+ m_state_scratch_elements = state_scratch_elements;
+ m_projection_scratch_elements = projection_scratch_elements;
+ m_metadata_scratch_elements = metadata_scratch_elements;
+ m_cached_projection_elements = projection_elements;
+ return m_scratch != nullptr;
+}
+
+bool PagedSelectiveSSMExecutor::update(const MemoryArgs& memory) {
+ return update_scratchpad(memory);
+}
+
+void PagedSelectiveSSMExecutor::execute(const MemoryArgs& memory) {
+ const auto& B_dims = memory.at(ARG_PAGED_SSM_B)->getStaticDims();
+ const auto& x_dims = memory.at(ARG_PAGED_SSM_X)->getStaticDims();
+ const auto& state_dims = memory.at(ARG_PAGED_SSM_STATE)->getStaticDims();
+ const auto& subsequence_dims = memory.at(ARG_PAGED_SSM_SUBSEQUENCE_BEGINS)->getStaticDims();
+ const auto& block_indices_dims = memory.at(ARG_PAGED_SSM_BLOCK_INDICES)->getStaticDims();
+ const auto& block_begins_dims = memory.at(ARG_PAGED_SSM_BLOCK_INDICES_BEGINS)->getStaticDims();
+ const auto& processed_dims = memory.at(ARG_PAGED_SSM_NUM_PROCESSED_TOKENS)->getStaticDims();
+ const auto& interval_dims = memory.at(ARG_PAGED_SSM_CACHE_INTERVAL)->getStaticDims();
+ OPENVINO_ASSERT(B_dims.size() == 3 && x_dims.size() == 3 && state_dims.size() == 4);
+ OPENVINO_ASSERT(subsequence_dims.size() == 1 && subsequence_dims[0] >= 1 && block_indices_dims.size() == 1);
+ const auto precision = memory.at(ARG_PAGED_SSM_X)->getDescPtr()->getPrecision();
+ const auto projection_elements =
+ node::kernel::checked_size_product({B_dims[0], B_dims[1], B_dims[2]}, "B/C projection");
+ const auto sequence_count = subsequence_dims[0] - 1;
+ const auto thread_count = static_cast<size_t>(m_context->getCpuParallel()->get_num_worker_threads());
+ const auto outer_work = node::kernel::checked_size_product({sequence_count, x_dims[1]}, "outer work items");
+ const auto expected_scratch_head_dim =
+ node::kernel::get_scratch_head_dim(x_dims[2], state_dims[3], outer_work, thread_count);
+ const auto expected_state_scratch_elements =
+ node::kernel::checked_size_product({thread_count, expected_scratch_head_dim, state_dims[3]}, "state scratch");
+ const auto expected_projection_scratch_elements =
+ precision == ov::element::f32
+ ? size_t{0}
+ : node::kernel::checked_size_product({size_t{2}, projection_elements}, "B/C projection scratch");
+ const auto expected_metadata_scratch_elements = state_dims[0];
+ OPENVINO_ASSERT(block_begins_dims.size() == 1 && processed_dims.size() == 1 && interval_dims.size() == 1 &&
+ block_begins_dims[0] == sequence_count + 1 && processed_dims[0] == sequence_count &&
+ interval_dims[0] == sequence_count,
+ "PagedSelectiveSSM metadata tensor lengths are inconsistent.");
+ // The node prepares parameters when input shapes change. Keep the executor self-contained as well: direct users
+ // and a changed worker count must refresh every scratch region before pointer offsets below are calculated.
+ if (!m_scratch || m_scratch_state_size != state_dims[3] || m_scratch_head_dim != expected_scratch_head_dim ||
+ m_state_scratch_elements != expected_state_scratch_elements ||
+ m_projection_scratch_elements != expected_projection_scratch_elements ||
+ m_metadata_scratch_elements != expected_metadata_scratch_elements ||
+ m_cached_projection_elements != projection_elements) {
+ OPENVINO_ASSERT(update_scratchpad(memory));
+ }
+
+ const node::kernel::PagedSelectiveSSMShape shape{x_dims[0],
+ x_dims[1],
+ x_dims[2],
+ B_dims[1],
+ B_dims[2],
+ state_dims[0],
+ block_indices_dims[0],
+ sequence_count};
+ auto* state_scratch = m_scratch->getDataAs<float>();
+ auto* metadata_validation_scratch =
+ reinterpret_cast<int32_t*>(state_scratch + m_state_scratch_elements + m_projection_scratch_elements);
+ const float* converted_B = nullptr;
+ const float* converted_C = nullptr;
+ if (precision != ov::element::f32) {
+ auto* projection_scratch = state_scratch + m_state_scratch_elements;
+ converted_B = projection_scratch;
+ converted_C = projection_scratch + projection_elements;
+ if (projection_elements > 0) {
+ cpu_parallel_convert(memory.at(ARG_PAGED_SSM_B)->getData(),
+ projection_scratch,
+ precision,
+ ov::element::f32,
+ projection_elements);
+ cpu_parallel_convert(memory.at(ARG_PAGED_SSM_C)->getData(),
+ projection_scratch + projection_elements,
+ precision,
+ ov::element::f32,
+ projection_elements);
+ }
+ }
+ node::kernel::paged_selective_ssm(memory.at(ARG_PAGED_SSM_A)->getData(),
+ memory.at(ARG_PAGED_SSM_DT)->getData(),
+ memory.at(ARG_PAGED_SSM_B)->getData(),
+ memory.at(ARG_PAGED_SSM_X)->getData(),
+ memory.at(ARG_PAGED_SSM_C)->getData(),
+ memory.at(ARG_PAGED_SSM_STATE)->getData(),
+ memory.at(ARG_PAGED_SSM_SUBSEQUENCE_BEGINS)->getData(),
+ memory.at(ARG_PAGED_SSM_BLOCK_INDICES)->getData(),
+ memory.at(ARG_PAGED_SSM_BLOCK_INDICES_BEGINS)->getData(),
+ memory.at(ARG_PAGED_SSM_NUM_PROCESSED_TOKENS)->getData(),
+ memory.at(ARG_PAGED_SSM_CACHE_INTERVAL)->getData(),
+ memory.at(ARG_PAGED_SSM_OUT)->getData(),
+ shape,
+ precision,
+ memory.at(ARG_PAGED_SSM_SUBSEQUENCE_BEGINS)->getDescPtr()->getPrecision(),
+ state_scratch,
+ m_scratch_head_dim,
+ metadata_validation_scratch,
+ m_context->getCpuParallel(),
+ converted_B,
+ converted_C);
+}
+
+impl_desc_type PagedSelectiveSSMExecutor::implType() const {
+ return impl_desc_type::ref_any;
+}
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/common/paged_selective_ssm_executor.hpp b/src/plugins/intel_cpu/src/nodes/executors/common/paged_selective_ssm_executor.hpp
new file mode 100644
index 00000000000..4c1c40ad539
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/common/paged_selective_ssm_executor.hpp
@@ -0,0 +1,40 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstddef>
+
+#include "cpu_memory.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/paged_selective_ssm_config.hpp"
+
+namespace ov::intel_cpu {
+
+class PagedSelectiveSSMExecutor : public Executor {
+public:
+ static bool supports(const PagedSelectiveSSMConfig& config);
+
+ PagedSelectiveSSMExecutor(const PagedSelectiveSSMAttrs& attrs,
+ const MemoryArgs& memory,
+ ExecutorContext::CPtr context);
+
+ bool update(const MemoryArgs& memory) override;
+ void execute(const MemoryArgs& memory) override;
+ [[nodiscard]] impl_desc_type implType() const override;
+
+private:
+ bool update_scratchpad(const MemoryArgs& memory);
+
+ ExecutorContext::CPtr m_context;
+ MemoryPtr m_scratch;
+ size_t m_scratch_head_dim = 0;
+ size_t m_scratch_state_size = 0;
+ size_t m_state_scratch_elements = 0;
+ size_t m_projection_scratch_elements = 0;
+ size_t m_metadata_scratch_elements = 0;
+ size_t m_cached_projection_elements = 0;
+};
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/common/selective_ssm_executor.cpp b/src/plugins/intel_cpu/src/nodes/executors/common/selective_ssm_executor.cpp
new file mode 100644
index 00000000000..c2ee121b929
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/common/selective_ssm_executor.cpp
@@ -0,0 +1,183 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "selective_ssm_executor.hpp"
+
+#include <algorithm>
+#include <array>
+#include <cstddef>
+#include <memory>
+#include <utility>
+
+#include "memory_desc/cpu_blocked_memory_desc.h"
+#include "nodes/common/cpu_convert.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/memory_arguments.hpp"
+#include "nodes/executors/selective_ssm_config.hpp"
+#include "nodes/kernels/selective_ssm.hpp"
+#include "onednn/iml_type_mapper.h"
+#include "openvino/core/except.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "utils/general_utils.h"
+
+namespace ov::intel_cpu {
+namespace {
+
+bool is_supported_precision(const ov::element::Type& precision) {
+ return any_of(precision, ov::element::f32, ov::element::f16, ov::element::bf16);
+}
+
+} // namespace
+
+bool SelectiveSSMExecutor::supports(const SelectiveSSMConfig& config) {
+ const auto precision = config.descs.at(ARG_SSM_A)->getPrecision();
+ if (!is_supported_precision(precision)) {
+ return false;
+ }
+ constexpr std::array args{
+ ARG_SSM_DT,
+ ARG_SSM_B,
+ ARG_SSM_X,
+ ARG_SSM_C,
+ ARG_SSM_STATE,
+ ARG_SSM_OUT,
+ ARG_SSM_OUT_STATE,
+ };
+ return std::all_of(args.begin(), args.end(), [&](const auto arg) {
+ return config.descs.at(arg)->getPrecision() == precision;
+ });
+}
+
+SelectiveSSMExecutor::SelectiveSSMExecutor(const SelectiveSSMAttrs& /*attrs*/,
+ const MemoryArgs& memory,
+ ExecutorContext::CPtr context)
+ : m_context(std::move(context)) {
+ update(memory);
+}
+
+bool SelectiveSSMExecutor::update_scratchpad(const MemoryArgs& memory) {
+ const auto& x_shape = memory.at(ARG_SSM_X)->getDescPtr()->getShape();
+ const auto& B_shape = memory.at(ARG_SSM_B)->getDescPtr()->getShape();
+ const auto& state_shape = memory.at(ARG_SSM_STATE)->getDescPtr()->getShape();
+ if (x_shape.isDynamic() || B_shape.isDynamic() || state_shape.isDynamic()) {
+ return true;
+ }
+ const auto& x_dims = x_shape.getStaticDims();
+ const auto& B_dims = B_shape.getStaticDims();
+ const auto& state_dims = state_shape.getStaticDims();
+ const auto precision = memory.at(ARG_SSM_X)->getDescPtr()->getPrecision();
+ OPENVINO_ASSERT(x_dims.size() == 4 && B_dims.size() == 4 && state_dims.size() == 4);
+ const auto head_dim = x_dims[3];
+ const auto state_size = state_dims[3];
+ const auto thread_count = static_cast<size_t>(m_context->getCpuParallel()->get_num_worker_threads());
+ const auto outer_work = node::kernel::checked_size_product({x_dims[0], x_dims[2]}, "outer work items");
+ const auto scratch_head_dim = node::kernel::get_scratch_head_dim(head_dim, state_size, outer_work, thread_count);
+ const auto needs_state_scratch = precision != ov::element::f32;
+ const auto state_scratch_elements =
+ needs_state_scratch
+ ? node::kernel::checked_size_product({thread_count, scratch_head_dim, state_size}, "state scratch")
+ : size_t{0};
+ const auto projection_elements =
+ node::kernel::checked_size_product({B_dims[0], B_dims[1], B_dims[2], B_dims[3]}, "B/C projection");
+ const auto projection_scratch_elements =
+ precision == ov::element::f32
+ ? size_t{0}
+ : node::kernel::checked_size_product({size_t{2}, projection_elements}, "B/C projection scratch");
+ if (m_scratch && m_scratch_head_dim == scratch_head_dim && m_scratch_state_size == state_size &&
+ m_state_scratch_elements == state_scratch_elements &&
+ m_projection_scratch_elements == projection_scratch_elements &&
+ m_cached_projection_elements == projection_elements) {
+ return true;
+ }
+
+ const auto total_scratch_elements =
+ node::kernel::checked_size_sum({state_scratch_elements, projection_scratch_elements},
+ "combined state and B/C projection scratch");
+ const auto desc =
+ std::make_shared<CpuBlockedMemoryDesc>(ov::element::f32,
+ ov::intel_cpu::Shape{std::max(size_t{1}, total_scratch_elements)});
+ m_scratch = m_context->getScratchPad()->createScratchPadMem(desc);
+ m_scratch_head_dim = scratch_head_dim;
+ m_scratch_state_size = state_size;
+ m_state_scratch_elements = state_scratch_elements;
+ m_projection_scratch_elements = projection_scratch_elements;
+ m_cached_projection_elements = projection_elements;
+ return m_scratch != nullptr;
+}
+
+bool SelectiveSSMExecutor::update(const MemoryArgs& memory) {
+ return update_scratchpad(memory);
+}
+
+void SelectiveSSMExecutor::execute(const MemoryArgs& memory) {
+ const auto& x_dims = memory.at(ARG_SSM_X)->getStaticDims();
+ const auto& B_dims = memory.at(ARG_SSM_B)->getStaticDims();
+ const auto& state_dims = memory.at(ARG_SSM_STATE)->getStaticDims();
+ OPENVINO_ASSERT(x_dims.size() == 4 && B_dims.size() == 4 && state_dims.size() == 4);
+ const auto precision = memory.at(ARG_SSM_X)->getDescPtr()->getPrecision();
+ const auto projection_elements =
+ node::kernel::checked_size_product({B_dims[0], B_dims[1], B_dims[2], B_dims[3]}, "B/C projection");
+ const auto thread_count = static_cast<size_t>(m_context->getCpuParallel()->get_num_worker_threads());
+ const auto outer_work = node::kernel::checked_size_product({x_dims[0], x_dims[2]}, "outer work items");
+ const auto expected_scratch_head_dim =
+ node::kernel::get_scratch_head_dim(x_dims[3], state_dims[3], outer_work, thread_count);
+ const auto expected_state_scratch_elements =
+ precision != ov::element::f32
+ ? node::kernel::checked_size_product({thread_count, expected_scratch_head_dim, state_dims[3]},
+ "state scratch")
+ : size_t{0};
+ const auto expected_projection_scratch_elements =
+ precision == ov::element::f32
+ ? size_t{0}
+ : node::kernel::checked_size_product({size_t{2}, projection_elements}, "B/C projection scratch");
+ if (!m_scratch || m_scratch_state_size != state_dims[3] || m_scratch_head_dim != expected_scratch_head_dim ||
+ m_state_scratch_elements != expected_state_scratch_elements ||
+ m_projection_scratch_elements != expected_projection_scratch_elements ||
+ m_cached_projection_elements != projection_elements) {
+ OPENVINO_ASSERT(update_scratchpad(memory));
+ }
+
+ node::kernel::SelectiveSSMShape shape{x_dims[0], x_dims[1], x_dims[2], x_dims[3], B_dims[2], B_dims[3]};
+ auto* state_scratch = m_scratch->getDataAs<float>();
+ const float* converted_B = nullptr;
+ const float* converted_C = nullptr;
+ if (precision != ov::element::f32) {
+ auto* projection_scratch = state_scratch + m_state_scratch_elements;
+ converted_B = projection_scratch;
+ converted_C = projection_scratch + projection_elements;
+ if (projection_elements > 0) {
+ cpu_parallel_convert(memory.at(ARG_SSM_B)->getData(),
+ projection_scratch,
+ precision,
+ ov::element::f32,
+ projection_elements);
+ cpu_parallel_convert(memory.at(ARG_SSM_C)->getData(),
+ projection_scratch + projection_elements,
+ precision,
+ ov::element::f32,
+ projection_elements);
+ }
+ }
+ node::kernel::selective_ssm(memory.at(ARG_SSM_A)->getData(),
+ memory.at(ARG_SSM_DT)->getData(),
+ memory.at(ARG_SSM_B)->getData(),
+ memory.at(ARG_SSM_X)->getData(),
+ memory.at(ARG_SSM_C)->getData(),
+ memory.at(ARG_SSM_STATE)->getData(),
+ memory.at(ARG_SSM_OUT)->getData(),
+ memory.at(ARG_SSM_OUT_STATE)->getData(),
+ shape,
+ precision,
+ state_scratch,
+ m_scratch_head_dim,
+ m_context->getCpuParallel(),
+ converted_B,
+ converted_C);
+}
+
+impl_desc_type SelectiveSSMExecutor::implType() const {
+ return impl_desc_type::ref_any;
+}
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/common/selective_ssm_executor.hpp b/src/plugins/intel_cpu/src/nodes/executors/common/selective_ssm_executor.hpp
new file mode 100644
index 00000000000..08d0ca63602
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/common/selective_ssm_executor.hpp
@@ -0,0 +1,37 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstddef>
+
+#include "cpu_memory.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/selective_ssm_config.hpp"
+
+namespace ov::intel_cpu {
+
+class SelectiveSSMExecutor : public Executor {
+public:
+ static bool supports(const SelectiveSSMConfig& config);
+
+ SelectiveSSMExecutor(const SelectiveSSMAttrs& attrs, const MemoryArgs& memory, ExecutorContext::CPtr context);
+
+ bool update(const MemoryArgs& memory) override;
+ void execute(const MemoryArgs& memory) override;
+ [[nodiscard]] impl_desc_type implType() const override;
+
+private:
+ bool update_scratchpad(const MemoryArgs& memory);
+
+ ExecutorContext::CPtr m_context;
+ MemoryPtr m_scratch;
+ size_t m_scratch_head_dim = 0;
+ size_t m_scratch_state_size = 0;
+ size_t m_state_scratch_elements = 0;
+ size_t m_projection_scratch_elements = 0;
+ size_t m_cached_projection_elements = 0;
+};
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/executor.hpp b/src/plugins/intel_cpu/src/nodes/executors/executor.hpp
index 13fc179af57..6c9c5d071b4 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/executor.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/executor.hpp
@@ -41,7 +41,16 @@ enum class ExecutorType : uint8_t {
Kleidiai,
};
-enum class OperationType : uint8_t { FullyConnected, MatMul, Convolution, Eltwise, GatherMatmul, GatedDeltaNet };
+enum class OperationType : uint8_t {
+ FullyConnected,
+ MatMul,
+ Convolution,
+ Eltwise,
+ GatherMatmul,
+ GatedDeltaNet,
+ SelectiveSSM,
+ PagedSelectiveSSM
+};
std::string ExecutorTypeToString(ExecutorType type);
ExecutorType ExecutorTypeFromString(const std::string& typeStr);
diff --git a/src/plugins/intel_cpu/src/nodes/executors/implementations.hpp b/src/plugins/intel_cpu/src/nodes/executors/implementations.hpp
index 9d93acde6c4..60901cd0691 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/implementations.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/implementations.hpp
@@ -14,6 +14,8 @@
#include "nodes/executors/gated_delta_net_config.hpp"
#include "nodes/executors/gathermatmul_config.hpp"
#include "nodes/executors/matmul_config.hpp"
+#include "nodes/executors/paged_selective_ssm_config.hpp"
+#include "nodes/executors/selective_ssm_config.hpp"
namespace ov::intel_cpu {
@@ -47,6 +49,14 @@ const std::vector<ExecutorImplementation<GatherMatmulAttrs>>& getImplementations
template <>
const std::vector<ExecutorImplementation<GatedDeltaNetAttrs>>& getImplementations();
+// SelectiveSSM
+template <>
+const std::vector<ExecutorImplementation<SelectiveSSMAttrs>>& getImplementations();
+
+// PagedSelectiveSSM
+template <>
+const std::vector<ExecutorImplementation<PagedSelectiveSSMAttrs>>& getImplementations();
+
// MatMul
template <>
const std::vector<ExecutorImplementation<MatMulAttrs>>& getImplementations();
diff --git a/src/plugins/intel_cpu/src/nodes/executors/memory_arguments.hpp b/src/plugins/intel_cpu/src/nodes/executors/memory_arguments.hpp
index d53b7ebe2c5..0ce9b54391b 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/memory_arguments.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/memory_arguments.hpp
@@ -14,17 +14,18 @@ using MemoryDescArgs = std::unordered_map<int, MemoryDescPtr>;
using MemoryArgs = std::unordered_map<int, MemoryPtr>;
// basic inputs
-#define ARG_SRC_0 1
-#define ARG_SRC ARG_SRC_0
-#define ARG_SRC_1 2
-#define ARG_SRC_2 3
-#define ARG_SRC_3 4
-#define ARG_SRC_4 5
-#define ARG_SRC_5 6
-#define ARG_SRC_6 7
-#define ARG_SRC_7 8
-#define ARG_SRC_8 9
-#define ARG_SRC_9 10
+#define ARG_SRC_0 1
+#define ARG_SRC ARG_SRC_0
+#define ARG_SRC_1 2
+#define ARG_SRC_2 3
+#define ARG_SRC_3 4
+#define ARG_SRC_4 5
+#define ARG_SRC_5 6
+#define ARG_SRC_6 7
+#define ARG_SRC_7 8
+#define ARG_SRC_8 9
+#define ARG_SRC_9 10
+#define ARG_SRC_10 11
#define ARG_SUM ARG_SRC_2
#define ARG_DST_0 17
diff --git a/src/plugins/intel_cpu/src/nodes/executors/paged_selective_ssm_config.hpp b/src/plugins/intel_cpu/src/nodes/executors/paged_selective_ssm_config.hpp
new file mode 100644
index 00000000000..1783634b67f
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/paged_selective_ssm_config.hpp
@@ -0,0 +1,33 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstdint>
+
+#include "executor_config.hpp"
+#include "nodes/executors/memory_arguments.hpp"
+
+namespace ov::intel_cpu {
+
+struct PagedSelectiveSSMAttrs {};
+
+using PagedSelectiveSSMConfig = executor::Config<PagedSelectiveSSMAttrs>;
+
+enum PagedSelectiveSSMArgId : uint8_t {
+ ARG_PAGED_SSM_A = ARG_SRC_0,
+ ARG_PAGED_SSM_DT = ARG_SRC_1,
+ ARG_PAGED_SSM_B = ARG_SRC_2,
+ ARG_PAGED_SSM_X = ARG_SRC_3,
+ ARG_PAGED_SSM_C = ARG_SRC_4,
+ ARG_PAGED_SSM_STATE = ARG_SRC_5,
+ ARG_PAGED_SSM_SUBSEQUENCE_BEGINS = ARG_SRC_6,
+ ARG_PAGED_SSM_BLOCK_INDICES = ARG_SRC_7,
+ ARG_PAGED_SSM_BLOCK_INDICES_BEGINS = ARG_SRC_8,
+ ARG_PAGED_SSM_NUM_PROCESSED_TOKENS = ARG_SRC_9,
+ ARG_PAGED_SSM_CACHE_INTERVAL = ARG_SRC_10,
+ ARG_PAGED_SSM_OUT = ARG_DST_0,
+};
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/paged_selective_ssm_implementations.cpp b/src/plugins/intel_cpu/src/nodes/executors/paged_selective_ssm_implementations.cpp
new file mode 100644
index 00000000000..e7a449a13b9
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/paged_selective_ssm_implementations.cpp
@@ -0,0 +1,38 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <vector>
+
+#include "nodes/executors/common/paged_selective_ssm_executor.hpp"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/executor_implementation.hpp"
+#include "nodes/executors/implementation_utils.hpp"
+#include "nodes/executors/implementations.hpp"
+#include "nodes/executors/paged_selective_ssm_config.hpp"
+#include "utils/arch_macros.h"
+
+namespace ov::intel_cpu {
+
+// clang-format off
+template <>
+const std::vector<ExecutorImplementation<PagedSelectiveSSMAttrs>>& getImplementations() {
+ static const std::vector<ExecutorImplementation<PagedSelectiveSSMAttrs>> implementations {
+ OV_CPU_INSTANCE_COMMON(
+ "paged_selective_ssm_common_executor",
+ ExecutorType::Common,
+ OperationType::PagedSelectiveSSM,
+ [](const PagedSelectiveSSMConfig& config) -> bool {
+ return PagedSelectiveSSMExecutor::supports(config);
+ },
+ HasNoOptimalConfig<PagedSelectiveSSMAttrs>{},
+ AcceptsAnyShape<PagedSelectiveSSMAttrs>,
+ CreateDefault<PagedSelectiveSSMExecutor, PagedSelectiveSSMAttrs>{}
+ )
+ };
+
+ return implementations;
+}
+// clang-format on
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/selective_ssm_config.hpp b/src/plugins/intel_cpu/src/nodes/executors/selective_ssm_config.hpp
new file mode 100644
index 00000000000..28b5c13f70e
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/selective_ssm_config.hpp
@@ -0,0 +1,29 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstdint>
+
+#include "executor_config.hpp"
+#include "nodes/executors/memory_arguments.hpp"
+
+namespace ov::intel_cpu {
+
+struct SelectiveSSMAttrs {};
+
+using SelectiveSSMConfig = executor::Config<SelectiveSSMAttrs>;
+
+enum SelectiveSSMArgId : uint8_t {
+ ARG_SSM_A = ARG_SRC_0,
+ ARG_SSM_DT = ARG_SRC_1,
+ ARG_SSM_B = ARG_SRC_2,
+ ARG_SSM_X = ARG_SRC_3,
+ ARG_SSM_C = ARG_SRC_4,
+ ARG_SSM_STATE = ARG_SRC_5,
+ ARG_SSM_OUT = ARG_DST_0,
+ ARG_SSM_OUT_STATE = ARG_DST_0 + 1,
+};
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/selective_ssm_implementations.cpp b/src/plugins/intel_cpu/src/nodes/executors/selective_ssm_implementations.cpp
new file mode 100644
index 00000000000..5681be72d91
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/selective_ssm_implementations.cpp
@@ -0,0 +1,38 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <vector>
+
+#include "nodes/executors/common/selective_ssm_executor.hpp"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/executor_implementation.hpp"
+#include "nodes/executors/implementation_utils.hpp"
+#include "nodes/executors/implementations.hpp"
+#include "nodes/executors/selective_ssm_config.hpp"
+#include "utils/arch_macros.h"
+
+namespace ov::intel_cpu {
+
+// clang-format off
+template <>
+const std::vector<ExecutorImplementation<SelectiveSSMAttrs>>& getImplementations() {
+ static const std::vector<ExecutorImplementation<SelectiveSSMAttrs>> implementations {
+ OV_CPU_INSTANCE_COMMON(
+ "selective_ssm_common_executor",
+ ExecutorType::Common,
+ OperationType::SelectiveSSM,
+ [](const SelectiveSSMConfig& config) -> bool {
+ return SelectiveSSMExecutor::supports(config);
+ },
+ HasNoOptimalConfig<SelectiveSSMAttrs>{},
+ AcceptsAnyShape<SelectiveSSMAttrs>,
+ CreateDefault<SelectiveSSMExecutor, SelectiveSSMAttrs>{}
+ )
+ };
+
+ return implementations;
+}
+// clang-format on
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/selective_ssm.cpp b/src/plugins/intel_cpu/src/nodes/kernels/selective_ssm.cpp
new file mode 100644
index 00000000000..2e030da74d5
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/kernels/selective_ssm.cpp
@@ -0,0 +1,660 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "selective_ssm.hpp"
+
+#include <algorithm>
+#include <cmath>
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+#include <initializer_list>
+#include <limits>
+#include <type_traits>
+
+#include "cpu_parallel.hpp"
+#include "nodes/kernels/scaled_attn/common.hpp"
+#include "openvino/core/except.hpp"
+#include "openvino/core/parallel.hpp"
+#include "openvino/core/type/bfloat16.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "openvino/core/type/float16.hpp"
+#include "openvino/util/math_util.hpp"
+#include "utils/general_utils.h"
+#include "utils/plain_tensor.hpp"
+
+namespace ov::intel_cpu::node::kernel {
+namespace {
+
+// Bound the portable executor's FP32 recurrent-state scratch independently of the CPU cache topology.
+// Machine-specific executors may use a cache-aware tiling policy instead.
+constexpr size_t max_scratch_bytes_per_worker = 32 * 1024;
+
+template <typename DstT, typename SrcT>
+inline void copy_convert(DstT* dst, const SrcT* src, size_t count) {
+ if constexpr (std::is_same_v<DstT, SrcT>) {
+ if (dst != src) {
+ std::memcpy(dst, src, count * sizeof(DstT));
+ }
+ } else {
+ ov::Extensions::Cpu::XARCH::cvt_copy(dst, const_cast<SrcT*>(src), 1, count, count, count);
+ }
+}
+
+template <typename ProjectionT>
+inline float update_state_and_reduce(float* state,
+ const ProjectionT* input_projection,
+ const ProjectionT* output_projection,
+ float decay,
+ float input_scale,
+ size_t state_size) {
+ for (size_t n = 0; n < state_size; ++n) {
+ state[n] = state[n] * decay + static_cast<float>(input_projection[n]) * input_scale;
+ }
+
+ if constexpr (std::is_same_v<ProjectionT, float>) {
+ return ov::Extensions::Cpu::XARCH::dot_product(state,
+ output_projection,
+ state_size,
+ nullptr,
+ nullptr,
+ nullptr,
+ 0);
+ }
+
+ float result = 0.F;
+ for (size_t n = 0; n < state_size; ++n) {
+ result += state[n] * static_cast<float>(output_projection[n]);
+ }
+ return result;
+}
+
+template <typename DataT, typename ProjectionT>
+void selective_ssm_typed(const DataT* A,
+ const DataT* dt,
+ const ProjectionT* B,
+ const DataT* x,
+ const ProjectionT* C,
+ const DataT* recurrent_state,
+ DataT* output,
+ DataT* output_recurrent_state,
+ const SelectiveSSMShape& shape,
+ float* state_scratch,
+ size_t scratch_head_dim,
+ const CpuParallelPtr& cpu_parallel) {
+ const auto batch_state_stride =
+ checked_size_product({shape.num_heads, shape.head_dim, shape.state_size}, "recurrent state batch");
+ const auto head_state_stride = checked_size_product({shape.head_dim, shape.state_size}, "recurrent state head");
+ const auto scratch_stride = checked_size_product({scratch_head_dim, shape.state_size}, "state scratch");
+ const auto heads_per_group = shape.num_heads / shape.num_groups;
+ const auto p_block_count = ov::util::ceil_div(shape.head_dim, scratch_head_dim);
+
+ cpu_parallel
+ ->parallel_for3d(shape.batch_size, shape.num_heads, p_block_count, [&](size_t batch, size_t head, size_t pb) {
+ const auto p_begin = pb * scratch_head_dim;
+ const auto p_end = p_begin + std::min(scratch_head_dim, shape.head_dim - p_begin);
+ const auto p_count = p_end - p_begin;
+ const auto group = head / heads_per_group;
+ const auto state_base = batch * batch_state_stride + head * head_state_stride + p_begin * shape.state_size;
+ float* local_state = nullptr;
+ if constexpr (std::is_same_v<DataT, float>) {
+ // FP32 can use the final state as its working buffer. Lower precisions retain FP32 scratch to avoid
+ // quantizing the recurrent state at every token.
+ local_state = output_recurrent_state + state_base;
+ } else {
+ local_state = state_scratch + static_cast<size_t>(parallel_get_thread_num()) * scratch_stride;
+ }
+
+ const auto state_elements = p_count * shape.state_size;
+ copy_convert(local_state, recurrent_state + state_base, state_elements);
+
+ const auto a_head = static_cast<float>(A[head]);
+ auto token_head = (batch * shape.sequence_length) * shape.num_heads + head;
+ auto projection_base = ((batch * shape.sequence_length) * shape.num_groups + group) * shape.state_size;
+ auto x_base = token_head * shape.head_dim + p_begin;
+ const auto projection_stride = shape.num_groups * shape.state_size;
+ const auto x_stride = shape.num_heads * shape.head_dim;
+
+ for (size_t token = 0; token < shape.sequence_length; ++token) {
+ const auto delta = static_cast<float>(dt[token_head]);
+ const float decay = std::exp(a_head * delta);
+ const auto* input_projection = B + projection_base;
+ const auto* output_projection = C + projection_base;
+ for (size_t p = 0; p < p_count; ++p) {
+ auto* state = local_state + p * shape.state_size;
+ const float input_scale = static_cast<float>(x[x_base + p]) * delta;
+ const float result = update_state_and_reduce(state,
+ input_projection,
+ output_projection,
+ decay,
+ input_scale,
+ shape.state_size);
+ output[x_base + p] = static_cast<DataT>(result);
+ }
+
+ token_head += shape.num_heads;
+ projection_base += projection_stride;
+ x_base += x_stride;
+ }
+
+ if constexpr (!std::is_same_v<DataT, float>) {
+ copy_convert(output_recurrent_state + state_base, local_state, state_elements);
+ }
+ });
+}
+
+struct PagedMetadata {
+ ov::intel_cpu::PlainTensor subsequence_begins;
+ ov::intel_cpu::PlainTensor block_indices;
+ ov::intel_cpu::PlainTensor block_indices_begins;
+ ov::intel_cpu::PlainTensor num_processed_tokens;
+ ov::intel_cpu::PlainTensor cache_interval;
+};
+
+int64_t index_at(const ov::intel_cpu::PlainTensor& tensor, size_t index) {
+ return tensor.get_precision() == ov::element::i64 ? tensor.ptr<int64_t>()[index] : tensor.ptr<int32_t>()[index];
+}
+
+ov::intel_cpu::PlainTensor make_index_tensor(const void* data, size_t count, const ov::element::Type& index_precision) {
+ ov::intel_cpu::PlainTensor tensor;
+ tensor.resize({count}, index_precision.size(), index_precision, const_cast<void*>(data));
+ return tensor;
+}
+
+PagedMetadata make_paged_metadata(const void* subsequence_begins,
+ const void* block_indices,
+ const void* block_indices_begins,
+ const void* num_processed_tokens,
+ const void* cache_interval,
+ const ov::element::Type& index_precision,
+ const PagedSelectiveSSMShape& shape) {
+ OPENVINO_ASSERT(any_of(index_precision, ov::element::i32, ov::element::i64),
+ "PagedSelectiveSSM supports only i32/i64 metadata, got ",
+ index_precision,
+ ".");
+ const auto sequence_offsets_count = checked_size_sum({shape.sequence_count, size_t{1}}, "metadata offsets");
+ return {make_index_tensor(subsequence_begins, sequence_offsets_count, index_precision),
+ make_index_tensor(block_indices, shape.logical_block_count, index_precision),
+ make_index_tensor(block_indices_begins, sequence_offsets_count, index_precision),
+ make_index_tensor(num_processed_tokens, shape.sequence_count, index_precision),
+ make_index_tensor(cache_interval, shape.sequence_count, index_precision)};
+}
+
+size_t checked_index(int64_t value, size_t limit, const char* name, size_t position) {
+ OPENVINO_ASSERT(value >= 0, "PagedSelectiveSSM: ", name, "[", position, "] must be non-negative, got ", value, ".");
+ const auto result = static_cast<uint64_t>(value);
+ OPENVINO_ASSERT(result < limit,
+ "PagedSelectiveSSM: ",
+ name,
+ "[",
+ position,
+ "] is out of range: ",
+ value,
+ " not in [0, ",
+ limit,
+ ").");
+ return static_cast<size_t>(result);
+}
+
+void validate_paged_metadata(const PagedMetadata& metadata,
+ const PagedSelectiveSSMShape& shape,
+ int32_t* block_owners) {
+ // Metadata controls pointer arithmetic and parallel cache writes and may change on every execution. Validate it
+ // here, limiting the per-sequence work below to the read block and the writable blocks the kernel will consume.
+ const auto& subsequence_begins = metadata.subsequence_begins;
+ const auto& block_indices = metadata.block_indices;
+ const auto& block_indices_begins = metadata.block_indices_begins;
+ const auto& num_processed_tokens = metadata.num_processed_tokens;
+ const auto& cache_interval = metadata.cache_interval;
+ OPENVINO_ASSERT(shape.sequence_count <= static_cast<size_t>(std::numeric_limits<int32_t>::max()),
+ "PagedSelectiveSSM supports at most INT32_MAX sequences.");
+ OPENVINO_ASSERT(shape.physical_block_count == 0 || block_owners != nullptr,
+ "PagedSelectiveSSM requires block-owner scratch for a non-empty state table.");
+
+ OPENVINO_ASSERT(index_at(subsequence_begins, 0) == 0,
+ "PagedSelectiveSSM: subsequence_begins[0] must be 0, got ",
+ index_at(subsequence_begins, 0),
+ ".");
+ OPENVINO_ASSERT(index_at(block_indices_begins, 0) == 0,
+ "PagedSelectiveSSM: block_indices_begins[0] must be 0, got ",
+ index_at(block_indices_begins, 0),
+ ".");
+ const auto final_token_offset = index_at(subsequence_begins, shape.sequence_count);
+ OPENVINO_ASSERT(static_cast<uint64_t>(final_token_offset) == shape.token_count,
+ "PagedSelectiveSSM: the last subsequence offset must equal token_count (",
+ shape.token_count,
+ "), got ",
+ final_token_offset,
+ ".");
+ const auto final_block_offset = index_at(block_indices_begins, shape.sequence_count);
+ OPENVINO_ASSERT(static_cast<uint64_t>(final_block_offset) == shape.logical_block_count,
+ "PagedSelectiveSSM: the last block offset must equal logical_block_count (",
+ shape.logical_block_count,
+ "), got ",
+ final_block_offset,
+ ".");
+
+ if (shape.physical_block_count > 0) {
+ std::fill(block_owners, block_owners + shape.physical_block_count, int32_t{-1});
+ }
+
+ // Validate only the metadata consumed by each sequence and register its writable blocks in the same pass.
+ for (size_t s = 0; s < shape.sequence_count; ++s) {
+ const auto token_begin = index_at(subsequence_begins, s);
+ const auto token_end = index_at(subsequence_begins, s + 1);
+ const auto block_begin_value = index_at(block_indices_begins, s);
+ const auto block_end_value = index_at(block_indices_begins, s + 1);
+ const auto processed_tokens = index_at(num_processed_tokens, s);
+ OPENVINO_ASSERT(token_begin >= 0 && token_end >= token_begin,
+ "PagedSelectiveSSM: subsequence_begins must be non-negative and non-decreasing at sequence ",
+ s,
+ ".");
+ OPENVINO_ASSERT(block_begin_value >= 0 && block_end_value >= block_begin_value,
+ "PagedSelectiveSSM: block_indices_begins must be non-negative and non-decreasing at sequence ",
+ s,
+ ".");
+ OPENVINO_ASSERT(processed_tokens >= 0,
+ "PagedSelectiveSSM: num_processed_tokens[",
+ s,
+ "] must be non-negative, got ",
+ processed_tokens,
+ ".");
+
+ const auto token_count = static_cast<uint64_t>(token_end - token_begin);
+ if (token_count == 0) {
+ continue;
+ }
+
+ const auto block_begin = static_cast<uint64_t>(block_begin_value);
+ const auto block_end = static_cast<uint64_t>(block_end_value);
+ OPENVINO_ASSERT(block_end > block_begin,
+ "PagedSelectiveSSM: non-empty sequence ",
+ s,
+ " requires a read block.");
+
+ const auto interval = index_at(cache_interval, s);
+ if (interval <= 0) {
+ continue;
+ }
+ const auto positive_interval = static_cast<uint64_t>(interval);
+ const auto offset = static_cast<uint64_t>(processed_tokens) % positive_interval;
+ OPENVINO_ASSERT(token_count <= std::numeric_limits<uint64_t>::max() - offset,
+ "PagedSelectiveSSM: token count overflow at sequence ",
+ s,
+ ".");
+ const auto cached_token_count = offset + token_count;
+ const auto write_count = (cached_token_count - 1) / positive_interval + 1;
+ OPENVINO_ASSERT(block_end - block_begin - 1 >= write_count,
+ "PagedSelectiveSSM: sequence ",
+ s,
+ " requires ",
+ write_count,
+ " writable logical blocks after the read block, got ",
+ block_end - block_begin - 1,
+ ".");
+
+ for (uint64_t slot = 1; slot <= write_count; ++slot) {
+ const auto logical = static_cast<size_t>(block_begin + slot);
+ const auto physical =
+ checked_index(index_at(block_indices, logical), shape.physical_block_count, "block_indices", logical);
+ OPENVINO_ASSERT(block_owners[physical] == -1,
+ "PagedSelectiveSSM: physical block ",
+ physical,
+ " is written more than once (previous sequence ",
+ block_owners[physical],
+ ", current sequence ",
+ s,
+ ").");
+ block_owners[physical] = static_cast<int32_t>(s);
+ }
+ }
+
+ // A read may alias this sequence's first write (the documented in-place case), but it
+ // must not race with another sequence's writer. Read/read sharing is harmless.
+ for (size_t s = 0; s < shape.sequence_count; ++s) {
+ if (index_at(subsequence_begins, s + 1) == index_at(subsequence_begins, s)) {
+ continue;
+ }
+ const auto logical = static_cast<size_t>(index_at(block_indices_begins, s));
+ const auto physical =
+ checked_index(index_at(block_indices, logical), shape.physical_block_count, "block_indices", logical);
+ const auto owner = block_owners[physical];
+ bool aliases_first_write = false;
+ if (owner == static_cast<int32_t>(s)) {
+ const auto first_write_logical = logical + 1;
+ const auto first_write_physical = checked_index(index_at(block_indices, first_write_logical),
+ shape.physical_block_count,
+ "block_indices",
+ first_write_logical);
+ aliases_first_write = first_write_physical == physical;
+ }
+ OPENVINO_ASSERT(owner == -1 || aliases_first_write,
+ "PagedSelectiveSSM: sequence ",
+ s,
+ " reads physical block ",
+ physical,
+ " while sequence ",
+ owner,
+ " writes it; a read may alias only the same sequence's first write.");
+ }
+}
+
+template <typename DataT, typename ProjectionT>
+void paged_selective_ssm_typed(const DataT* A,
+ const DataT* dt,
+ const ProjectionT* B,
+ const DataT* x,
+ const ProjectionT* C,
+ DataT* recurrent_state_table,
+ const PagedMetadata& metadata,
+ DataT* output,
+ const PagedSelectiveSSMShape& shape,
+ float* state_scratch,
+ size_t scratch_head_dim,
+ const CpuParallelPtr& cpu_parallel) {
+ const auto& subsequence_begins = metadata.subsequence_begins;
+ const auto& block_indices = metadata.block_indices;
+ const auto& block_indices_begins = metadata.block_indices_begins;
+ const auto& num_processed_tokens = metadata.num_processed_tokens;
+ const auto& cache_interval = metadata.cache_interval;
+
+ const auto block_stride = checked_size_product({shape.num_heads, shape.head_dim, shape.state_size}, "state block");
+ const auto head_stride = checked_size_product({shape.head_dim, shape.state_size}, "state head");
+ const auto scratch_stride = checked_size_product({scratch_head_dim, shape.state_size}, "state scratch");
+ const auto heads_per_group = shape.num_heads / shape.num_groups;
+ const auto p_block_count = ov::util::ceil_div(shape.head_dim, scratch_head_dim);
+
+ cpu_parallel->parallel_for3d(
+ shape.sequence_count,
+ shape.num_heads,
+ p_block_count,
+ [&](size_t sequence, size_t head, size_t pb) {
+ const auto token_begin = static_cast<size_t>(index_at(subsequence_begins, sequence));
+ const auto token_end = static_cast<size_t>(index_at(subsequence_begins, sequence + 1));
+ if (token_begin == token_end) {
+ return;
+ }
+
+ const auto p_begin = pb * scratch_head_dim;
+ const auto p_end = p_begin + std::min(scratch_head_dim, shape.head_dim - p_begin);
+ const auto p_count = p_end - p_begin;
+ const auto group = head / heads_per_group;
+ const auto logical_block_begin = static_cast<size_t>(index_at(block_indices_begins, sequence));
+ const auto read_block = static_cast<size_t>(index_at(block_indices, logical_block_begin));
+ const auto state_slice = head * head_stride + p_begin * shape.state_size;
+ const auto* initial_state = recurrent_state_table + read_block * block_stride + state_slice;
+ const auto a_head = static_cast<float>(A[head]);
+ const auto interval = index_at(cache_interval, sequence);
+ const bool cache_enabled = interval > 0;
+ auto token_head = token_begin * shape.num_heads + head;
+ auto projection_base = (token_begin * shape.num_groups + group) * shape.state_size;
+ auto x_base = token_head * shape.head_dim + p_begin;
+ const auto projection_stride = shape.num_groups * shape.state_size;
+ const auto x_stride = shape.num_heads * shape.head_dim;
+ auto* local_state = state_scratch + static_cast<size_t>(parallel_get_thread_num()) * scratch_stride;
+ const auto state_elements = p_count * shape.state_size;
+ copy_convert(local_state, initial_state, state_elements);
+ const uint64_t positive_interval = cache_enabled ? static_cast<uint64_t>(interval) : 1;
+ const uint64_t cache_offset =
+ cache_enabled ? static_cast<uint64_t>(index_at(num_processed_tokens, sequence)) % positive_interval : 0;
+
+ for (size_t token = token_begin; token < token_end; ++token) {
+ const auto delta = static_cast<float>(dt[token_head]);
+ const float decay = std::exp(a_head * delta);
+ const auto* input_projection = B + projection_base;
+ const auto* output_projection = C + projection_base;
+ for (size_t p = 0; p < p_count; ++p) {
+ auto* state = local_state + p * shape.state_size;
+ const float input_scale = static_cast<float>(x[x_base + p]) * delta;
+ const float result = update_state_and_reduce(state,
+ input_projection,
+ output_projection,
+ decay,
+ input_scale,
+ shape.state_size);
+ output[x_base + p] = static_cast<DataT>(result);
+ }
+
+ const auto processed_tokens = static_cast<uint64_t>((token - token_begin) + 1);
+ const auto cached_tokens = cache_offset + processed_tokens;
+ const bool interval_hit = cache_enabled && cached_tokens % positive_interval == 0;
+ const bool is_last = token + 1 == token_end;
+ if (cache_enabled && (interval_hit || is_last)) {
+ const auto write_slot = 1 + (cached_tokens - 1) / positive_interval;
+ const auto write_block =
+ static_cast<size_t>(index_at(block_indices, logical_block_begin + write_slot));
+ auto* snapshot = recurrent_state_table + write_block * block_stride + state_slice;
+ copy_convert(snapshot, local_state, state_elements);
+ }
+
+ token_head += shape.num_heads;
+ projection_base += projection_stride;
+ x_base += x_stride;
+ }
+ });
+}
+
+template <typename DataT>
+void dispatch_selective_projection(const void* A,
+ const void* dt,
+ const void* B,
+ const void* x,
+ const void* C,
+ const void* recurrent_state,
+ void* output,
+ void* output_recurrent_state,
+ const SelectiveSSMShape& shape,
+ float* state_scratch,
+ size_t scratch_head_dim,
+ const CpuParallelPtr& cpu_parallel,
+ const float* converted_B,
+ const float* converted_C) {
+ const auto dispatch = [&](const auto* B_data, const auto* C_data) {
+ selective_ssm_typed(static_cast<const DataT*>(A),
+ static_cast<const DataT*>(dt),
+ B_data,
+ static_cast<const DataT*>(x),
+ C_data,
+ static_cast<const DataT*>(recurrent_state),
+ static_cast<DataT*>(output),
+ static_cast<DataT*>(output_recurrent_state),
+ shape,
+ state_scratch,
+ scratch_head_dim,
+ cpu_parallel);
+ };
+ if (converted_B != nullptr) {
+ dispatch(converted_B, converted_C);
+ } else {
+ dispatch(static_cast<const DataT*>(B), static_cast<const DataT*>(C));
+ }
+}
+
+template <typename DataT>
+void dispatch_paged_projection(const void* A,
+ const void* dt,
+ const void* B,
+ const void* x,
+ const void* C,
+ void* recurrent_state_table,
+ const PagedMetadata& metadata,
+ void* output,
+ const PagedSelectiveSSMShape& shape,
+ float* state_scratch,
+ size_t scratch_head_dim,
+ const CpuParallelPtr& cpu_parallel,
+ const float* converted_B,
+ const float* converted_C) {
+ const auto dispatch = [&](const auto* B_data, const auto* C_data) {
+ paged_selective_ssm_typed(static_cast<const DataT*>(A),
+ static_cast<const DataT*>(dt),
+ B_data,
+ static_cast<const DataT*>(x),
+ C_data,
+ static_cast<DataT*>(recurrent_state_table),
+ metadata,
+ static_cast<DataT*>(output),
+ shape,
+ state_scratch,
+ scratch_head_dim,
+ cpu_parallel);
+ };
+ if (converted_B != nullptr) {
+ dispatch(converted_B, converted_C);
+ } else {
+ dispatch(static_cast<const DataT*>(B), static_cast<const DataT*>(C));
+ }
+}
+
+} // namespace
+
+size_t checked_size_product(std::initializer_list<size_t> dimensions, const char* tensor_name) {
+ if (std::find(dimensions.begin(), dimensions.end(), size_t{0}) != dimensions.end()) {
+ return 0;
+ }
+
+ size_t result = 1;
+ for (const auto dimension : dimensions) {
+ OPENVINO_ASSERT(result <= std::numeric_limits<size_t>::max() / dimension,
+ "SelectiveSSM size overflow while calculating ",
+ tensor_name,
+ ".");
+ result *= dimension;
+ }
+ return result;
+}
+
+size_t checked_size_sum(std::initializer_list<size_t> values, const char* buffer_name) {
+ size_t result = 0;
+ for (const auto value : values) {
+ OPENVINO_ASSERT(result <= std::numeric_limits<size_t>::max() - value,
+ "SelectiveSSM size overflow while calculating ",
+ buffer_name,
+ ".");
+ result += value;
+ }
+ return result;
+}
+
+size_t get_scratch_head_dim(size_t head_dim, size_t state_size, size_t outer_work_items, size_t thread_count) {
+ OPENVINO_ASSERT(state_size > 0);
+ if (head_dim == 0) {
+ return 1;
+ }
+ const auto scratch_elements = max_scratch_bytes_per_worker / sizeof(float);
+ const auto scratch_limited = std::max(size_t{1}, std::min(head_dim, scratch_elements / state_size));
+ const auto outer_work = std::max(size_t{1}, outer_work_items);
+ const auto workers = std::max(size_t{1}, thread_count);
+ const auto blocks_for_parallelism = ov::util::ceil_div(workers, outer_work);
+ const auto parallelism_limited = ov::util::ceil_div(head_dim, blocks_for_parallelism);
+ return std::max(size_t{1}, std::min(scratch_limited, parallelism_limited));
+}
+
+void selective_ssm(const void* A,
+ const void* dt,
+ const void* B,
+ const void* x,
+ const void* C,
+ const void* recurrent_state,
+ void* output,
+ void* output_recurrent_state,
+ const SelectiveSSMShape& shape,
+ const ov::element::Type& precision,
+ float* state_scratch,
+ size_t scratch_head_dim,
+ const CpuParallelPtr& cpu_parallel,
+ const float* converted_B,
+ const float* converted_C) {
+ OPENVINO_ASSERT(scratch_head_dim > 0 && state_scratch != nullptr);
+ OPENVINO_ASSERT(cpu_parallel != nullptr, "SelectiveSSM requires a CPU parallel executor.");
+ OPENVINO_ASSERT((converted_B == nullptr) == (converted_C == nullptr));
+#define OV_CPU_SSM_CALL(DataT) \
+ dispatch_selective_projection<DataT>(A, \
+ dt, \
+ B, \
+ x, \
+ C, \
+ recurrent_state, \
+ output, \
+ output_recurrent_state, \
+ shape, \
+ state_scratch, \
+ scratch_head_dim, \
+ cpu_parallel, \
+ converted_B, \
+ converted_C)
+ if (precision == ov::element::f32) {
+ OV_CPU_SSM_CALL(float);
+ } else if (precision == ov::element::f16) {
+ OV_CPU_SSM_CALL(ov::float16);
+ } else if (precision == ov::element::bf16) {
+ OV_CPU_SSM_CALL(ov::bfloat16);
+ } else {
+ OPENVINO_THROW("SelectiveSSM supports only f32/f16/bf16, got ", precision, ".");
+ }
+#undef OV_CPU_SSM_CALL
+}
+
+void paged_selective_ssm(const void* A,
+ const void* dt,
+ const void* B,
+ const void* x,
+ const void* C,
+ void* recurrent_state_table,
+ const void* subsequence_begins,
+ const void* block_indices,
+ const void* block_indices_begins,
+ const void* num_processed_tokens,
+ const void* cache_interval,
+ void* output,
+ const PagedSelectiveSSMShape& shape,
+ const ov::element::Type& precision,
+ const ov::element::Type& index_precision,
+ float* state_scratch,
+ size_t scratch_head_dim,
+ int32_t* metadata_validation_scratch,
+ const CpuParallelPtr& cpu_parallel,
+ const float* converted_B,
+ const float* converted_C) {
+ OPENVINO_ASSERT(scratch_head_dim > 0 && state_scratch != nullptr);
+ OPENVINO_ASSERT(cpu_parallel != nullptr, "PagedSelectiveSSM requires a CPU parallel executor.");
+ OPENVINO_ASSERT((converted_B == nullptr) == (converted_C == nullptr));
+ const auto metadata = make_paged_metadata(subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ num_processed_tokens,
+ cache_interval,
+ index_precision,
+ shape);
+ if (metadata_validation_scratch != nullptr) {
+ validate_paged_metadata(metadata, shape, metadata_validation_scratch);
+ }
+#define OV_CPU_PAGED_SSM_CALL(DataT) \
+ dispatch_paged_projection<DataT>(A, \
+ dt, \
+ B, \
+ x, \
+ C, \
+ recurrent_state_table, \
+ metadata, \
+ output, \
+ shape, \
+ state_scratch, \
+ scratch_head_dim, \
+ cpu_parallel, \
+ converted_B, \
+ converted_C)
+ if (precision == ov::element::f32) {
+ OV_CPU_PAGED_SSM_CALL(float);
+ } else if (precision == ov::element::f16) {
+ OV_CPU_PAGED_SSM_CALL(ov::float16);
+ } else if (precision == ov::element::bf16) {
+ OV_CPU_PAGED_SSM_CALL(ov::bfloat16);
+ } else {
+ OPENVINO_THROW("PagedSelectiveSSM supports only f32/f16/bf16, got ", precision, ".");
+ }
+#undef OV_CPU_PAGED_SSM_CALL
+}
+
+} // namespace ov::intel_cpu::node::kernel
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/selective_ssm.hpp b/src/plugins/intel_cpu/src/nodes/kernels/selective_ssm.hpp
new file mode 100644
index 00000000000..964f7c313f9
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/kernels/selective_ssm.hpp
@@ -0,0 +1,79 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstddef>
+#include <initializer_list>
+
+#include "cpu_parallel.hpp"
+#include "openvino/core/type/element_type.hpp"
+
+namespace ov::intel_cpu::node::kernel {
+
+struct SelectiveSSMShape {
+ size_t batch_size = 0;
+ size_t sequence_length = 0;
+ size_t num_heads = 0;
+ size_t head_dim = 0;
+ size_t num_groups = 0;
+ size_t state_size = 0;
+};
+
+struct PagedSelectiveSSMShape {
+ size_t token_count = 0;
+ size_t num_heads = 0;
+ size_t head_dim = 0;
+ size_t num_groups = 0;
+ size_t state_size = 0;
+ size_t physical_block_count = 0;
+ size_t logical_block_count = 0;
+ size_t sequence_count = 0;
+};
+
+size_t checked_size_product(std::initializer_list<size_t> dimensions, const char* tensor_name);
+
+size_t checked_size_sum(std::initializer_list<size_t> values, const char* buffer_name);
+
+size_t get_scratch_head_dim(size_t head_dim, size_t state_size, size_t outer_work_items, size_t thread_count);
+
+void selective_ssm(const void* A,
+ const void* dt,
+ const void* B,
+ const void* x,
+ const void* C,
+ const void* recurrent_state,
+ void* output,
+ void* output_recurrent_state,
+ const SelectiveSSMShape& shape,
+ const ov::element::Type& precision,
+ float* state_scratch,
+ size_t scratch_head_dim,
+ const CpuParallelPtr& cpu_parallel,
+ const float* converted_B = nullptr,
+ const float* converted_C = nullptr);
+
+void paged_selective_ssm(const void* A,
+ const void* dt,
+ const void* B,
+ const void* x,
+ const void* C,
+ void* recurrent_state_table,
+ const void* subsequence_begins,
+ const void* block_indices,
+ const void* block_indices_begins,
+ const void* num_processed_tokens,
+ const void* cache_interval,
+ void* output,
+ const PagedSelectiveSSMShape& shape,
+ const ov::element::Type& precision,
+ const ov::element::Type& index_precision,
+ float* state_scratch,
+ size_t scratch_head_dim,
+ int32_t* metadata_validation_scratch,
+ const CpuParallelPtr& cpu_parallel,
+ const float* converted_B = nullptr,
+ const float* converted_C = nullptr);
+
+} // namespace ov::intel_cpu::node::kernel
diff --git a/src/plugins/intel_cpu/src/nodes/paged_selective_ssm.cpp b/src/plugins/intel_cpu/src/nodes/paged_selective_ssm.cpp
new file mode 100644
index 00000000000..6b0ce309563
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/paged_selective_ssm.cpp
@@ -0,0 +1,146 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "paged_selective_ssm.h"
+
+#include <array>
+#include <cstddef>
+#include <memory>
+#include <oneapi/dnnl/dnnl_common.hpp>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "graph_context.h"
+#include "memory_desc/cpu_memory_desc.h"
+#include "node.h"
+#include "nodes/common/blocked_desc_creator.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/executor_factory.hpp"
+#include "nodes/executors/memory_arguments.hpp"
+#include "nodes/executors/paged_selective_ssm_config.hpp"
+#include "nodes/node_config.h"
+#include "onednn/iml_type_mapper.h"
+#include "openvino/core/except.hpp"
+#include "openvino/core/node.hpp"
+#include "openvino/core/type.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "openvino/op/paged_selective_ssm.hpp"
+#include "shape_inference/shape_inference_cpu.hpp"
+#include "utils/general_utils.h"
+
+namespace ov::intel_cpu::node {
+
+namespace {
+
+using InputPortBinding = std::pair<int, size_t>;
+
+constexpr std::array input_port_bindings{
+ InputPortBinding{ARG_PAGED_SSM_A, 0},
+ InputPortBinding{ARG_PAGED_SSM_DT, 1},
+ InputPortBinding{ARG_PAGED_SSM_B, 2},
+ InputPortBinding{ARG_PAGED_SSM_X, 3},
+ InputPortBinding{ARG_PAGED_SSM_C, 4},
+ InputPortBinding{ARG_PAGED_SSM_STATE, 5},
+ InputPortBinding{ARG_PAGED_SSM_SUBSEQUENCE_BEGINS, 6},
+ InputPortBinding{ARG_PAGED_SSM_BLOCK_INDICES, 7},
+ InputPortBinding{ARG_PAGED_SSM_BLOCK_INDICES_BEGINS, 8},
+ InputPortBinding{ARG_PAGED_SSM_NUM_PROCESSED_TOKENS, 9},
+ InputPortBinding{ARG_PAGED_SSM_CACHE_INTERVAL, 10},
+};
+
+} // namespace
+
+PagedSelectiveSSM::PagedSelectiveSSM(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context)
+ : Node(op, context, NgraphShapeInferFactory(op)) {
+ std::string error_message;
+ if (!isSupportedOperation(op, error_message)) {
+ OPENVINO_THROW_NOT_IMPLEMENTED(error_message);
+ }
+}
+
+void PagedSelectiveSSM::initSupportedPrimitiveDescriptors() {
+ const auto data_precision = getOriginalInputPrecisionAtPort(0);
+ OPENVINO_ASSERT(any_of(data_precision, ov::element::f32, ov::element::f16, ov::element::bf16),
+ "PagedSelectiveSSM supports only f32/f16/bf16 data, got ",
+ data_precision,
+ ".");
+ for (size_t port = 1; port <= 5; ++port) {
+ OPENVINO_ASSERT(getOriginalInputPrecisionAtPort(port) == data_precision,
+ "PagedSelectiveSSM requires one data precision on ports 0..5.");
+ }
+ const auto index_precision = getOriginalInputPrecisionAtPort(6);
+ OPENVINO_ASSERT(any_of(index_precision, ov::element::i32, ov::element::i64),
+ "PagedSelectiveSSM supports only i32/i64 metadata, got ",
+ index_precision,
+ ".");
+ for (size_t port = 7; port <= 10; ++port) {
+ OPENVINO_ASSERT(getOriginalInputPrecisionAtPort(port) == index_precision,
+ "PagedSelectiveSSM requires one metadata precision on ports 6..10.");
+ }
+
+ const auto& creators_map = BlockedDescCreator::getCommonCreators();
+ MemoryDescArgs descs;
+ for (const auto& [arg_id, port_id] : input_port_bindings) {
+ descs[arg_id] = creators_map.at(LayoutType::ncsp)
+ ->createSharedDesc(getOriginalInputPrecisionAtPort(port_id), getInputShapeAtPort(port_id));
+ }
+ descs[ARG_PAGED_SSM_OUT] = creators_map.at(LayoutType::ncsp)
+ ->createSharedDesc(getOriginalOutputPrecisionAtPort(0), getOutputShapeAtPort(0));
+
+ auto execution_context = std::make_shared<ExecutorContext>(context, getImplPriority(), privateWeightCache);
+ m_factory = std::make_shared<ExecutorFactory<PagedSelectiveSSMAttrs>>(m_attrs, execution_context, descs);
+
+ const auto node_descriptors_list = m_factory->getProperMemoryDescriptors(descs);
+ for (const auto& node_descriptors : node_descriptors_list) {
+ NodeConfig node_config;
+ node_config.inConfs.resize(getParentEdges().size());
+ for (const auto& [arg_id, port_id] : input_port_bindings) {
+ if (node_descriptors.count(arg_id)) {
+ node_config.inConfs[port_id] = PortConfig{node_descriptors.at(arg_id)};
+ }
+ }
+ node_config.outConfs.emplace_back(node_descriptors.at(ARG_PAGED_SSM_OUT));
+ supportedPrimitiveDescriptors.emplace_back(node_config, impl_desc_type::undef);
+ }
+}
+
+void PagedSelectiveSSM::bindMemoryArguments() {
+ for (const auto& [arg_id, port_id] : input_port_bindings) {
+ m_memory[arg_id] = getSrcMemoryAtPort(port_id);
+ }
+ m_memory[ARG_PAGED_SSM_OUT] = getDstMemoryAtPort(0);
+}
+
+void PagedSelectiveSSM::createPrimitive() {
+ bindMemoryArguments();
+
+ m_executor = m_factory->make(m_memory);
+ Node::createPrimitive();
+ getSelectedPrimitiveDescriptor()->setImplementationType(m_executor->implType());
+}
+
+void PagedSelectiveSSM::prepareParams() {
+ bindMemoryArguments();
+
+ m_executor->update(m_memory);
+ getSelectedPrimitiveDescriptor()->setImplementationType(m_executor->implType());
+}
+
+void PagedSelectiveSSM::execute([[maybe_unused]] const dnnl::stream& strm) {
+ bindMemoryArguments();
+
+ m_executor->execute(m_memory);
+}
+
+bool PagedSelectiveSSM::isSupportedOperation(const std::shared_ptr<const ov::Node>& op,
+ std::string& error_message) noexcept {
+ if (op == nullptr || !ov::is_type<ov::op::internal::PagedSelectiveSSM>(op)) {
+ error_message = "Node is not an instance of ov::op::internal::PagedSelectiveSSM.";
+ return false;
+ }
+ return true;
+}
+
+} // namespace ov::intel_cpu::node
diff --git a/src/plugins/intel_cpu/src/nodes/paged_selective_ssm.h b/src/plugins/intel_cpu/src/nodes/paged_selective_ssm.h
new file mode 100644
index 00000000000..dfb55922056
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/paged_selective_ssm.h
@@ -0,0 +1,50 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <memory>
+#include <oneapi/dnnl/dnnl_common.hpp>
+#include <string>
+
+#include "cpu_types.h"
+#include "graph_context.h"
+#include "node.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/executor_factory.hpp"
+#include "nodes/executors/paged_selective_ssm_config.hpp"
+#include "openvino/core/node.hpp"
+
+namespace ov::intel_cpu::node {
+
+class PagedSelectiveSSM : public Node {
+public:
+ PagedSelectiveSSM(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context);
+
+ void getSupportedDescriptors() override {}
+ bool created() const override {
+ return getType() == Type::PagedSelectiveSSM;
+ }
+ bool isExecutable() const override {
+ return !isInputTensorAtPortEmpty(3);
+ }
+
+ void createPrimitive() override;
+ void prepareParams() override;
+ void executeDynamicImpl(const dnnl::stream& strm) override {
+ execute(strm);
+ }
+ void initSupportedPrimitiveDescriptors() override;
+ void execute(const dnnl::stream& strm) override;
+ static bool isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& error_message) noexcept;
+
+private:
+ void bindMemoryArguments();
+ PagedSelectiveSSMAttrs m_attrs;
+ ExecutorFactoryPtr<PagedSelectiveSSMAttrs> m_factory;
+ ExecutorPtr m_executor;
+ MemoryArgs m_memory;
+};
+
+} // namespace ov::intel_cpu::node
diff --git a/src/plugins/intel_cpu/src/nodes/selective_ssm.cpp b/src/plugins/intel_cpu/src/nodes/selective_ssm.cpp
new file mode 100644
index 00000000000..846d07de05b
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/selective_ssm.cpp
@@ -0,0 +1,127 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "selective_ssm.h"
+
+#include <array>
+#include <cstddef>
+#include <memory>
+#include <oneapi/dnnl/dnnl_common.hpp>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "graph_context.h"
+#include "memory_desc/cpu_memory_desc.h"
+#include "node.h"
+#include "nodes/common/blocked_desc_creator.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/executor_factory.hpp"
+#include "nodes/executors/memory_arguments.hpp"
+#include "nodes/executors/selective_ssm_config.hpp"
+#include "nodes/node_config.h"
+#include "onednn/iml_type_mapper.h"
+#include "openvino/core/except.hpp"
+#include "openvino/core/node.hpp"
+#include "openvino/core/type.hpp"
+#include "openvino/op/selective_ssm.hpp"
+#include "shape_inference/shape_inference_cpu.hpp"
+
+namespace ov::intel_cpu::node {
+
+namespace {
+
+using InputPortBinding = std::pair<int, size_t>;
+
+constexpr std::array input_port_bindings{
+ InputPortBinding{ARG_SSM_A, 0},
+ InputPortBinding{ARG_SSM_DT, 1},
+ InputPortBinding{ARG_SSM_B, 2},
+ InputPortBinding{ARG_SSM_X, 3},
+ InputPortBinding{ARG_SSM_C, 4},
+ InputPortBinding{ARG_SSM_STATE, 5},
+};
+
+} // namespace
+
+SelectiveSSM::SelectiveSSM(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context)
+ : Node(op, context, NgraphShapeInferFactory(op)) {
+ std::string error_message;
+ if (!isSupportedOperation(op, error_message)) {
+ OPENVINO_THROW_NOT_IMPLEMENTED(error_message);
+ }
+}
+
+void SelectiveSSM::initSupportedPrimitiveDescriptors() {
+ const auto& creators_map = BlockedDescCreator::getCommonCreators();
+
+ MemoryDescArgs descs;
+ for (const auto& [arg_id, port_id] : input_port_bindings) {
+ descs[arg_id] = creators_map.at(LayoutType::ncsp)
+ ->createSharedDesc(getOriginalInputPrecisionAtPort(port_id), getInputShapeAtPort(port_id));
+ }
+ descs[ARG_SSM_OUT] = creators_map.at(LayoutType::ncsp)
+ ->createSharedDesc(getOriginalOutputPrecisionAtPort(0), getOutputShapeAtPort(0));
+ descs[ARG_SSM_OUT_STATE] = creators_map.at(LayoutType::ncsp)
+ ->createSharedDesc(getOriginalOutputPrecisionAtPort(1), getOutputShapeAtPort(1));
+
+ auto execution_context = std::make_shared<ExecutorContext>(context, getImplPriority(), privateWeightCache);
+ m_factory = std::make_shared<ExecutorFactory<SelectiveSSMAttrs>>(m_attrs, execution_context, descs);
+
+ const auto node_descriptors_list = m_factory->getProperMemoryDescriptors(descs);
+ for (const auto& node_descriptors : node_descriptors_list) {
+ NodeConfig node_config;
+ node_config.inConfs.resize(getParentEdges().size());
+
+ for (const auto& [arg_id, port_id] : input_port_bindings) {
+ if (node_descriptors.count(arg_id)) {
+ node_config.inConfs[port_id] = PortConfig{node_descriptors.at(arg_id)};
+ }
+ }
+
+ node_config.outConfs.emplace_back(node_descriptors.at(ARG_SSM_OUT));
+ node_config.outConfs.emplace_back(node_descriptors.at(ARG_SSM_OUT_STATE));
+ supportedPrimitiveDescriptors.emplace_back(node_config, impl_desc_type::undef);
+ }
+}
+
+void SelectiveSSM::bindMemoryArguments() {
+ for (const auto& [arg_id, port_id] : input_port_bindings) {
+ m_memory[arg_id] = getSrcMemoryAtPort(port_id);
+ }
+ m_memory[ARG_SSM_OUT] = getDstMemoryAtPort(0);
+ m_memory[ARG_SSM_OUT_STATE] = getDstMemoryAtPort(1);
+}
+
+void SelectiveSSM::createPrimitive() {
+ bindMemoryArguments();
+
+ m_executor = m_factory->make(m_memory);
+ Node::createPrimitive();
+ getSelectedPrimitiveDescriptor()->setImplementationType(m_executor->implType());
+}
+
+void SelectiveSSM::prepareParams() {
+ bindMemoryArguments();
+
+ m_executor->update(m_memory);
+ getSelectedPrimitiveDescriptor()->setImplementationType(m_executor->implType());
+}
+
+void SelectiveSSM::execute([[maybe_unused]] const dnnl::stream& strm) {
+ bindMemoryArguments();
+
+ m_executor->execute(m_memory);
+}
+
+bool SelectiveSSM::isSupportedOperation(const std::shared_ptr<const ov::Node>& op,
+ std::string& error_message) noexcept {
+ if (op == nullptr || !ov::is_type<ov::op::internal::SelectiveSSM>(op)) {
+ error_message = "Node is not an instance of ov::op::internal::SelectiveSSM.";
+ return false;
+ }
+ return true;
+}
+
+} // namespace ov::intel_cpu::node
diff --git a/src/plugins/intel_cpu/src/nodes/selective_ssm.h b/src/plugins/intel_cpu/src/nodes/selective_ssm.h
new file mode 100644
index 00000000000..6c090c83d9f
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/selective_ssm.h
@@ -0,0 +1,52 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <memory>
+#include <oneapi/dnnl/dnnl_common.hpp>
+#include <string>
+
+#include "cpu_types.h"
+#include "graph_context.h"
+#include "node.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/executor_factory.hpp"
+#include "nodes/executors/selective_ssm_config.hpp"
+#include "openvino/core/node.hpp"
+
+namespace ov::intel_cpu::node {
+
+class SelectiveSSM : public Node {
+public:
+ SelectiveSSM(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context);
+
+ void getSupportedDescriptors() override {}
+ bool created() const override {
+ return getType() == Type::SelectiveSSM;
+ }
+
+ bool isExecutable() const override {
+ return true;
+ }
+
+ void createPrimitive() override;
+ void prepareParams() override;
+
+ void executeDynamicImpl(const dnnl::stream& strm) override {
+ execute(strm);
+ }
+ void initSupportedPrimitiveDescriptors() override;
+ void execute(const dnnl::stream& strm) override;
+ static bool isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& error_message) noexcept;
+
+private:
+ void bindMemoryArguments();
+ SelectiveSSMAttrs m_attrs;
+ ExecutorFactoryPtr<SelectiveSSMAttrs> m_factory;
+ ExecutorPtr m_executor;
+ MemoryArgs m_memory;
+};
+
+} // namespace ov::intel_cpu::node
diff --git a/src/plugins/intel_cpu/src/nodes_factory.cpp b/src/plugins/intel_cpu/src/nodes_factory.cpp
index f26e5a1578d..327cdbafc73 100644
--- a/src/plugins/intel_cpu/src/nodes_factory.cpp
+++ b/src/plugins/intel_cpu/src/nodes_factory.cpp
@@ -70,6 +70,7 @@
#include "nodes/pad.h"
#include "nodes/paged_causal_conv1d.h"
#include "nodes/paged_gated_delta_net.h"
+#include "nodes/paged_selective_ssm.h"
#include "nodes/pooling.h"
#include "nodes/priorbox.h"
#include "nodes/priorbox_clustered.h"
@@ -94,6 +95,7 @@
#include "nodes/scatter_update.h"
#include "nodes/search_sorted.h"
#include "nodes/segment_max.h"
+#include "nodes/selective_ssm.h"
#include "nodes/shapeof.h"
#include "nodes/shuffle_channels.h"
#include "nodes/softmax.h"
@@ -249,6 +251,8 @@ Node::NodesFactory::NodesFactory() : Factory("NodesFactory") {
INTEL_CPU_NODE(GatherMatmul, Type::GatherMatmul);
INTEL_CPU_NODE(GatedDeltaNet, Type::GatedDeltaNet);
INTEL_CPU_NODE(PagedGatedDeltaNet, Type::PagedGatedDeltaNet);
+ INTEL_CPU_NODE(SelectiveSSM, Type::SelectiveSSM);
+ INTEL_CPU_NODE(PagedSelectiveSSM, Type::PagedSelectiveSSM);
INTEL_CPU_NODE(PagedCausalConv1D, Type::PagedCausalConv1D);
#if defined(OPENVINO_ARCH_X86_64)
INTEL_CPU_NODE(FakeQuantize, Type::FakeQuantize);
diff --git a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
index 557a0e3b925..a5e54eb2041 100644
--- a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
+++ b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
@@ -47,6 +47,7 @@
#include "openvino/op/reduce_sum.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/result.hpp"
+#include "openvino/op/swish.hpp"
#include "openvino/op/transpose.hpp"
#include "openvino/op/util/attr_types.hpp"
#include "ov_ops/gather_compressed.hpp"
@@ -179,7 +180,6 @@
#if defined(OPENVINO_ARCH_ARM64)
# include "cpu/aarch64/cpu_isa_traits.hpp"
# include "openvino/op/add.hpp"
-# include "openvino/op/swish.hpp"
# include "transformations/snippets/aarch64/pass/snippets_mark_skipped.hpp"
#else
# include "openvino/op/convolution.hpp"
@@ -276,7 +276,6 @@
#if defined(OPENVINO_ARCH_RISCV64)
# include "nodes/kernels/riscv64/cpu_isa_traits.hpp"
-# include "openvino/op/swish.hpp"
#endif
#if defined(SNIPPETS_LIBXSMM_TPP)
diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/paged_selective_ssm.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/paged_selective_ssm.cpp
new file mode 100644
index 00000000000..3e72511e667
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/paged_selective_ssm.cpp
@@ -0,0 +1,674 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "custom/single_layer_tests/classes/paged_selective_ssm.hpp"
+
+#include <algorithm>
+#include <cmath>
+#include <cstdint>
+#include <numeric>
+#include <sstream>
+#include <vector>
+
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "openvino/core/type/bfloat16.hpp"
+#include "openvino/core/type/float16.hpp"
+#include "openvino/op/paged_selective_ssm.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/result.hpp"
+#include "openvino/runtime/core.hpp"
+#include "openvino/runtime/remote_context.hpp"
+#include "openvino/runtime/remote_tensor.hpp"
+#include "openvino/runtime/tensor.hpp"
+#include "transformations/rt_info/keep_const_precision.hpp"
+
+namespace {
+
+template <typename T, typename IndexT>
+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>& recurrent_state_table,
+ const std::vector<IndexT>& subsequence_begins,
+ const std::vector<IndexT>& block_indices,
+ const std::vector<IndexT>& block_indices_begins,
+ const std::vector<IndexT>& num_processed_tokens,
+ const std::vector<IndexT>& cache_interval,
+ size_t num_heads,
+ size_t num_groups,
+ size_t head_dim,
+ size_t state_size,
+ std::vector<T>& output) {
+ const size_t tokens = x.size() / (num_heads * head_dim);
+ const size_t heads_per_group = num_heads / num_groups;
+ const size_t num_sequences = subsequence_begins.size() - 1;
+ output.resize(tokens * num_heads * head_dim);
+
+ const auto state_off = [=](size_t block, size_t head, size_t position, size_t state) {
+ return ((block * num_heads + head) * head_dim + position) * state_size + state;
+ };
+
+ for (size_t sequence = 0; sequence < num_sequences; ++sequence) {
+ const auto token_begin = static_cast<size_t>(subsequence_begins[sequence]);
+ const auto token_end = static_cast<size_t>(subsequence_begins[sequence + 1]);
+ if (token_begin == token_end) {
+ continue;
+ }
+
+ const auto logical_block_begin = static_cast<size_t>(block_indices_begins[sequence]);
+ const auto logical_block_end = static_cast<size_t>(block_indices_begins[sequence + 1]);
+ const auto interval = cache_interval[sequence];
+ const auto read_block = static_cast<size_t>(block_indices[logical_block_begin]);
+
+ for (size_t head = 0; head < num_heads; ++head) {
+ const size_t group = head / heads_per_group;
+ std::vector<float> state(head_dim * state_size);
+ for (size_t position = 0; position < head_dim; ++position) {
+ for (size_t state_index = 0; state_index < state_size; ++state_index) {
+ state[position * state_size + state_index] =
+ static_cast<float>(recurrent_state_table[state_off(read_block, head, position, state_index)]);
+ }
+ }
+
+ for (size_t token = token_begin; token < token_end; ++token) {
+ const float delta = static_cast<float>(dt[token * num_heads + head]);
+ const float decay = std::exp(static_cast<float>(A[head]) * delta);
+ const auto projection_base = (token * num_groups + group) * state_size;
+ std::vector<float> input_projection(state_size);
+ for (size_t state_index = 0; state_index < state_size; ++state_index) {
+ input_projection[state_index] =
+ delta * static_cast<float>(B[projection_base + state_index]);
+ }
+
+ for (size_t position = 0; position < head_dim; ++position) {
+ const auto state_base = position * state_size;
+ const float input = static_cast<float>(x[(token * num_heads + head) * head_dim + position]);
+ for (size_t state_index = 0; state_index < state_size; ++state_index) {
+ auto& state_value = state[state_base + state_index];
+ state_value = state_value * decay + input * input_projection[state_index];
+ }
+
+ double reduction = 0.0;
+ for (size_t state_index = 0; state_index < state_size; ++state_index) {
+ reduction += static_cast<double>(state[state_base + state_index]) *
+ static_cast<float>(C[projection_base + state_index]);
+ }
+ output[(token * num_heads + head) * head_dim + position] = static_cast<T>(reduction);
+ }
+
+ if (interval > 0) {
+ const auto positive_interval = static_cast<uint64_t>(interval);
+ const auto previous_offset =
+ static_cast<uint64_t>(num_processed_tokens[sequence]) % positive_interval;
+ const auto current_tokens = token - token_begin + 1;
+ const auto cached_tokens = previous_offset + current_tokens;
+ const bool is_boundary = cached_tokens % positive_interval == 0;
+ const bool is_last = token + 1 == token_end;
+ if (is_boundary || is_last) {
+ const auto write_slot = 1 + (cached_tokens - 1) / positive_interval;
+ OPENVINO_ASSERT(logical_block_begin + write_slot < logical_block_end);
+ const auto write_block =
+ static_cast<size_t>(block_indices[logical_block_begin + write_slot]);
+ for (size_t position = 0; position < head_dim; ++position) {
+ for (size_t state_index = 0; state_index < state_size; ++state_index) {
+ recurrent_state_table[state_off(write_block, head, position, state_index)] =
+ static_cast<T>(state[position * state_size + state_index]);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+template <typename T>
+std::vector<T> tensor_to_vector(const ov::Tensor& tensor) {
+ const auto* ptr = tensor.data<const T>();
+ return std::vector<T>(ptr, ptr + tensor.get_size());
+}
+
+ov::Tensor make_index_tensor(const std::vector<int32_t>& values, const ov::element::Type& index_type) {
+ ov::Tensor tensor(index_type, ov::Shape{values.size()});
+ if (index_type == ov::element::i32) {
+ std::copy(values.begin(), values.end(), tensor.data<int32_t>());
+ } else {
+ std::transform(values.begin(), values.end(), tensor.data<int64_t>(), [](int32_t value) {
+ return static_cast<int64_t>(value);
+ });
+ }
+ return tensor;
+}
+
+ov::Tensor make_f32_tensor(const ov::Shape& shape, const std::vector<float>& values) {
+ ov::Tensor tensor(ov::element::f32, shape);
+ OPENVINO_ASSERT(tensor.get_size() == values.size());
+ std::copy(values.begin(), values.end(), tensor.data<float>());
+ return tensor;
+}
+
+std::shared_ptr<ov::Model> make_paged_validation_model() {
+ auto A = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1});
+ auto dt = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 1});
+ auto B = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 1, 1});
+ auto x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 1, 1});
+ auto C = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 1, 1});
+ auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{2, 1, 1, 1});
+ auto subsequences = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{2});
+ auto blocks = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{2});
+ auto block_begins = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{2});
+ auto processed = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{1});
+ auto intervals = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{1});
+ const ov::ParameterVector
+ parameters{A, dt, B, x, C, state, subsequences, blocks, block_begins, processed, intervals};
+ const auto ssm = std::make_shared<ov::op::internal::PagedSelectiveSSM>(A,
+ dt,
+ B,
+ x,
+ C,
+ state,
+ subsequences,
+ blocks,
+ block_begins,
+ processed,
+ intervals);
+ return std::make_shared<ov::Model>(ssm->outputs(), parameters);
+}
+
+template <typename T, typename IndexT>
+std::vector<ov::Tensor> calculate_typed_refs(const std::map<std::shared_ptr<ov::Node>, ov::Tensor>& host_inputs,
+ const std::shared_ptr<ov::Model>& function,
+ size_t num_heads,
+ size_t num_groups,
+ size_t head_dim,
+ size_t state_size,
+ const ov::element::Type& data_type) {
+ const auto& params = function->get_parameters();
+
+ auto A = tensor_to_vector<T>(host_inputs.at(params[0]));
+ auto dt = tensor_to_vector<T>(host_inputs.at(params[1]));
+ auto B = tensor_to_vector<T>(host_inputs.at(params[2]));
+ auto x = tensor_to_vector<T>(host_inputs.at(params[3]));
+ auto C = tensor_to_vector<T>(host_inputs.at(params[4]));
+ auto state = tensor_to_vector<T>(host_inputs.at(params[5]));
+ auto subsequence_begins = tensor_to_vector<IndexT>(host_inputs.at(params[6]));
+ auto block_indices = tensor_to_vector<IndexT>(host_inputs.at(params[7]));
+ auto block_indices_begins = tensor_to_vector<IndexT>(host_inputs.at(params[8]));
+ auto num_processed_tokens = tensor_to_vector<IndexT>(host_inputs.at(params[9]));
+ auto cache_interval = tensor_to_vector<IndexT>(host_inputs.at(params[10]));
+
+ std::vector<T> ref_output;
+ run_reference(A,
+ dt,
+ B,
+ x,
+ C,
+ state,
+ subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ num_processed_tokens,
+ cache_interval,
+ num_heads,
+ num_groups,
+ head_dim,
+ state_size,
+ ref_output);
+
+ ov::Tensor output_tensor(data_type, host_inputs.at(params[3]).get_shape());
+ std::copy(ref_output.begin(), ref_output.end(), output_tensor.data<T>());
+
+ ov::Tensor state_tensor(data_type, host_inputs.at(params[5]).get_shape());
+ std::copy(state.begin(), state.end(), state_tensor.data<T>());
+
+ return {output_tensor, state_tensor};
+}
+
+template <typename T>
+std::vector<ov::Tensor> calculate_data_typed_refs(
+ const std::map<std::shared_ptr<ov::Node>, ov::Tensor>& host_inputs,
+ const std::shared_ptr<ov::Model>& function,
+ size_t num_heads,
+ size_t num_groups,
+ size_t head_dim,
+ size_t state_size,
+ const ov::element::Type& data_type,
+ const ov::element::Type& index_type) {
+ if (index_type == ov::element::i64) {
+ return calculate_typed_refs<T, int64_t>(
+ host_inputs, function, num_heads, num_groups, head_dim, state_size, data_type);
+ }
+ return calculate_typed_refs<T, int32_t>(
+ host_inputs, function, num_heads, num_groups, head_dim, state_size, data_type);
+}
+
+int32_t count_logical_blocks(const std::vector<int32_t>& sequence_lengths,
+ const std::vector<int32_t>& processed_tokens,
+ const std::vector<int32_t>& cache_intervals) {
+ OPENVINO_ASSERT(sequence_lengths.size() == processed_tokens.size());
+ OPENVINO_ASSERT(sequence_lengths.size() == cache_intervals.size());
+
+ int32_t result = 0;
+ for (size_t sequence = 0; sequence < sequence_lengths.size(); ++sequence) {
+ const auto sequence_length = sequence_lengths[sequence];
+ if (sequence_length == 0) {
+ continue;
+ }
+
+ const auto interval = cache_intervals[sequence];
+ if (interval <= 0) {
+ ++result;
+ continue;
+ }
+
+ const auto previous_offset = processed_tokens[sequence] % interval;
+ const auto write_count = (previous_offset + sequence_length + interval - 1) / interval;
+ result += 1 + write_count;
+ }
+ return result;
+}
+} // namespace
+
+namespace ov::test {
+
+std::string PagedSelectiveSSMLayerTest::getTestCaseName(
+ const testing::TestParamInfo<PagedSelectiveSSMLayerParams>& obj) {
+ const auto& [num_heads,
+ num_groups,
+ head_dim,
+ state_size,
+ seq_lengths,
+ num_processed_tokens,
+ cache_intervals,
+ element_type,
+ index_type,
+ target_device] = obj.param;
+ std::ostringstream result;
+ result << "Heads=" << num_heads;
+ result << "_Groups=" << num_groups;
+ result << "_HeadDim=" << head_dim;
+ result << "_StateSize=" << state_size;
+ result << "_SeqLens=";
+ for (size_t i = 0; i < seq_lengths.size(); i++) {
+ if (i > 0)
+ result << "x";
+ result << seq_lengths[i];
+ }
+ result << "_Processed=";
+ for (size_t i = 0; i < num_processed_tokens.size(); i++) {
+ if (i > 0)
+ result << "x";
+ result << num_processed_tokens[i];
+ }
+ result << "_Intervals=";
+ for (size_t i = 0; i < cache_intervals.size(); i++) {
+ if (i > 0)
+ result << "x";
+ if (cache_intervals[i] < 0) {
+ result << "neg" << -cache_intervals[i];
+ } else {
+ result << cache_intervals[i];
+ }
+ }
+ result << "_Type=" << element_type;
+ result << "_IndexType=" << index_type;
+ result << "_Target=" << target_device;
+ return result.str();
+}
+
+void PagedSelectiveSSMLayerTest::SetUp() {
+ const auto& [num_heads,
+ num_groups,
+ head_dim,
+ state_size,
+ seq_lengths,
+ num_processed_tokens,
+ cache_intervals,
+ data_type,
+ index_type,
+ device] = GetParam();
+ targetDevice = device;
+ this->data_type = data_type;
+ configuration[ov::hint::inference_precision.name()] = data_type;
+ OPENVINO_ASSERT(!seq_lengths.empty());
+ OPENVINO_ASSERT(seq_lengths.size() == num_processed_tokens.size());
+ OPENVINO_ASSERT(seq_lengths.size() == cache_intervals.size());
+
+ auto alternate_seq_lengths = seq_lengths;
+ auto alternate_processed_tokens = num_processed_tokens;
+ auto alternate_cache_intervals = cache_intervals;
+ alternate_seq_lengths.push_back(1);
+ alternate_processed_tokens.push_back(0);
+ alternate_cache_intervals.push_back(2);
+
+ const auto tokens = std::accumulate(seq_lengths.begin(), seq_lengths.end(), int32_t{0});
+ const auto alternate_tokens =
+ std::accumulate(alternate_seq_lengths.begin(), alternate_seq_lengths.end(), int32_t{0});
+ const auto num_sequences = static_cast<int32_t>(seq_lengths.size());
+ const auto alternate_num_sequences = static_cast<int32_t>(alternate_seq_lengths.size());
+ const auto num_blocks = count_logical_blocks(seq_lengths, num_processed_tokens, cache_intervals);
+ const auto alternate_num_blocks =
+ count_logical_blocks(alternate_seq_lengths, alternate_processed_tokens, alternate_cache_intervals);
+
+ const ov::Shape A_shape{static_cast<size_t>(num_heads)};
+ const ov::Shape dt_shape{static_cast<size_t>(tokens), static_cast<size_t>(num_heads)};
+ const ov::Shape alternate_dt_shape{static_cast<size_t>(alternate_tokens), static_cast<size_t>(num_heads)};
+ const ov::Shape BC_shape{static_cast<size_t>(tokens),
+ static_cast<size_t>(num_groups),
+ static_cast<size_t>(state_size)};
+ const ov::Shape alternate_BC_shape{static_cast<size_t>(alternate_tokens),
+ static_cast<size_t>(num_groups),
+ static_cast<size_t>(state_size)};
+ const ov::Shape x_shape{static_cast<size_t>(tokens), static_cast<size_t>(num_heads), static_cast<size_t>(head_dim)};
+ const ov::Shape alternate_x_shape{static_cast<size_t>(alternate_tokens),
+ static_cast<size_t>(num_heads),
+ static_cast<size_t>(head_dim)};
+ const ov::Shape state_shape{static_cast<size_t>(num_blocks) + 2,
+ static_cast<size_t>(num_heads),
+ static_cast<size_t>(head_dim),
+ static_cast<size_t>(state_size)};
+ const ov::Shape alternate_state_shape{static_cast<size_t>(alternate_num_blocks) + 2,
+ static_cast<size_t>(num_heads),
+ static_cast<size_t>(head_dim),
+ static_cast<size_t>(state_size)};
+ const auto repeated = [](const ov::Shape& shape) {
+ return std::vector<ov::Shape>{shape, shape, shape};
+ };
+ init_input_shapes(
+ {InputShape{ov::PartialShape{num_heads}, repeated(A_shape)},
+ InputShape{ov::PartialShape{-1, num_heads}, {dt_shape, alternate_dt_shape, dt_shape}},
+ InputShape{ov::PartialShape{-1, num_groups, state_size}, {BC_shape, alternate_BC_shape, BC_shape}},
+ InputShape{ov::PartialShape{-1, num_heads, head_dim}, {x_shape, alternate_x_shape, x_shape}},
+ InputShape{ov::PartialShape{-1, num_groups, state_size}, {BC_shape, alternate_BC_shape, BC_shape}},
+ InputShape{ov::PartialShape{-1, num_heads, head_dim, state_size},
+ {state_shape, alternate_state_shape, state_shape}},
+ InputShape{ov::PartialShape::dynamic(1),
+ {ov::Shape{static_cast<size_t>(num_sequences + 1)},
+ ov::Shape{static_cast<size_t>(alternate_num_sequences + 1)},
+ ov::Shape{static_cast<size_t>(num_sequences + 1)}}},
+ InputShape{ov::PartialShape::dynamic(1),
+ {ov::Shape{static_cast<size_t>(num_blocks)},
+ ov::Shape{static_cast<size_t>(alternate_num_blocks)},
+ ov::Shape{static_cast<size_t>(num_blocks)}}},
+ InputShape{ov::PartialShape::dynamic(1),
+ {ov::Shape{static_cast<size_t>(num_sequences + 1)},
+ ov::Shape{static_cast<size_t>(alternate_num_sequences + 1)},
+ ov::Shape{static_cast<size_t>(num_sequences + 1)}}},
+ InputShape{ov::PartialShape::dynamic(1),
+ {ov::Shape{static_cast<size_t>(num_sequences)},
+ ov::Shape{static_cast<size_t>(alternate_num_sequences)},
+ ov::Shape{static_cast<size_t>(num_sequences)}}},
+ InputShape{ov::PartialShape::dynamic(1),
+ {ov::Shape{static_cast<size_t>(num_sequences)},
+ ov::Shape{static_cast<size_t>(alternate_num_sequences)},
+ ov::Shape{static_cast<size_t>(num_sequences)}}}});
+
+ auto p_A = std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{num_heads});
+ auto p_dt = std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, num_heads});
+ auto p_B = std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, num_groups, state_size});
+ auto p_x = std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, num_heads, head_dim});
+ auto p_C = std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, num_groups, state_size});
+ auto p_state =
+ std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, num_heads, head_dim, state_size});
+ // The state table is mutable, and PagedSelectiveSSM requires one type for the complete data group.
+ for (const auto& parameter : {p_A, p_dt, p_B, p_x, p_C, p_state}) {
+ ov::enable_keep_const_precision(parameter);
+ }
+ auto p_subseq = std::make_shared<ov::op::v0::Parameter>(index_type, ov::PartialShape{-1});
+ auto p_blocks = std::make_shared<ov::op::v0::Parameter>(index_type, ov::PartialShape{-1});
+ auto p_block_begins = std::make_shared<ov::op::v0::Parameter>(index_type, ov::PartialShape{-1});
+ auto p_num_processed = std::make_shared<ov::op::v0::Parameter>(index_type, ov::PartialShape{-1});
+ auto p_cache_interval = std::make_shared<ov::op::v0::Parameter>(index_type, ov::PartialShape{-1});
+ auto pssm = std::make_shared<ov::op::internal::PagedSelectiveSSM>(p_A,
+ p_dt,
+ p_B,
+ p_x,
+ p_C,
+ p_state,
+ p_subseq,
+ p_blocks,
+ p_block_begins,
+ p_num_processed,
+ p_cache_interval);
+
+ function = std::make_shared<ov::Model>(ov::ResultVector{std::make_shared<ov::op::v0::Result>(pssm)},
+ ov::ParameterVector{p_A,
+ p_dt,
+ p_B,
+ p_x,
+ p_C,
+ p_state,
+ p_subseq,
+ p_blocks,
+ p_block_begins,
+ p_num_processed,
+ p_cache_interval});
+}
+
+void PagedSelectiveSSMLayerTest::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {
+ inputs.clear();
+ host_inputs.clear();
+
+ const auto& [num_heads,
+ num_groups,
+ head_dim,
+ state_size,
+ seq_lengths,
+ num_processed_tokens_param,
+ cache_intervals,
+ element_type,
+ index_type,
+ device] = GetParam();
+ const auto num_sequences = static_cast<int32_t>(targetInputStaticShapes[9][0]);
+ OPENVINO_ASSERT(targetInputStaticShapes[6][0] == static_cast<size_t>(num_sequences + 1));
+ OPENVINO_ASSERT(targetInputStaticShapes[8][0] == static_cast<size_t>(num_sequences + 1));
+ OPENVINO_ASSERT(targetInputStaticShapes[10][0] == static_cast<size_t>(num_sequences));
+ const bool use_alternate_metadata = static_cast<size_t>(num_sequences) != seq_lengths.size();
+ auto active_seq_lengths = seq_lengths;
+ auto active_processed_tokens = num_processed_tokens_param;
+ auto active_cache_intervals = cache_intervals;
+ if (use_alternate_metadata) {
+ active_seq_lengths.push_back(1);
+ active_processed_tokens.push_back(0);
+ active_cache_intervals.push_back(2);
+ }
+ OPENVINO_ASSERT(static_cast<size_t>(num_sequences) == active_seq_lengths.size());
+
+ std::vector<int32_t> subsequence_begins;
+ std::vector<int32_t> block_indices;
+ std::vector<int32_t> block_indices_begins;
+ std::vector<int32_t> num_processed_tokens;
+ std::vector<int32_t> cache_interval;
+
+ subsequence_begins.reserve(static_cast<size_t>(num_sequences + 1));
+ block_indices_begins.reserve(static_cast<size_t>(num_sequences + 1));
+ num_processed_tokens.reserve(static_cast<size_t>(num_sequences));
+ cache_interval.reserve(static_cast<size_t>(num_sequences));
+
+ subsequence_begins.push_back(0);
+ block_indices_begins.push_back(0);
+
+ int32_t next_physical_block = 0;
+ for (int32_t seq = 0; seq < num_sequences; seq++) {
+ const int32_t seq_len = active_seq_lengths[seq];
+ const int32_t seq_interval = active_cache_intervals[seq];
+ const int32_t processed = active_processed_tokens[seq];
+
+ subsequence_begins.push_back(subsequence_begins.back() + seq_len);
+ num_processed_tokens.push_back(processed);
+ cache_interval.push_back(seq_interval);
+
+ if (seq_len > 0) {
+ const int32_t read_block = next_physical_block++;
+ block_indices.push_back(read_block);
+ }
+ if (seq_len > 0 && seq_interval > 0) {
+ const int32_t prev_nums = processed % seq_interval;
+ const int32_t write_blocks = (prev_nums + seq_len + seq_interval - 1) / seq_interval;
+ const bool alias_first_write = processed == 0 || prev_nums != 0;
+ const int32_t read_block = block_indices.back();
+ for (int32_t write = 0; write < write_blocks; ++write) {
+ block_indices.push_back(write == 0 && alias_first_write ? read_block : next_physical_block++);
+ }
+ }
+ block_indices_begins.push_back(static_cast<int32_t>(block_indices.size()));
+ }
+
+ const auto& params = function->get_parameters();
+ const bool use_remote_tensors = targetDevice == "GPU";
+ ov::RemoteContext remote_context;
+ if (use_remote_tensors) {
+ remote_context = compiledModel.get_context();
+ }
+
+ for (size_t i = 0; i < params.size(); i++) {
+ const auto& param = params[i];
+ const auto& shape = targetInputStaticShapes[i];
+ ov::Tensor tensor;
+
+ if (i == 0) {
+ tensor = ov::test::utils::create_and_fill_tensor_real_distribution(param->get_element_type(),
+ shape,
+ -0.5f,
+ 0.2f,
+ 1);
+ } else if (i == 1) {
+ tensor = ov::test::utils::create_and_fill_tensor_real_distribution(param->get_element_type(),
+ shape,
+ 0.0f,
+ 0.5f,
+ 1);
+ } else if (i <= 5) {
+ tensor = ov::test::utils::create_and_fill_tensor(param->get_element_type(),
+ shape,
+ ov::test::utils::InputGenerateData(-0.5f, 1.0f, 1000, 1));
+ } else if (i == 6) {
+ tensor = make_index_tensor(subsequence_begins, index_type);
+ } else if (i == 7) {
+ tensor = make_index_tensor(block_indices, index_type);
+ } else if (i == 8) {
+ tensor = make_index_tensor(block_indices_begins, index_type);
+ } else if (i == 9) {
+ tensor = make_index_tensor(num_processed_tokens, index_type);
+ } else if (i == 10) {
+ tensor = make_index_tensor(cache_interval, index_type);
+ }
+
+ // The operation updates the state input in place, so the oracle needs an independent pre-inference snapshot.
+ ov::Tensor host_tensor(tensor.get_element_type(), tensor.get_shape());
+ tensor.copy_to(host_tensor);
+ host_inputs[param] = host_tensor;
+ if (use_remote_tensors && i <= 5) {
+ auto remote_tensor = remote_context.create_tensor(param->get_element_type(), shape);
+ remote_tensor.copy_from(tensor);
+ inputs[param] = remote_tensor;
+ } else {
+ inputs[param] = tensor;
+ }
+ }
+}
+
+std::vector<ov::Tensor> PagedSelectiveSSMLayerTest::calculate_refs() {
+ const auto& [num_heads,
+ num_groups,
+ head_dim,
+ state_size,
+ seq_lengths,
+ num_processed_tokens,
+ cache_intervals,
+ element_type,
+ index_type,
+ device] = GetParam();
+
+ if (element_type == ov::element::f16) {
+ return calculate_data_typed_refs<ov::float16>(
+ host_inputs, function, num_heads, num_groups, head_dim, state_size, element_type, index_type);
+ }
+ if (element_type == ov::element::bf16) {
+ return calculate_data_typed_refs<ov::bfloat16>(
+ host_inputs, function, num_heads, num_groups, head_dim, state_size, element_type, index_type);
+ }
+ return calculate_data_typed_refs<float>(
+ host_inputs, function, num_heads, num_groups, head_dim, state_size, element_type, index_type);
+}
+
+std::vector<ov::Tensor> PagedSelectiveSSMLayerTest::get_plugin_outputs() {
+ auto outputs = SubgraphBaseTest::get_plugin_outputs();
+
+ const auto& state_param = function->get_parameters().at(5);
+ const auto actual_state_tensor = inferRequest.get_tensor(state_param);
+ ov::Tensor host_state_tensor(actual_state_tensor.get_element_type(), actual_state_tensor.get_shape());
+ actual_state_tensor.copy_to(host_state_tensor);
+ outputs.push_back(host_state_tensor);
+
+ return outputs;
+}
+
+void PagedSelectiveSSMLayerTest::compare(const std::vector<ov::Tensor>& expected,
+ const std::vector<ov::Tensor>& actual) {
+ ASSERT_EQ(expected.size(), actual.size());
+ if (data_type == ov::element::bf16) {
+ abs_threshold = 1e-3f;
+ rel_threshold = 1e-2f;
+ } else if (data_type == ov::element::f16) {
+ abs_threshold = 5e-4f;
+ rel_threshold = 1e-5f;
+ } else {
+ abs_threshold = 2e-4f;
+ rel_threshold = 1e-5f;
+ }
+ ov::test::utils::compare(expected[0], actual[0], abs_threshold, rel_threshold);
+ ov::test::utils::compare(expected[1], actual[1], abs_threshold, rel_threshold);
+}
+
+TEST_P(PagedSelectiveSSMLayerTest, Inference) {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED();
+ run();
+ const auto runtime_model = compiledModel.get_runtime_model();
+ CheckNumberOfNodesWithType(runtime_model, {"PagedSelectiveSSM"}, 1);
+ CheckNumberOfNodesWithType(runtime_model, {"Loop"}, 0);
+}
+
+TEST(PagedSelectiveSSMFunctionalTest, RejectsMalformedMetadataBeforeExecution) {
+ struct MetadataCase {
+ const char* name;
+ std::vector<int32_t> subsequences;
+ std::vector<int32_t> blocks;
+ std::vector<int32_t> block_begins;
+ std::vector<int32_t> processed;
+ std::vector<int32_t> intervals;
+ };
+
+ const std::vector<MetadataCase> cases{
+ {"negative sequence offset", {-1, 1}, {0, 1}, {0, 2}, {0}, {1}},
+ {"wrong final sequence offset", {0, 0}, {0, 1}, {0, 2}, {0}, {1}},
+ {"negative block index", {0, 1}, {-1, 1}, {0, 2}, {0}, {1}},
+ {"out of range block index", {0, 1}, {0, 2}, {0, 2}, {0}, {1}},
+ {"negative processed token count", {0, 1}, {0, 1}, {0, 2}, {-1}, {1}},
+ {"insufficient writable blocks", {0, 1}, {0, 1}, {0, 1}, {0}, {1}},
+ };
+
+ ov::Core core;
+ auto compiled_model = core.compile_model(make_paged_validation_model(), "CPU");
+ for (const auto& test_case : cases) {
+ SCOPED_TRACE(test_case.name);
+ auto request = compiled_model.create_infer_request();
+ request.set_input_tensor(0, make_f32_tensor({1}, {-0.2F}));
+ request.set_input_tensor(1, make_f32_tensor({1, 1}, {0.1F}));
+ request.set_input_tensor(2, make_f32_tensor({1, 1, 1}, {0.2F}));
+ request.set_input_tensor(3, make_f32_tensor({1, 1, 1}, {0.3F}));
+ request.set_input_tensor(4, make_f32_tensor({1, 1, 1}, {0.4F}));
+ request.set_input_tensor(5, make_f32_tensor({2, 1, 1, 1}, {0.F, 0.F}));
+ request.set_input_tensor(6, make_index_tensor(test_case.subsequences, ov::element::i32));
+ request.set_input_tensor(7, make_index_tensor(test_case.blocks, ov::element::i32));
+ request.set_input_tensor(8, make_index_tensor(test_case.block_begins, ov::element::i32));
+ request.set_input_tensor(9, make_index_tensor(test_case.processed, ov::element::i32));
+ request.set_input_tensor(10, make_index_tensor(test_case.intervals, ov::element::i32));
+ EXPECT_THROW(request.infer(), ov::Exception);
+ }
+}
+
+} // namespace ov::test
diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/paged_selective_ssm.hpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/paged_selective_ssm.hpp
new file mode 100644
index 00000000000..3a34a8777fc
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/paged_selective_ssm.hpp
@@ -0,0 +1,48 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstdint>
+#include <map>
+#include <string>
+#include <tuple>
+#include <vector>
+
+#include "gtest/gtest.h"
+#include "shared_test_classes/base/ov_subgraph.hpp"
+
+namespace ov::test {
+
+using PagedSelectiveSSMLayerParams = std::tuple<int32_t,
+ int32_t,
+ int32_t,
+ int32_t,
+ std::vector<int32_t>,
+ std::vector<int32_t>,
+ std::vector<int32_t>,
+ ov::element::Type,
+ ov::element::Type,
+ std::string>; // num_heads, num_groups, head_dim, state_size,
+ // seq_lengths, num_processed_tokens, cache_intervals,
+ // element_type, index_type, target_device
+
+class PagedSelectiveSSMLayerTest : public testing::WithParamInterface<PagedSelectiveSSMLayerParams>,
+ virtual public ov::test::SubgraphBaseTest {
+public:
+ static std::string getTestCaseName(const testing::TestParamInfo<PagedSelectiveSSMLayerParams>& obj);
+ void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;
+
+protected:
+ std::vector<ov::Tensor> calculate_refs() override;
+ std::vector<ov::Tensor> get_plugin_outputs() override;
+ void compare(const std::vector<ov::Tensor>& expected, const std::vector<ov::Tensor>& actual) override;
+ void SetUp() override;
+
+private:
+ std::map<std::shared_ptr<ov::Node>, ov::Tensor> host_inputs;
+ ov::element::Type data_type;
+};
+
+} // namespace ov::test
diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/paged_selective_ssm.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/paged_selective_ssm.cpp
new file mode 100644
index 00000000000..7312411cf5a
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/paged_selective_ssm.cpp
@@ -0,0 +1,37 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "custom/single_layer_tests/classes/paged_selective_ssm.hpp"
+
+namespace ov::test {
+
+std::vector<PagedSelectiveSSMLayerParams> paged_selective_ssm_test_cases = {
+ {4, 2, 5, 3, {3}, {0}, {2}, ov::element::f32, ov::element::i32, "CPU"},
+ {4, 2, 5, 3, {3}, {4}, {2}, ov::element::f32, ov::element::i32, "CPU"},
+ {4, 2, 5, 3, {4}, {1}, {3}, ov::element::f32, ov::element::i32, "CPU"},
+ {4, 2, 5, 3, {1}, {4}, {2}, ov::element::f32, ov::element::i32, "CPU"},
+ {4, 2, 5, 3, {1}, {3}, {2}, ov::element::f32, ov::element::i32, "CPU"},
+ {4, 2, 5, 3, {0, 2, 1}, {7, 1, 0}, {2, 2, 4}, ov::element::f32, ov::element::i32, "CPU"},
+ {4, 2, 5, 3, {0, 0}, {0, 7}, {2, -3}, ov::element::f32, ov::element::i32, "CPU"},
+ {4, 1, 3, 4, {3, 2}, {5, 9}, {0, -3}, ov::element::f32, ov::element::i32, "CPU"},
+ {3, 3, 1, 1, {4}, {0}, {1}, ov::element::f32, ov::element::i64, "CPU"},
+ {4, 2, 5, 3, {1}, {0}, {2}, ov::element::f32, ov::element::i64, "CPU"},
+ {64, 1, 64, 128, {1}, {0}, {1}, ov::element::f32, ov::element::i32, "CPU"},
+ {96, 8, 80, 80, {5}, {0}, {2}, ov::element::f32, ov::element::i64, "CPU"},
+ {4, 2, 5, 3, {1}, {0}, {2}, ov::element::f16, ov::element::i32, "CPU"},
+ {4, 2, 5, 3, {3, 1}, {1, 4}, {3, 2}, ov::element::f16, ov::element::i32, "CPU"},
+ {4, 2, 5, 3, {1}, {0}, {2}, ov::element::f16, ov::element::i64, "CPU"},
+ {4, 2, 5, 3, {3, 1}, {1, 4}, {3, 2}, ov::element::f16, ov::element::i64, "CPU"},
+ {4, 2, 5, 3, {1}, {0}, {2}, ov::element::bf16, ov::element::i32, "CPU"},
+ {4, 2, 5, 3, {3, 1}, {1, 4}, {3, 2}, ov::element::bf16, ov::element::i32, "CPU"},
+ {4, 2, 5, 3, {1}, {0}, {2}, ov::element::bf16, ov::element::i64, "CPU"},
+ {4, 2, 5, 3, {3, 1}, {1, 4}, {3, 2}, ov::element::bf16, ov::element::i64, "CPU"},
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_PagedSelectiveSSM,
+ PagedSelectiveSSMLayerTest,
+ ::testing::ValuesIn(paged_selective_ssm_test_cases),
+ PagedSelectiveSSMLayerTest::getTestCaseName);
+
+} // namespace ov::test
diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/include/selective_ssm.hpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/include/selective_ssm.hpp
new file mode 100644
index 00000000000..64a77a05c7b
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/include/selective_ssm.hpp
@@ -0,0 +1,32 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "shared_test_classes/base/ov_subgraph.hpp"
+
+namespace ov::test {
+
+using selective_ssm_params = std::tuple<int32_t, // B
+ int32_t, // T
+ int32_t, // H
+ int32_t, // G
+ int32_t, // P
+ int32_t, // N
+ ov::element::Type, // infer_precision
+ std::string // device
+ >;
+
+class SelectiveSSM : public testing::WithParamInterface<selective_ssm_params>, public ov::test::SubgraphBaseTest {
+public:
+ void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;
+ static std::string getTestCaseName(const testing::TestParamInfo<selective_ssm_params>& obj);
+
+protected:
+ std::vector<ov::Tensor> calculate_refs() override;
+ void compare(const std::vector<ov::Tensor>& expected, const std::vector<ov::Tensor>& actual) override;
+ void SetUp() override;
+};
+
+} // namespace ov::test
diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/selective_ssm.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/selective_ssm.cpp
new file mode 100644
index 00000000000..9dedf6ccb62
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/selective_ssm.cpp
@@ -0,0 +1,245 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "custom/subgraph_tests/include/selective_ssm.hpp"
+
+#include <algorithm>
+#include <cmath>
+#include <map>
+#include <sstream>
+#include <vector>
+
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "openvino/core/type/bfloat16.hpp"
+#include "openvino/core/type/float16.hpp"
+#include "openvino/op/selective_ssm.hpp"
+#include "openvino/runtime/properties.hpp"
+
+namespace {
+
+template <typename T>
+std::vector<ov::Tensor> calculate_selective_ssm_refs(const std::map<std::shared_ptr<ov::Node>, ov::Tensor>& inputs,
+ const std::shared_ptr<ov::Model>& function) {
+ const auto& params = function->get_parameters();
+ const auto& A_tensor = inputs.at(params[0]);
+ const auto& dt_tensor = inputs.at(params[1]);
+ const auto& B_tensor = inputs.at(params[2]);
+ const auto& x_tensor = inputs.at(params[3]);
+ const auto& C_tensor = inputs.at(params[4]);
+ const auto& initial_state_tensor = inputs.at(params[5]);
+ const auto& x_shape = x_tensor.get_shape();
+ const auto& B_shape = B_tensor.get_shape();
+ const auto& state_shape = initial_state_tensor.get_shape();
+ const auto batch_size = x_shape[0];
+ const auto sequence_length = x_shape[1];
+ const auto num_heads = x_shape[2];
+ const auto head_dim = x_shape[3];
+ const auto num_groups = B_shape[2];
+ const auto state_size = B_shape[3];
+ const auto heads_per_group = num_heads / num_groups;
+
+ const auto* A = A_tensor.data<const T>();
+ const auto* dt = dt_tensor.data<const T>();
+ const auto* B = B_tensor.data<const T>();
+ const auto* x = x_tensor.data<const T>();
+ const auto* C = C_tensor.data<const T>();
+ const auto* initial_state = initial_state_tensor.data<const T>();
+ std::vector<float> state(initial_state_tensor.get_size());
+ std::transform(initial_state, initial_state + state.size(), state.begin(), [](T value) {
+ return static_cast<float>(value);
+ });
+
+ // Deliberately materialize the small discretized terms in the oracle. The production kernel does not use this
+ // decomposition, so this catches indexing/grouping mistakes independently of its fused update-reduction loop.
+ const auto token_heads = batch_size * sequence_length * num_heads;
+ std::vector<float> decay(token_heads);
+ std::vector<float> discretized_B(token_heads * state_size);
+ for (size_t batch = 0; batch < batch_size; ++batch) {
+ for (size_t token = 0; token < sequence_length; ++token) {
+ for (size_t head = 0; head < num_heads; ++head) {
+ const auto token_head = (batch * sequence_length + token) * num_heads + head;
+ const auto group = head / heads_per_group;
+ const auto grouped_projection =
+ ((batch * sequence_length + token) * num_groups + group) * state_size;
+ const float delta = static_cast<float>(dt[token_head]);
+ decay[token_head] = std::exp(static_cast<float>(A[head]) * delta);
+ for (size_t state_index = 0; state_index < state_size; ++state_index) {
+ discretized_B[token_head * state_size + state_index] =
+ delta * static_cast<float>(B[grouped_projection + state_index]);
+ }
+ }
+ }
+ }
+
+ ov::Tensor output_tensor(x_tensor.get_element_type(), x_shape);
+ auto* output = output_tensor.data<T>();
+ const auto state_batch_stride = num_heads * head_dim * state_size;
+ const auto state_head_stride = head_dim * state_size;
+ for (size_t batch = 0; batch < batch_size; ++batch) {
+ for (size_t head = 0; head < num_heads; ++head) {
+ const auto group = head / heads_per_group;
+ for (size_t position = 0; position < head_dim; ++position) {
+ const auto state_base =
+ batch * state_batch_stride + head * state_head_stride + position * state_size;
+ for (size_t token = 0; token < sequence_length; ++token) {
+ const auto token_head = (batch * sequence_length + token) * num_heads + head;
+ const auto projection_base =
+ ((batch * sequence_length + token) * num_groups + group) * state_size;
+ const auto x_index = token_head * head_dim + position;
+ const float input = static_cast<float>(x[x_index]);
+ for (size_t state_index = 0; state_index < state_size; ++state_index) {
+ auto& state_value = state[state_base + state_index];
+ state_value = state_value * decay[token_head] +
+ input * discretized_B[token_head * state_size + state_index];
+ }
+
+ double reduction = 0.0;
+ for (size_t state_index = 0; state_index < state_size; ++state_index) {
+ reduction += static_cast<double>(state[state_base + state_index]) *
+ static_cast<float>(C[projection_base + state_index]);
+ }
+ output[x_index] = static_cast<T>(reduction);
+ }
+ }
+ }
+ }
+
+ ov::Tensor state_tensor(initial_state_tensor.get_element_type(), state_shape);
+ std::transform(state.begin(), state.end(), state_tensor.data<T>(), [](float value) {
+ return static_cast<T>(value);
+ });
+ return {output_tensor, state_tensor};
+}
+} // namespace
+
+namespace ov::test {
+
+std::string SelectiveSSM::getTestCaseName(const testing::TestParamInfo<selective_ssm_params>& obj) {
+ const auto& [batch, seq_len, num_heads, num_groups, head_dim, state_size, prec, device] = obj.param;
+ std::ostringstream result;
+ result << "batch=" << batch;
+ result << ",seq_len=" << seq_len;
+ result << ",num_heads=" << num_heads;
+ result << ",num_groups=" << num_groups;
+ result << ",head_dim=" << head_dim;
+ result << ",state_size=" << state_size;
+ result << ",prec=" << prec;
+ result << ",device=" << device;
+ return result.str();
+}
+
+void SelectiveSSM::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {
+ inputs.clear();
+ const auto& params = function->get_parameters();
+ for (size_t i = 0; i < params.size(); ++i) {
+ const auto& param = params[i];
+ const auto& shape = targetInputStaticShapes[i];
+ if (i == 0) {
+ inputs[param] = ov::test::utils::create_and_fill_tensor_real_distribution(param->get_element_type(),
+ shape,
+ -0.5f,
+ 0.2f,
+ 1);
+ } else if (i == 1) {
+ inputs[param] = ov::test::utils::create_and_fill_tensor_real_distribution(param->get_element_type(),
+ shape,
+ 0.0f,
+ 0.5f,
+ 1);
+ } else {
+ inputs[param] =
+ ov::test::utils::create_and_fill_tensor(param->get_element_type(),
+ shape,
+ ov::test::utils::InputGenerateData(-0.5f, 1.0f, 1000, 1));
+ }
+ }
+}
+
+std::vector<ov::Tensor> SelectiveSSM::calculate_refs() {
+ const auto& precision = std::get<6>(GetParam());
+ if (precision == ov::element::f16) {
+ return calculate_selective_ssm_refs<ov::float16>(inputs, function);
+ }
+ if (precision == ov::element::bf16) {
+ return calculate_selective_ssm_refs<ov::bfloat16>(inputs, function);
+ }
+ return calculate_selective_ssm_refs<float>(inputs, function);
+}
+
+void SelectiveSSM::compare(const std::vector<ov::Tensor>& expected, const std::vector<ov::Tensor>& actual) {
+ ASSERT_EQ(expected.size(), actual.size());
+ ov::test::utils::compare(expected[0], actual[0], abs_threshold, rel_threshold);
+ ov::test::utils::compare(expected[1], actual[1], abs_threshold, rel_threshold);
+}
+
+void SelectiveSSM::SetUp() {
+ const auto& [batch, seq_len, num_heads, num_groups, head_dim, state_size, prec, device] = GetParam();
+
+ targetDevice = device;
+ inType = prec;
+ configuration[ov::hint::inference_precision.name()] = prec;
+
+ abs_threshold = prec == ov::element::f32 ? 1e-6f : 1e-3f;
+ rel_threshold = 1e-5f;
+
+ const ov::Shape A_shape{static_cast<size_t>(num_heads)};
+ const ov::Shape dt_shape{static_cast<size_t>(batch), static_cast<size_t>(seq_len), static_cast<size_t>(num_heads)};
+ const ov::Shape alternate_dt_shape{static_cast<size_t>(batch == 1 ? 2 : 1),
+ static_cast<size_t>(seq_len + 2),
+ static_cast<size_t>(num_heads)};
+ const ov::Shape B_shape{static_cast<size_t>(batch),
+ static_cast<size_t>(seq_len),
+ static_cast<size_t>(num_groups),
+ static_cast<size_t>(state_size)};
+ const ov::Shape x_shape{static_cast<size_t>(batch),
+ static_cast<size_t>(seq_len),
+ static_cast<size_t>(num_heads),
+ static_cast<size_t>(head_dim)};
+ const ov::Shape alternate_B_shape{alternate_dt_shape[0],
+ alternate_dt_shape[1],
+ static_cast<size_t>(num_groups),
+ static_cast<size_t>(state_size)};
+ const ov::Shape alternate_x_shape{alternate_dt_shape[0],
+ alternate_dt_shape[1],
+ static_cast<size_t>(num_heads),
+ static_cast<size_t>(head_dim)};
+ const ov::Shape state_shape{static_cast<size_t>(batch),
+ static_cast<size_t>(num_heads),
+ static_cast<size_t>(head_dim),
+ static_cast<size_t>(state_size)};
+ const ov::Shape alternate_state_shape{alternate_dt_shape[0],
+ static_cast<size_t>(num_heads),
+ static_cast<size_t>(head_dim),
+ static_cast<size_t>(state_size)};
+
+ init_input_shapes(
+ {InputShape{ov::PartialShape{num_heads}, {A_shape, A_shape, A_shape}},
+ InputShape{ov::PartialShape{-1, -1, num_heads}, {dt_shape, alternate_dt_shape, dt_shape}},
+ InputShape{ov::PartialShape{-1, -1, num_groups, state_size}, {B_shape, alternate_B_shape, B_shape}},
+ InputShape{ov::PartialShape{-1, -1, num_heads, head_dim}, {x_shape, alternate_x_shape, x_shape}},
+ InputShape{ov::PartialShape{-1, -1, num_groups, state_size}, {B_shape, alternate_B_shape, B_shape}},
+ InputShape{ov::PartialShape{-1, num_heads, head_dim, state_size},
+ {state_shape, alternate_state_shape, state_shape}}});
+
+ auto A = std::make_shared<ov::op::v0::Parameter>(prec, ov::PartialShape{num_heads});
+ auto dt = std::make_shared<ov::op::v0::Parameter>(prec, ov::PartialShape{-1, -1, num_heads});
+ auto B = std::make_shared<ov::op::v0::Parameter>(prec, ov::PartialShape{-1, -1, num_groups, state_size});
+ auto x = std::make_shared<ov::op::v0::Parameter>(prec, ov::PartialShape{-1, -1, num_heads, head_dim});
+ auto C = std::make_shared<ov::op::v0::Parameter>(prec, ov::PartialShape{-1, -1, num_groups, state_size});
+ auto state = std::make_shared<ov::op::v0::Parameter>(prec, ov::PartialShape{-1, num_heads, head_dim, state_size});
+ auto selective_ssm = std::make_shared<ov::op::internal::SelectiveSSM>(A, dt, B, x, C, state);
+ function = std::make_shared<ov::Model>(selective_ssm->outputs(),
+ ov::ParameterVector{A, dt, B, x, C, state},
+ "SelectiveSSM");
+}
+
+TEST_P(SelectiveSSM, CompareWithRefs) {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED();
+ run();
+ const auto runtime_model = compiledModel.get_runtime_model();
+ CheckNumberOfNodesWithType(runtime_model, {"SelectiveSSM"}, 1);
+ CheckNumberOfNodesWithType(runtime_model, {"Loop"}, 0);
+}
+
+} // namespace ov::test
diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/common/selective_ssm.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/common/selective_ssm.cpp
new file mode 100644
index 00000000000..4cea2f07c5c
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/common/selective_ssm.cpp
@@ -0,0 +1,29 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "custom/subgraph_tests/include/selective_ssm.hpp"
+
+namespace ov::test {
+
+std::vector<selective_ssm_params> selective_ssm_test_cases = {
+ {1, 1, 1, 1, 1, 1, ov::element::f32, "CPU"},
+ {1, 0, 2, 1, 3, 4, ov::element::f32, "CPU"},
+ {1, 3, 4, 4, 5, 3, ov::element::f32, "CPU"},
+ {2, 5, 6, 3, 7, 5, ov::element::f32, "CPU"},
+ {1, 4, 4, 2, 8, 16, ov::element::f32, "CPU"},
+ {2, 3, 4, 1, 8, 8, ov::element::f32, "CPU"},
+ {1, 4, 4, 2, 8, 16, ov::element::f16, "CPU"},
+ {1, 1, 4, 2, 8, 16, ov::element::f16, "CPU"},
+ {1, 4, 4, 2, 8, 16, ov::element::bf16, "CPU"},
+ {1, 1, 4, 2, 8, 16, ov::element::bf16, "CPU"},
+ {1, 1, 64, 1, 64, 128, ov::element::f32, "CPU"},
+ {1, 5, 96, 8, 80, 80, ov::element::f32, "CPU"},
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_SelectiveSSM,
+ SelectiveSSM,
+ ::testing::ValuesIn(selective_ssm_test_cases),
+ SelectiveSSM::getTestCaseName);
+
+} // namespace ov::test