OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[CPU][DOCS] Add executors README, remove duplicated skill sections (#38025)
Vladislav Golubevae5eba017d0a
diff --git a/.github/agents-prototype/skills/add-cpu-op/step2-implementation.md b/.github/agents-prototype/skills/add-cpu-op/step2-implementation.mdindex 9a8ffb47531..32310ae2786 100644--- a/.github/agents-prototype/skills/add-cpu-op/step2-implementation.md+++ b/.github/agents-prototype/skills/add-cpu-op/step2-implementation.md@@ -108,343 +108,15 @@ Verify no compilation errors before proceeding.## Executor Pattern (Standard Architecture for Non-Trivial Ops)-The executor framework is the **standard architecture** for any CPU node that is-more complex than simple portable C++ code. This includes ops with:-- JIT kernels (these become `ExecutorType::Jit` implementations)-- oneDNN primitives (these become `ExecutorType::Dnnl` implementations)-- Multiple backend targets (x64/ARM/RISC-V)-- Any ISA-specific optimisation--Study these canonical implementations in this order:-1. `eltwise_implementations.cpp` — simplest executor pattern (Jit + ACL + Reference)-2. `fullyconnected_implementations.cpp` — full-featured (MLAS, 1x1conv, ACL, KleidiAI, oneDNN)-3. `convolution_implementations.cpp` — layout-aware implementations with `MemoryFormatFilter`--### Architecture Overview--```-Node (e.g. Eltwise, FullyConnected, Convolution)- ├── OpNameAttrs (op config struct: <op_name>_config.hpp)- ├── MemoryArgs memory (maps ARG_SRC/ARG_DST/... → MemoryPtr)- ├── ExecutorFactoryPtr<OpNameAttrs> factory- │ ├── filters ExecutorImplementation<Attrs> list by:- │ │ ├── supports(config, memoryFormatFilter) — ISA, precision, layout- │ │ ├── createOptimalConfig(config) — preferred memory format- │ │ └── acceptsShape(attrs, memory) — shape-dependent heuristics- │ └── make(memory) → returns ExecutorPtr or VariableExecutor- └── ExecutorPtr executor- ├── update(memory) — called in prepareParams()- └── execute(memory) — called in execute()-```--### Step 1: Define the Attrs Struct--Create `src/plugins/intel_cpu/src/nodes/executors/<op_name>_config.hpp`:--```cpp-// Copyright (C) 2018-2026 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#pragma once--#include "executor_config.hpp"-#include "post_ops.hpp" // if post-ops fusion is supported--namespace ov::intel_cpu {--struct OpNameAttrs {- // Op-specific attributes needed by all implementations.- // Examples: float epsilon; int axis; bool keep_dims;- PostOps postOps; // include if the op supports post-op fusion-};--using OpNameConfig = executor::Config<OpNameAttrs>;--} // namespace ov::intel_cpu-```--### Step 2: Register the `getImplementations` Specialisation--**a) Declare in `implementations.hpp`** — add alongside existing declarations:--```cpp-// OpName-template <>-const std::vector<ExecutorImplementation<OpNameAttrs>>& getImplementations();-```--**b) Define in `<op_name>_implementations.cpp`:**--The file registers all implementation variants in **priority order** (highest-first). Each entry uses an `OV_CPU_INSTANCE_*` macro that conditionally compiles-the implementation based on the target architecture:--| Macro | Active When |-|-------|-------------|-| `OV_CPU_INSTANCE_COMMON(...)` | Always (portable code) |-| `OV_CPU_INSTANCE_X64(...)` | x86-64 only |-| `OV_CPU_INSTANCE_DNNL_X64(...)` | x86-64 with oneDNN |-| `OV_CPU_INSTANCE_DNNL(...)` | Any arch with oneDNN |-| `OV_CPU_INSTANCE_ACL(...)` | AArch64 with ARM Compute Library |-| `OV_CPU_INSTANCE_KLEIDIAI(...)` | AArch64 with KleidiAI |-| `OV_CPU_INSTANCE_MLAS_X64(...)` | x86-64 with MLAS |-| `OV_CPU_INSTANCE_RISCV64(...)` | RISC-V 64 only |--Each `ExecutorImplementation<Attrs>` has 6 fields:-1. **name** — unique human-readable string (e.g. `"op_name_jit_ncsp"`)-2. **ExecutorType** — `Jit`, `Dnnl`, `Acl`, `Reference`, etc.-3. **OperationType** — `OperationType::OpName`-4. **supports** — lambda returning `bool`. Use `VERIFY(condition, MESSAGE)` macro- for debuggable rejection. Can take `(const Config&)` or- `(const Config&, const MemoryFormatFilter&)`.-5. **createOptimalConfig** — lambda returning `std::optional<Config>`. Return- `{}` (nullopt) if the current memory config is already acceptable. Use- `createOptimalConfigCommon()` helper with `TypeMapping` and `LayoutConfig`.-6. **acceptsShape** — lambda `(const Attrs&, const MemoryArgs&) -> bool`. Pass- `AcceptsAnyShape<Attrs>` (or `{}`) for shape-agnostic implementations.-7. **create** — lambda returning `ExecutorPtr`. Use `CreateDefault<Executor, Attrs>{}`- for simple cases or a custom lambda for complex wiring (e.g., `DnnlExecutor`).--```cpp-// Copyright (C) 2018-2026 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#include "nodes/executors/executor_implementation.hpp"-#include "nodes/executors/implementations.hpp"-#include "nodes/executors/implementation_utils.hpp"-#include "nodes/executors/debug_messages.hpp"-#include "nodes/executors/<op_name>_config.hpp"-#include "nodes/executors/precision_translation.hpp"-#include "nodes/executors/type_mask.hpp"-#include "utils/arch_macros.h"--// Include the actual executor headers:-#include "nodes/executors/jit/<op_name>_jit.hpp" // JIT executor (x64)-// #include "nodes/executors/acl/<op_name>_acl.hpp" // ACL executor (ARM)-#include "nodes/executors/ref/<op_name>_ref.hpp" // Reference executor--#if defined(OPENVINO_ARCH_X86_64)-# include "cpu/x64/cpu_isa_traits.hpp"-#endif--namespace ov::intel_cpu {--using namespace ov::element;-using namespace TypeMaskAlias;-using namespace executor;--using LayoutConfig = std::vector<LayoutType>;--// TypeMapping defines precision transformations per implementation.-// Each row: {input_precisions..., output_precisions...} → {transform_functions...}-// Transform helpers: bypass() = keep as-is, just<T>() = force to T, use<N>() = match arg N-static const TypeMapping opNameTypeMapping {- // {src, dst} pt<src, dst>- {{_f32, _f32}, {bypass(), bypass()}},- {{_bf16, _bf16 | _f32}, {bypass(), bypass()}},- {{_any, _any}, {just<f32>(), just<f32>()}}, // fallback-};--static const MappingNotation opNameMappingNotation {- {ARG_SRC, 0},- {ARG_DST, 1},-};--// to keep OV_CPU_INSTANCE macros aligned-// clang-format off-template <>-const std::vector<ExecutorImplementation<OpNameAttrs>>& getImplementations() {- static const std::vector<ExecutorImplementation<OpNameAttrs>> implementations {- OV_CPU_INSTANCE_X64(- "op_name_jit_ncsp",- ExecutorType::Jit,- OperationType::OpName,- [](const OpNameConfig& config) -> bool {- VERIFY(dnnl::impl::cpu::x64::mayiuse(- dnnl::impl::cpu::x64::avx2), UNSUPPORTED_ISA);- // Add precision / attr checks as needed- return true;- },- // createOptimalConfig- [](const OpNameConfig& config) -> std::optional<OpNameConfig> {- return createOptimalConfigCommon(config,- opNameTypeMapping,- LayoutConfig{LayoutType::ncsp, LayoutType::ncsp},- opNameMappingNotation);- },- AcceptsAnyShape<OpNameAttrs>,- CreateDefault<JitOpNameExecutor, OpNameAttrs>{}- )- OV_CPU_INSTANCE_COMMON(- "op_name_ref_ncsp",- ExecutorType::Reference,- OperationType::OpName,- [](const OpNameConfig& config) -> bool { return true; },- [](const OpNameConfig& config) -> std::optional<OpNameConfig> {- return createOptimalConfigCommon(config,- opNameTypeMapping,- LayoutConfig{LayoutType::ncsp, LayoutType::ncsp},- opNameMappingNotation);- },- AcceptsAnyShape<OpNameAttrs>,- CreateDefault<RefOpNameExecutor, OpNameAttrs>{}- )- };- return implementations;-}-// clang-format on--} // namespace ov::intel_cpu-```--### Step 3: Implement the Concrete Executor Classes--Each executor implements the `Executor` base class from `executor.hpp`:--```cpp-class Executor {-public:- virtual bool update(const MemoryArgs& memory) = 0; // reshape / re-init- virtual void execute(const MemoryArgs& memory) = 0; // run computation- virtual impl_desc_type implType() const = 0; // report impl type- virtual ~Executor() = default;-};-```--**Reference executor** (portable C++):--```cpp-class RefOpNameExecutor : public Executor {-public:- RefOpNameExecutor(const OpNameAttrs& attrs,- const MemoryArgs& memory,- const ExecutorContext::CPtr& context);- bool update(const MemoryArgs& memory) override;- void execute(const MemoryArgs& memory) override;- impl_desc_type implType() const override { return impl_desc_type::ref; }-};-```--**JIT executor** (wraps JIT kernel + CpuParallel):--```cpp-class JitOpNameExecutor : public Executor {-public:- JitOpNameExecutor(const OpNameAttrs& attrs,- const MemoryArgs& memory,- const ExecutorContext::CPtr& context);- bool update(const MemoryArgs& memory) override;- void execute(const MemoryArgs& memory) override;- impl_desc_type implType() const override { return impl_desc_type::jit_avx2; }-private:- std::shared_ptr<JitKernelBase> m_kernel;- // ... kernel compile params, context, etc.-};-```--### Step 4: Wire the Node to Use ExecutorFactory--In the **node header**, replace direct `execute()` logic with executor fields:--```cpp-#include "nodes/executors/executor.hpp"-#include "nodes/executors/executor_factory.hpp"-#include "nodes/executors/<op_name>_config.hpp"-#include "nodes/executors/memory_arguments.hpp"--// Inside the class:-private:- OpNameAttrs m_attrs;- MemoryArgs m_memory;- ExecutorFactoryPtr<OpNameAttrs> m_factory;- ExecutorPtr m_executor = nullptr;-```--In **`initSupportedPrimitiveDescriptors()`** (follows `conv.cpp` pattern):--```cpp-void OpName::initSupportedPrimitiveDescriptors() {- // 1. Populate m_attrs from the core op- // m_attrs.epsilon = ...; m_attrs.axis = ...;- // m_attrs.postOps = getPostOps(fusedWith);-- // 2. Build memory descriptors per port- const auto& creatorsMap = BlockedDescCreator::getCommonCreators();- VecMemoryDescs srcDescs;- for (size_t i = 0; i < getOriginalInputsNumber(); i++) {- srcDescs.push_back(creatorsMap.at(LayoutType::ncsp)->createSharedDesc(- getOriginalInputPrecisionAtPort(i), getInputShapeAtPort(i)));- }- auto dstDesc = creatorsMap.at(LayoutType::ncsp)->createSharedDesc(- getOriginalOutputPrecisionAtPort(0), getOutputShapeAtPort(0));-- MemoryDescArgs descs{- {ARG_SRC, srcDescs[0]},- {ARG_DST, dstDesc},- };-- // 3. Create executor factory — this filters & ranks implementations- auto executionContext = std::make_shared<ExecutorContext>(- context, getImplPriority());- m_factory = std::make_shared<ExecutorFactory<OpNameAttrs>>(- m_attrs, executionContext, descs);-- // 4. Let factory decide optimal memory descriptors- const auto nodeDescList = m_factory->getProperMemoryDescriptors(descs);- for (const auto& nodeDescs : nodeDescList) {- NodeConfig nodeConfig;- nodeConfig.inConfs.resize(srcDescs.size());- // ... populate from nodeDescs (see conv.cpp / fc.cpp pattern) ...- nodeConfig.outConfs.emplace_back(nodeDescs.at(ARG_DST));- supportedPrimitiveDescriptors.emplace_back(nodeConfig, impl_desc_type::undef);- }-}-```--In **`prepareParams()`**:--```cpp-void OpName::prepareParams() {- m_memory[ARG_SRC] = getSrcMemoryAtPort(0);- m_memory[ARG_DST] = getDstMemoryAtPort(0);-- if (!m_executor) {- m_executor = m_factory->make(m_memory);- }- m_executor->update(m_memory);-}-```--In **`execute()`**:--```cpp-void OpName::execute([[maybe_unused]] const dnnl::stream& strm) {- m_executor->execute(m_memory);-}-```--### Key Executor Framework Utilities--| Utility | Location | Purpose |-|---------|----------|---------|-| `VERIFY(cond, msg)` | `debug_messages.hpp` | Debug-logged rejection in `supports()` |-| `TypeMapping` / `MappingNotation` | `precision_translation.hpp` | Precision transform rules |-| `createOptimalConfigCommon()` | `implementation_utils.hpp` | Standard config optimisation |-| `AcceptsAnyShape<Attrs>` | `implementation_utils.hpp` | Shape-agnostic stub |-| `HasNoOptimalConfig<Attrs>` | `implementation_utils.hpp` | No config override stub |-| `SupportsAnyConfig<Attrs>` | `implementation_utils.hpp` | Unconditional support stub |-| `CreateDefault<Executor, Attrs>` | `implementation_utils.hpp` | Simple `make_shared` factory |-| `CreateDnnlDefault<Prim, Attrs>` | `implementation_utils.hpp` | `DnnlExecutor` wrapper factory |-| `OV_CPU_INSTANCE_*` macros | `utils/arch_macros.h` | Conditional compilation per arch |--> **Key advantage:** The `ExecutorFactory` automatically handles runtime-> selection between JIT / oneDNN / ACL / Reference implementations based on-> hardware capabilities, precision matching, and memory format preferences.-> When multiple implementations match, `VariableExecutor` handles fallback.-> The `OV_CPU_INSTANCE_*` macros ensure that code for unavailable platforms is-> compiled away, supporting the conditional compilation infrastructure.+1. Read [`executors/README.md`](../../../../src/plugins/intel_cpu/src/nodes/executors/README.md) —+ it covers the `ExecutorFactory`/`ExecutorImplementation` architecture, the+ 7 `ExecutorImplementation` fields, the `OV_CPU_INSTANCE_*` macros and+ `getImplementations` registration, the `Executor` base class and concrete+ (reference/JIT) executors, wiring a node to an `ExecutorFactory`, and the+ framework utilities.+2. Define the attrs struct, register the `getImplementations<OpNameAttrs>()`+ specialisation, implement the concrete executor classes, and wire the node+ to the `ExecutorFactory`, following that guide's patterns.## Code Quality Checklistdiff --git a/.github/agents-prototype/skills/add-cpu-op/step3-optimization.md b/.github/agents-prototype/skills/add-cpu-op/step3-optimization.mdindex c2b3c7bdd53..461981ba01e 100644--- a/.github/agents-prototype/skills/add-cpu-op/step3-optimization.md+++ b/.github/agents-prototype/skills/add-cpu-op/step3-optimization.md@@ -29,258 +29,12 @@ ordering, and precision matching — see `cpu_op_implementation` skill forthe full wiring pattern. This skill focuses on the code that goes **inside**each executor class.-### CpuParallel Multithreading--The simplest and most common optimization. Use `CpuParallel` (available via-`context->getCpuParallel()`) to parallelise the execution loop inside any-executor — Reference, JIT, or oneDNN.--**File:** `src/plugins/intel_cpu/src/cpu_parallel.hpp`--**Available methods:**--| Method | Signature | Use Case |-|--------|-----------|----------|-| `parallel_for` | `(D0, func(i))` | 1D iteration |-| `parallel_for2d` | `(D0, D1, func(i, j))` | 2D iteration |-| `parallel_for3d` | `(D0, D1, D2, func(i, j, k))` | 3D iteration (batch × spatial) |-| `parallel_for4d` | `(D0, D1, D2, D3, func(...))` | 4D (batch × channels × H × W) |-| `parallel_for5d` | `(D0, D1, D2, D3, D4, func(...))` | 5D tensors |-| `parallel_for6d` | `(D0, ..., D5, func(...))` | 6D tensors |-| `parallel_sum` | `(D0, init, func(i))` | Parallel reduction |-| `parallel_sum2d` | `(D0, D1, init, func(i, j))` | 2D parallel reduction |-| `parallel_sum3d` | `(D0, D1, D2, init, func(i, j, k))` | 3D parallel reduction |-| `parallel_simple` | `(nthr, func(ithr, nthr))` | Manual thread partitioning |--**Example — element-wise op with CpuParallel inside a Reference executor:**--```cpp-void RefOpNameExecutor::execute(const MemoryArgs& memory) {- auto* src = memory.at(ARG_SRC)->getDataAs<const float>();- auto* dst = memory.at(ARG_DST)->getDataAs<float>();- auto total = memory.at(ARG_SRC)->getShape().getElementsCount();-- m_context->getCpuParallel()->parallel_for(total, [&](size_t i) {- dst[i] = /* element-wise computation on */ src[i];- });-}-```--**Example — batch-parallelised reduction:**--```cpp-const auto& shape = memory.at(ARG_SRC)->getStaticDims();-auto batch = shape_size(shape) / shape.back();-auto inner = shape.back();--m_context->getCpuParallel()->parallel_for(batch, [&](size_t b) {- auto* row_src = src + b * inner;- auto* row_dst = dst + b * inner;- // Per-row reduction + normalization- float sum = 0.0f;- for (size_t i = 0; i < inner; i++) {- sum += row_src[i] * row_src[i];- }- float scale = 1.0f / std::sqrt(sum / inner + eps);- for (size_t i = 0; i < inner; i++) {- row_dst[i] = row_src[i] * scale;- }-});-```--### Creating JIT Executor Implementations--JIT kernels are **not** used directly from the node class. Instead, they are-wrapped inside an executor class that implements the `Executor` interface and-is registered as an `ExecutorType::Jit` entry in `<op_name>_implementations.cpp`.--The ISA dispatch (`mayiuse(avx512_core)` vs `mayiuse(avx2)`) happens in the-`supports()` predicate of the `ExecutorImplementation`, **not** in the node.--**Study** `eltwise_implementations.cpp` — it shows Jit executors-(`eltwise_jit_ncsp`, `eltwise_jit_nspc`) alongside Reference executors, all-as `ExecutorImplementation<EltwiseAttrs>` entries.--#### Step 1: Write the JIT Kernel--**Directory:** `src/plugins/intel_cpu/src/nodes/kernels/x64/`--```cpp-// <op_name>_kernel.hpp-#pragma once--#include "nodes/kernels/x64/jit_kernel_base.hpp"--namespace ov::intel_cpu::kernel {--struct jit_<op_name>_compile_params {- ov::element::Type src_prc;- ov::element::Type dst_prc;- size_t data_size;- // Op-specific compile-time parameters-};--struct jit_<op_name>_call_args {- const uint8_t* src;- uint8_t* dst;- // Op-specific runtime arguments-};--template <dnnl::impl::cpu::x64::cpu_isa_t isa>-class jit_<op_name>_kernel : public JitKernelBase {-public:- DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_<op_name>_kernel)-- explicit jit_<op_name>_kernel(const jit_<op_name>_compile_params& jcp);- void generate() override;--private:- jit_<op_name>_compile_params m_jcp;- // Register assignments, helper methods-};--} // namespace ov::intel_cpu::kernel-```--#### Step 2: Wrap the Kernel in a JIT Executor Class--Place in `src/plugins/intel_cpu/src/nodes/executors/jit/<op_name>_jit.hpp`:--```cpp-#pragma once--#include "nodes/executors/executor.hpp"-#include "nodes/executors/<op_name>_config.hpp"-#include "nodes/executors/executor_context.hpp"--namespace ov::intel_cpu {--class JitOpNameExecutor : public Executor {-public:- JitOpNameExecutor(const OpNameAttrs& attrs,- const MemoryArgs& memory,- const ExecutorContext::CPtr& context);-- bool update(const MemoryArgs& memory) override;- void execute(const MemoryArgs& memory) override;- impl_desc_type implType() const override { return impl_desc_type::jit_avx2; }--private:- OpNameAttrs m_attrs;- ExecutorContext::CPtr m_context;- std::shared_ptr<kernel::JitKernelBase> m_kernel;- // ... cached shape info, working buffers-};-```--The constructor creates / compiles the JIT kernel. `update()` re-compiles if-shapes changed. `execute()` sets up call args and invokes the kernel inside-a `CpuParallel` loop over the outer dimension.--#### Step 3: Register in `<op_name>_implementations.cpp`--```cpp-OV_CPU_INSTANCE_X64(- "op_name_jit_ncsp",- ExecutorType::Jit,- OperationType::OpName,- [](const OpNameConfig& config) -> bool {- VERIFY(dnnl::impl::cpu::x64::mayiuse(- dnnl::impl::cpu::x64::avx2), UNSUPPORTED_ISA);- return true;- },- [](const OpNameConfig& config) -> std::optional<OpNameConfig> {- return createOptimalConfigCommon(config,- opNameTypeMapping,- LayoutConfig{LayoutType::ncsp, LayoutType::ncsp},- opNameMappingNotation);- },- AcceptsAnyShape<OpNameAttrs>,- CreateDefault<JitOpNameExecutor, OpNameAttrs>{}- )-```--For an AVX-512 variant, add a **second** entry before the AVX2 one (higher-priority first) with `mayiuse(avx512_core)` in the `supports` predicate and-a correspondingly wider implementation.--**ISA-specific considerations:**--| ISA | Vector Width | Key Features |-|-----|-------------|--------------|-| AVX2 | 256-bit (8×f32) | `ymm` registers, FMA, most common JIT baseline |-| AVX-512 (Core) | 512-bit (16×f32) | `zmm` registers, mask registers, wider SIMD |-| AVX-512 BF16 | 512-bit | `avx512_core_bf16` — required for BF16 compute |-| AVX-512 VNNI | 512-bit | `vpdpbusd` for INT8 dot products |-| AMX | Tile-based | `tdpbf16ps` / `tdpbssd` for matrix ops |--> **Note:** SSE 4.2 is no longer a target ISA. The minimal baseline is portable-> C++ code. JIT kernels start from AVX2.--**Reference JIT executor implementations to study:**--| Op | Executor | Key Pattern |-|----|----------|-------------|-| Eltwise | `EltwiseStatefulExecutor` (Jit + Ref) | Element-wise, multiple layouts |-| RMSNorm | `nodes/kernels/x64/rms_kernel.hpp` | Reduction + normalize |-| RoPE | `nodes/kernels/x64/rope_kernel.hpp` | Element-wise with indexing |--### Creating oneDNN Executor Implementations--For ops that map to oneDNN primitives (convolutions, matmul, pooling, softmax,-layer normalization, etc.), create an `ExecutorType::Dnnl` implementation using-the `DnnlExecutor` wrapper.--**Study** `convolution_implementations.cpp` — it registers multiple oneDNN-variants differentiated by memory layout (nspc, ncsp, nCsp16c, nCsp8c), each-as a separate `ExecutorImplementation<ConvAttrs>`.--#### DnnlExecutor Pattern--Use the `CreateDnnlDefault<Primitive, Attrs>` helper to create a standard-`DnnlExecutor` that wraps a oneDNN primitive:--```cpp-OV_CPU_INSTANCE_DNNL_X64(- "op_name_dnnl_nspc",- ExecutorType::Dnnl,- OperationType::OpName,- [](const OpNameConfig& config, const MemoryFormatFilter& filter) -> bool {- VERIFY(filter.isSuitableMemoryFormatFilter(- MemoryFormatFilter::nspc), UNSUPPORTED_MEMORY_FORMAT);- return true;- },- [](const OpNameConfig& config) -> std::optional<OpNameConfig> {- return createOptimalConfigCommon(config,- opNameDnnlTypeMapping,- LayoutConfig{LayoutType::nspc, LayoutType::nspc},- opNameMappingNotation);- },- AcceptsAnyShape<OpNameAttrs>,- CreateDnnlDefault<DnnlOpNamePrimitive, OpNameAttrs>{}- )-```--The `DnnlExecutor<Primitive, Attrs, ShapeAgnosticData>` template:-- Calls `Primitive::createDescriptors()` to build oneDNN primitive descriptors-- Manages primitive caching via `ExecutorContext`-- Implements `update()` / `execute()` around the oneDNN primitive execution--**Note:** `CreateDnnlDefault` accepts optional flags: `{cacheWeights, fc3Das2D}`.--#### `MemoryFormatFilter`--oneDNN implementations typically require specific memory layouts. Use the-extended `supports` predicate form that takes `MemoryFormatFilter`:--```cpp-[](const OpNameConfig& config, const MemoryFormatFilter& filter) -> bool {- VERIFY(filter.isSuitableMemoryFormatFilter(- MemoryFormatFilter::nspc), UNSUPPORTED_MEMORY_FORMAT);- // additional ISA / precision checks- return true;-}-```+1. Read [`executors/README.md`](../../../../src/plugins/intel_cpu/src/nodes/executors/README.md) —+ it covers `CpuParallel` multithreading (the method table), writing a JIT+ kernel and registering it via `OV_CPU_INSTANCE_*` (the ISA table), and+ registering oneDNN executor implementations via `CreateDnnlDefault`.+2. Parallelise the executor's inner loop with `CpuParallel`, and add JIT or+ oneDNN executor implementations as needed, following that guide's patterns.## JIT Eltwise Emittersdiff --git a/src/plugins/intel_cpu/docs/selective_build.md b/src/plugins/intel_cpu/docs/selective_build.mdindex 78b9b65f08f..a02a4e84c9a 100644--- a/src/plugins/intel_cpu/docs/selective_build.md+++ b/src/plugins/intel_cpu/docs/selective_build.md@@ -14,7 +14,7 @@ OV_SWITCH(intel_cpu, OpNameExecute, ctx, precision,OV_CASE(ov::element::i32, int32_t))```-**`OV_CPU_INSTANCE_*`** — architecture/backend guards for executor implementation lists, defined in [`src/utils/arch_macros.h`](../src/utils/arch_macros.h): `OV_CPU_INSTANCE_COMMON`, `OV_CPU_INSTANCE_X64`, `OV_CPU_INSTANCE_ARM64`, `OV_CPU_INSTANCE_ACL`, `OV_CPU_INSTANCE_ACL32`, `OV_CPU_INSTANCE_ACL64`, `OV_CPU_INSTANCE_DNNL`, `OV_CPU_INSTANCE_DNNL_X64`, `OV_CPU_INSTANCE_DNNL_ARM64`, `OV_CPU_INSTANCE_MLAS_X64`, `OV_CPU_INSTANCE_MLAS_ARM64`, `OV_CPU_INSTANCE_RISCV64`, `OV_CPU_INSTANCE_KLEIDIAI`. Each wraps an `ExecutorImplementation` so code for unavailable platforms is compiled away.+**`OV_CPU_INSTANCE_*`** — architecture/backend guards for executor implementation lists, defined in [`src/utils/arch_macros.h`](../src/utils/arch_macros.h): `OV_CPU_INSTANCE_COMMON`, `OV_CPU_INSTANCE_X64`, `OV_CPU_INSTANCE_ARM64`, `OV_CPU_INSTANCE_ACL`, `OV_CPU_INSTANCE_ACL32`, `OV_CPU_INSTANCE_ACL64`, `OV_CPU_INSTANCE_DNNL`, `OV_CPU_INSTANCE_DNNL_X64`, `OV_CPU_INSTANCE_DNNL_ARM64`, `OV_CPU_INSTANCE_MLAS_X64`, `OV_CPU_INSTANCE_MLAS_ARM64`, `OV_CPU_INSTANCE_RISCV64`, `OV_CPU_INSTANCE_KLEIDIAI`. Each wraps an `ExecutorImplementation` so code for unavailable platforms is compiled away — see [executors/README.md](../src/nodes/executors/README.md#getimplementations-and-the-ov_cpu_instance-macros) for the full macro-to-condition table and how they're used in `getImplementations()`.For the OpenVINO-wide conditional-compilation guide see [docs/dev/conditional_compilation.md](../../../../docs/dev/conditional_compilation.md).diff --git a/src/plugins/intel_cpu/src/nodes/README.md b/src/plugins/intel_cpu/src/nodes/README.mdindex 1d00a46467f..413a74409ff 100644--- a/src/plugins/intel_cpu/src/nodes/README.md+++ b/src/plugins/intel_cpu/src/nodes/README.md@@ -176,7 +176,7 @@ private:| Question | If yes | If no ||----------|--------|-------|-| Does the op need ISA-specific or multi-backend paths? | Use the Executor framework (`ExecutorFactory` + `ExecutorPtr`) — see [Executor Pattern](../../../../../.github/agents-prototype/skills/add-cpu-op/step2-implementation.md#executor-pattern-standard-architecture-for-non-trivial-ops) | Use direct `execute()` with `OV_SWITCH` type dispatch |+| Does the op need ISA-specific or multi-backend paths? | Use the Executor framework (`ExecutorFactory` + `ExecutorPtr`) — see [executors/README.md](executors/README.md) | Use direct `execute()` with `OV_SWITCH` type dispatch || Does the op need custom shape inference? | Add custom `ShapeInferFactory` | Use `NgraphShapeInferFactory` || Does the op need `prepareParams()`? | Override `needPrepareParams` → `true` | Override → `false` || Does the op have a data-dependent output shape? | Override `needShapeInfer()` | Don't override |@@ -261,9 +261,10 @@ void OpName::execute([[maybe_unused]] const dnnl::stream& strm) {For nodes more complex than portable C++ (JIT, oneDNN, multi-ISA), the body of`initSupportedPrimitiveDescriptors`/`prepareParams`/`execute` is driven by the-executor framework, documented separately.+executor framework — see [executors/README.md](executors/README.md).## See also+- [executors/README.md](executors/README.md) — executor framework for non-trivial ops.- [kernels/simd/README.md](kernels/simd/README.md) — SIMD abstraction for kernels.- [../../docs/selective_build.md](../../docs/selective_build.md#in-code-conditional-compilation) — `OV_SWITCH` / `OV_CPU_INSTANCE_*` and conditional compilation.diff --git a/src/plugins/intel_cpu/src/nodes/executors/README.md b/src/plugins/intel_cpu/src/nodes/executors/README.mdnew file mode 100644index 00000000000..3be84c3f085--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/executors/README.md@@ -0,0 +1,356 @@+# CPU Plugin Executor Framework++The executor framework is the standard architecture for any CPU node more complex+than portable C++. A node holds an attributes struct and an `ExecutorFactory`; the+factory filters and ranks a list of `ExecutorImplementation` entries by ISA,+precision, and memory layout, then produces an `ExecutorPtr` that the node drives.+JIT kernels, oneDNN primitives, ACL/MLAS/KleidiAI backends, and a portable+reference all coexist as separate implementations of the same op.++This is the reference for the framework itself; for the node side (lifecycle,+registration) see [../README.md](../README.md).++## Contents++- [Architecture](#architecture)+- [ExecutorImplementation](#executorimplementation)+- [getImplementations and the OV_CPU_INSTANCE macros](#getimplementations-and-the-ov_cpu_instance-macros)+- [Concrete executors](#concrete-executors)+- [Wiring a node to an ExecutorFactory](#wiring-a-node-to-an-executorfactory)+- [Framework utilities](#framework-utilities)+- [CpuParallel multithreading](#cpuparallel-multithreading)+- [oneDNN executors](#onednn-executors)++Study these canonical implementations in order: `eltwise_implementations.cpp`+(simplest — Jit + ACL + Reference), `fullyconnected_implementations.cpp`+(full-featured — MLAS, 1x1conv, ACL, KleidiAI, oneDNN),+`convolution_implementations.cpp` (layout-aware with `MemoryFormatFilter`).++## Architecture++```+Node (e.g. Eltwise, FullyConnected, Convolution)+ ├── OpNameAttrs (op config struct: <op_name>_config.hpp)+ ├── MemoryArgs memory (maps ARG_SRC/ARG_DST/... → MemoryPtr)+ ├── ExecutorFactoryPtr<OpNameAttrs> factory+ │ ├── filters ExecutorImplementation<Attrs> list by:+ │ │ ├── supports(config, memoryFormatFilter) — ISA, precision, layout+ │ │ ├── createOptimalConfig(config) — preferred memory format+ │ │ └── acceptsShape(attrs, memory) — shape-dependent heuristics+ │ └── make(memory) → returns ExecutorPtr or VariableExecutor+ └── ExecutorPtr executor+ ├── update(memory) — called in prepareParams()+ └── execute(memory) — called in execute()+```++The `ExecutorFactory` handles runtime selection between JIT / oneDNN / ACL /+Reference based on hardware, precision matching, and memory-format preferences.+When several implementations match, `VariableExecutor` handles fallback.++## ExecutorImplementation++Each `ExecutorImplementation<Attrs>` has these fields:++1. **name** — unique human-readable string (e.g. `"op_name_jit_ncsp"`).+2. **ExecutorType** — `Jit`, `Dnnl`, `Acl`, `Reference`, etc.+3. **OperationType** — `OperationType::OpName`.+4. **supports** — lambda returning `bool`. Use the `VERIFY(condition, MESSAGE)`+ macro for debuggable rejection. Can take `(const Config&)` or+ `(const Config&, const MemoryFormatFilter&)`.+5. **createOptimalConfig** — lambda returning `std::optional<Config>`. Return `{}`+ (nullopt) if the current memory config is already acceptable; otherwise use+ `createOptimalConfigCommon()` with a `TypeMapping` and `LayoutConfig`.+6. **acceptsShape** — lambda `(const Attrs&, const MemoryArgs&) -> bool`. Pass+ `AcceptsAnyShape<Attrs>` for shape-agnostic implementations.+7. **create** — lambda returning `ExecutorPtr`. Use `CreateDefault<Executor, Attrs>{}`+ for simple cases, or `CreateDnnlDefault<Primitive, Attrs>{}` / a custom lambda.++## getImplementations and the OV_CPU_INSTANCE macros++A `getImplementations<OpNameAttrs>()` specialisation returns the implementation+list in **priority order** (highest first). Each entry is wrapped in an+`OV_CPU_INSTANCE_*` macro (defined in [../../utils/arch_macros.h](../../utils/arch_macros.h))+that conditionally compiles it for the target architecture, so code for+unavailable platforms is compiled away (see+[selective_build.md](../../../docs/selective_build.md#in-code-conditional-compilation)).++| Macro | Active When |+|-------|-------------|+| `OV_CPU_INSTANCE_COMMON(...)` | Always (portable code) |+| `OV_CPU_INSTANCE_X64(...)` | x86-64 (`OPENVINO_ARCH_X86_64`) |+| `OV_CPU_INSTANCE_ARM64(...)` | AArch64 (`OPENVINO_ARCH_ARM64`) |+| `OV_CPU_INSTANCE_ACL(...)` | ARM Compute Library, AArch32 or AArch64 |+| `OV_CPU_INSTANCE_ACL32(...)` | ARM Compute Library, AArch32 only |+| `OV_CPU_INSTANCE_ACL64(...)` | ARM Compute Library, AArch64 only |+| `OV_CPU_INSTANCE_DNNL(...)` | oneDNN available, any architecture |+| `OV_CPU_INSTANCE_DNNL_X64(...)` | oneDNN available on x86-64 |+| `OV_CPU_INSTANCE_DNNL_ARM64(...)` | oneDNN available on AArch64 |+| `OV_CPU_INSTANCE_MLAS_X64(...)` | MLAS available on x86-64 |+| `OV_CPU_INSTANCE_MLAS_ARM64(...)` | MLAS available on AArch64 |+| `OV_CPU_INSTANCE_RISCV64(...)` | RISC-V 64 (`OPENVINO_ARCH_RISCV64`) |+| `OV_CPU_INSTANCE_KLEIDIAI(...)` | KleidiAI available |++```cpp+using LayoutConfig = std::vector<LayoutType>;++// TypeMapping defines precision transformations per implementation.+// Each row: {input precisions, output precisions} → {transform functions}.+// Helpers: bypass() = keep, just<T>() = force to T, use<N>() = match arg N.+static const TypeMapping opNameTypeMapping {+ {{_f32, _f32}, {bypass(), bypass()}},+ {{_bf16, _bf16 | _f32}, {bypass(), bypass()}},+ {{_any, _any}, {just<f32>(), just<f32>()}}, // fallback+};++static const MappingNotation opNameMappingNotation { {ARG_SRC, 0}, {ARG_DST, 1} };++// clang-format off+template <>+const std::vector<ExecutorImplementation<OpNameAttrs>>& getImplementations() {+ static const std::vector<ExecutorImplementation<OpNameAttrs>> implementations {+ OV_CPU_INSTANCE_X64(+ "op_name_jit_ncsp",+ ExecutorType::Jit,+ OperationType::OpName,+ [](const OpNameConfig& config) -> bool {+ VERIFY(dnnl::impl::cpu::x64::mayiuse(+ dnnl::impl::cpu::x64::avx2), UNSUPPORTED_ISA);+ return true;+ },+ [](const OpNameConfig& config) -> std::optional<OpNameConfig> {+ return createOptimalConfigCommon(config, opNameTypeMapping,+ LayoutConfig{LayoutType::ncsp, LayoutType::ncsp}, opNameMappingNotation);+ },+ AcceptsAnyShape<OpNameAttrs>,+ CreateDefault<JitOpNameExecutor, OpNameAttrs>{}+ )+ OV_CPU_INSTANCE_COMMON(+ "op_name_ref_ncsp",+ ExecutorType::Reference,+ OperationType::OpName,+ [](const OpNameConfig& config) -> bool { return true; },+ [](const OpNameConfig& config) -> std::optional<OpNameConfig> {+ return createOptimalConfigCommon(config, opNameTypeMapping,+ LayoutConfig{LayoutType::ncsp, LayoutType::ncsp}, opNameMappingNotation);+ },+ AcceptsAnyShape<OpNameAttrs>,+ CreateDefault<RefOpNameExecutor, OpNameAttrs>{}+ )+ };+ return implementations;+}+// clang-format on+```++For an AVX-512 variant, add a **second** `OV_CPU_INSTANCE_X64` entry **before** the+AVX2 one (higher priority first) with `mayiuse(avx512_core)` in `supports` and a+correspondingly wider implementation.++The attributes struct and `Config` alias live in `<op_name>_config.hpp`:++```cpp+struct OpNameAttrs {+ // Op-specific attributes needed by all implementations.+ PostOps postOps; // include if the op supports post-op fusion+};+using OpNameConfig = executor::Config<OpNameAttrs>;+```++## Concrete executors++Each executor implements the `Executor` base class from `executor.hpp`:++```cpp+class Executor {+public:+ virtual bool update(const MemoryArgs& memory); // reshape / re-init+ virtual void execute(const MemoryArgs& memory); // run computation+ [[nodiscard]] virtual impl_desc_type implType() const = 0; // report impl type+ virtual ~Executor() = default;+};+```++Only `implType()` is pure virtual; `update()`/`execute()` have default bodies that+throw `OPENVINO_THROW_NOT_IMPLEMENTED` so a concrete executor only needs to+override the overload(s) it actually uses.++A reference executor returns `impl_desc_type::ref`; a JIT executor wraps a kernel+(see [Writing a JIT kernel](#writing-a-jit-kernel) below and the+[emitters README](../../emitters/README.md)) and returns e.g.+`impl_desc_type::jit_avx2`. ISA dispatch (`mayiuse(avx512_core)` vs `mayiuse(avx2)`)+happens in the implementation's `supports()` predicate, **not** in the node or the+executor.++```cpp+class JitOpNameExecutor : public Executor {+public:+ JitOpNameExecutor(const OpNameAttrs& attrs, const MemoryArgs& memory,+ const ExecutorContext::CPtr& context);+ bool update(const MemoryArgs& memory) override;+ void execute(const MemoryArgs& memory) override;+ impl_desc_type implType() const override { return impl_desc_type::jit_avx2; }+private:+ OpNameAttrs m_attrs;+ ExecutorContext::CPtr m_context;+ std::shared_ptr<kernel::JitKernelBase> m_kernel;+};+```++The constructor compiles the JIT kernel; `update()` recompiles on shape change;+`execute()` sets up call args and invokes the kernel inside a `CpuParallel` loop.++## Wiring a node to an ExecutorFactory++In the node header, hold the attrs, memory, factory, and executor:++```cpp+private:+ OpNameAttrs m_attrs;+ MemoryArgs m_memory;+ ExecutorFactoryPtr<OpNameAttrs> m_factory;+ ExecutorPtr m_executor = nullptr;+```++In `initSupportedPrimitiveDescriptors()` (follows `conv.cpp`): populate `m_attrs`,+build per-port `MemoryDescArgs`, create the factory, and let it pick the optimal+memory descriptors:++```cpp+auto executionContext = std::make_shared<ExecutorContext>(context, getImplPriority());+m_factory = std::make_shared<ExecutorFactory<OpNameAttrs>>(m_attrs, executionContext, descs);+const auto nodeDescList = m_factory->getProperMemoryDescriptors(descs);+// emplace one supportedPrimitiveDescriptor per returned descriptor set+```++In `createPrimitive()`: bind the selected memories, create the executor, and record+its implementation type:++```cpp+m_memory[ARG_SRC] = getSrcMemoryAtPort(0);+m_memory[ARG_DST] = getDstMemoryAtPort(0);+m_executor = m_factory->make(m_memory);+getSelectedPrimitiveDescriptor()->setImplementationType(m_executor->implType());+```++In `prepareParams()`: refresh `m_memory`, then update the existing executor:++```cpp+m_memory[ARG_SRC] = getSrcMemoryAtPort(0);+m_memory[ARG_DST] = getDstMemoryAtPort(0);+m_executor->update(m_memory);+```++In `execute()`: `m_executor->execute(m_memory);`++## Framework utilities++| Utility | Location | Purpose |+|---------|----------|---------|+| `VERIFY(cond, msg)` | `debug_messages.hpp` | Debug-logged rejection in `supports()` |+| `TypeMapping` / `MappingNotation` | `precision_translation.hpp` | Precision transform rules |+| `createOptimalConfigCommon()` | `implementation_utils.hpp` | Standard config optimisation |+| `AcceptsAnyShape<Attrs>` | `implementation_utils.hpp` | Shape-agnostic stub |+| `HasNoOptimalConfig<Attrs>` | `implementation_utils.hpp` | No config override stub |+| `SupportsAnyConfig<Attrs>` | `implementation_utils.hpp` | Unconditional support stub |+| `CreateDefault<Executor, Attrs>` | `implementation_utils.hpp` | Simple `make_shared` factory |+| `CreateDnnlDefault<Prim, Attrs>` | `implementation_utils.hpp` | `DnnlExecutor` wrapper factory |+| `OV_CPU_INSTANCE_*` macros | `../../utils/arch_macros.h` | Conditional compilation per arch |++## CpuParallel multithreading++`CpuParallel` (via `context->getCpuParallel()`, defined in+[../../cpu_parallel.hpp](../../cpu_parallel.hpp)) parallelises the execution loop+inside any executor — Reference, JIT, or oneDNN.++| Method | Signature | Use Case |+|--------|-----------|----------|+| `parallel_for` | `(D0, func(i))` | 1D iteration |+| `parallel_for2d` | `(D0, D1, func(i, j))` | 2D iteration |+| `parallel_for3d` | `(D0, D1, D2, func(i, j, k))` | 3D (batch × spatial) |+| `parallel_for4d` | `(D0, D1, D2, D3, func(...))` | 4D (batch × channels × H × W) |+| `parallel_for5d` | `(D0, D1, D2, D3, D4, func(...))` | 5D tensors |+| `parallel_for6d` | `(D0, ..., D5, func(...))` | 6D tensors |+| `parallel_sum` | `(D0, init, func(i))` | Parallel reduction |+| `parallel_sum2d` | `(D0, D1, init, func(i, j))` | 2D parallel reduction |+| `parallel_sum3d` | `(D0, D1, D2, init, func(i, j, k))` | 3D parallel reduction |+| `parallel_simple` | `(nthr, func(ithr, nthr))` | Manual thread partitioning |++```cpp+void RefOpNameExecutor::execute(const MemoryArgs& memory) {+ auto* src = memory.at(ARG_SRC)->getDataAs<const float>();+ auto* dst = memory.at(ARG_DST)->getDataAs<float>();+ auto total = memory.at(ARG_SRC)->getShape().getElementsCount();++ m_context->getCpuParallel()->parallel_for(total, [&](size_t i) {+ dst[i] = /* element-wise computation on */ src[i];+ });+}+```++### Writing a JIT kernel++A JIT kernel lives under [kernels/x64/](../kernels/x64/) with compile-params and+call-args structs and a `jit_<op_name>_kernel<isa>` template; the executor above+wraps it. For emitter internals (xbyak, register allocation, debugging) see the+[emitters README](../../emitters/README.md); for the portable SIMD abstraction+(`vec<T, isa>`) see the [SIMD README](../kernels/simd/README.md).++| ISA | Vector Width | Key Features |+|-----|-------------|--------------|+| AVX2 | 256-bit (8×f32) | `ymm` registers, FMA; the baseline most new JIT executors gate on |+| AVX-512 (Core) | 512-bit (16×f32) | `zmm` registers, mask registers, wider SIMD |+| AVX-512 BF16 | 512-bit | `avx512_core_bf16` — required for BF16 compute |+| AVX-512 VNNI | 512-bit | `vpdpbusd` for INT8 dot products |+| AMX | Tile-based | `tdpbf16ps` / `tdpbssd` for matrix ops |++> SSE4.1 is still used as the last-resort ISA fallback in some existing JIT+> kernels (e.g. the generic eltwise JIT executor in `jit/eltwise.cpp`), but new+> executor implementations should gate on AVX2 as the minimal JIT baseline and+> fall back to the portable reference executor below that.++Reference JIT executor implementations to study:++| Op | Executor | Key Pattern |+|----|----------|-------------|+| Eltwise | `EltwiseStatefulExecutor` (Jit + Ref) | Element-wise, multiple layouts |+| RMSNorm | [`kernels/x64/rms_kernel.hpp`](../kernels/x64/rms_kernel.hpp) | Reduction + normalize |+| RoPE | [`kernels/x64/rope_kernel.hpp`](../kernels/x64/rope_kernel.hpp) | Element-wise with indexing |++## oneDNN executors++For ops that map to oneDNN primitives (convolution, matmul, pooling, softmax,+layer norm, …), register an `ExecutorType::Dnnl` implementation built with+`CreateDnnlDefault<Primitive, Attrs>`. `convolution_implementations.cpp` registers+several oneDNN variants differentiated by memory layout (nspc, ncsp, nCsp16c,+nCsp8c).++```cpp+OV_CPU_INSTANCE_DNNL_X64(+ "op_name_dnnl_nspc",+ ExecutorType::Dnnl,+ OperationType::OpName,+ [](const OpNameConfig& config, const MemoryFormatFilter& filter) -> bool {+ VERIFY(filter.isSuitableMemoryFormatFilter(+ MemoryFormatFilter::nspc), UNSUPPORTED_MEMORY_FORMAT);+ return true;+ },+ [](const OpNameConfig& config) -> std::optional<OpNameConfig> {+ return createOptimalConfigCommon(config, opNameDnnlTypeMapping,+ LayoutConfig{LayoutType::nspc, LayoutType::nspc}, opNameMappingNotation);+ },+ AcceptsAnyShape<OpNameAttrs>,+ CreateDnnlDefault<DnnlOpNamePrimitive, OpNameAttrs>{}+ )+```++The `DnnlExecutor<Primitive, Attrs, ShapeAgnosticData>` template uses a two-phase+lifecycle. Its constructor calls `Primitive::createShapeAgnosticData()` up front+to build shape-agnostic data (and, from it, the primitive descriptor). On each+`update()`, `CreateDnnlDefault` calls `Primitive::create(memory, attrs, context,+shapeAgnosticData)` to instantiate the executable primitive, then updates its+memory arguments. It manages primitive caching via `ExecutorContext` and+implements `execute()` around the oneDNN primitive. `CreateDnnlDefault` accepts+optional flags `{cacheWeights, fc3Das2D}`.+`MemoryFormatFilter` (in the extended `supports` predicate) expresses required+layouts. For convolution-specific post-op and zero-point mechanisms see+[convolution_post_ops.md](../../../docs/convolution_post_ops.md).