Skip to content

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

[CPU] GDN uses native bf16/f16 instruction. (#36160)

Zhang Yi974c183277da
diff --git a/src/plugins/intel_cpu/src/nodes/executors/executor.hpp b/src/plugins/intel_cpu/src/nodes/executors/executor.hpp
index b7790175b93..13fc179af57 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/executor.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/executor.hpp
@@ -41,7 +41,7 @@ enum class ExecutorType : uint8_t {
Kleidiai,
};
-enum class OperationType : uint8_t { FullyConnected, MatMul, Convolution, Eltwise, GatherMatmul };
+enum class OperationType : uint8_t { FullyConnected, MatMul, Convolution, Eltwise, GatherMatmul, GatedDeltaNet };
std::string ExecutorTypeToString(ExecutorType type);
ExecutorType ExecutorTypeFromString(const std::string& typeStr);
diff --git a/src/plugins/intel_cpu/src/nodes/executors/gated_delta_net_config.hpp b/src/plugins/intel_cpu/src/nodes/executors/gated_delta_net_config.hpp
new file mode 100644
index 00000000000..e7f5ea87246
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/gated_delta_net_config.hpp
@@ -0,0 +1,34 @@
+// 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 GatedDeltaNetAttrs {
+ bool fuse_qk_l2norm = false;
+ float q_l2_norm_eps = 1e-6F;
+ float k_l2_norm_eps = 1e-6F;
+ size_t jit_v_tile = 16;
+};
+
+using GatedDeltaNetConfig = executor::Config<GatedDeltaNetAttrs>;
+
+enum GatedDeltaNetArgId : uint8_t {
+ ARG_GDN_QUERY = ARG_SRC_0,
+ ARG_GDN_KEY = ARG_SRC_1,
+ ARG_GDN_VALUE = ARG_SRC_2,
+ ARG_GDN_STATE = ARG_SRC_3,
+ ARG_GDN_GATE = ARG_SRC_4,
+ ARG_GDN_BETA = ARG_SRC_5,
+ ARG_GDN_OUT_ATTN = ARG_DST_0,
+ ARG_GDN_OUT_STATE = ARG_DST_0 + 1,
+};
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/gdn_implementations.cpp b/src/plugins/intel_cpu/src/nodes/executors/gdn_implementations.cpp
new file mode 100644
index 00000000000..ed525b4b912
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/gdn_implementations.cpp
@@ -0,0 +1,78 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <vector>
+
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/executor_implementation.hpp"
+#include "nodes/executors/gated_delta_net_config.hpp"
+#include "nodes/executors/implementation_utils.hpp"
+#include "nodes/executors/implementations.hpp"
+#include "nodes/executors/ref/gdn_ref_executor.hpp"
+#include "utils/arch_macros.h"
+
+#if defined(OPENVINO_ARCH_X86_64)
+# include <cstddef>
+
+# include "nodes/executors/debug_messages.hpp"
+# include "nodes/executors/memory_arguments.hpp"
+# include "nodes/executors/x64/gdn_jit_executor.hpp"
+# include "openvino/core/type/element_type.hpp"
+#endif
+
+namespace ov::intel_cpu {
+
+// clang-format off
+template <>
+const std::vector<ExecutorImplementation<GatedDeltaNetAttrs>>& getImplementations() {
+ static const std::vector<ExecutorImplementation<GatedDeltaNetAttrs>> gatedDeltaNetImplementations {
+ OV_CPU_INSTANCE_X64(
+ "gdn_jit_executor",
+ ExecutorType::Jit,
+ OperationType::GatedDeltaNet,
+ [](const GatedDeltaNetConfig& config) -> bool {
+ return GdnJitExecutor::supports(config);
+ },
+ HasNoOptimalConfig<GatedDeltaNetAttrs>{},
+ [](const GatedDeltaNetAttrs& attrs, const MemoryArgs& memory) -> bool {
+ const auto precision = memory.at(ARG_GDN_QUERY)->getDescPtr()->getPrecision();
+ const auto& queryShape = memory.at(ARG_GDN_QUERY)->getDescPtr()->getShape();
+ const size_t jitVTile = precision == ov::element::f32 ? 1 : attrs.jit_v_tile;
+ const auto& valueShape = memory.at(ARG_GDN_VALUE)->getDescPtr()->getShape();
+ VERIFY(!queryShape.isDynamic() && !valueShape.isDynamic(), UNSUPPORTED_BY_EXECUTOR, " dynamic shape");
+
+ const auto& queryDims = queryShape.getStaticDims();
+ VERIFY(!queryDims.empty(), UNSUPPORTED_BY_EXECUTOR, " empty query dims");
+
+ VERIFY((precision != ov::element::f16 && precision != ov::element::bf16) || queryDims.back() % 32 == 0,
+ UNSUPPORTED_BY_EXECUTOR,
+ " xf16 requires qk_head_size % 32 == 0");
+
+ const auto& valueDims = valueShape.getStaticDims();
+ VERIFY(!valueDims.empty(), UNSUPPORTED_BY_EXECUTOR, " empty value dims");
+ VERIFY(valueDims.back() % jitVTile == 0,
+ UNSUPPORTED_BY_EXECUTOR,
+ " value head dim is not divisible by JIT tile");
+ return true;
+ },
+ CreateDefault<GdnJitExecutor, GatedDeltaNetAttrs>{}
+ )
+ OV_CPU_INSTANCE_COMMON(
+ "gdn_ref_executor",
+ ExecutorType::Common,
+ OperationType::GatedDeltaNet,
+ [](const GatedDeltaNetConfig& config) -> bool {
+ return GdnRefExecutor::supports(config);
+ },
+ HasNoOptimalConfig<GatedDeltaNetAttrs>{},
+ AcceptsAnyShape<GatedDeltaNetAttrs>,
+ CreateDefault<GdnRefExecutor, GatedDeltaNetAttrs>{}
+ )
+ };
+
+ return gatedDeltaNetImplementations;
+}
+// clang-format on
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/implementations.hpp b/src/plugins/intel_cpu/src/nodes/executors/implementations.hpp
index 88f1f1db3a5..9d93acde6c4 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/implementations.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/implementations.hpp
@@ -11,6 +11,7 @@
#include "nodes/executors/eltwise_config.hpp"
#include "nodes/executors/executor_implementation.hpp"
#include "nodes/executors/fullyconnected_config.hpp"
+#include "nodes/executors/gated_delta_net_config.hpp"
#include "nodes/executors/gathermatmul_config.hpp"
#include "nodes/executors/matmul_config.hpp"
@@ -42,6 +43,10 @@ const std::vector<ExecutorImplementation<EltwiseAttrs>>& getImplementations();
template <>
const std::vector<ExecutorImplementation<GatherMatmulAttrs>>& getImplementations();
+// GatedDeltaNet
+template <>
+const std::vector<ExecutorImplementation<GatedDeltaNetAttrs>>& getImplementations();
+
// MatMul
template <>
const std::vector<ExecutorImplementation<MatMulAttrs>>& getImplementations();
diff --git a/src/plugins/intel_cpu/src/nodes/executors/ref/gdn_ref_executor.cpp b/src/plugins/intel_cpu/src/nodes/executors/ref/gdn_ref_executor.cpp
new file mode 100644
index 00000000000..58e2a7ed765
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/ref/gdn_ref_executor.cpp
@@ -0,0 +1,102 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "nodes/executors/ref/gdn_ref_executor.hpp"
+
+#include <cstddef>
+#include <memory>
+#include <utility>
+
+#include "memory_desc/cpu_blocked_memory_desc.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/gated_delta_net_config.hpp"
+#include "nodes/executors/memory_arguments.hpp"
+#include "nodes/kernels/linear_attn/recurrent_linear_attn.hpp"
+#include "onednn/iml_type_mapper.h"
+#include "openvino/core/except.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "utils/plain_tensor.hpp"
+
+namespace ov::intel_cpu {
+
+bool GdnRefExecutor::supports(const GatedDeltaNetConfig& config) {
+ const auto precision = config.descs.at(ARG_GDN_QUERY)->getPrecision();
+ return precision == ov::element::f32 || precision == ov::element::f16 || precision == ov::element::bf16;
+}
+
+GdnRefExecutor::GdnRefExecutor(const GatedDeltaNetAttrs& attrs, const MemoryArgs& memory, ExecutorContext::CPtr context)
+ : m_attrs(attrs),
+ m_context(std::move(context)) {
+ update(memory);
+}
+
+bool GdnRefExecutor::updateScratchpad(const MemoryArgs& memory) {
+ const auto& queryShape = memory.at(ARG_GDN_QUERY)->getDescPtr()->getShape();
+ if (queryShape.isDynamic()) {
+ return true;
+ }
+
+ const auto& queryDims = queryShape.getStaticDims();
+ OPENVINO_ASSERT(!queryDims.empty(), "GatedDeltaNet query tensor rank must be >= 1");
+ const size_t headSize = queryDims.back();
+ if (m_tmpInpBuffer != nullptr && m_cachedHeadSize == headSize) {
+ return true;
+ }
+
+ const auto numWorkerThreads = m_context->getCpuParallel()->get_num_worker_threads();
+ auto newMemDesc = std::make_shared<CpuBlockedMemoryDesc>(
+ ov::element::f32,
+ ov::intel_cpu::Shape{static_cast<size_t>(numWorkerThreads), 3 * headSize});
+ m_tmpInpBuffer = m_context->getScratchPad()->createScratchPadMem(newMemDesc);
+ m_cachedHeadSize = headSize;
+ return m_tmpInpBuffer != nullptr;
+}
+
+bool GdnRefExecutor::update(const MemoryArgs& memory) {
+ return updateScratchpad(memory);
+}
+
+void GdnRefExecutor::execute(const MemoryArgs& memory) {
+ PlainTensor query(memory.at(ARG_GDN_QUERY));
+ PlainTensor key(memory.at(ARG_GDN_KEY));
+ PlainTensor value(memory.at(ARG_GDN_VALUE));
+ PlainTensor recurrent_state(memory.at(ARG_GDN_STATE));
+ PlainTensor gate(memory.at(ARG_GDN_GATE));
+ PlainTensor beta(memory.at(ARG_GDN_BETA));
+ PlainTensor output_attn(memory.at(ARG_GDN_OUT_ATTN));
+ PlainTensor output_recurrent_state(memory.at(ARG_GDN_OUT_STATE));
+
+ const size_t headSize = query.m_dims[3];
+ if (m_tmpInpBuffer == nullptr || m_cachedHeadSize != headSize) {
+ const auto numWorkerThreads = m_context->getCpuParallel()->get_num_worker_threads();
+ auto newMemDesc = std::make_shared<CpuBlockedMemoryDesc>(
+ ov::element::f32,
+ ov::intel_cpu::Shape{static_cast<size_t>(numWorkerThreads), 3 * headSize});
+ m_tmpInpBuffer = m_context->getScratchPad()->createScratchPadMem(newMemDesc);
+ m_cachedHeadSize = headSize;
+ }
+
+ OPENVINO_ASSERT(m_tmpInpBuffer != nullptr, "GatedDeltaNet intrinsic executor scratchpad is not initialized");
+
+ auto* temp_buffer = reinterpret_cast<float*>(m_tmpInpBuffer->getData());
+ ov::Extensions::Cpu::XARCH::recurrent_linear_attn(query,
+ key,
+ value,
+ recurrent_state,
+ gate,
+ beta,
+ m_attrs.q_l2_norm_eps,
+ m_attrs.k_l2_norm_eps,
+ m_attrs.fuse_qk_l2norm,
+ output_attn,
+ output_recurrent_state,
+ temp_buffer,
+ m_context->getCpuParallel());
+}
+
+impl_desc_type GdnRefExecutor::implType() const {
+ return impl_desc_type::ref_any;
+}
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/ref/gdn_ref_executor.hpp b/src/plugins/intel_cpu/src/nodes/executors/ref/gdn_ref_executor.hpp
new file mode 100644
index 00000000000..849b93c8771
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/ref/gdn_ref_executor.hpp
@@ -0,0 +1,35 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstddef>
+#include <utility>
+
+#include "cpu_memory.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/gated_delta_net_config.hpp"
+
+namespace ov::intel_cpu {
+
+class GdnRefExecutor : public Executor {
+public:
+ static bool supports(const GatedDeltaNetConfig& config);
+
+ GdnRefExecutor(const GatedDeltaNetAttrs& 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 updateScratchpad(const MemoryArgs& memory);
+
+ GatedDeltaNetAttrs m_attrs;
+ ExecutorContext::CPtr m_context;
+ MemoryPtr m_tmpInpBuffer;
+ size_t m_cachedHeadSize = 0;
+};
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/x64/gdn_jit_executor.cpp b/src/plugins/intel_cpu/src/nodes/executors/x64/gdn_jit_executor.cpp
new file mode 100644
index 00000000000..8befa7546f2
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/x64/gdn_jit_executor.cpp
@@ -0,0 +1,283 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "nodes/executors/x64/gdn_jit_executor.hpp"
+
+#include <cstddef>
+#include <cstdint>
+#include <memory>
+#include <utility>
+
+#include "common/utils.hpp"
+#include "cpu/x64/cpu_isa_traits.hpp"
+#include "cpu_parallel.hpp"
+#include "memory_desc/cpu_blocked_memory_desc.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/gated_delta_net_config.hpp"
+#include "nodes/executors/memory_arguments.hpp"
+#include "nodes/kernels/x64/gdn_jit_kernel.hpp"
+#include "onednn/iml_type_mapper.h"
+#include "openvino/core/except.hpp"
+#include "openvino/core/parallel.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "utils/general_utils.h"
+#include "utils/plain_tensor.hpp"
+
+using namespace dnnl::impl::cpu::x64;
+
+namespace ov::intel_cpu {
+namespace {
+
+struct GatedDeltaNetJitKey {
+ ov::element::Type precision;
+ size_t qk_head_size;
+ size_t v_tile;
+ float q_l2_norm_eps;
+ float k_l2_norm_eps;
+ bool fuse_qk_l2norm;
+
+ [[nodiscard]] size_t hash() const {
+ size_t seed = 0;
+ seed = dnnl::impl::hash_combine(seed, precision.hash());
+ seed = dnnl::impl::hash_combine(seed, qk_head_size);
+ seed = dnnl::impl::hash_combine(seed, v_tile);
+ seed = dnnl::impl::hash_combine(seed, q_l2_norm_eps);
+ seed = dnnl::impl::hash_combine(seed, k_l2_norm_eps);
+ seed = dnnl::impl::hash_combine(seed, fuse_qk_l2norm);
+ return seed;
+ }
+
+ bool operator==(const GatedDeltaNetJitKey& rhs) const {
+ return precision == rhs.precision && qk_head_size == rhs.qk_head_size && v_tile == rhs.v_tile &&
+ q_l2_norm_eps == rhs.q_l2_norm_eps && k_l2_norm_eps == rhs.k_l2_norm_eps &&
+ fuse_qk_l2norm == rhs.fuse_qk_l2norm;
+ }
+};
+
+size_t getJitVTile(const ov::element::Type& precision, const size_t defaultTile) {
+ return precision == ov::element::f32 ? 1 : defaultTile;
+}
+
+void recurrent_linear_attn_jit(const ov::intel_cpu::PlainTensor& query,
+ const ov::intel_cpu::PlainTensor& key,
+ const ov::intel_cpu::PlainTensor& value,
+ const ov::intel_cpu::PlainTensor& recurrent_state,
+ const ov::intel_cpu::PlainTensor& gate,
+ const ov::intel_cpu::PlainTensor& beta,
+ ov::intel_cpu::PlainTensor& output_attn,
+ ov::intel_cpu::PlainTensor& output_recurrent_state,
+ uint8_t* temp_buffer,
+ const ov::intel_cpu::CpuParallelPtr& cpu_parallel,
+ const std::shared_ptr<kernel::JitKernelBase>& jit_kernel,
+ const size_t gdn_jit_v_tile) {
+ OPENVINO_ASSERT(jit_kernel, "GDN JIT kernel is not created");
+
+ const size_t B = query.m_dims[0];
+ const size_t T = query.m_dims[1];
+ const size_t qk_heads = query.m_dims[2];
+ const size_t K = query.m_dims[3];
+ const size_t v_heads = value.m_dims[2];
+ const size_t V = value.m_dims[3];
+ const auto data_prc = query.m_dt;
+ const size_t elem_size = ov::element::Type(data_prc).size();
+ OPENVINO_ASSERT(ov::intel_cpu::any_of(data_prc, ov::element::f16, ov::element::bf16, ov::element::f32),
+ "GDN JIT supports only f16/bf16/f32 state copy path");
+ const size_t group_size = v_heads / qk_heads;
+ OPENVINO_ASSERT(V % gdn_jit_v_tile == 0, "GDN JIT requires V divisible by ", gdn_jit_v_tile, ", got V=", V);
+ const size_t v_tiles = V / gdn_jit_v_tile;
+ const size_t state_tile_size = gdn_jit_v_tile * K * elem_size;
+ const size_t thread_buffer_size = (gdn_jit_v_tile + 2) * K * elem_size;
+
+ cpu_parallel->parallel_for3d(B, v_heads, v_tiles, [&](size_t i_b, size_t i_h, size_t i_v_tile) {
+ const size_t tid = parallel_get_thread_num();
+ const size_t i_v_begin = i_v_tile * gdn_jit_v_tile;
+
+ uint8_t* state_buffer = temp_buffer + tid * thread_buffer_size;
+ uint8_t* b_k = state_buffer + state_tile_size;
+ uint8_t* b_q = b_k + K * elem_size;
+
+ const size_t hk = i_h / group_size;
+ auto* q_ptr = query.ptr_v(i_b, 0, hk);
+ auto* k_ptr = key.ptr_v(i_b, 0, hk);
+ auto* v_ptr = value.ptr_v(i_b, 0, i_h, i_v_begin);
+ auto* out_ptr = output_attn.ptr_v(i_b, 0, i_h, i_v_begin);
+
+ auto* gate_ptr = gate.ptr_v(i_b, 0, i_h);
+ auto* beta_ptr = beta.ptr_v(i_b, 0, i_h);
+
+ const size_t recurrent_state_stride_k = recurrent_state.stride(2);
+ const size_t recurrent_state_stride_v = recurrent_state.stride(3);
+ const size_t output_state_stride_k = output_recurrent_state.stride(2);
+ const size_t output_state_stride_v = output_recurrent_state.stride(3);
+
+ if (data_prc == ov::element::f32) {
+ auto* init_state_f32 = reinterpret_cast<float*>(state_buffer);
+ const auto* recurrent_state_f32 =
+ reinterpret_cast<const float*>(recurrent_state.ptr_v(i_b, i_h, 0, i_v_begin));
+ for (size_t j = 0; j < K; j++) {
+ const auto* src_row = recurrent_state_f32 + j * recurrent_state_stride_k;
+ for (size_t v_idx = 0; v_idx < gdn_jit_v_tile; v_idx++) {
+ init_state_f32[v_idx * K + j] = src_row[v_idx * recurrent_state_stride_v];
+ }
+ }
+ } else {
+ auto* init_state_u16 = reinterpret_cast<uint16_t*>(state_buffer);
+ const auto* recurrent_state_u16 =
+ reinterpret_cast<const uint16_t*>(recurrent_state.ptr_v(i_b, i_h, 0, i_v_begin));
+ for (size_t j = 0; j < K; j++) {
+ const auto* src_row = recurrent_state_u16 + j * recurrent_state_stride_k;
+ for (size_t v_idx = 0; v_idx < gdn_jit_v_tile; v_idx++) {
+ init_state_u16[v_idx * K + j] = src_row[v_idx * recurrent_state_stride_v];
+ }
+ }
+ }
+
+ kernel::jit_gdn_call_args args{};
+ args.state = state_buffer;
+ args.key_seq = reinterpret_cast<const uint8_t*>(k_ptr);
+ args.query_seq = reinterpret_cast<const uint8_t*>(q_ptr);
+ args.value_seq = reinterpret_cast<const uint8_t*>(v_ptr);
+ args.gate_seq = reinterpret_cast<const uint8_t*>(gate_ptr);
+ args.beta_seq = reinterpret_cast<const uint8_t*>(beta_ptr);
+ args.t_size = T;
+ args.key_query_stride = qk_heads * K;
+ args.gate_beta_stride = v_heads;
+ args.value_stride = v_heads * V;
+ args.output_stride = v_heads * V;
+ args.key_tmp = b_k;
+ args.query_tmp = b_q;
+ args.output_seq = reinterpret_cast<uint8_t*>(out_ptr);
+ (*jit_kernel)(&args);
+
+ if (data_prc == ov::element::f32) {
+ const auto* final_state_f32 = reinterpret_cast<const float*>(state_buffer);
+ auto* output_state_f32 = reinterpret_cast<float*>(output_recurrent_state.ptr_v(i_b, i_h, 0, i_v_begin));
+ for (size_t j = 0; j < K; j++) {
+ auto* dst_row = output_state_f32 + j * output_state_stride_k;
+ for (size_t v_idx = 0; v_idx < gdn_jit_v_tile; v_idx++) {
+ dst_row[v_idx * output_state_stride_v] = final_state_f32[v_idx * K + j];
+ }
+ }
+ } else {
+ const auto* final_state_u16 = reinterpret_cast<const uint16_t*>(state_buffer);
+ auto* output_state_u16 = reinterpret_cast<uint16_t*>(output_recurrent_state.ptr_v(i_b, i_h, 0, i_v_begin));
+ for (size_t j = 0; j < K; j++) {
+ auto* dst_row = output_state_u16 + j * output_state_stride_k;
+ for (size_t v_idx = 0; v_idx < gdn_jit_v_tile; v_idx++) {
+ dst_row[v_idx * output_state_stride_v] = final_state_u16[v_idx * K + j];
+ }
+ }
+ }
+ });
+}
+
+} // namespace
+
+bool GdnJitExecutor::supports(const GatedDeltaNetConfig& config) {
+ const auto precision = config.descs.at(ARG_GDN_QUERY)->getPrecision();
+ if (precision == ov::element::f32) {
+ return mayiuse(dnnl::impl::cpu::x64::avx512_core) || mayiuse(dnnl::impl::cpu::x64::avx2);
+ }
+
+ if (precision == ov::element::f16) {
+ return mayiuse(dnnl::impl::cpu::x64::avx512_core_fp16);
+ }
+ if (precision == ov::element::bf16) {
+ return mayiuse(dnnl::impl::cpu::x64::avx512_core_bf16);
+ }
+
+ return false;
+}
+
+GdnJitExecutor::GdnJitExecutor(const GatedDeltaNetAttrs& attrs, const MemoryArgs& memory, ExecutorContext::CPtr context)
+ : m_attrs(attrs),
+ m_context(std::move(context)) {
+ update(memory);
+}
+
+bool GdnJitExecutor::updateKernelAndScratchpad(const MemoryArgs& memory) {
+ const auto precision = memory.at(ARG_GDN_QUERY)->getDescPtr()->getPrecision();
+ const auto& queryShape = memory.at(ARG_GDN_QUERY)->getDescPtr()->getShape();
+ const auto& queryDims = queryShape.getStaticDims();
+ const size_t headSize = queryDims.back();
+ const size_t jitVTile = getJitVTile(precision, m_attrs.jit_v_tile);
+
+ GatedDeltaNetJitKey key{precision,
+ headSize,
+ jitVTile,
+ m_attrs.q_l2_norm_eps,
+ m_attrs.k_l2_norm_eps,
+ m_attrs.fuse_qk_l2norm};
+
+ auto builder = [](const GatedDeltaNetJitKey& compile_key) -> std::shared_ptr<kernel::JitKernelBase> {
+ return kernel::create_gdn_jit_kernel(compile_key.precision,
+ compile_key.qk_head_size,
+ compile_key.v_tile,
+ compile_key.fuse_qk_l2norm,
+ compile_key.q_l2_norm_eps,
+ compile_key.k_l2_norm_eps);
+ };
+
+ auto cache = m_context->getRuntimeCache();
+ auto result = cache->getOrCreate(key, builder);
+ m_jitKernel = result.first;
+ OPENVINO_ASSERT(m_jitKernel, "Failed to create GatedDeltaNet JIT kernel");
+
+ const bool needRecreateScratchpad = m_tmpInpBuffer == nullptr || m_cachedPrecision != precision ||
+ m_cachedHeadSize != headSize || m_cachedVTile != jitVTile;
+ if (needRecreateScratchpad) {
+ const auto numWorkerThreads = m_context->getCpuParallel()->get_num_worker_threads();
+ auto newMemDesc = std::make_shared<CpuBlockedMemoryDesc>(
+ precision,
+ ov::intel_cpu::Shape{static_cast<size_t>(numWorkerThreads), (jitVTile + 2) * headSize});
+ m_tmpInpBuffer = m_context->getScratchPad()->createScratchPadMem(newMemDesc);
+ }
+
+ m_cachedPrecision = precision;
+ m_cachedHeadSize = headSize;
+ m_cachedVTile = jitVTile;
+
+ return m_jitKernel != nullptr && m_tmpInpBuffer != nullptr;
+}
+
+bool GdnJitExecutor::update(const MemoryArgs& memory) {
+ return updateKernelAndScratchpad(memory);
+}
+
+void GdnJitExecutor::execute(const MemoryArgs& memory) {
+ OPENVINO_ASSERT(m_jitKernel != nullptr, "GatedDeltaNet JIT executor kernel is not initialized");
+ OPENVINO_ASSERT(m_tmpInpBuffer != nullptr, "GatedDeltaNet JIT executor scratchpad is not initialized");
+
+ PlainTensor query(memory.at(ARG_GDN_QUERY));
+ PlainTensor key(memory.at(ARG_GDN_KEY));
+ PlainTensor value(memory.at(ARG_GDN_VALUE));
+ PlainTensor recurrent_state(memory.at(ARG_GDN_STATE));
+ PlainTensor gate(memory.at(ARG_GDN_GATE));
+ PlainTensor beta(memory.at(ARG_GDN_BETA));
+ PlainTensor output_attn(memory.at(ARG_GDN_OUT_ATTN));
+ PlainTensor output_recurrent_state(memory.at(ARG_GDN_OUT_STATE));
+
+ auto* temp_buffer = reinterpret_cast<uint8_t*>(m_tmpInpBuffer->getData());
+ recurrent_linear_attn_jit(query,
+ key,
+ value,
+ recurrent_state,
+ gate,
+ beta,
+ output_attn,
+ output_recurrent_state,
+ temp_buffer,
+ m_context->getCpuParallel(),
+ m_jitKernel,
+ m_cachedVTile);
+}
+
+impl_desc_type GdnJitExecutor::implType() const {
+ if (mayiuse(dnnl::impl::cpu::x64::avx512_core)) {
+ return impl_desc_type::jit_avx512;
+ }
+ return impl_desc_type::jit_avx2;
+}
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/x64/gdn_jit_executor.hpp b/src/plugins/intel_cpu/src/nodes/executors/x64/gdn_jit_executor.hpp
new file mode 100644
index 00000000000..1437eb4b31f
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/x64/gdn_jit_executor.hpp
@@ -0,0 +1,44 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstddef>
+#include <memory>
+#include <utility>
+
+#include "cpu_memory.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/gated_delta_net_config.hpp"
+
+namespace ov::intel_cpu::kernel {
+class JitKernelBase;
+}
+
+namespace ov::intel_cpu {
+
+class GdnJitExecutor : public Executor {
+public:
+ static bool supports(const GatedDeltaNetConfig& config);
+
+ GdnJitExecutor(const GatedDeltaNetAttrs& 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 updateKernelAndScratchpad(const MemoryArgs& memory);
+
+ GatedDeltaNetAttrs m_attrs;
+ ExecutorContext::CPtr m_context;
+ std::shared_ptr<kernel::JitKernelBase> m_jitKernel;
+ MemoryPtr m_tmpInpBuffer;
+
+ ov::element::Type m_cachedPrecision = ov::element::dynamic;
+ size_t m_cachedHeadSize = 0;
+ size_t m_cachedVTile = 0;
+};
+
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/gated_delta_net.cpp b/src/plugins/intel_cpu/src/nodes/gated_delta_net.cpp
index b2c727d7fe1..d131d75348c 100644
--- a/src/plugins/intel_cpu/src/nodes/gated_delta_net.cpp
+++ b/src/plugins/intel_cpu/src/nodes/gated_delta_net.cpp
@@ -4,29 +4,26 @@
#include "gated_delta_net.h"
-#include <cstddef>
#include <memory>
#include <oneapi/dnnl/dnnl_common.hpp>
#include <string>
#include <vector>
-#include "cpu_memory.h"
#include "graph_context.h"
-#include "kernels/linear_attn/recurrent_linear_attn.hpp"
-#include "memory_desc/cpu_blocked_memory_desc.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/gated_delta_net_config.hpp"
+#include "nodes/executors/memory_arguments.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/gated_delta_net.hpp"
#include "shape_inference/shape_inference_cpu.hpp"
-#include "utils/plain_tensor.hpp"
-
-using namespace ov::Extensions::Cpu;
-using namespace ov::Extensions::Cpu::XARCH;
namespace ov::intel_cpu::node {
@@ -40,66 +37,83 @@ GatedDeltaNet::GatedDeltaNet(const std::shared_ptr<ov::Node>& op, const GraphCon
m_fuse_qk_l2norm = gdn->get_fuse_qk_l2norm();
m_q_l2_norm_eps = gdn->get_q_l2_norm_eps();
m_k_l2_norm_eps = gdn->get_k_l2_norm_eps();
+ m_attrs.fuse_qk_l2norm = m_fuse_qk_l2norm;
+ m_attrs.q_l2_norm_eps = m_q_l2_norm_eps;
+ m_attrs.k_l2_norm_eps = m_k_l2_norm_eps;
+ m_atoi[ARG_GDN_QUERY] = 0;
+ m_atoi[ARG_GDN_KEY] = 1;
+ m_atoi[ARG_GDN_VALUE] = 2;
+ m_atoi[ARG_GDN_STATE] = 3;
+ m_atoi[ARG_GDN_GATE] = 4;
+ m_atoi[ARG_GDN_BETA] = 5;
}
void GatedDeltaNet::initSupportedPrimitiveDescriptors() {
- // TODO: support other precision CVS-182464
- auto dataPrecision = ov::element::f32;
- std::vector<PortConfigurator> inPortConfigs;
- for (size_t i = 0; i < getParentEdges().size(); ++i) {
- inPortConfigs.emplace_back(LayoutType::ncsp, dataPrecision, getInputShapeAtPort(i), false, -1);
+ auto dataPrecision = getOriginalOutputPrecisionAtPort(0);
+ const auto& creatorsMap = BlockedDescCreator::getCommonCreators();
+
+ MemoryDescArgs descs;
+ for (const auto& [argId, portId] : m_atoi) {
+ descs[argId] = creatorsMap.at(LayoutType::ncsp)->createSharedDesc(dataPrecision, getInputShapeAtPort(portId));
+ }
+ descs[ARG_GDN_OUT_ATTN] =
+ creatorsMap.at(LayoutType::ncsp)->createSharedDesc(dataPrecision, getOutputShapeAtPort(0));
+ descs[ARG_GDN_OUT_STATE] =
+ creatorsMap.at(LayoutType::ncsp)->createSharedDesc(dataPrecision, getOutputShapeAtPort(1));
+
+ auto executionContext = std::make_shared<ExecutorContext>(context, getImplPriority(), privateWeightCache);
+ m_factory = std::make_shared<ExecutorFactory<GatedDeltaNetAttrs>>(m_attrs, executionContext, descs);
+
+ const auto nodeDescriptorsList = m_factory->getProperMemoryDescriptors(descs);
+ for (const auto& nodeDescriptors : nodeDescriptorsList) {
+ NodeConfig nodeConfig;
+ nodeConfig.inConfs.resize(getParentEdges().size());
+
+ for (const auto& [argId, portId] : m_atoi) {
+ if (nodeDescriptors.count(argId)) {
+ nodeConfig.inConfs[portId] = PortConfig{nodeDescriptors.at(argId)};
+ }
+ }
+
+ nodeConfig.outConfs.emplace_back(nodeDescriptors.at(ARG_GDN_OUT_ATTN));
+ nodeConfig.outConfs.emplace_back(nodeDescriptors.at(ARG_GDN_OUT_STATE));
+
+ supportedPrimitiveDescriptors.emplace_back(nodeConfig, impl_desc_type::undef);
}
- std::vector<PortConfigurator> outPortConfigs = {
- PortConfigurator{LayoutType::ncsp, dataPrecision, getOutputShapeAtPort(0), false, -1},
- PortConfigurator{LayoutType::ncsp, dataPrecision, getOutputShapeAtPort(1), false, -1}};
- addSupportedPrimDesc(inPortConfigs, outPortConfigs, impl_desc_type::ref_any);
}
void GatedDeltaNet::createPrimitive() {
- const auto queryDims = getInputShapeAtPort(0).getDims();
- auto headSize = *(queryDims.end() - 1);
- const auto numWorkerThreads = context->getCpuParallel()->get_num_worker_threads();
- auto newMemDesc = std::make_shared<CpuBlockedMemoryDesc>(
- ov::element::f32,
- ov::intel_cpu::Shape{static_cast<size_t>(numWorkerThreads), 3 * headSize});
- m_tmpInpBuffer = context->getScratchPad()->createScratchPadMem(newMemDesc);
+ for (const auto& [argId, portId] : m_atoi) {
+ m_memory[argId] = getSrcMemoryAtPort(portId);
+ }
+ m_memory[ARG_GDN_OUT_ATTN] = getDstMemoryAtPort(0);
+ m_memory[ARG_GDN_OUT_STATE] = getDstMemoryAtPort(1);
+
+ m_executor = m_factory->make(m_memory);
+
+ Node::createPrimitive();
+ getSelectedPrimitiveDescriptor()->setImplementationType(m_executor->implType());
}
-void GatedDeltaNet::execute([[maybe_unused]] const dnnl::stream& strm) {
- auto originalInputNumber = getOriginalInputsNumber();
- std::vector<MemoryPtr> inputs(originalInputNumber);
- std::vector<MemoryPtr> outputs(2);
+void GatedDeltaNet::prepareParams() {
+ for (const auto& [argId, portId] : m_atoi) {
+ m_memory[argId] = getSrcMemoryAtPort(portId);
+ }
+ m_memory[ARG_GDN_OUT_ATTN] = getDstMemoryAtPort(0);
+ m_memory[ARG_GDN_OUT_STATE] = getDstMemoryAtPort(1);
+
+ m_executor->update(m_memory);
+ getSelectedPrimitiveDescriptor()->setImplementationType(m_executor->implType());
+}
- for (size_t i = 0; i < originalInputNumber; i++) {
- inputs[i] = getSrcMemoryAtPort(i);
+void GatedDeltaNet::execute([[maybe_unused]] const dnnl::stream& strm) {
+ for (const auto& [argId, portId] : m_atoi) {
+ m_memory[argId] = getSrcMemoryAtPort(portId);
}
+ m_memory[ARG_GDN_OUT_ATTN] = getDstMemoryAtPort(0);
+ m_memory[ARG_GDN_OUT_STATE] = getDstMemoryAtPort(1);
- outputs[0] = getDstMemoryAtPort(0);
- outputs[1] = getDstMemoryAtPort(1);
-
- PlainTensor query(inputs[0]);
- PlainTensor key(inputs[1]);
- PlainTensor value(inputs[2]);
- PlainTensor recurrent_state(inputs[3]);
- PlainTensor gate(inputs[4]);
- PlainTensor beta(inputs[5]);
- PlainTensor output_attn(outputs[0]);
- PlainTensor output_recurrent_state(outputs[1]);
-
- auto* temp_buffer = m_tmpInpBuffer->getDataAs<float>();
- recurrent_linear_attn(query,
- key,
- value,
- recurrent_state,
- gate,
- beta,
- m_q_l2_norm_eps,
- m_k_l2_norm_eps,
- m_fuse_qk_l2norm,
- output_attn,
- output_recurrent_state,
- temp_buffer,
- context->getCpuParallel());
+ m_executor->execute(m_memory);
}
bool GatedDeltaNet::isSupportedOperation(const std::shared_ptr<const ov::Node>& op,
diff --git a/src/plugins/intel_cpu/src/nodes/gated_delta_net.h b/src/plugins/intel_cpu/src/nodes/gated_delta_net.h
index b7f908ae06c..2487a2a7842 100644
--- a/src/plugins/intel_cpu/src/nodes/gated_delta_net.h
+++ b/src/plugins/intel_cpu/src/nodes/gated_delta_net.h
@@ -7,11 +7,15 @@
#include <memory>
#include <oneapi/dnnl/dnnl_common.hpp>
#include <string>
+#include <unordered_map>
#include "config.h"
#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/gated_delta_net_config.hpp"
#include "openvino/core/node.hpp"
#include "openvino/core/type/element_type.hpp"
@@ -30,11 +34,8 @@ public:
return true;
}
- bool needPrepareParams() const override {
- return false;
- }
-
void createPrimitive() override;
+ void prepareParams() override;
void executeDynamicImpl(const dnnl::stream& strm) override {
execute(strm);
@@ -44,10 +45,14 @@ public:
static bool isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept;
private:
- MemoryPtr m_tmpInpBuffer = nullptr;
bool m_fuse_qk_l2norm = false;
float m_q_l2_norm_eps = 1e-6F;
float m_k_l2_norm_eps = 1e-6F;
+ GatedDeltaNetAttrs m_attrs;
+ ExecutorFactoryPtr<GatedDeltaNetAttrs> m_factory;
+ ExecutorPtr m_executor;
+ MemoryArgs m_memory;
+ std::unordered_map<int, int> m_atoi;
};
} // namespace ov::intel_cpu::node
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.cpp b/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.cpp
index f0e93e59cc3..58b8e90aeaf 100644
--- a/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.cpp
+++ b/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.cpp
@@ -78,21 +78,22 @@ static inline void l2norm(float* a, size_t n, float eps) {
#endif
}
-void recurrent_linear_attn(const ov::intel_cpu::PlainTensor& query,
- const ov::intel_cpu::PlainTensor& key,
- const ov::intel_cpu::PlainTensor& value,
- const ov::intel_cpu::PlainTensor& recurrent_state,
- const ov::intel_cpu::PlainTensor& gate,
- const ov::intel_cpu::PlainTensor& beta,
- float q_l2_norm_eps,
- float k_l2_norm_eps,
- bool use_qk_l2norm,
- ov::intel_cpu::PlainTensor& output_attn,
- ov::intel_cpu::PlainTensor& output_recurrent_state,
- float* temp_buffer,
- const ov::intel_cpu::CpuParallelPtr& cpu_parallel) {
+template <typename T>
+static void recurrent_linear_attn_impl(const ov::intel_cpu::PlainTensor& query,
+ const ov::intel_cpu::PlainTensor& key,
+ const ov::intel_cpu::PlainTensor& value,
+ const ov::intel_cpu::PlainTensor& recurrent_state,
+ const ov::intel_cpu::PlainTensor& gate,
+ const ov::intel_cpu::PlainTensor& beta,
+ float q_l2_norm_eps,
+ float k_l2_norm_eps,
+ bool use_qk_l2norm,
+ ov::intel_cpu::PlainTensor& output_attn,
+ ov::intel_cpu::PlainTensor& output_recurrent_state,
+ float* temp_buffer,
+ const ov::intel_cpu::CpuParallelPtr& cpu_parallel) {
size_t B = query.m_dims[0];
- size_t T = query.m_dims[1];
+ size_t timesteps = query.m_dims[1];
size_t qk_heads = query.m_dims[2];
size_t K = query.m_dims[3];
size_t v_heads = value.m_dims[2];
@@ -108,24 +109,25 @@ void recurrent_linear_attn(const ov::intel_cpu::PlainTensor& query,
float* b_q = temp_buffer + tid * 3 * K_HEAD_DIMS + 2 * K_HEAD_DIMS;
const size_t hk = i_h / group_size;
// B, T, qk, K
- float* q_ptr = query.ptr<float>(i_b, 0, hk);
- float* k_ptr = key.ptr<float>(i_b, 0, hk);
+ T* q_ptr = query.ptr<T>(i_b, 0, hk);
+ T* k_ptr = key.ptr<T>(i_b, 0, hk);
// B, T, v_heads, V
- float* v_ptr = value.ptr<float>(i_b, 0, i_h);
+ T* v_ptr = value.ptr<T>(i_b, 0, i_h);
// B, v_heads, K, V
+ // Load recurrent state with stride V in K dimension
+ T* state_ptr = recurrent_state.ptr<T>(i_b, i_h, 0, i_v);
for (size_t j = 0; j < K_HEAD_DIMS; j++) {
- init_state[j] = recurrent_state.at<float>({i_b, i_h, j, i_v});
+ init_state[j] = static_cast<float>(state_ptr[j * V_HEAD_DIMS]);
}
- for (size_t i = 0; i < T; i++) {
+ for (size_t i = 0; i < timesteps; i++) {
// gate: B, T, v_heads
- float b_g = gate.at<float>({i_b, i, i_h});
- float b_beta = beta.at<float>({i_b, i, i_h});
- b_g = exp(b_g);
- for (size_t j = 0; j < K_HEAD_DIMS; j++) {
- b_k[j] = k_ptr[i * qk_heads * K_HEAD_DIMS + j];
- b_q[j] = q_ptr[i * qk_heads * K_HEAD_DIMS + j];
- }
+ float b_g = static_cast<float>(gate.at<T>({i_b, i, i_h}));
+ float b_beta = static_cast<float>(beta.at<T>({i_b, i, i_h}));
+ b_g = std::exp(b_g);
+ // Vectorized load of contiguous k and q
+ cvt_copy(b_k, k_ptr + i * qk_heads * K_HEAD_DIMS, 1, K_HEAD_DIMS, 0, 0);
+ cvt_copy(b_q, q_ptr + i * qk_heads * K_HEAD_DIMS, 1, K_HEAD_DIMS, 0, 0);
if (use_qk_l2norm) {
l2norm(b_k, K_HEAD_DIMS, k_l2_norm_eps);
l2norm(b_q, K_HEAD_DIMS, q_l2_norm_eps);
@@ -135,7 +137,7 @@ void recurrent_linear_attn(const ov::intel_cpu::PlainTensor& query,
multiply_scalar(init_state, init_state, b_g, K_HEAD_DIMS);
float h_k = dot_product(init_state, b_k, K_HEAD_DIMS, nullptr, nullptr, nullptr, 0);
// B, T, v_heads, V
- float b_v = v_ptr[i_v + i * v_heads * V_HEAD_DIMS];
+ float b_v = static_cast<float>(v_ptr[i_v + i * v_heads * V_HEAD_DIMS]);
b_v -= h_k;
// b_v * b_k
b_v *= b_beta;
@@ -143,14 +145,78 @@ void recurrent_linear_attn(const ov::intel_cpu::PlainTensor& query,
// h = h0 + update
cvt_add(init_state, init_state, b_k, 1, K_HEAD_DIMS, 0, 0, 0);
float b_output = dot_product(init_state, b_q, K_HEAD_DIMS, nullptr, nullptr, nullptr, 0);
- output_attn.at<float>({i_b, i, i_h, i_v}) = b_output;
+ output_attn.at<T>({i_b, i, i_h, i_v}) = static_cast<T>(b_output);
}
+ // Store recurrent state with stride V in K dimension
+ T* state_out_ptr = output_recurrent_state.ptr<T>(i_b, i_h, 0, i_v);
for (size_t j = 0; j < K_HEAD_DIMS; j++) {
- output_recurrent_state.at<float>({i_b, i_h, j, i_v}) = init_state[j];
+ state_out_ptr[j * V_HEAD_DIMS] = static_cast<T>(init_state[j]);
}
});
}
+void recurrent_linear_attn(const ov::intel_cpu::PlainTensor& query,
+ const ov::intel_cpu::PlainTensor& key,
+ const ov::intel_cpu::PlainTensor& value,
+ const ov::intel_cpu::PlainTensor& recurrent_state,
+ const ov::intel_cpu::PlainTensor& gate,
+ const ov::intel_cpu::PlainTensor& beta,
+ float q_l2_norm_eps,
+ float k_l2_norm_eps,
+ bool use_qk_l2norm,
+ ov::intel_cpu::PlainTensor& output_attn,
+ ov::intel_cpu::PlainTensor& output_recurrent_state,
+ float* temp_buffer,
+ const ov::intel_cpu::CpuParallelPtr& cpu_parallel) {
+ const auto data_prc = query.get_precision();
+
+ if (data_prc == ov::element::f32) {
+ recurrent_linear_attn_impl<float>(query,
+ key,
+ value,
+ recurrent_state,
+ gate,
+ beta,
+ q_l2_norm_eps,
+ k_l2_norm_eps,
+ use_qk_l2norm,
+ output_attn,
+ output_recurrent_state,
+ temp_buffer,
+ cpu_parallel);
+ } else if (data_prc == ov::element::f16) {
+ recurrent_linear_attn_impl<ov::float16>(query,
+ key,
+ value,
+ recurrent_state,
+ gate,
+ beta,
+ q_l2_norm_eps,
+ k_l2_norm_eps,
+ use_qk_l2norm,
+ output_attn,
+ output_recurrent_state,
+ temp_buffer,
+ cpu_parallel);
+ } else if (data_prc == ov::element::bf16) {
+ recurrent_linear_attn_impl<ov::bfloat16>(query,
+ key,
+ value,
+ recurrent_state,
+ gate,
+ beta,
+ q_l2_norm_eps,
+ k_l2_norm_eps,
+ use_qk_l2norm,
+ output_attn,
+ output_recurrent_state,
+ temp_buffer,
+ cpu_parallel);
+ } else {
+ OPENVINO_ASSERT(false, "[CPU] gdn: unsupported precision", data_prc);
+ }
+}
+
template <typename T>
static void recurrent_linear_attn_paged_impl(const ov::intel_cpu::PlainTensor& query,
const ov::intel_cpu::PlainTensor& key,
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/x64/gdn_jit_kernel.cpp b/src/plugins/intel_cpu/src/nodes/kernels/x64/gdn_jit_kernel.cpp
new file mode 100644
index 00000000000..838c511d5d6
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/kernels/x64/gdn_jit_kernel.cpp
@@ -0,0 +1,893 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "gdn_jit_kernel.hpp"
+
+#include <xbyak/xbyak.h>
+
+#include <algorithm>
+#include <cmath>
+#include <common/c_types_map.hpp>
+#include <cpu/x64/cpu_isa_traits.hpp>
+#include <cpu/x64/injectors/jit_uni_eltwise_injector.hpp>
+#include <cpu/x64/jit_generator.hpp>
+#include <cstddef>
+#include <memory>
+
+#include "emitters/plugin/x64/jit_load_store_emitters.hpp"
+#include "jit_kernel_base.hpp"
+#include "openvino/core/type/element_type.hpp"
+
+using namespace dnnl::impl::cpu;
+using namespace dnnl::impl::cpu::x64;
+
+namespace ov::intel_cpu::kernel {
+
+#define GET_OFF(field) offsetof(jit_gdn_call_args, field)
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::load(const Vmm& vmm_dst,
+ const Xbyak::Reg64& reg_src,
+ ov::element::Type src_prc,
+ const int& elt_num,
+ bool fill,
+ size_t offset,
+ ov::element::Type dst_prc) {
+ // Typed load helper (src_prc -> dst_prc VMM via jit emitter)
+ const auto seed = load_emitter_params(src_prc, dst_prc, elt_num, fill, "float_min").hash();
+ if (!emitters[seed]) {
+ constexpr cpu_isa_t load_isa = ((isa & zmm_bit) != 0) ? avx512_core : isa;
+ emitters[seed] =
+ std::make_unique<jit_load_emitter>(this, load_isa, src_prc, dst_prc, elt_num, dst_prc, fill, "float_min");
+ }
+ emitters[seed]->emit_code({static_cast<size_t>(reg_src.getIdx()), offset},
+ {static_cast<size_t>(vmm_dst.getIdx())},
+ pool_aux_vmm_idxs,
+ pool_aux_gpr_idxs);
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::store(const Xbyak::Reg64& reg_dst,
+ const Vmm& vmm_src,
+ ov::element::Type dst_prc,
+ const int& elt_num,
+ size_t offset,
+ ov::element::Type src_prc) {
+ // Typed store helper (src_prc VMM -> dst_prc via jit emitter)
+ const auto seed = store_emitter_params(src_prc, dst_prc, elt_num).hash();
+ if (!emitters[seed]) {
+ constexpr cpu_isa_t store_isa = ((isa & zmm_bit) != 0) ? avx512_core : isa;
+ emitters[seed] = std::make_unique<jit_store_emitter>(this, store_isa, src_prc, dst_prc, elt_num);
+ }
+ emitters[seed]->emit_code({static_cast<size_t>(vmm_src.getIdx())},
+ {static_cast<size_t>(reg_dst.getIdx()), offset},
+ pool_aux_vmm_idxs,
+ pool_aux_gpr_idxs);
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::reduce_zmm_f32_to_xmm_scalar(const Xbyak::Zmm& zmm_src,
+ const Xbyak::Xmm& xmm_dst,
+ const Xbyak::Xmm& xmm_tmp0,
+ const Xbyak::Xmm& xmm_tmp1) {
+ // Horizontal reduce 16x f32 (ZMM) into scalar lane of xmm_dst.
+ // Prefer shuffle/add pattern over vhaddps on AVX-512.
+ vextractf32x8(Xbyak::Ymm(xmm_tmp1.getIdx()), zmm_src, 1);
+ vaddps(Xbyak::Ymm(xmm_tmp0.getIdx()), Xbyak::Ymm(zmm_src.getIdx()), Xbyak::Ymm(xmm_tmp1.getIdx()));
+ vextractf128(xmm_tmp1, Xbyak::Ymm(xmm_tmp0.getIdx()), 1);
+ vaddps(xmm_tmp0, xmm_tmp0, xmm_tmp1);
+ vpermilps(xmm_tmp1, xmm_tmp0, 0xB1);
+ vaddps(xmm_tmp0, xmm_tmp0, xmm_tmp1);
+ vpermilps(xmm_tmp1, xmm_tmp0, 0x4E);
+ vaddps(xmm_tmp0, xmm_tmp0, xmm_tmp1);
+ vaddss(xmm_dst, xmm_dst, xmm_tmp0);
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::dot_product_scalar(const Xbyak::Xmm& xmm_dst,
+ const Xbyak::Reg64& reg_a,
+ const Xbyak::Reg64& reg_b,
+ size_t tail_count,
+ size_t base_off,
+ size_t elem_size,
+ const Xbyak::Xmm& xmm_tmp0,
+ const Xbyak::Xmm& xmm_tmp1) {
+ // Tail handling via load-emitter masks: process full vectors then one masked vector.
+ if (tail_count == 0) {
+ return;
+ }
+
+ const size_t step = vec_size * elem_size;
+ const size_t vec_cnt = tail_count / vec_size;
+ const size_t tail = tail_count % vec_size;
+
+ uni_vpxor(v_aux0, v_aux0, v_aux0);
+ for (size_t i = 0; i < vec_cnt; i++) {
+ const size_t off = base_off + i * step;
+ load(v_aux1, reg_a, m_jcp.data_prc, static_cast<int>(vec_size), false, off);
+ load(v_aux2, reg_b, m_jcp.data_prc, static_cast<int>(vec_size), false, off);
+ vfmadd231ps(v_aux0, v_aux1, v_aux2);
+ }
+
+ if (tail > 0) {
+ const size_t off = base_off + vec_cnt * step;
+ load(v_aux1, reg_a, m_jcp.data_prc, static_cast<int>(tail), false, off);
+ load(v_aux2, reg_b, m_jcp.data_prc, static_cast<int>(tail), false, off);
+ vfmadd231ps(v_aux0, v_aux1, v_aux2);
+ }
+
+ if constexpr (std::is_same_v<Vmm, Xbyak::Ymm>) {
+ vextractf128(xmm_tmp1, v_aux0, 1);
+ vaddps(xmm_tmp0, Xbyak::Xmm(v_aux0.getIdx()), xmm_tmp1);
+ vpermilps(xmm_tmp1, xmm_tmp0, 0xB1);
+ vaddps(xmm_tmp0, xmm_tmp0, xmm_tmp1);
+ vpermilps(xmm_tmp1, xmm_tmp0, 0x4E);
+ vaddps(xmm_tmp0, xmm_tmp0, xmm_tmp1);
+ vaddss(xmm_dst, xmm_dst, xmm_tmp0);
+ } else {
+ reduce_zmm_f32_to_xmm_scalar(Xbyak::Zmm(v_aux0.getIdx()), xmm_dst, xmm_tmp0, xmm_tmp1);
+ }
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::dot_product_to_scalar(const Xbyak::Xmm& xmm_dst,
+ const Xbyak::Reg64& reg_a,
+ const Xbyak::Reg64& reg_b) {
+ // Dot product dispatcher (f32 vectorized, otherwise scalar) -> scalar xmm_dst
+ uni_vpxor(xmm_dst, xmm_dst, xmm_dst);
+ const size_t qk = m_jcp.qk_head_size;
+
+ if (m_jcp.data_prc == ov::element::f32) {
+ const size_t vec_cnt = qk / vec_size;
+ const size_t tail = qk % vec_size;
+
+ uni_vpxor(v_aux0, v_aux0, v_aux0);
+
+ for (size_t i = 0; i < vec_cnt; i++) {
+ const size_t off = i * vec_bytes;
+ load(v_aux1, reg_a, ov::element::f32, static_cast<int>(vec_size), false, off);
+ load(v_aux2, reg_b, ov::element::f32, static_cast<int>(vec_size), false, off);
+ vfmadd231ps(v_aux0, v_aux1, v_aux2);
+ }
+
+ if constexpr (std::is_same_v<Vmm, Xbyak::Ymm>) {
+ vextractf128(x_tmp0, v_aux0, 1);
+ vaddps(Xbyak::Xmm(v_aux0.getIdx()), Xbyak::Xmm(v_aux0.getIdx()), x_tmp0);
+ vpermilps(x_tmp0, Xbyak::Xmm(v_aux0.getIdx()), 0xB1);
+ vaddps(Xbyak::Xmm(v_aux0.getIdx()), Xbyak::Xmm(v_aux0.getIdx()), x_tmp0);
+ vpermilps(x_tmp0, Xbyak::Xmm(v_aux0.getIdx()), 0x4E);
+ vaddps(Xbyak::Xmm(v_aux0.getIdx()), Xbyak::Xmm(v_aux0.getIdx()), x_tmp0);
+ vaddss(xmm_dst, xmm_dst, Xbyak::Xmm(v_aux0.getIdx()));
+ } else {
+ reduce_zmm_f32_to_xmm_scalar(Xbyak::Zmm(v_aux0.getIdx()), xmm_dst, x_tmp0, x_tmp1);
+ }
+
+ dot_product_scalar(xmm_dst, reg_a, reg_b, tail, vec_cnt * vec_bytes, sizeof(float), x_tmp0, x_tmp1);
+ } else {
+ dot_product_scalar(xmm_dst, reg_a, reg_b, qk, 0, m_jcp.data_prc.size(), x_tmp0, x_tmp1);
+ }
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::multiply_scalar(const Xbyak::Reg64& reg_vec, const Xbyak::Xmm& xmm_scalar) {
+ // In-place vector scale: reg_vec[i] *= xmm_scalar
+ const auto elt_num = static_cast<int>(vec_size);
+ const size_t elem_size = m_jcp.data_prc.size();
+ const size_t step = static_cast<size_t>(elt_num) * elem_size;
+ const size_t vec_cnt = m_jcp.qk_head_size / static_cast<size_t>(elt_num);
+ const size_t tail = m_jcp.qk_head_size % static_cast<size_t>(elt_num);
+
+ vbroadcastss(v_tmp1, xmm_scalar);
+
+ for (size_t i = 0; i < vec_cnt; i++) {
+ const size_t off = i * step;
+ load(v_tmp0, reg_vec, m_jcp.data_prc, elt_num, false, off);
+ vmulps(v_tmp0, v_tmp0, v_tmp1);
+ store(reg_vec, v_tmp0, m_jcp.data_prc, elt_num, off);
+ }
+ if (tail > 0) {
+ const size_t off = vec_cnt * step;
+ load(v_tmp0, reg_vec, m_jcp.data_prc, static_cast<int>(tail), false, off);
+ vmulps(v_tmp0, v_tmp0, v_tmp1);
+ store(reg_vec, v_tmp0, m_jcp.data_prc, static_cast<int>(tail), off);
+ }
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::l2norm_inplace(const Xbyak::Reg64& reg_vec,
+ const Xbyak::Xmm& xmm_eps,
+ const Xbyak::Xmm& xmm_tmp0,
+ const Xbyak::Xmm& xmm_tmp1,
+ const Xbyak::Xmm& xmm_sum) {
+ // In-place L2 normalization over one head vector (with eps)
+ const size_t qk = m_jcp.qk_head_size;
+ const size_t vec_cnt = qk / vec_size;
+ const size_t tail = qk % vec_size;
+
+ uni_vpxor(xmm_sum, xmm_sum, xmm_sum);
+ uni_vpxor(v_aux0, v_aux0, v_aux0);
+
+ for (size_t i = 0; i < vec_cnt; i++) {
+ const size_t off = i * vec_bytes;
+ load(v_aux1, reg_vec, ov::element::f32, static_cast<int>(vec_size), false, off);
+ vfmadd231ps(v_aux0, v_aux1, v_aux1);
+ }
+
+ if (tail > 0) {
+ const size_t off = vec_cnt * vec_bytes;
+ load(v_aux1, reg_vec, ov::element::f32, static_cast<int>(tail), false, off);
+ vfmadd231ps(v_aux0, v_aux1, v_aux1);
+ }
+
+ if constexpr (std::is_same_v<Vmm, Xbyak::Ymm>) {
+ vextractf128(x_tmp1, v_aux0, 1);
+ vaddps(xmm_sum, Xbyak::Xmm(v_aux0.getIdx()), x_tmp1);
+ vpermilps(x_tmp1, xmm_sum, 0xB1);
+ vaddps(xmm_sum, xmm_sum, x_tmp1);
+ vpermilps(x_tmp1, xmm_sum, 0x4E);
+ vaddps(xmm_sum, xmm_sum, x_tmp1);
+ } else {
+ reduce_zmm_f32_to_xmm_scalar(Xbyak::Zmm(v_aux0.getIdx()), xmm_sum, xmm_tmp0, xmm_tmp1);
+ }
+
+ vaddss(xmm_sum, xmm_sum, xmm_eps);
+ vsqrtss(xmm_sum, xmm_sum, xmm_sum);
+ vmovd(xmm_tmp1, reg_one.cvt32());
+ vdivss(xmm_tmp1, xmm_tmp1, xmm_sum);
+
+ vbroadcastss(v_tmp1, xmm_tmp1);
+
+ for (size_t i = 0; i < vec_cnt; i++) {
+ const size_t off = i * vec_bytes;
+ load(v_tmp0, reg_vec, ov::element::f32, static_cast<int>(vec_size), false, off);
+ vmulps(v_tmp0, v_tmp0, v_tmp1);
+ store(reg_vec, v_tmp0, ov::element::f32, static_cast<int>(vec_size), off);
+ }
+
+ if (tail > 0) {
+ const size_t off = vec_cnt * vec_bytes;
+ load(v_tmp0, reg_vec, ov::element::f32, static_cast<int>(tail), false, off);
+ vmulps(v_tmp0, v_tmp0, v_tmp1);
+ store(reg_vec, v_tmp0, ov::element::f32, static_cast<int>(tail), off);
+ }
+}
+
+// ============================================
+// Native xf16 helpers
+// ============================================
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::load_vector_native_xf16(Vmm* vmm_array, const Xbyak::Reg64& reg_src, int num_regs) {
+ // Load fp16 vector (up to 4 ZMMs) directly from memory
+ for (int i = 0; i < num_regs; i++) {
+ vmovups(vmm_array[i], ptr[reg_src + i * 64]);
+ }
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::store_vector_native_xf16(const Xbyak::Reg64& reg_dst, Vmm* vmm_array, int num_regs) {
+ // Store fp16 vector (up to 4 ZMMs) to memory
+ for (int i = 0; i < num_regs; i++) {
+ vmovups(ptr[reg_dst + i * 64], vmm_array[i]);
+ }
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::dot_product_native_xf16(const Xbyak::Xmm& xmm_dst, Vmm* vmm_a, Vmm* vmm_b, int num_regs) {
+ if (m_jcp.data_prc == ov::element::bf16) {
+ // bf16 path: accumulate directly in fp32 with vdpbf16ps
+ uni_vpxor(v_aux0, v_aux0, v_aux0);
+ for (int i = 0; i < num_regs; i++) {
+ vdpbf16ps(v_aux0, vmm_a[i], vmm_b[i]);
+ }
+ uni_vpxor(xmm_dst, xmm_dst, xmm_dst);
+ reduce_zmm_f32_to_xmm_scalar(Xbyak::Zmm(v_aux0.getIdx()), xmm_dst, x_tmp0, x_tmp1);
+ return;
+ }
+
+ // f16 path: native fp16 accumulation then fp32 reduction
+ uni_vpxor(v_tmp0, v_tmp0, v_tmp0); // fp16 accumulator (32 lanes)
+
+ for (int i = 0; i < num_regs; i++) {
+ vfmadd231ph(v_tmp0, vmm_a[i], vmm_b[i]);
+ }
+
+ vcvtph2ps(v_aux0, Xbyak::Ymm(v_tmp0.getIdx()));
+ vextractf32x8(Xbyak::Ymm(x_tmp0.getIdx()), Xbyak::Zmm(v_tmp0.getIdx()), 1);
+ vcvtph2ps(v_aux1, Xbyak::Ymm(x_tmp0.getIdx()));
+ vaddps(v_aux0, v_aux0, v_aux1);
+
+ uni_vpxor(xmm_dst, xmm_dst, xmm_dst);
+ reduce_zmm_f32_to_xmm_scalar(Xbyak::Zmm(v_aux0.getIdx()), xmm_dst, x_tmp0, x_tmp1);
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::scale_vector_native_xf16(Vmm* vmm_array, const Xbyak::Xmm& xmm_scalar, int num_regs) {
+ if (m_jcp.data_prc == ov::element::bf16) {
+ // bf16 path: unpack->fp32 mul->pack bf16 per half
+ vbroadcastss(v_aux2, xmm_scalar);
+
+ for (int i = 0; i < num_regs; i++) {
+ // lower 16 bf16 -> fp32
+ vpmovzxwd(v_aux0, Xbyak::Ymm(vmm_array[i].getIdx()));
+ vpslld(v_aux0, v_aux0, 16);
+ vmulps(v_aux0, v_aux0, v_aux2);
+ vcvtneps2bf16(Xbyak::Ymm(x_tmp0.getIdx()), v_aux0);
+
+ // upper 16 bf16 -> fp32
+ vextractf32x8(Xbyak::Ymm(v_aux1.getIdx()), Xbyak::Zmm(vmm_array[i].getIdx()), 1);
+ vpmovzxwd(v_aux1, Xbyak::Ymm(v_aux1.getIdx()));
+ vpslld(v_aux1, v_aux1, 16);
+ vmulps(v_aux1, v_aux1, v_aux2);
+ vcvtneps2bf16(Xbyak::Ymm(x_tmp1.getIdx()), v_aux1);
+
+ vinsertf32x8(Xbyak::Zmm(vmm_array[i].getIdx()),
+ Xbyak::Zmm(x_tmp0.getIdx()),
+ Xbyak::Ymm(x_tmp1.getIdx()),
+ 1);
+ }
+ return;
+ }
+
+ // f16 path
+ vcvtps2ph(x_tmp0, xmm_scalar, 0);
+ vpbroadcastw(v_aux2, x_tmp0);
+
+ for (int i = 0; i < num_regs; i++) {
+ vmulph(vmm_array[i], vmm_array[i], v_aux2);
+ }
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::fmadd_vector_native_xf16(Vmm* vmm_dst,
+ Vmm* vmm_src,
+ const Xbyak::Xmm& xmm_scalar,
+ int num_regs) {
+ if (m_jcp.data_prc == ov::element::bf16) {
+ // bf16 path: unpack dst/src -> fp32 fma -> pack bf16 per half
+ vbroadcastss(v_aux2, xmm_scalar);
+
+ for (int i = 0; i < num_regs; i++) {
+ // lower half
+ vpmovzxwd(v_aux0, Xbyak::Ymm(vmm_dst[i].getIdx()));
+ vpslld(v_aux0, v_aux0, 16);
+ vpmovzxwd(v_aux1, Xbyak::Ymm(vmm_src[i].getIdx()));
+ vpslld(v_aux1, v_aux1, 16);
+ vfmadd231ps(v_aux0, v_aux1, v_aux2);
+ vcvtneps2bf16(Xbyak::Ymm(x_tmp0.getIdx()), v_aux0);
+
+ // upper half
+ vextractf32x8(Xbyak::Ymm(v_aux0.getIdx()), Xbyak::Zmm(vmm_dst[i].getIdx()), 1);
+ vpmovzxwd(v_aux0, Xbyak::Ymm(v_aux0.getIdx()));
+ vpslld(v_aux0, v_aux0, 16);
+ vextractf32x8(Xbyak::Ymm(v_aux1.getIdx()), Xbyak::Zmm(vmm_src[i].getIdx()), 1);
+ vpmovzxwd(v_aux1, Xbyak::Ymm(v_aux1.getIdx()));
+ vpslld(v_aux1, v_aux1, 16);
+ vfmadd231ps(v_aux0, v_aux1, v_aux2);
+ vcvtneps2bf16(Xbyak::Ymm(x_tmp1.getIdx()), v_aux0);
+
+ vinsertf32x8(Xbyak::Zmm(vmm_dst[i].getIdx()), Xbyak::Zmm(x_tmp0.getIdx()), Xbyak::Ymm(x_tmp1.getIdx()), 1);
+ }
+ return;
+ }
+
+ // f16 path
+ vcvtps2ph(x_tmp0, xmm_scalar, 0);
+ vpbroadcastw(v_aux2, x_tmp0);
+
+ for (int i = 0; i < num_regs; i++) {
+ vfmadd231ph(vmm_dst[i], vmm_src[i], v_aux2);
+ }
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::l2norm_inplace_native_xf16(Vmm* vmm_array, const Xbyak::Xmm& xmm_eps, int num_regs) {
+ // L2 normalization: vmm /= sqrt(sum(vmm^2) + eps)
+ uni_vpxor(v_aux0, v_aux0, v_aux0); // fp32 accumulator
+
+ if (m_jcp.data_prc == ov::element::bf16) {
+ for (int i = 0; i < num_regs; i++) {
+ vdpbf16ps(v_aux0, vmm_array[i], vmm_array[i]);
+ }
+ } else {
+ for (int i = 0; i < num_regs; i++) {
+ // lower 16 fp16 lanes
+ vcvtph2ps(v_aux1, Xbyak::Ymm(vmm_array[i].getIdx()));
+ vfmadd231ps(v_aux0, v_aux1, v_aux1);
+
+ // upper 16 fp16 lanes
+ vextractf32x8(Xbyak::Ymm(v_tmp0.getIdx()), Xbyak::Zmm(vmm_array[i].getIdx()), 1);
+ vcvtph2ps(v_aux1, Xbyak::Ymm(v_tmp0.getIdx()));
+ vfmadd231ps(v_aux0, v_aux1, v_aux1);
+ }
+ }
+
+ // Reduce to scalar: sqrt(sum + eps), then compute reciprocal
+ uni_vpxor(x_hk, x_hk, x_hk);
+ reduce_zmm_f32_to_xmm_scalar(Xbyak::Zmm(v_aux0.getIdx()), x_hk, x_tmp0, x_tmp1);
+ vaddss(x_hk, x_hk, xmm_eps);
+ vsqrtss(x_hk, x_hk, x_hk);
+
+ vmovd(x_tmp1, reg_one.cvt32());
+ vdivss(x_tmp1, x_tmp1, x_hk); // reciprocal
+
+ // Scale vector by reciprocal
+ scale_vector_native_xf16(vmm_array, x_tmp1, num_regs);
+}
+
+// ============================================
+// Buffer-based L2 norm helper for qk_head_size > 128
+// ============================================
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::l2norm_buffer_compute_scale_native_xf16(const Xbyak::Reg64& reg_buffer,
+ const Xbyak::Xmm& xmm_eps,
+ const Xbyak::Xmm& xmm_scale_out,
+ int num_regs,
+ int num_chunks) {
+ // Compute L2 norm scale: 1/sqrt(sum(x^2) + eps)
+ // Accumulates across all chunks from buffer, returns scale factor
+ uni_vpxor(v_aux0, v_aux0, v_aux0);
+ if (m_jcp.data_prc == ov::element::f16) {
+ uni_vpxor(v_tmp0, v_tmp0, v_tmp0);
+ }
+
+ // Accumulate sum of squares across all chunks
+ for (int chunk = 0; chunk < num_chunks; chunk++) {
+ const int chunk_start = chunk * MAX_REGS_PER_VEC;
+ const int chunk_regs = std::min(MAX_REGS_PER_VEC, num_regs - chunk_start);
+ const size_t chunk_offset = chunk_start * XF16_ELEMS_PER_ZMM * m_jcp.data_prc.size();
+
+ mov(reg_aux2, reg_buffer);
+ add(reg_aux2, chunk_offset);
+ load_vector_native_xf16(const_cast<Vmm*>(v_k), reg_aux2, chunk_regs);
+
+ if (m_jcp.data_prc == ov::element::bf16) {
+ for (int i = 0; i < chunk_regs; i++) {
+ vdpbf16ps(v_aux0, v_k[i], v_k[i]);
+ }
+ } else {
+ // fp16 path - accumulate in native fp16
+ for (int i = 0; i < chunk_regs; i++) {
+ vfmadd231ph(v_tmp0, v_k[i], v_k[i]);
+ }
+ }
+ }
+
+ // Convert fp16 to fp32 after all chunks
+ if (m_jcp.data_prc == ov::element::f16) {
+ vcvtph2ps(v_aux1, Xbyak::Ymm(v_tmp0.getIdx()));
+ vextractf32x8(Xbyak::Ymm(x_tmp0.getIdx()), Xbyak::Zmm(v_tmp0.getIdx()), 1);
+ vcvtph2ps(v_aux2, Xbyak::Ymm(x_tmp0.getIdx()));
+ vaddps(v_aux0, v_aux1, v_aux2);
+ }
+
+ // Compute reciprocal: 1/sqrt(sum + eps)
+ uni_vpxor(xmm_scale_out, xmm_scale_out, xmm_scale_out);
+ reduce_zmm_f32_to_xmm_scalar(Xbyak::Zmm(v_aux0.getIdx()), xmm_scale_out, x_tmp0, x_tmp1);
+ vaddss(xmm_scale_out, xmm_scale_out, xmm_eps);
+ vsqrtss(xmm_scale_out, xmm_scale_out, xmm_scale_out);
+ vmovd(x_value, reg_one.cvt32());
+ vdivss(xmm_scale_out, x_value, xmm_scale_out);
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::scale_buffer_native_xf16(const Xbyak::Reg64& reg_buffer,
+ const Xbyak::Xmm& xmm_scale,
+ Vmm* vmm_temp,
+ int num_regs,
+ int num_chunks) {
+ // Scale all chunks of a buffer by a scalar
+ for (int chunk = 0; chunk < num_chunks; chunk++) {
+ const int chunk_start = chunk * MAX_REGS_PER_VEC;
+ const int chunk_regs = std::min(MAX_REGS_PER_VEC, num_regs - chunk_start);
+ const size_t chunk_offset = chunk_start * XF16_ELEMS_PER_ZMM * m_jcp.data_prc.size();
+
+ mov(reg_aux2, reg_buffer);
+ add(reg_aux2, chunk_offset);
+ load_vector_native_xf16(vmm_temp, reg_aux2, chunk_regs);
+ scale_vector_native_xf16(vmm_temp, xmm_scale, chunk_regs);
+ store_vector_native_xf16(reg_aux2, vmm_temp, chunk_regs);
+ }
+}
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::load_qk(bool is_f32, bool use_registers, int num_regs, int num_chunks) {
+ if (!is_f32 && use_registers) {
+ // Load K, Q directly into registers
+ load_vector_native_xf16(const_cast<Vmm*>(v_k), reg_key_seq, num_regs);
+ load_vector_native_xf16(const_cast<Vmm*>(v_q), reg_query_seq, num_regs);
+
+ // Optional L2 normalization
+ if (m_jcp.fuse_qk_l2norm) {
+ l2norm_inplace_native_xf16(const_cast<Vmm*>(v_k), x_eps_k, num_regs);
+ l2norm_inplace_native_xf16(const_cast<Vmm*>(v_q), x_eps_q, num_regs);
+ }
+
+ // Scale query
+ scale_vector_native_xf16(const_cast<Vmm*>(v_q), x_qscale, num_regs);
+ } else {
+ // Temp-buffer path: f32 and large-head xf16 share this skeleton.
+ mov(reg_key_tmp, ptr[reg_args + GET_OFF(key_tmp)]);
+ mov(reg_query_tmp, ptr[reg_args + GET_OFF(query_tmp)]);
+
+ const auto copy_elt_num = static_cast<int>(vec_size);
+ const size_t copy_step = static_cast<size_t>(copy_elt_num) * m_jcp.data_prc.size();
+ const size_t vec_cnt = m_jcp.qk_head_size / static_cast<size_t>(copy_elt_num);
+ const size_t tail = m_jcp.qk_head_size % static_cast<size_t>(copy_elt_num);
+
+ // State/temp copy: keep storage precision (no conversion).
+ for (size_t i = 0; i < vec_cnt; i++) {
+ const size_t off = i * copy_step;
+ load(v_tmp0, reg_key_seq, m_jcp.data_prc, copy_elt_num, false, off, m_jcp.data_prc);
+ store(reg_key_tmp, v_tmp0, m_jcp.data_prc, copy_elt_num, off, m_jcp.data_prc);
+ load(v_tmp1, reg_query_seq, m_jcp.data_prc, copy_elt_num, false, off, m_jcp.data_prc);
+ store(reg_query_tmp, v_tmp1, m_jcp.data_prc, copy_elt_num, off, m_jcp.data_prc);
+ }
+ if (tail > 0) {
+ const size_t off = vec_cnt * copy_step;
+ load(v_tmp0, reg_key_seq, m_jcp.data_prc, static_cast<int>(tail), false, off, m_jcp.data_prc);
+ store(reg_key_tmp, v_tmp0, m_jcp.data_prc, static_cast<int>(tail), off, m_jcp.data_prc);
+ load(v_tmp1, reg_query_seq, m_jcp.data_prc, static_cast<int>(tail), false, off, m_jcp.data_prc);
+ store(reg_query_tmp, v_tmp1, m_jcp.data_prc, static_cast<int>(tail), off, m_jcp.data_prc);
+ }
+
+ if (is_f32) {
+ mov(reg_key_tmp, ptr[reg_args + GET_OFF(key_tmp)]);
+ mov(reg_query_tmp, ptr[reg_args + GET_OFF(query_tmp)]);
+
+ if (m_jcp.fuse_qk_l2norm) {
+ l2norm_inplace(reg_key_tmp, x_eps_k, x_tmp0, x_tmp1, x_hk);
+ l2norm_inplace(reg_query_tmp, x_eps_q, x_tmp0, x_tmp1, x_hk);
+ }
+
+ multiply_scalar(reg_query_tmp, x_qscale);
+ } else {
+ // Optional L2 normalization (process in chunks)
+ if (m_jcp.fuse_qk_l2norm) {
+ // Normalize K
+ l2norm_buffer_compute_scale_native_xf16(reg_key_tmp, x_eps_k, x_beta, num_regs, num_chunks);
+ scale_buffer_native_xf16(reg_key_tmp, x_beta, const_cast<Vmm*>(v_k), num_regs, num_chunks);
+
+ // Normalize Q and combine with q_scale
+ l2norm_buffer_compute_scale_native_xf16(reg_query_tmp, x_eps_q, x_beta, num_regs, num_chunks);
+ vmulss(x_beta, x_beta, x_qscale); // Combine: l2norm_scale * q_scale
+ scale_buffer_native_xf16(reg_query_tmp, x_beta, const_cast<Vmm*>(v_q), num_regs, num_chunks);
+ } else {
+ // No L2 norm, just scale Q by q_scale
+ scale_buffer_native_xf16(reg_query_tmp, x_qscale, const_cast<Vmm*>(v_q), num_regs, num_chunks);
+ }
+ }
+ }
+}
+
+// ============================================
+// Main native xf16 kernel
+// ============================================
+
+template <cpu_isa_t isa>
+void jit_gdn_kernel<isa>::generate() {
+ // JIT codegen for native xf16 path
+ // For qk_head_size <= 128: register-resident Q/K/H
+ // For qk_head_size > 128: use temp buffers
+
+ auto exp_injector = std::make_shared<jit_uni_eltwise_injector_t<isa>>(this,
+ dnnl::impl::alg_kind::eltwise_exp,
+ 0.F,
+ 0.F,
+ 1.F,
+ dnnl::impl::data_type::f32,
+ true,
+ Xbyak::Reg64(Xbyak::Operand::RCX),
+ Xbyak::Opmask(1),
+ true,
+ false,
+ false,
+ false);
+
+ this->preamble();
+
+ Xbyak::Label l_t_loop;
+ Xbyak::Label l_end;
+
+ mov(reg_args, abi_param1);
+
+ const bool is_f32 = (m_jcp.data_prc == ov::element::f32);
+ const size_t qk = m_jcp.qk_head_size;
+ const auto data_size = static_cast<int>(m_jcp.data_prc.size());
+ const bool use_registers = !is_f32 && (qk <= 128);
+ const auto num_regs = is_f32 ? 0 : static_cast<int>(qk / XF16_ELEMS_PER_ZMM);
+ const auto num_chunks = is_f32 ? 0 : (num_regs + MAX_REGS_PER_VEC - 1) / MAX_REGS_PER_VEC;
+
+ // One-time setup
+ exp_injector->load_table_addr();
+ mov(reg_aux.cvt32(), float2int(m_jcp.k_l2_norm_eps));
+ vmovd(x_eps_k, reg_aux.cvt32());
+ mov(reg_aux.cvt32(), float2int(m_jcp.q_l2_norm_eps));
+ vmovd(x_eps_q, reg_aux.cvt32());
+ mov(reg_aux.cvt32(), float2int(m_jcp.q_scale));
+ vmovd(x_qscale, reg_aux.cvt32());
+ mov(reg_one.cvt32(), float2int(1.0F));
+
+ mov(reg_key_seq, ptr[reg_args + GET_OFF(key_seq)]);
+ mov(reg_query_seq, ptr[reg_args + GET_OFF(query_seq)]);
+ mov(reg_gate_seq, ptr[reg_args + GET_OFF(gate_seq)]);
+ mov(reg_beta_seq, ptr[reg_args + GET_OFF(beta_seq)]);
+ mov(reg_value_seq, ptr[reg_args + GET_OFF(value_seq)]);
+ mov(reg_out_seq, ptr[reg_args + GET_OFF(output_seq)]);
+ mov(reg_t, ptr[reg_args + GET_OFF(t_size)]);
+
+ if (!is_f32 && !use_registers) {
+ mov(reg_key_tmp, ptr[reg_args + GET_OFF(key_tmp)]);
+ mov(reg_query_tmp, ptr[reg_args + GET_OFF(query_tmp)]);
+ }
+
+ test(reg_t, reg_t);
+ jz(l_end, T_NEAR);
+
+ L(l_t_loop);
+ {
+ load_qk(is_f32, use_registers, num_regs, num_chunks);
+
+ // Compute gate and beta once per timestep and share across V lanes
+ load(Vmm(x_gate.getIdx()), reg_gate_seq, m_jcp.data_prc, 1, false);
+ exp_injector->compute_vector_range(x_gate.getIdx(), x_gate.getIdx() + 1);
+ load(Vmm(x_beta.getIdx()), reg_beta_seq, m_jcp.data_prc, 1, false);
+
+ // accumulate dot product of two vectors into v_aux0
+ auto accumulate_dot_product = [&](Vmm* vmm_a, Vmm* vmm_b, int chunk_regs) {
+ if (m_jcp.data_prc == ov::element::bf16) {
+ for (int i = 0; i < chunk_regs; i++) {
+ vdpbf16ps(v_aux0, vmm_a[i], vmm_b[i]);
+ }
+ } else {
+ for (int i = 0; i < chunk_regs; i++) {
+ // lower 16 elements
+ vcvtph2ps(v_aux1, Xbyak::Ymm(vmm_a[i].getIdx()));
+ vcvtph2ps(v_aux2, Xbyak::Ymm(vmm_b[i].getIdx()));
+ vfmadd231ps(v_aux0, v_aux1, v_aux2);
+ // upper 16 elements
+ vextractf32x8(Xbyak::Ymm(v_aux1.getIdx()), Xbyak::Zmm(vmm_a[i].getIdx()), 1);
+ vcvtph2ps(v_aux1, Xbyak::Ymm(v_aux1.getIdx()));
+ vextractf32x8(Xbyak::Ymm(v_aux2.getIdx()), Xbyak::Zmm(vmm_b[i].getIdx()), 1);
+ vcvtph2ps(v_aux2, Xbyak::Ymm(v_aux2.getIdx()));
+ vfmadd231ps(v_aux0, v_aux1, v_aux2);
+ }
+ }
+ };
+
+ // Unrolled V lanes: all lanes share same K/Q path above
+ for (size_t v_idx = 0; v_idx < m_jcp.v_tile; ++v_idx) {
+ mov(reg_state, ptr[reg_args + GET_OFF(state)]);
+ add(reg_state, static_cast<size_t>(v_idx * m_jcp.qk_head_size * m_jcp.data_prc.size()));
+
+ // Preload value scalar to overlap memory latency with hk reduction work.
+ mov(reg_aux2, reg_value_seq);
+ add(reg_aux2, static_cast<size_t>(v_idx * m_jcp.data_prc.size()));
+ load(Vmm(x_value.getIdx()), reg_aux2, m_jcp.data_prc, 1, false);
+
+ if (!is_f32 && use_registers) {
+ // Load H for current V lane
+ load_vector_native_xf16(const_cast<Vmm*>(v_h), reg_state, num_regs);
+
+ // Scale hidden state by exp(gate)
+ scale_vector_native_xf16(const_cast<Vmm*>(v_h), x_gate, num_regs);
+
+ // Compute hk = dot(H, K)
+ dot_product_native_xf16(x_hk, const_cast<Vmm*>(v_h), const_cast<Vmm*>(v_k), num_regs);
+
+ // delta = (value - hk) * beta
+ vsubss(x_delta, x_value, x_hk);
+ vmulss(x_delta, x_delta, x_beta);
+
+ // Update: H += K * delta
+ fmadd_vector_native_xf16(const_cast<Vmm*>(v_h), const_cast<Vmm*>(v_k), x_delta, num_regs);
+
+ // Output: out = dot(H, Q)
+ dot_product_native_xf16(x_out, const_cast<Vmm*>(v_h), const_cast<Vmm*>(v_q), num_regs);
+
+ // Store output and H state for current V lane
+ mov(reg_aux2, reg_out_seq);
+ add(reg_aux2, static_cast<size_t>(v_idx * m_jcp.data_prc.size()));
+ store(reg_aux2, Vmm(x_out.getIdx()), m_jcp.data_prc, 1);
+ store_vector_native_xf16(reg_state, const_cast<Vmm*>(v_h), num_regs);
+ } else {
+ // Temp-buffer compute path shared by f32 and xf16-large.
+ if (is_f32) {
+ multiply_scalar(reg_state, x_gate);
+
+ mov(reg_query_tmp, reg_state);
+ mov(reg_key_tmp, ptr[reg_args + GET_OFF(key_tmp)]);
+ dot_product_to_scalar(x_hk, reg_query_tmp, reg_key_tmp);
+ } else {
+ // Scale H by exp(gate)
+ scale_buffer_native_xf16(reg_state, x_gate, const_cast<Vmm*>(v_h), num_regs, num_chunks);
+
+ // Compute hk = dot(H, K)
+ uni_vpxor(v_aux0, v_aux0, v_aux0);
+ for (int chunk = 0; chunk < num_chunks; chunk++) {
+ const int chunk_start = chunk * MAX_REGS_PER_VEC;
+ const int chunk_regs = std::min(MAX_REGS_PER_VEC, num_regs - chunk_start);
+ const size_t chunk_offset = chunk_start * XF16_ELEMS_PER_ZMM * m_jcp.data_prc.size();
+
+ mov(reg_aux2, reg_state);
+ add(reg_aux2, chunk_offset);
+ load_vector_native_xf16(const_cast<Vmm*>(v_h), reg_aux2, chunk_regs);
+
+ mov(reg_aux2, reg_key_tmp);
+ add(reg_aux2, chunk_offset);
+ load_vector_native_xf16(const_cast<Vmm*>(v_k), reg_aux2, chunk_regs);
+
+ accumulate_dot_product(const_cast<Vmm*>(v_h), const_cast<Vmm*>(v_k), chunk_regs);
+ }
+ uni_vpxor(x_hk, x_hk, x_hk);
+ reduce_zmm_f32_to_xmm_scalar(Xbyak::Zmm(v_aux0.getIdx()), x_hk, x_tmp0, x_tmp1);
+ }
+
+ // delta = (value - hk) * beta
+ vsubss(x_delta, x_value, x_hk);
+ vmulss(x_delta, x_delta, x_beta);
+
+ if (is_f32) {
+ // Update: H += K * delta
+ const auto update_elt_num = static_cast<int>(vec_size);
+ const size_t update_step = static_cast<size_t>(update_elt_num) * sizeof(float);
+ const size_t update_vec_cnt = m_jcp.qk_head_size / static_cast<size_t>(update_elt_num);
+ const size_t update_tail = m_jcp.qk_head_size % static_cast<size_t>(update_elt_num);
+
+ vbroadcastss(v_aux2, x_delta);
+
+ mov(reg_aux2, ptr[reg_args + GET_OFF(key_tmp)]);
+ for (size_t i = 0; i < update_vec_cnt; i++) {
+ const size_t off = i * update_step;
+ load(v_tmp0, reg_state, ov::element::f32, update_elt_num, false, off);
+ load(v_tmp1, reg_aux2, ov::element::f32, update_elt_num, false, off);
+ vfmadd231ps(v_tmp0, v_tmp1, v_aux2);
+ store(reg_state, v_tmp0, ov::element::f32, update_elt_num, off);
+ }
+ if (update_tail > 0) {
+ const size_t off = update_vec_cnt * update_step;
+ load(v_tmp0, reg_state, ov::element::f32, static_cast<int>(update_tail), false, off);
+ load(v_tmp1, reg_aux2, ov::element::f32, static_cast<int>(update_tail), false, off);
+ vfmadd231ps(v_tmp0, v_tmp1, v_aux2);
+ store(reg_state, v_tmp0, ov::element::f32, static_cast<int>(update_tail), off);
+ }
+
+ mov(reg_query_tmp, reg_state);
+ mov(reg_key_tmp, ptr[reg_args + GET_OFF(query_tmp)]);
+ dot_product_to_scalar(x_out, reg_query_tmp, reg_key_tmp);
+ } else {
+ // Update: H += K * delta
+ for (int chunk = 0; chunk < num_chunks; chunk++) {
+ const int chunk_start = chunk * MAX_REGS_PER_VEC;
+ const int chunk_regs = std::min(MAX_REGS_PER_VEC, num_regs - chunk_start);
+ const size_t chunk_offset = chunk_start * XF16_ELEMS_PER_ZMM * m_jcp.data_prc.size();
+
+ mov(reg_aux2, reg_state);
+ add(reg_aux2, chunk_offset);
+ load_vector_native_xf16(const_cast<Vmm*>(v_h), reg_aux2, chunk_regs);
+
+ mov(reg_aux2, reg_key_tmp);
+ add(reg_aux2, chunk_offset);
+ load_vector_native_xf16(const_cast<Vmm*>(v_k), reg_aux2, chunk_regs);
+
+ fmadd_vector_native_xf16(const_cast<Vmm*>(v_h), const_cast<Vmm*>(v_k), x_delta, chunk_regs);
+
+ mov(reg_aux2, reg_state);
+ add(reg_aux2, chunk_offset);
+ store_vector_native_xf16(reg_aux2, const_cast<Vmm*>(v_h), chunk_regs);
+ }
+
+ // Output: out = dot(H, Q)
+ uni_vpxor(v_aux0, v_aux0, v_aux0);
+ for (int chunk = 0; chunk < num_chunks; chunk++) {
+ const int chunk_start = chunk * MAX_REGS_PER_VEC;
+ const int chunk_regs = std::min(MAX_REGS_PER_VEC, num_regs - chunk_start);
+ const size_t chunk_offset = chunk_start * XF16_ELEMS_PER_ZMM * m_jcp.data_prc.size();
+
+ mov(reg_aux2, reg_state);
+ add(reg_aux2, chunk_offset);
+ load_vector_native_xf16(const_cast<Vmm*>(v_h), reg_aux2, chunk_regs);
+
+ mov(reg_aux2, reg_query_tmp);
+ add(reg_aux2, chunk_offset);
+ load_vector_native_xf16(const_cast<Vmm*>(v_q), reg_aux2, chunk_regs);
+
+ accumulate_dot_product(const_cast<Vmm*>(v_h), const_cast<Vmm*>(v_q), chunk_regs);
+ }
+ uni_vpxor(x_out, x_out, x_out);
+ reduce_zmm_f32_to_xmm_scalar(Xbyak::Zmm(v_aux0.getIdx()), x_out, x_tmp0, x_tmp1);
+ }
+
+ mov(reg_aux2, reg_out_seq);
+ add(reg_aux2, static_cast<size_t>(v_idx * m_jcp.data_prc.size()));
+ store(reg_aux2, Vmm(x_out.getIdx()), m_jcp.data_prc, 1);
+ }
+ }
+
+ // Advance pointers using stride parameters.
+ mov(reg_aux2, ptr[reg_args + GET_OFF(key_query_stride)]);
+ lea(reg_key_seq, ptr[reg_key_seq + reg_aux2 * data_size]);
+ lea(reg_query_seq, ptr[reg_query_seq + reg_aux2 * data_size]);
+
+ mov(reg_aux2, ptr[reg_args + GET_OFF(value_stride)]);
+ lea(reg_value_seq, ptr[reg_value_seq + reg_aux2 * data_size]);
+
+ mov(reg_aux2, ptr[reg_args + GET_OFF(gate_beta_stride)]);
+ lea(reg_gate_seq, ptr[reg_gate_seq + reg_aux2 * data_size]);
+ lea(reg_beta_seq, ptr[reg_beta_seq + reg_aux2 * data_size]);
+
+ mov(reg_aux2, ptr[reg_args + GET_OFF(output_stride)]);
+ lea(reg_out_seq, ptr[reg_out_seq + reg_aux2 * data_size]);
+
+ dec(reg_t);
+ jnz(l_t_loop, T_NEAR);
+ }
+
+ L(l_end);
+
+ this->postamble();
+
+ exp_injector->prepare_table();
+}
+
+std::shared_ptr<JitKernelBase> create_gdn_jit_kernel(ov::element::Type data_prc,
+ size_t qk_head_size,
+ size_t v_tile,
+ bool fuse_qk_l2norm,
+ float q_l2_norm_eps,
+ float k_l2_norm_eps) {
+ std::shared_ptr<JitKernelBase> res;
+ jit_gdn_compile_params jcp;
+ jcp.data_prc = data_prc;
+ jcp.qk_head_size = qk_head_size;
+ jcp.v_tile = v_tile;
+ jcp.fuse_qk_l2norm = fuse_qk_l2norm;
+ jcp.q_l2_norm_eps = q_l2_norm_eps;
+ jcp.k_l2_norm_eps = k_l2_norm_eps;
+ jcp.q_scale = 1.0F / std::sqrt(static_cast<float>(qk_head_size));
+
+ if (data_prc != ov::element::bf16 && data_prc != ov::element::f16 && data_prc != ov::element::f32) {
+ return res;
+ }
+ if (qk_head_size == 0) {
+ return res;
+ }
+ if (v_tile == 0) {
+ return res;
+ }
+
+ if ((data_prc == ov::element::bf16 || data_prc == ov::element::f16) && qk_head_size % 32 != 0) {
+ return res;
+ }
+
+ if (data_prc == ov::element::bf16) {
+ if (mayiuse(avx512_core_bf16)) {
+ res = std::make_shared<jit_gdn_kernel<avx512_core_bf16>>(jcp);
+ }
+ } else if (data_prc == ov::element::f16) {
+ if (mayiuse(avx512_core_fp16)) {
+ res = std::make_shared<jit_gdn_kernel<avx512_core_fp16>>(jcp);
+ }
+ } else if (data_prc == ov::element::f32) {
+ if (mayiuse(avx512_core)) {
+ res = std::make_shared<jit_gdn_kernel<avx512_core>>(jcp);
+ } else if (mayiuse(avx2)) {
+ res = std::make_shared<jit_gdn_kernel<avx2>>(jcp);
+ }
+ }
+
+ if (res) {
+ res->create_kernel();
+ }
+
+ return res;
+}
+
+template struct jit_gdn_kernel<avx2>;
+template struct jit_gdn_kernel<avx512_core>;
+template struct jit_gdn_kernel<avx512_core_bf16>;
+template struct jit_gdn_kernel<avx512_core_fp16>;
+
+} // namespace ov::intel_cpu::kernel
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/x64/gdn_jit_kernel.hpp b/src/plugins/intel_cpu/src/nodes/kernels/x64/gdn_jit_kernel.hpp
new file mode 100644
index 00000000000..7155b909683
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/kernels/x64/gdn_jit_kernel.hpp
@@ -0,0 +1,175 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <xbyak/xbyak.h>
+
+#include <cpu/x64/cpu_isa_traits.hpp>
+#include <cstddef>
+#include <memory>
+#include <type_traits>
+#include <unordered_map>
+#include <vector>
+
+#include "emitters/plugin/x64/jit_emitter.hpp"
+#include "jit_kernel_base.hpp"
+#include "openvino/core/type/element_type.hpp"
+
+namespace ov::intel_cpu::kernel {
+
+struct jit_gdn_compile_params {
+ ov::element::Type data_prc = ov::element::f32;
+ size_t qk_head_size = 0;
+ size_t v_tile = 1;
+ bool fuse_qk_l2norm = false;
+ float q_l2_norm_eps = 1e-6F;
+ float k_l2_norm_eps = 1e-6F;
+ float q_scale = 1.0F;
+};
+
+struct jit_gdn_call_args {
+ uint8_t* state;
+ const uint8_t* key_seq;
+ const uint8_t* query_seq;
+ const uint8_t* value_seq;
+ const uint8_t* gate_seq;
+ const uint8_t* beta_seq;
+ size_t t_size;
+ size_t key_query_stride;
+ size_t gate_beta_stride;
+ size_t value_stride;
+ size_t output_stride;
+ uint8_t* key_tmp;
+ uint8_t* query_tmp;
+ uint8_t* output_seq;
+};
+
+template <dnnl::impl::cpu::x64::cpu_isa_t isa>
+struct jit_gdn_kernel : public JitKernel<jit_gdn_compile_params, jit_gdn_call_args> {
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_gdn_kernel)
+
+ explicit jit_gdn_kernel(const jit_gdn_compile_params& jcp) : JitKernel(jit_name(), jcp, isa) {}
+
+private:
+ using Xmm = Xbyak::Xmm;
+ using Vmm = std::conditional_t<isa == dnnl::impl::cpu::x64::avx2, Xbyak::Ymm, Xbyak::Zmm>;
+
+ static constexpr size_t vec_size = dnnl::impl::cpu::x64::cpu_isa_traits_t<isa>::vlen / sizeof(float);
+ static constexpr size_t vec_bytes = vec_size * sizeof(float);
+ static constexpr int vec_shift = isa == dnnl::impl::cpu::x64::avx2 ? 3 : 4;
+
+ // GPR map
+ const Xbyak::Reg64 reg_args = rbx;
+ const Xbyak::Reg64 reg_state = r8;
+ const Xbyak::Reg64 reg_key_tmp = r9;
+ const Xbyak::Reg64 reg_query_tmp = r10;
+ const Xbyak::Reg64 reg_t = r12;
+ const Xbyak::Reg64 reg_key_seq = r13;
+ const Xbyak::Reg64 reg_query_seq = r14;
+ const Xbyak::Reg64 reg_value_seq = r15;
+ const Xbyak::Reg64 reg_aux = r11;
+ const Xbyak::Reg64 reg_one = rdx;
+ const Xbyak::Reg64 reg_gate_seq = rsi;
+ const Xbyak::Reg64 reg_beta_seq = rdi;
+ const Xbyak::Reg64 reg_out_seq = rbp;
+ const Xbyak::Reg64 reg_aux2 = rax;
+
+ // XMM map
+ const Xmm x_hk = Xmm(0);
+ const Xmm x_tmp0 = Xmm(1);
+ const Xmm x_tmp1 = Xmm(2);
+ const Xmm x_delta = Xmm(3);
+ const Xmm x_out = Xmm(4);
+ const Xmm x_gate = Xmm(5);
+ const Xmm x_beta = Xmm(6);
+ const Xmm x_value = Xmm(7);
+ const Xmm x_eps_k = Xmm(8);
+ const Xmm x_eps_q = Xmm(9);
+ const Xmm x_qscale = Xmm(10);
+
+ const Vmm v_tmp0 = Vmm(x_tmp0.getIdx());
+ const Vmm v_tmp1 = Vmm(x_tmp1.getIdx());
+ const Vmm v_aux0 = Vmm(11);
+ const Vmm v_aux1 = Vmm(12);
+ const Vmm v_aux2 = Vmm(13);
+
+ // Register-based Q/K/H storage for native f16
+ // Supports head_dims that are multiples of 32, up to 128
+ static constexpr int XF16_ELEMS_PER_ZMM = 32; // 32 xf16 elements per ZMM register
+ static constexpr int MAX_REGS_PER_VEC = 4; // Max ZMMs per vector (for head_dims=128)
+
+ const Vmm v_q[MAX_REGS_PER_VEC] = {Vmm(14), Vmm(15), Vmm(16), Vmm(17)}; // Query
+ const Vmm v_k[MAX_REGS_PER_VEC] = {Vmm(18), Vmm(19), Vmm(20), Vmm(21)}; // Key
+ const Vmm v_h[MAX_REGS_PER_VEC] = {Vmm(22), Vmm(23), Vmm(24), Vmm(25)}; // Hidden state
+
+ void generate() override;
+
+ // Native xf16 helpers - f16/bf16, head_dims must be multiple of 32
+ void load_vector_native_xf16(Vmm* vmm_array, const Xbyak::Reg64& reg_src, int num_regs);
+ void store_vector_native_xf16(const Xbyak::Reg64& reg_dst, Vmm* vmm_array, int num_regs);
+ void dot_product_native_xf16(const Xbyak::Xmm& xmm_dst, Vmm* vmm_a, Vmm* vmm_b, int num_regs);
+ void scale_vector_native_xf16(Vmm* vmm_array, const Xbyak::Xmm& xmm_scalar, int num_regs);
+ void fmadd_vector_native_xf16(Vmm* vmm_dst, Vmm* vmm_src, const Xbyak::Xmm& xmm_scalar, int num_regs);
+ void l2norm_inplace_native_xf16(Vmm* vmm_array, const Xbyak::Xmm& xmm_eps, int num_regs);
+
+ // Buffer-based helpers for qk_head_size > 128
+ void l2norm_buffer_compute_scale_native_xf16(const Xbyak::Reg64& reg_buffer,
+ const Xbyak::Xmm& xmm_eps,
+ const Xbyak::Xmm& xmm_scale_out,
+ int num_regs,
+ int num_chunks);
+ void scale_buffer_native_xf16(const Xbyak::Reg64& reg_buffer,
+ const Xbyak::Xmm& xmm_scale,
+ Vmm* vmm_temp,
+ int num_regs,
+ int num_chunks);
+ void load_qk(bool is_f32, bool use_registers, int num_regs, int num_chunks);
+
+ void reduce_zmm_f32_to_xmm_scalar(const Xbyak::Zmm& zmm_src,
+ const Xbyak::Xmm& xmm_dst,
+ const Xbyak::Xmm& xmm_tmp0,
+ const Xbyak::Xmm& xmm_tmp1);
+ void dot_product_scalar(const Xbyak::Xmm& xmm_dst,
+ const Xbyak::Reg64& reg_a,
+ const Xbyak::Reg64& reg_b,
+ size_t tail_count,
+ size_t base_off,
+ size_t elem_size,
+ const Xbyak::Xmm& xmm_tmp0,
+ const Xbyak::Xmm& xmm_tmp1);
+ void dot_product_to_scalar(const Xbyak::Xmm& xmm_dst, const Xbyak::Reg64& reg_a, const Xbyak::Reg64& reg_b);
+ void multiply_scalar(const Xbyak::Reg64& reg_vec, const Xbyak::Xmm& xmm_scalar);
+ void l2norm_inplace(const Xbyak::Reg64& reg_vec,
+ const Xbyak::Xmm& xmm_eps,
+ const Xbyak::Xmm& xmm_tmp0,
+ const Xbyak::Xmm& xmm_tmp1,
+ const Xbyak::Xmm& xmm_sum);
+ void store(const Xbyak::Reg64& reg_dst,
+ const Vmm& vmm_src,
+ ov::element::Type dst_prc,
+ const int& elt_num,
+ size_t offset = 0,
+ ov::element::Type src_prc = ov::element::f32);
+ void load(const Vmm& vmm_dst,
+ const Xbyak::Reg64& reg_src,
+ ov::element::Type src_prc,
+ const int& elt_num,
+ bool fill,
+ size_t offset = 0,
+ ov::element::Type dst_prc = ov::element::f32);
+
+ std::unordered_map<size_t, std::unique_ptr<jit_emitter>> emitters;
+ const std::vector<size_t> pool_aux_gpr_idxs;
+ const std::vector<size_t> pool_aux_vmm_idxs;
+};
+
+std::shared_ptr<JitKernelBase> create_gdn_jit_kernel(ov::element::Type data_prc = ov::element::f32,
+ size_t qk_head_size = 0,
+ size_t v_tile = 1,
+ bool fuse_qk_l2norm = false,
+ float q_l2_norm_eps = 1e-6F,
+ float k_l2_norm_eps = 1e-6F);
+
+} // namespace ov::intel_cpu::kernel
diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/gated_delta_net.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/gated_delta_net.cpp
index 0ad3d105825..6a15f966775 100644
--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/gated_delta_net.cpp
+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/gated_delta_net.cpp
@@ -25,6 +25,20 @@ std::vector<gated_delta_net_params> test_cases = {
{1, 2, 2, 2, 15, 15, ov::element::f32, "CPU"},
{1, 2, 2, 2, 31, 31, ov::element::f32, "CPU"},
{1, 2, 2, 2, 1, 1, ov::element::f32, "CPU"},
+ // f16 cases
+ {1, 32, 2, 2, 128, 128, ov::element::f16, "CPU"},
+ {1, 32, 4, 4, 128, 128, ov::element::f16, "CPU"},
+ {1, 32, 2, 4, 128, 128, ov::element::f16, "CPU"},
+ {1, 16, 2, 2, 64, 128, ov::element::f16, "CPU"},
+ {1, 32, 4, 4, 256, 256, ov::element::f16, "CPU"},
+ {1, 32, 2, 4, 256, 256, ov::element::f16, "CPU"},
+ // bf16 cases
+ {1, 32, 2, 2, 128, 128, ov::element::bf16, "CPU"},
+ {1, 32, 4, 4, 128, 128, ov::element::bf16, "CPU"},
+ {1, 32, 2, 4, 128, 128, ov::element::bf16, "CPU"},
+ {1, 16, 2, 2, 64, 128, ov::element::bf16, "CPU"},
+ {1, 32, 4, 4, 256, 256, ov::element::bf16, "CPU"},
+ {1, 32, 2, 4, 256, 256, ov::element::bf16, "CPU"},
};
INSTANTIATE_TEST_SUITE_P(smoke_GatedDeltaNet,
GatedDeltaNet,