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][RV64] Implemented JIT Kernel for Eltwise ops (#28727)
Alexandra Sidorova40bf06ec5a27
diff --git a/.gitmodules b/.gitmodulesindex 8c2664a42fb..d9733bc0d84 100644--- a/.gitmodules+++ b/.gitmodules@@ -90,3 +90,6 @@[submodule "src/plugins/intel_cpu/thirdparty/kleidiai"]path = src/plugins/intel_cpu/thirdparty/kleidiaiurl = https://github.com/ARM-software/kleidiai.git+[submodule "src/plugins/intel_cpu/thirdparty/xbyak_riscv"]+ path = src/plugins/intel_cpu/thirdparty/xbyak_riscv+ url = https://github.com/herumi/xbyak_riscv.gitdiff --git a/docs/dev/build_riscv64.md b/docs/dev/build_riscv64.mdindex 19d6e8714b4..ed5cd48944e 100644--- a/docs/dev/build_riscv64.md+++ b/docs/dev/build_riscv64.md@@ -18,10 +18,16 @@ The software was validated on the following devices:## How to buildCurrently, there are three ways to build OpenVINO Runtime for 64-bit RISC-V platforms:-1. **Recommended**. The build with vectorized (using RVV instructions) primitives for limited scope of operations from [`SHL`](https://github.com/XUANTIE-RV/csi-nn2) using [`xuantie-gnu-toolchain`](https://github.com/XUANTIE-RV/). This GNU Compiler Toolchain supports RVV 0.7.1, ratified RVV 1.0 and Xuantie-specific instruction sets. The vector intrinsics don't use the common prefix `__riscv_`. This method provides the best performance available at the moment.-2. The build without optimized primitives using [`riscv-gnu-toolchain`](https://github.com/riscv-collab/riscv-gnu-toolchain.git). This GNU Compiler Toolchain supports RVV 0.7.1 and ratified RVV 1.0. The vector intrinsics use the common prefix `__riscv_`. However, as mentioned earlier, this build method doesn't yet provide optimized primitives implemented using the RVV intrinsics.+1. **Recommended**. The build with vectorized (using RVV intrinsics) primitives for limited scope of operations from [`SHL`](https://github.com/XUANTIE-RV/csi-nn2) operations using [`xuantie-gnu-toolchain`](https://github.com/XUANTIE-RV/).+This GNU Compiler Toolchain supports RVV 0.7.1, ratified RVV 1.0 and Xuantie-specific instruction sets.+The vector intrinsics don't use the common prefix `__riscv_`.+This method provides the best performance available at the moment.+2. The build without optimized primitives implemented with RVV intrinsics using [`riscv-gnu-toolchain`](https://github.com/riscv-collab/riscv-gnu-toolchain.git). This GNU Compiler Toolchain supports RVV 0.7.1 and ratified RVV 1.0. The vector intrinsics use the common prefix `__riscv_`. However, as mentioned earlier, this build method doesn't yet provide optimized primitives implemented using the RVV intrinsics.3. The build without optimized primitives using installed Linux packages. The compilers in these packages don't support RVV intrinsics.+> **NOTE**: Currently CPU Plugin in OpenVINO supports [Just-In-Time (JIT) code generation](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/src/emitters/README.md) for limited scope of operations on devices with RVV 1.0.+ All three described above ways to build OpenVINO Runtime for 64-bit RISC-V supports JIT code generation.+### Steps0. Prerequisite:diff --git a/src/plugins/intel_cpu/CMakeLists.txt b/src/plugins/intel_cpu/CMakeLists.txtindex aad567f0ce5..0f28352cd89 100644--- a/src/plugins/intel_cpu/CMakeLists.txt+++ b/src/plugins/intel_cpu/CMakeLists.txt@@ -232,6 +232,11 @@ if(NOT AARCH64)${CMAKE_CURRENT_SOURCE_DIR}/src/emitters/snippets/aarch64/*)endif()+if (NOT RISCV64)+ list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/emitters/plugin/riscv64/*+ ${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/kernels/riscv64/*)+endif()+if (NOT ENABLE_MLAS_FOR_CPU)list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/executors/mlas/*)list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/mlas/*)@@ -286,7 +291,12 @@ endif()if(ENABLE_KLEIDIAI_FOR_CPU)target_link_libraries(${TARGET_NAME} PRIVATE kleidiai)endif()-+if(RISCV64)+ # Set `XBYAK_RISCV_V=1` to compile Xbyak-code for RVV-related instructions+ target_compile_definitions(xbyak_riscv INTERFACE XBYAK_RISCV_V=1)+ target_link_libraries(${TARGET_NAME} PRIVATE xbyak_riscv)+ target_include_directories(${TARGET_NAME} SYSTEM INTERFACE $<TARGET_PROPERTY:xbyak_riscv::xbyak_riscv,INTERFACE_INCLUDE_DIRECTORIES>)+endif()target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $<TARGET_PROPERTY:dnnl,INCLUDE_DIRECTORIES>)# Temporal solution to use template reference implementations in cases where optimizied implementation@@ -362,7 +372,13 @@ set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELif(BUILD_SHARED_LIBS)add_library(${TARGET_NAME}_obj OBJECT ${SOURCES} ${HEADERS})- ov_link_system_libraries(${TARGET_NAME}_obj PUBLIC dnnl openvino::pugixml)++ set(CPU_OBJ_LINK_SYSTEM LIBRARIES dnnl openvino::pugixml)+ if(RISCV64)+ list(APPEND CPU_OBJ_LINK_SYSTEM xbyak_riscv::xbyak_riscv)+ endif()++ ov_link_system_libraries(${TARGET_NAME}_obj PUBLIC ${CPU_OBJ_LINK_SYSTEM})ov_add_version_defines(src/plugin.cpp ${TARGET_NAME}_obj)@@ -393,6 +409,9 @@ if(BUILD_SHARED_LIBS)if(ENABLE_KLEIDIAI_FOR_CPU)target_include_directories(${TARGET_NAME}_obj SYSTEM PUBLIC $<TARGET_PROPERTY:kleidiai,INTERFACE_INCLUDE_DIRECTORIES>)endif()+ if(RISCV64)+ target_include_directories(${TARGET_NAME}_obj SYSTEM PUBLIC $<TARGET_PROPERTY:xbyak_riscv::xbyak_riscv,INTERFACE_INCLUDE_DIRECTORIES>)+ endif()ov_set_threading_interface_for(${TARGET_NAME}_obj)diff --git a/src/plugins/intel_cpu/src/emitters/README.md b/src/plugins/intel_cpu/src/emitters/README.mdindex 77aa89d378c..b6cbbe6d28d 100644--- a/src/plugins/intel_cpu/src/emitters/README.md+++ b/src/plugins/intel_cpu/src/emitters/README.md@@ -11,6 +11,7 @@ Just-in-time (JIT) emitters is a type of emitter designed for just-in-time codeFor JIT source code generation `Xbyak JIT Assembler` is used:* [Xbyak for X64](https://github.com/herumi/xbyak)* [Xbyak for ARM64](https://github.com/fujitsu/xbyak_aarch64)+ * [Xbyak for RISCV64](https://github.com/herumi/xbyak_riscv)Emitters are splitted into two groups based on their usage model: common plugin emitters for complex kernels ([plugin emitters](https://github.com/openvinotoolkit/openvino/tree/master/src/plugins/intel_cpu/src/emitters/plugin)) and basic blocks for tensor compiler ([snippets emitters](https://github.com/openvinotoolkit/openvino/tree/master/src/plugins/intel_cpu/src/emitters/snippets)).@@ -18,12 +19,14 @@ Emitters are splitted into two groups based on their usage model: common pluginEach emitter is linked with OpenVINO operation. For example for `plugin emitters`:* Element-wise `plugin emitters` are linked in element-wise JIT kernel `jit_uni_eltwise_generic::create_eltwise_emitter` method which implementation depends on platform:- * [X64 specific](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/src/nodes/eltwise.cpp)+ * [X64 specific](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/src/nodes/kernels/x64/jit_uni_eltwise_generic.cpp)* [ARM64 SIMD specific](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/src/nodes/kernels/aarch64/jit_uni_eltwise_generic.cpp)+ * [RISCV64 RVV1.0 specific](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_uni_eltwise_generic.cpp)JIT emitters are inherited from `jit_emitter` base class. The base class implementation depends on architecture:* X64: [jit_emitter.hpp](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/src/emitters/plugin/x64/jit_emitter.hpp)* ARM64: [jit_emitter.hpp](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/src/emitters/plugin/aarch64/jit_emitter.hpp)+ * RISCV64: [jit_emitter.hpp](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_emitter.hpp)### Class diagramJIT emitters should be inherited from `jit_emitter` base class and it's usage should be added in platform dependent JIT kernel.@@ -107,6 +110,7 @@ There are two types of tests instantiations which are used to test JIT emitters:* [platform independent element-wise operation tests](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/eltwise.cpp)* [X64 specific element-wise operation tests](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/eltwise.cpp)* [ARM64 element-wise operation tests](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/eltwise.cpp)+ * [RISCV64 element-wise operation tests](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/riscv64/eltwise.cpp)* element-wise operations which are used as activations:* [platform independent activation operation tests](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/activation.cpp)* [X64 activation operation tests](https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/activation.cpp)diff --git a/src/plugins/intel_cpu/src/emitters/plugin/aarch64/jit_eltwise_emitters.cpp b/src/plugins/intel_cpu/src/emitters/plugin/aarch64/jit_eltwise_emitters.cppindex a2e1524c0ae..ab95dfd098a 100644--- a/src/plugins/intel_cpu/src/emitters/plugin/aarch64/jit_eltwise_emitters.cpp+++ b/src/plugins/intel_cpu/src/emitters/plugin/aarch64/jit_eltwise_emitters.cpp@@ -17,23 +17,6 @@ using namespace dnnl::impl::utils;using namespace dnnl::impl::cpu;using namespace Xbyak_aarch64;-namespace {-ov::element::Type get_arithmetic_binary_exec_precision(const std::shared_ptr<ov::Node>& n) {- std::vector<ov::element::Type> input_precisions;- for (const auto& input : n->inputs()) {- input_precisions.push_back(input.get_source_output().get_element_type());- }-- assert(std::all_of(input_precisions.begin(),- input_precisions.end(),- [&input_precisions](const ov::element::Type& precision) {- return precision == input_precisions[0];- }));-- return input_precisions[0];-}-} // namespace-/// ABS ///jit_abs_emitter::jit_abs_emitter(dnnl::impl::cpu::aarch64::jit_generator* host,dnnl::impl::cpu::aarch64::cpu_isa_t host_isa,diff --git a/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_eltwise_emitters.cpp b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_eltwise_emitters.cppnew file mode 100644index 00000000000..aa9227cbfa3--- /dev/null+++ b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_eltwise_emitters.cpp@@ -0,0 +1,772 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "jit_eltwise_emitters.hpp"++#include "transformations/cpu_opset/common/op/leaky_relu.hpp"++namespace ov::intel_cpu::riscv64 {++using namespace Xbyak_riscv;++#define CONST_1_F 0x3f800000 // 1.f++/// ADD ///+jit_add_emitter::jit_add_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node)+ : jit_emitter(host, host_isa, get_arithmetic_binary_exec_precision(node)) {}++jit_add_emitter::jit_add_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {}++size_t jit_add_emitter::get_inputs_num() const {+ return 2;+}++void jit_add_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_add_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src0 = VReg(in_vec_idxs[0]);+ VReg src1 = VReg(in_vec_idxs[1]);+ VReg dst = VReg(out_vec_idxs[0]);++ switch (exec_prc_) {+ case ov::element::f32:+ h->vfadd_vv(dst, src0, src1);+ break;+ case ov::element::i32:+ h->vadd_vv(dst, src0, src1);+ break;+ default:+ OV_CPU_JIT_EMITTER_THROW("Unsupported precision");+ }+}++std::set<std::vector<element::Type>> jit_add_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32, element::f32}, {element::i32, element::i32}};+}++/// Clamp ///+jit_clamp_emitter::jit_clamp_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node, const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {+ if (const auto clamp = ov::as_type_ptr<ov::op::v0::Clamp>(node)) {+ min = static_cast<float>(clamp->get_min());+ max = static_cast<float>(clamp->get_max());+ } else {+ OPENVINO_THROW("Incompatible node!");+ }+ prepare_table();+}++jit_clamp_emitter::jit_clamp_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ float min, float max, const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc), min(min), max(max) {+ prepare_table();+}++size_t jit_clamp_emitter::get_inputs_num() const {+ return 1;+}++size_t jit_clamp_emitter::aux_fp_gprs_count() const {+ return 1;+}++void jit_clamp_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_clamp_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src = VReg(in_vec_idxs[0]);+ VReg dst = VReg(out_vec_idxs[0]);+ FReg bound = FReg(aux_fp_gpr_idxs[0]);++ load_table_val("min", bound);+ h->vfmax_vf(dst, src, bound);++ load_table_val("max", bound);+ h->vfmin_vf(dst, dst, bound);+}++void jit_clamp_emitter::register_table_entries() {+ push_arg_entry_of("min", dnnl::impl::float2int(min));+ push_arg_entry_of("max", dnnl::impl::float2int(max));+}++std::set<std::vector<element::Type>> jit_clamp_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32}};+}++/// DIV ///+jit_divide_emitter::jit_divide_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node)+ : jit_emitter(host, host_isa, get_arithmetic_binary_exec_precision(node)) {}++jit_divide_emitter::jit_divide_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {}++size_t jit_divide_emitter::get_inputs_num() const {+ return 2;+}++void jit_divide_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_divide_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src0 = VReg(in_vec_idxs[0]);+ VReg src1 = VReg(in_vec_idxs[1]);+ VReg dst = VReg(out_vec_idxs[0]);++ h->vfdiv_vv(dst, src0, src1);+}++std::set<std::vector<element::Type>> jit_divide_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32, element::f32}};+}++/// Exp ///+jit_exp_emitter::jit_exp_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node, const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {+ prepare_table();+}++jit_exp_emitter::jit_exp_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {+ prepare_table();+}++size_t jit_exp_emitter::get_inputs_num() const {+ return 1;+}++size_t jit_exp_emitter::aux_gprs_count() const {+ return 2;+}++size_t jit_exp_emitter::aux_vecs_count() const {+ return 3;+}++size_t jit_exp_emitter::aux_fp_gprs_count() const {+ return 2;+}++void jit_exp_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_exp_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src = VReg(in_vec_idxs[0]);+ VReg dst = VReg(out_vec_idxs[0]);+ VReg aux0 = VReg(aux_vec_idxs[0]);+ VReg aux1 = VReg(aux_vec_idxs[1]);+ VReg zero_mask = VReg(aux_vec_idxs[2]);+ VReg aux2 = zero_mask;+ FReg fp0 = FReg(aux_fp_gpr_idxs[0]);+ FReg fp1 = FReg(aux_fp_gpr_idxs[1]);+ Reg tmp = Reg(aux_gpr_idxs[0]);++ FReg ln_flt_min_f = fp0;+ load_table_val("ln_flt_min_f", ln_flt_min_f);+ // get mask of values lower than log(FLT_MIN) to zero them in the output+ h->vmflt_vf(mask_vreg(), src, ln_flt_min_f);+ h->vmv1r_v(zero_mask, mask_vreg()); // save mask++ h->vfmax_vf(dst, src, ln_flt_min_f);++ load_table_val("ln_flt_max_f", fp1);+ h->vfmin_vf(dst, dst, fp1);++ // keep dst = x for further computations+ h->vmv_v_v(aux0, dst);++ // calculate exp(x)+ // fx = x * log2ef + 0.5+ load_table_val("log2ef", fp1);+ h->vfmul_vf(dst, dst, fp1);+ load_table_val("half", fp1);+ h->vfadd_vf(dst, dst, fp1);++ // aux1 = floorf(fx)+ h->vfcvt_x_f_v(aux1, dst); // fp32 -> int32+ h->vfcvt_f_x_v(aux1, aux1); // int32 -> fp32+ h->vmfgt_vv(mask_vreg(), aux1, dst);+ load_table_val("one", fp1);+ h->vfsub_vf(aux1, aux1, fp1, VM::masked);++ // keep dst = floorf(fx) for further computations+ h->vmv_v_v(dst, aux1);++ // x = x - fx * ln2+ load_table_val("ln2f", fp1);+ h->vfnmsac_vf(aux0, fp1, aux1);++ // compute 2^n+ h->vfcvt_x_f_v(aux1, dst);+ load_table_val("exponent_bias", tmp);+ h->vadd_vx(aux1, aux1, tmp);+ const int n_mantissa_bits = 23;+ h->vsll_vi(aux1, aux1, n_mantissa_bits);++ // set zeroes at those points which were < log(FLT_MIN)+ // Note: Xbyak doesn't support vmv_v_i with mask to set zero where masked+ h->vmv1r_v(mask_vreg(), zero_mask); // pop mask+ h->vand_vx(aux1, aux1, zero, VM::masked);++ // compute polynomial+ FReg pol = fp1;+ load_table_val("pol5", pol);+ h->vfmv_v_f(dst, pol);++ load_table_val("pol4", pol);+ h->vfmv_v_f(aux2, pol);+ h->vfmadd_vv(dst, aux0, aux2);++ load_table_val("pol3", pol);+ h->vfmv_v_f(aux2, pol);+ h->vfmadd_vv(dst, aux0, aux2);++ load_table_val("pol2", pol);+ h->vfmv_v_f(aux2, pol);+ h->vfmadd_vv(dst, aux0, aux2);++ load_table_val("pol1", pol);+ h->vfmv_v_f(aux2, pol);+ h->vfmadd_vv(dst, aux0, aux2);++ load_table_val("one", pol);+ h->vfmv_v_f(aux2, pol);+ h->vfmadd_vv(dst, aux0, aux2);++ // y = y * 2^n+ h->vfmul_vv(dst, dst, aux1);+}++std::set<std::vector<element::Type>> jit_exp_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32}};+}++void jit_exp_emitter::register_table_entries() {+ push_arg_entry_of("pol1", 0x3f7ffffb); // p1 = 0.999999701f+ push_arg_entry_of("pol2", 0x3efffee3); // p2 = 0.499991506f+ push_arg_entry_of("pol3", 0x3e2aad40); // p3 = 0.166676521f+ push_arg_entry_of("pol4", 0x3d2b9d0d); // p4 = 0.0418978221f+ push_arg_entry_of("pol5", 0x3c07cfce); // p5 = 0.00828929059f++ push_arg_entry_of("one", CONST_1_F);+ push_arg_entry_of("half", 0x3f000000);+ push_arg_entry_of("ln2f", 0x3f317218);+ push_arg_entry_of("log2ef", 0x3fb8aa3b);+ push_arg_entry_of("ln_flt_max_f", 0x42b17218);+ push_arg_entry_of("ln_flt_min_f", 0xc2aeac50);+ push_arg_entry_of("exponent_bias", 0x0000007f);+}++/// MUL_ADD ///+jit_mul_add_emitter::jit_mul_add_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node)+: jit_emitter(host, host_isa, get_arithmetic_binary_exec_precision(node)) {}++jit_mul_add_emitter::jit_mul_add_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc)+: jit_emitter(host, host_isa, exec_prc) {}++size_t jit_mul_add_emitter::get_inputs_num() const {+ return 3;+}++void jit_mul_add_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_mul_add_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src0 = VReg(in_vec_idxs[0]);+ VReg src1 = VReg(in_vec_idxs[1]);+ VReg src2 = VReg(in_vec_idxs[2]);+ VReg dst = VReg(out_vec_idxs[0]);++ if (src1.getIdx() == dst.getIdx()) {+ h->vfmadd_vv(dst, src0, src2);+ return;+ }++ if (src2.getIdx() == dst.getIdx()) {+ h->vfmacc_vv(dst, src0, src1);+ return;+ }++ if (src0.getIdx() != dst.getIdx()) {+ h->vmv_v_v(dst, src0);+ }+ h->vfmadd_vv(dst, src1, src2);+}++std::set<std::vector<element::Type>> jit_mul_add_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32, element::f32, element::f32}};+}++/// MUL ///+jit_multiply_emitter::jit_multiply_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node)+ : jit_emitter(host, host_isa, get_arithmetic_binary_exec_precision(node)) {}++jit_multiply_emitter::jit_multiply_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {}++size_t jit_multiply_emitter::get_inputs_num() const {+ return 2;+}++void jit_multiply_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_multiply_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src0 = VReg(in_vec_idxs[0]);+ VReg src1 = VReg(in_vec_idxs[1]);+ VReg dst = VReg(out_vec_idxs[0]);++ h->vfmul_vv(dst, src0, src1);+}++std::set<std::vector<element::Type>> jit_multiply_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32, element::f32}};+}++/// PReLU ///+jit_prelu_emitter::jit_prelu_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node, const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {}++jit_prelu_emitter::jit_prelu_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {}++size_t jit_prelu_emitter::get_inputs_num() const {+ return 2;+}++size_t jit_prelu_emitter::aux_fp_gprs_count() const {+ return 1;+}++void jit_prelu_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_prelu_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src0 = VReg(in_vec_idxs[0]);+ VReg src1 = VReg(in_vec_idxs[1]);+ VReg dst = VReg(out_vec_idxs[0]);+ FReg fzero = FReg(aux_fp_gpr_idxs[0]);++ if (src0.getIdx() != dst.getIdx())+ h->vmv_v_v(dst, src0);++ h->fmv_w_x(fzero, zero);+ h->vmflt_vf(mask_vreg(), src0, fzero);++ h->vfmul_vv(dst, src0, src1, VM::masked);+}++std::set<std::vector<element::Type>> jit_prelu_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32, element::f32}};+}++/// ReLU ///+jit_relu_emitter::jit_relu_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node, const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {+ if (const auto leaky_relu = ov::as_type_ptr<LeakyReluNode>(node)) {+ alpha = leaky_relu->get_slope();+ } else if (ov::is_type<ov::op::v0::Relu>(node)) {+ alpha = 0.f;+ } else {+ OPENVINO_THROW("Incompatible node!");+ }+ prepare_table();+}++jit_relu_emitter::jit_relu_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ float alpha, const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc), alpha(alpha) {+ prepare_table();+}++size_t jit_relu_emitter::get_inputs_num() const {+ return 1;+}++size_t jit_relu_emitter::aux_fp_gprs_count() const {+ return 1;+}++void jit_relu_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_relu_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src = VReg(in_vec_idxs[0]);+ VReg dst = VReg(out_vec_idxs[0]);+ FReg fzero = FReg(aux_fp_gpr_idxs[0]);+ h->fmv_w_x(fzero, zero);++ if (alpha == 0) {+ h->vfmax_vf(dst, src, fzero);+ return;+ }++ if (src.getIdx() != dst.getIdx())+ h->vmv_v_v(dst, src);++ h->vmflt_vf(mask_vreg(), dst, fzero);++ FReg alpha_reg = fzero;+ load_table_val("alpha", alpha_reg);+ h->vfmul_vf(dst, dst, alpha_reg, VM::masked);+}++std::set<std::vector<element::Type>> jit_relu_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32}};+}++void jit_relu_emitter::register_table_entries() {+ if (alpha != 0)+ push_arg_entry_of("alpha", dnnl::impl::float2int(alpha));+}++/// Power Static ///+jit_power_static_emitter::jit_power_static_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ float power, float scale, float shift, ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc), power(power), scale(scale), shift(shift) {+ prepare_table();+}++size_t jit_power_static_emitter::get_inputs_num() const {+ return 1;+}++size_t jit_power_static_emitter::aux_gprs_count() const {+ if ((power == 0) || is_scale_shift() || (!is_sqrt() && !is_int_pow()))+ return 2;+ return 1;+}++bool jit_power_static_emitter::is_lmul_supported() const {+ return jit_emitter::is_lmul_supported() && (is_int_pow() || is_sqrt());+}++size_t jit_power_static_emitter::aux_vecs_count() const {+ if (is_scale_shift())+ return 2;+ if (is_int_pow())+ return 1;+ return 0;+}++size_t jit_power_static_emitter::aux_fp_gprs_count() const {+ return power < 0 ? 1 : 0;+}++void jit_power_static_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_power_static_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src = VReg(in_vec_idxs[0]);+ VReg dst = VReg(out_vec_idxs[0]);++ if (power == 0) {+ Reg tmp = Reg(aux_gpr_idxs[0]);+ load_table_val("one", dst, tmp);+ return;+ }++ if (is_scale_shift()) {+ VReg aux0 = VReg(aux_vec_idxs[0]);+ VReg aux1 = VReg(aux_vec_idxs[1]);+ Reg tmp = Reg(aux_gpr_idxs[0]);+ load_table_val("shift", aux0, tmp);+ load_table_val("scale", aux1, tmp);+ h->vfmacc_vv(aux0, aux1, src);+ h->vmv_v_v(dst, aux0);+ } else {+ if (src.getIdx() != dst.getIdx())+ h->vmv_v_v(dst, src);+ }++ // for power `-0.5f` there is `vfrsqrt7_v` instruction with worse accuracy+ if (is_sqrt()) {+ h->vfsqrt_v(dst, dst);++ if (power < 0) {+ FReg one = FReg(aux_fp_gpr_idxs[0]);+ load_table_val("one", one);+ h->vfrdiv_vf(dst, dst, one);+ }+ } else if (is_int_pow()) {+ int64_t ipower = std::abs(static_cast<int64_t>(power)) - 1;++ VReg aux0 = VReg(aux_vec_idxs[0]);+ h->vmv_v_v(aux0, dst);++ while (ipower > 0) {+ if (ipower & 0x1) {+ h->vfmul_vv(dst, dst, aux0);+ }+ if (ipower > 1) {+ h->vfmul_vv(aux0, aux0, aux0);+ }+ ipower = ipower >> 1;+ }++ if (power < 0) {+ FReg one = FReg(aux_fp_gpr_idxs[0]);+ load_table_val("one", one);+ h->vfrdiv_vf(dst, dst, one);+ }+ } else {+ auto pow_f32_addr = reinterpret_cast<uintptr_t>(::powf);++ Reg func_reg(aux_gpr_idxs[0]);+ h->uni_li(func_reg, pow_f32_addr);++ // Before binary call we have to save caller-saver registers:+ // - all caller-saver general-purpose regs + func_reg (if it's caller-saver)+ // - all caller-saver fp general-purpose regs except aux registers+ // - all vector registers except aux, src and dst registers+ auto exclude_vec_regs = aux_vec_idxs;+ aux_vec_idxs.push_back(src.getIdx());+ aux_vec_idxs.push_back(dst.getIdx());+ call_preamble({}, aux_fp_gpr_idxs, aux_vec_idxs);++ const auto sp_size = rnd_up(get_vec_length(), 16);+ h->addi(sp, sp, -sp_size);+ h->vse32_v(dst, sp);++ // TODO: Support any LMUL here (via vl from csr + labels)+ for (size_t i = 0; i < get_vec_length(); i += sizeof(float)) {+ h->flw(fa0, sp, i);+ load_table_val("power", fa1);++ h->jalr(ra, func_reg);++ h->fsw(fa0, sp, i);+ }++ h->vle32_v(dst, sp);+ h->addi(sp, sp, sp_size);++ call_postamble({}, aux_fp_gpr_idxs, aux_vec_idxs);+ }+}++std::set<std::vector<element::Type>> jit_power_static_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32}};+}++void jit_power_static_emitter::register_table_entries() {+ if (scale != 1.f || shift != 0.f) {+ push_arg_entry_of("scale", dnnl::impl::float2int(scale));+ push_arg_entry_of("shift", dnnl::impl::float2int(shift));+ }+ if (power != 1.f)+ push_arg_entry_of("power", dnnl::impl::float2int(power));+ if (power < 0)+ push_arg_entry_of("one", CONST_1_F);+}++/// Sigmoid ///+jit_sigmoid_emitter::jit_sigmoid_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node, const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {+ jit_exp_emitter_.reset(new jit_exp_emitter(host, host_isa, exec_prc));+ prepare_table();+}++jit_sigmoid_emitter::jit_sigmoid_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {+ jit_exp_emitter_.reset(new jit_exp_emitter(host, host_isa, exec_prc));+ prepare_table();+}++size_t jit_sigmoid_emitter::get_inputs_num() const {+ return 1;+}++size_t jit_sigmoid_emitter::aux_gprs_count() const {+ OPENVINO_ASSERT(jit_exp_emitter_, "JIT Exp emitter is missed!");+ return jit_exp_emitter_->aux_gprs_count();+}++size_t jit_sigmoid_emitter::aux_vecs_count() const {+ OPENVINO_ASSERT(jit_exp_emitter_, "JIT Exp emitter is missed!");+ return jit_exp_emitter_->aux_vecs_count() + 1;+}++size_t jit_sigmoid_emitter::aux_fp_gprs_count() const {+ OPENVINO_ASSERT(jit_exp_emitter_, "JIT Exp emitter is missed!");+ return std::max(jit_exp_emitter_->aux_fp_gprs_count(), 1lu);+}++void jit_sigmoid_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_sigmoid_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src = VReg(in_vec_idxs[0]);+ VReg dst = VReg(out_vec_idxs[0]);+ VReg sign_mask = VReg(aux_vec_idxs[aux_vecs_count() - 1]);+ VReg aux = VReg(aux_vec_idxs[aux_vecs_count() - 2]);++ // To avoid exp(x) overflow happened at x > logf(FLT_MAX), negate positive,+ // compute exp(x), where x <= 0 to get 0 <= exp(x) <= 1 and restore value+ // sign at the end. This is possible due to logistic is symmetric function.++ // we store the original sign and make x negative+ FReg fzero = FReg(aux_fp_gpr_idxs[0]);+ h->vmfgt_vf(mask_vreg(), src, fzero);+ h->vfneg_vv(src, src, VM::masked);+ h->vmv1r_v(sign_mask, mask_vreg()); // save mask since exp uses mask too++ const auto exp_src_idxs = std::vector<size_t>{static_cast<size_t>(src.getIdx())};+ const auto exp_dst_idxs = std::vector<size_t>{static_cast<size_t>(dst.getIdx())};+ const auto exp_aux_vec_idxs = std::vector<size_t>{aux_vec_idxs.cbegin(), aux_vec_idxs.cbegin() + jit_exp_emitter_->aux_vecs_count()};+ jit_exp_emitter_->emit_code(exp_src_idxs, exp_dst_idxs, exp_aux_vec_idxs, aux_gpr_idxs, aux_fp_gpr_idxs);++ FReg one = FReg(aux_fp_gpr_idxs[0]);+ load_table_val("one", one);+ // aux = copy exp(x)+ h->vmv_v_v(aux, dst);+ // aux = (exp(x) + 1)+ h->vfadd_vf(aux, aux, one);+ // dst = exp(x) / (exp(x) + 1) = dst / aux+ h->vfdiv_vv(dst, dst, aux);++ // Now we have to apply the "symmetry" based on original sign+ // aux = dst - 1 = 1 - ( 1 / (exp(x) + 1))+ h->vfrsub_vf(aux, dst, one);+ h->vmv1r_v(mask_vreg(), sign_mask); // pop mask+ h->vmerge_vvm(dst, dst, aux);+}++void jit_sigmoid_emitter::register_table_entries() {+ push_arg_entry_of("one", CONST_1_F);+}++void jit_sigmoid_emitter::emit_data() const {+ jit_emitter::emit_data();+ jit_exp_emitter_->emit_data();+}++std::set<std::vector<element::Type>> jit_sigmoid_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32}};+}++/// SUB ///+jit_subtract_emitter::jit_subtract_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node)+ : jit_emitter(host, host_isa, get_arithmetic_binary_exec_precision(node)) {}++jit_subtract_emitter::jit_subtract_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc)+ : jit_emitter(host, host_isa, exec_prc) {}++size_t jit_subtract_emitter::get_inputs_num() const {+ return 2;+}++void jit_subtract_emitter::emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ if (host_isa_ == ov::intel_cpu::riscv64::cpu_isa_t::gv) {+ emit_isa<ov::intel_cpu::riscv64::cpu_isa_t::gv>(in_vec_idxs, out_vec_idxs);+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_subtract_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const {+ VReg src0 = VReg(in_vec_idxs[0]);+ VReg src1 = VReg(in_vec_idxs[1]);+ VReg dst = VReg(out_vec_idxs[0]);++ switch (exec_prc_) {+ case ov::element::f32:+ h->vfsub_vv(dst, src0, src1);+ break;+ case ov::element::i32:+ h->vsub_vv(dst, src0, src1);+ break;+ default:+ OV_CPU_JIT_EMITTER_THROW("Unsupported precision");+ }+}++std::set<std::vector<element::Type>> jit_subtract_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {{element::f32, element::f32}, {element::i32, element::i32}};+}++#undef CONST_1_F++} // ov::intel_cpu::riscv64diff --git a/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_eltwise_emitters.hpp b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_eltwise_emitters.hppnew file mode 100644index 00000000000..9d484ff5d45--- /dev/null+++ b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_eltwise_emitters.hpp@@ -0,0 +1,247 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "jit_emitter.hpp"++namespace ov::intel_cpu::riscv64 {++class jit_add_emitter : public jit_emitter {+public:+ jit_add_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc = ov::element::f32);+ jit_add_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node);++ size_t get_inputs_num() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;+};++class jit_clamp_emitter : public jit_emitter {+public:+ jit_clamp_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ float min, float max, const ov::element::Type exec_prc = ov::element::f32);+ jit_clamp_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node, const ov::element::Type exec_prc = ov::element::f32);++ size_t get_inputs_num() const override;+ size_t aux_fp_gprs_count() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;++ void register_table_entries() override;++ float min {0.f};+ float max {0.f};+};++class jit_divide_emitter : public jit_emitter {+public:+ jit_divide_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc = ov::element::f32);+ jit_divide_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node);++ size_t get_inputs_num() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;+};++class jit_exp_emitter : public jit_emitter {+public:+ jit_exp_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc = ov::element::f32);+ jit_exp_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node, const ov::element::Type exec_prc = ov::element::f32);++ size_t get_inputs_num() const override;+ size_t aux_gprs_count() const override;+ size_t aux_vecs_count() const override;+ size_t aux_fp_gprs_count() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;++ void register_table_entries() override;+};++class jit_mul_add_emitter : public jit_emitter {+public:+ jit_mul_add_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc = ov::element::f32);+ jit_mul_add_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node);++ size_t get_inputs_num() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;+};+class jit_multiply_emitter : public jit_emitter {+public:+ jit_multiply_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc = ov::element::f32);+ jit_multiply_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node);++ size_t get_inputs_num() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;+};++class jit_power_static_emitter : public jit_emitter {+public:+ jit_power_static_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ float power, float scale, float shift, const ov::element::Type exec_prc = ov::element::f32);++ size_t get_inputs_num() const override;+ size_t aux_gprs_count() const override;+ size_t aux_vecs_count() const override;+ size_t aux_fp_gprs_count() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++ bool is_lmul_supported() const override;++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;++ void register_table_entries() override;++ inline bool is_sqrt() const { return power == 0.5f || power == -0.5f; }+ inline bool is_int_pow() const { return std::floor(power) == power && power != 0; }+ inline bool is_scale_shift() const { return scale != 1.f || shift != 0.f; }++ float power {1.f};+ float scale {1.f};+ float shift {0.f};+};++class jit_prelu_emitter : public jit_emitter {+public:+ jit_prelu_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc = ov::element::f32);+ jit_prelu_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node, const ov::element::Type exec_prc = ov::element::f32);++ size_t get_inputs_num() const override;+ size_t aux_fp_gprs_count() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;+};++class jit_relu_emitter : public jit_emitter {+public:+ jit_relu_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ float alpha, const ov::element::Type exec_prc = ov::element::f32);+ jit_relu_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node, const ov::element::Type exec_prc = ov::element::f32);++ size_t get_inputs_num() const override;+ size_t aux_fp_gprs_count() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;++ void register_table_entries() override;++ float alpha {0.f};+};++class jit_sigmoid_emitter : public jit_emitter {+public:+ jit_sigmoid_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc = ov::element::f32);+ jit_sigmoid_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node, const ov::element::Type exec_prc = ov::element::f32);++ size_t get_inputs_num() const override;+ size_t aux_gprs_count() const override;+ size_t aux_vecs_count() const override;+ size_t aux_fp_gprs_count() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;+ void emit_data() const override;++ void register_table_entries() override;++ std::unique_ptr<jit_exp_emitter> jit_exp_emitter_ {nullptr};+};++class jit_subtract_emitter : public jit_emitter {+public:+ jit_subtract_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const ov::element::Type exec_prc = ov::element::f32);+ jit_subtract_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ const std::shared_ptr<ov::Node>& node);++ size_t get_inputs_num() const override;++ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++private:+ void emit_impl(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const override;+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>+ void emit_isa(const std::vector<size_t>& in_vec_idxs, const std::vector<size_t>& out_vec_idxs) const;+};++} // ov::intel_cpu::riscv64+diff --git a/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_emitter.cpp b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_emitter.cppnew file mode 100644index 00000000000..5e87d73b5f4--- /dev/null+++ b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_emitter.cpp@@ -0,0 +1,358 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "jit_emitter.hpp"++namespace ov::intel_cpu::riscv64 {++using namespace Xbyak_riscv;++jit_emitter::jit_emitter(ov::intel_cpu::riscv64::jit_generator* host, ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ ov::element::Type exec_prc, emitter_in_out_map in_out_type)+ : Emitter(), h(host), host_isa_(host_isa), exec_prc_(exec_prc), l_table(new Xbyak_riscv::Label()), in_out_type_(in_out_type) {+ OPENVINO_ASSERT(h, "JIT Generator is missed");+}++void jit_emitter::emit_code_impl(const std::vector<size_t>& in_idxs,+ const std::vector<size_t>& out_idxs,+ const std::vector<size_t>& pool_vec_idxs,+ const std::vector<size_t>& pool_gpr_idxs,+ const std::vector<size_t>& pool_fp_gpr_idxs) const {+ emitter_preamble(in_idxs, out_idxs, pool_vec_idxs, pool_gpr_idxs, pool_fp_gpr_idxs);++ emit_impl(in_idxs, out_idxs);++ emitter_postamble();+}++void jit_emitter::emit_data() const {+ h->align(64);+ h->L(*l_table.get());++ // Assumption: entries can be inserted with dd, so they should be 4 bytes.+ assert(sizeof(table_entry_val_t) == 4);++ // Run through the map and insert values stored there+ for (auto it = entry_map_.begin(); it != entry_map_.end(); it++) {+ const auto& te = (*it).second; // get map entry for a given key+ const auto len = sizeof(table_entry_val_t);+ for (size_t d = 0; d < len; d += sizeof(table_entry_val_t)) {+ h->append4B(te.val);+ }+ }+}++size_t jit_emitter::aux_vecs_count() const {+ return 0;+}++size_t jit_emitter::aux_gprs_count() const {+ // We need one gpr to load table address+ return entry_map_.empty() ? 0 : 1;+}++size_t jit_emitter::aux_fp_gprs_count() const {+ return 0;+}++emitter_in_out_map jit_emitter::get_in_out_type() const {+ return in_out_type_;+}++std::set<std::vector<element::Type>> jit_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {+ return {};+}++size_t jit_emitter::get_gpr_length() const {+ return xlen;+}++size_t jit_emitter::get_fp_gpr_length() const {+ return flen;+}++size_t jit_emitter::get_vec_length() const {+ return vlen;+}++void jit_emitter::emitter_preamble(const std::vector<size_t>& in_idxs,+ const std::vector<size_t>& out_idxs,+ const std::vector<size_t>& pool_vec_idxs,+ const std::vector<size_t>& pool_gpr_idxs,+ const std::vector<size_t>& pool_fp_gpr_idxs) const {+ bool is_vec_input =+ (in_out_type_ == emitter_in_out_map::vec_to_vec) || (in_out_type_ == emitter_in_out_map::vec_to_gpr);+ bool is_vec_output =+ (in_out_type_ == emitter_in_out_map::vec_to_vec) || (in_out_type_ == emitter_in_out_map::gpr_to_vec);++ for (auto idx : pool_vec_idxs) {+ aux_vec_idxs.push_back(idx);+ }++ for (size_t idx = 0; idx < get_max_vecs_count(); idx++) {+ if (aux_vec_idxs.size() >= aux_vecs_count()) {+ break;+ }++ if (is_vec_input) {+ if (std::find(in_idxs.begin(), in_idxs.end(), idx) != in_idxs.end()) {+ continue;+ }+ }+ if (is_vec_output) {+ if (std::find(out_idxs.begin(), out_idxs.end(), idx) != out_idxs.end()) {+ continue;+ }+ }+ if (std::find(aux_vec_idxs.begin(), aux_vec_idxs.end(), idx) != aux_vec_idxs.end()) {+ continue;+ }+ if (std::find(preserved_vec_idxs.begin(), preserved_vec_idxs.end(), idx) != preserved_vec_idxs.end()) {+ continue;+ }++ aux_vec_idxs.push_back(idx);+ preserved_vec_idxs.push_back(idx);+ }+ OPENVINO_ASSERT(aux_vecs_count() <= aux_vec_idxs.size(), "Failed to allocate required number of vector registers");++ // FP REGISTERS //+ for (auto idx : pool_fp_gpr_idxs) {+ aux_fp_gpr_idxs.push_back(idx);+ }++ for (size_t idx = 0; idx < get_max_fp_gpr_count(); idx++) {+ if (aux_fp_gpr_idxs.size() >= aux_fp_gprs_count()) {+ break;+ }++ if (std::find(aux_fp_gpr_idxs.begin(), aux_fp_gpr_idxs.end(), idx) != aux_fp_gpr_idxs.end()) {+ continue;+ }+ if (std::find(preserved_fp_gpr_idxs.begin(), preserved_fp_gpr_idxs.end(), idx) != preserved_fp_gpr_idxs.end()) {+ continue;+ }++ aux_fp_gpr_idxs.push_back(idx);+ preserved_fp_gpr_idxs.push_back(idx);+ }+ OPENVINO_ASSERT(aux_fp_gprs_count() <= aux_fp_gpr_idxs.size(), "Failed to allocate required number of FP registers");++ // INT REGISTERS //+ for (auto idx : pool_gpr_idxs) {+ aux_gpr_idxs.push_back(idx);+ }++ const std::unordered_set<size_t> blacklist_gpr = {+ Xbyak_riscv::zero.getIdx(), Xbyak_riscv::ra.getIdx(), Xbyak_riscv::sp.getIdx(), Xbyak_riscv::gp.getIdx(), Xbyak_riscv::tp.getIdx()+ };++ const size_t last_gpr_idx = x31.getIdx();+ for (size_t gpr_idx = 0; gpr_idx <= last_gpr_idx; ++gpr_idx) {+ size_t _idx = last_gpr_idx - gpr_idx; // we allocate from the end++ if (aux_gpr_idxs.size() >= aux_gprs_count()) {+ break;+ }+ if (blacklist_gpr.count(_idx) > 0) {+ continue;+ }+ if (!is_vec_input) {+ if (std::find(in_idxs.begin(), in_idxs.end(), _idx) != in_idxs.end()) {+ continue;+ }+ }+ if (!is_vec_output) {+ if (std::find(out_idxs.begin(), out_idxs.end(), _idx) != out_idxs.end()) {+ continue;+ }+ }+ if (std::find(aux_gpr_idxs.begin(), aux_gpr_idxs.end(), _idx) != aux_gpr_idxs.end()) {+ continue;+ }+ if (std::find(preserved_gpr_idxs.begin(), preserved_gpr_idxs.end(), _idx) != preserved_gpr_idxs.end()) {+ continue;+ }++ aux_gpr_idxs.push_back(_idx);+ preserved_gpr_idxs.push_back(_idx);+ }+ OPENVINO_ASSERT(aux_gprs_count() <= aux_gpr_idxs.size(), "Failed to allocate required number of general-purpose registers");++ if (!entry_map_.empty()) {+ // last aux_gpr_idx is for p_table, we can use aux_gpr_idxs from idx 0 for other purpose+ p_table = Reg(aux_gpr_idxs[aux_gprs_count() - 1]);+ aux_gpr_idxs.erase(aux_gpr_idxs.end() - 1);+ }++ store_context(preserved_gpr_idxs, preserved_fp_gpr_idxs, preserved_vec_idxs);++ if (!entry_map_.empty()) {+ load_table_addr();+ }+}++void jit_emitter::emitter_postamble() const {+ restore_context(preserved_gpr_idxs, preserved_fp_gpr_idxs, preserved_vec_idxs);++ preserved_vec_idxs.clear();+ preserved_gpr_idxs.clear();+ preserved_fp_gpr_idxs.clear();++ aux_vec_idxs.clear();+ aux_gpr_idxs.clear();+ aux_fp_gpr_idxs.clear();+}++namespace {+std::vector<size_t> get_caller_saved_gprs(const jit_generator* h, const std::vector<size_t>& exclude_gpr_regs, size_t count) {+ std::vector<size_t> gprs;+ gprs.reserve(count);+ for (size_t j = 0; j < count; ++j) {+ const int i = static_cast<int>(j);+ if (std::find(exclude_gpr_regs.cbegin(), exclude_gpr_regs.cend(), i) != exclude_gpr_regs.cend())+ continue;+ if (std::find_if(std::begin(h->abi_save_gpr_regs), std::end(h->abi_save_gpr_regs),+ [i](const Reg& r) { return r.getIdx() == i; }) != std::end(h->abi_save_gpr_regs))+ continue;+ if (i == zero.getIdx() || i == sp.getIdx() || i == gp.getIdx() || i == tp.getIdx())+ continue;+ gprs.push_back(i);+ }+ return gprs;+}+std::vector<size_t> get_caller_saved_fp_gprs(const jit_generator* h, const std::vector<size_t>& exclude_fp_gpr_regs, size_t count) {+ std::vector<size_t> fp_gprs;+ fp_gprs.reserve(count);+ for (size_t j = 0; j < count; ++j) {+ const int i = static_cast<int>(j);+ if (std::find(exclude_fp_gpr_regs.cbegin(), exclude_fp_gpr_regs.cend(), i) != exclude_fp_gpr_regs.cend())+ continue;+ if (std::find_if(std::begin(h->abi_save_fp_gpr_regs), std::end(h->abi_save_fp_gpr_regs),+ [i](const FReg& r) { return r.getIdx() == i; }) != std::end(h->abi_save_fp_gpr_regs))+ continue;+ fp_gprs.push_back(i);+ }+ return fp_gprs;+}+std::vector<size_t> get_caller_saved_vec_gprs(const jit_generator* h, const std::vector<size_t>& exclude_vec_regs, size_t count) {+ std::vector<size_t> vecs;+ vecs.reserve(count);+ for (size_t j = 0; j < count; ++j) {+ const int i = static_cast<int>(j);+ if (std::find(exclude_vec_regs.cbegin(), exclude_vec_regs.cend(), i) != exclude_vec_regs.cend())+ continue;+ vecs.push_back(i);+ }+ return vecs;+}+} // namespace++void jit_emitter::call_preamble(const std::vector<size_t>& exclude_gpr_regs,+ const std::vector<size_t>& exclude_fp_gpr_regs,+ const std::vector<size_t>& exclude_vec_regs) const {+ store_context(get_caller_saved_gprs(h, exclude_gpr_regs, get_max_gpr_count()),+ get_caller_saved_fp_gprs(h, exclude_fp_gpr_regs, get_max_fp_gpr_count()),+ get_caller_saved_vec_gprs(h, exclude_vec_regs, get_max_vecs_count()));+}++void jit_emitter::call_postamble(const std::vector<size_t>& exclude_gpr_regs,+ const std::vector<size_t>& exclude_fp_gpr_regs,+ const std::vector<size_t>& exclude_vec_regs) const {+ restore_context(get_caller_saved_gprs(h, exclude_gpr_regs, get_max_gpr_count()),+ get_caller_saved_fp_gprs(h, exclude_fp_gpr_regs, get_max_fp_gpr_count()),+ get_caller_saved_vec_gprs(h, exclude_vec_regs, get_max_vecs_count()));+}++void jit_emitter::store_context(const std::vector<size_t>& gpr_regs,+ const std::vector<size_t>& fp_gpr_regs,+ const std::vector<size_t>& vec_regs) const {+ // GPRs+ {+ const auto gpr_all_size = gpr_regs.size() * get_gpr_length();+ const int frame_size = rnd_up(gpr_all_size, sp_aligment);+ h->addi(sp, sp, -frame_size);+ int imm = 0;+ for (const auto& gpr_idx : gpr_regs) {+ h->sd(Reg(gpr_idx), sp, imm);+ imm += get_gpr_length();+ }+ }++ // FPs+ {+ const auto fp_gpr_all_size = fp_gpr_regs.size() * get_fp_gpr_length();+ const int frame_size = rnd_up(fp_gpr_all_size, sp_aligment);+ h->addi(sp, sp, -frame_size);+ int imm = 0;+ for (const auto& fp_gpr_idx : fp_gpr_regs) {+ h->fsd(FReg(fp_gpr_idx), sp, imm);+ imm += get_fp_gpr_length();+ }+ }++ // Vec regs+ {+ // TODO: support lmul+ const int step = -rnd_up(get_vec_length(), sp_aligment);+ for (const auto& vec_idx : vec_regs) {+ h->addi(sp, sp, step);+ h->vse32_v(VReg(vec_idx), sp);+ }+ }+}++void jit_emitter::restore_context(const std::vector<size_t>& gpr_regs,+ const std::vector<size_t>& fp_gpr_regs,+ const std::vector<size_t>& vec_regs) const {+ // Vec regs+ {+ // TODO: support lmul+ const int step = rnd_up(get_vec_length(), sp_aligment);+ for (const auto& vec_idx : vec_regs) {+ h->addi(sp, sp, step);+ h->vle32_v(VReg(vec_idx), sp);+ }+ }+ // FPs+ {+ const auto fp_gpr_all_size = fp_gpr_regs.size() * get_fp_gpr_length();+ const int frame_size = rnd_up(fp_gpr_all_size, sp_aligment);+ int imm = 0;+ for (const auto& fp_gpr_idx : fp_gpr_regs) {+ h->fld(FReg(fp_gpr_idx), sp, imm);+ imm += get_fp_gpr_length();+ }+ h->addi(sp, sp, frame_size);+ }+ // GPRs+ {+ const auto gpr_all_size = gpr_regs.size() * get_gpr_length();+ const int frame_size = rnd_up(gpr_all_size, sp_aligment);+ int imm = 0;+ for (const auto& gpr_idx : gpr_regs) {+ h->ld(Reg(gpr_idx), sp, imm);+ imm += get_gpr_length();+ }+ h->addi(sp, sp, frame_size);+ }+}++void jit_emitter::prepare_table() {+ register_table_entries();++ // Now that we registered the entries, we set the offsets. No+ // entries should be registered after this point. This allows to+ // expect the same order when injecting the table entries in+ // prepare_table.+ size_t off = 0;+ for (auto it = entry_map_.begin(); it != entry_map_.end(); it++) {+ auto& te = (*it).second;+ te.off = off;+ off += sizeof(table_entry_val_t);+ }+}++} // ov::intel_cpu::riscv64+diff --git a/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_emitter.hpp b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_emitter.hppnew file mode 100644index 00000000000..90406272ddc--- /dev/null+++ b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_emitter.hpp@@ -0,0 +1,206 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "node.h"++#include "nodes/kernels/riscv64/cpu_isa_traits.hpp"+#include "nodes/kernels/riscv64/jit_generator.hpp"+#include "emitters/utils.hpp"+#include "snippets/generator.hpp"+#include "snippets/snippets_isa.hpp"++#include <set>++namespace ov::intel_cpu::riscv64 {++enum emitter_in_out_map {+ vec_to_vec,+ vec_to_gpr,+ gpr_to_vec,+ gpr_to_gpr,+};++class jit_emitter : public ov::snippets::Emitter {+public:+ jit_emitter(ov::intel_cpu::riscv64::jit_generator* host,+ ov::intel_cpu::riscv64::cpu_isa_t host_isa,+ ov::element::Type exec_prc = ov::element::f32,+ emitter_in_out_map in_out_type = emitter_in_out_map::vec_to_vec);++ // We have to define second "emit_code" to pass FP registers because+ // the base class method doesn't support them for code emission+ virtual void emit_code(const std::vector<size_t>& in_idxs,+ const std::vector<size_t>& out_idxs,+ const std::vector<size_t>& pool_vec_idxs,+ const std::vector<size_t>& pool_gpr_idxs,+ const std::vector<size_t>& pool_fp_gpr_idxs) const {+ emit_code_impl(in_idxs, out_idxs, pool_vec_idxs, pool_gpr_idxs, pool_fp_gpr_idxs);+ }++ void emit_data() const override;++ virtual size_t get_inputs_num() const = 0;+ virtual size_t aux_vecs_count() const;+ virtual size_t aux_gprs_count() const;+ virtual size_t aux_fp_gprs_count() const;+ emitter_in_out_map get_in_out_type() const;++ /**+ * @brief Returns supported precisions.+ * Precisions are ordered, the first bigger bitness precision with the same type will be selected.+ * Empty collection means the emitter supports any input precisions.+ */+ static std::set<std::vector<element::Type>> get_supported_precisions(+ const std::shared_ptr<ov::Node>& node = nullptr);++ // TODO: RV64 supports vector multiplier.+ // However, currently not all JIT emitter support LMUL > 1:+ // - if aux_vec registers are needed - preamble/postamble support only m1.+ // These JIT emitters should known exact value of LMUL to preserve vec regs with correct idxs.+ // - etc+ virtual bool is_lmul_supported() const {+ return aux_vecs_count() == 0;+ }++protected:+ size_t get_max_gpr_count() const { return 32; }+ size_t get_max_fp_gpr_count() const { return 32; }+ size_t get_max_vecs_count() const { return 32; }++ size_t get_gpr_length() const;+ size_t get_fp_gpr_length() const;+ size_t get_vec_length() const;++ Xbyak_riscv::VReg mask_vreg() const { return Xbyak_riscv::v0; }++ void emit_code_impl(const std::vector<size_t>& in_idxs,+ const std::vector<size_t>& out_idxs,+ const std::vector<size_t>& pool_vec_idxs,+ const std::vector<size_t>& pool_gpr_idxs) const override {+ emit_code_impl(in_idxs, out_idxs, pool_vec_idxs, pool_gpr_idxs, {});+ }++ virtual void emit_code_impl(const std::vector<size_t>& in_idxs,+ const std::vector<size_t>& out_idxs,+ const std::vector<size_t>& pool_vec_idxs,+ const std::vector<size_t>& pool_gpr_idxs,+ const std::vector<size_t>& pool_fp_gpr_idxs) const;++ virtual void emit_impl(const std::vector<size_t>& in_idxs, const std::vector<size_t>& out_idxs) const = 0;++ virtual void emitter_preamble(const std::vector<size_t>& in_idxs,+ const std::vector<size_t>& out_idxs,+ const std::vector<size_t>& pool_vec_idxs,+ const std::vector<size_t>& pool_gpr_idxs,+ const std::vector<size_t>& pool_fp_gpr_idxs) const;+ virtual void emitter_postamble() const;++ void store_context(const std::vector<size_t>& gpr_regs,+ const std::vector<size_t>& fp_gpr_regs,+ const std::vector<size_t>& vec_regs) const;+ void restore_context(const std::vector<size_t>& gpr_regs,+ const std::vector<size_t>& fp_gpr_regs,+ const std::vector<size_t>& vec_regs) const;++ // Save all caller-saved registers (gp, fp-gp, vec) exclude passed arguments+ // These helpers might be called for save binary call+ void call_preamble(const std::vector<size_t>& exclude_gpr_regs,+ const std::vector<size_t>& exclude_fp_gpr_regs,+ const std::vector<size_t>& exclude_vec_regs) const;+ void call_postamble(const std::vector<size_t>& exclude_gpr_regs,+ const std::vector<size_t>& exclude_fp_gpr_regs,+ const std::vector<size_t>& exclude_vec_regs) const;++ virtual void validate_arguments(const std::vector<size_t>&, const std::vector<size_t>&) const {}++ // we accept only 32bit hexadecimal table values to avoid any rounding+ using table_entry_val_t = uint32_t;+ using table_entry_offset_t = size_t; // offsets are in bytes wrt p_table++ struct mapped_table_entry_t {+ table_entry_offset_t off;+ table_entry_val_t val;+ };++ using table_t = std::multimap<std::string, table_entry_val_t>;+ using mapped_table_t = std::multimap<std::string, mapped_table_entry_t>;++ void push_arg_entry_of(const std::string& key, const table_entry_val_t val) {+ mapped_table_entry_t te{0, val};+ entry_map_.insert(std::make_pair(key, te));+ }++ void push_entries_of(const table_t& t) {+ for (auto it = t.begin(); it != t.end(); it++) {+ auto key = (*it).first;+ auto te = (*it).second; // copy values from table+ push_arg_entry_of(key, te);+ }+ }++ virtual void prepare_table();+ virtual void register_table_entries() {}++ void load_table_addr() const {+ const auto address = reinterpret_cast<uintptr_t>(l_table->getAddress());+ OPENVINO_ASSERT(address != 0, "Address of data section is missed!");+ h->uni_li(p_table, address);+ }++ inline void load_table_val(const std::string& key, const Xbyak_riscv::FReg& freg, size_t key_off_val_shift = 0) const {+ auto off = table_off(key, key_off_val_shift);+ h->flw(freg, p_table, off);+ }++ inline void load_table_val(const std::string& key, const Xbyak_riscv::Reg& reg, size_t key_off_val_shift = 0) const {+ auto off = table_off(key, key_off_val_shift);+ h->lw(reg, p_table, off);+ }++ // Load scalar to vector with broadcast+ inline void load_table_val(const std::string& key, const Xbyak_riscv::VReg& vreg, const Xbyak_riscv::Reg& tmp, size_t key_off_val_shift = 0) const {+ auto off = table_off(key, key_off_val_shift);+ h->lw(tmp, p_table, off);+ h->vmv_v_x(vreg, tmp);+ }++ ov::intel_cpu::riscv64::jit_generator* h;+ ov::intel_cpu::riscv64::cpu_isa_t host_isa_;+ ov::element::Type exec_prc_;++ mutable std::shared_ptr<Xbyak_riscv::Label> l_table;+ mutable Xbyak_riscv::Reg p_table;+ mutable std::vector<size_t> aux_vec_idxs;+ mutable std::vector<size_t> aux_gpr_idxs;+ mutable std::vector<size_t> aux_fp_gpr_idxs;++ emitter_in_out_map in_out_type_;+ mapped_table_t entry_map_;++private:+ mutable std::vector<size_t> preserved_vec_idxs;+ mutable std::vector<size_t> preserved_gpr_idxs;+ mutable std::vector<size_t> preserved_fp_gpr_idxs;++ // In the standard RISC-V calling convention, the stack pointer is always kept 16-byte aligned+ const size_t sp_aligment = 16;+ // integer gpr byte size+ const size_t xlen = Xbyak_riscv::CPU().getXlen() / 8;+ // fp gpr byte size+ const size_t flen = Xbyak_riscv::CPU().getFlen() / 8;+ // vector register byte size+ const size_t vlen = Xbyak_riscv::CPU().getVlen() / 8;++ size_t table_off(const std::string& key, size_t key_off_val_shift = 0) const {+ const auto it = entry_map_.find(key); // search an entry for a key+ OV_CPU_JIT_EMITTER_ASSERT(it != entry_map_.end(), "Value has not been found in the table");+ const auto& te = (*it).second;+ const auto scale = sizeof(table_entry_val_t);+ return te.off + key_off_val_shift * scale;+ }+};++} // ov::intel_cpu::riscv64diff --git a/src/plugins/intel_cpu/src/emitters/plugin/x64/jit_eltwise_emitters.cpp b/src/plugins/intel_cpu/src/emitters/plugin/x64/jit_eltwise_emitters.cppindex 1212b4f6343..7aa5e5bf0fc 100644--- a/src/plugins/intel_cpu/src/emitters/plugin/x64/jit_eltwise_emitters.cpp+++ b/src/plugins/intel_cpu/src/emitters/plugin/x64/jit_eltwise_emitters.cpp@@ -18,24 +18,6 @@ enum {namespace ov::intel_cpu {-namespace {-ov::element::Type get_arithmetic_binary_exec_precision(const std::shared_ptr<ov::Node>& n) {- std::vector<ov::element::Type> input_precisions;- for (const auto& input : n->inputs()) {- input_precisions.push_back(input.get_source_output().get_element_type());- }-- OV_CPU_JIT_EMITTER_ASSERT(std::all_of(input_precisions.cbegin(),- input_precisions.cend(),- [&input_precisions](const ov::element::Type& precision) {- return precision == input_precisions[0];- }),- "Arithmetic binary node has not equal input precisions");-- return input_precisions[0];-}-} // namespace-/// ADD ///jit_add_emitter::jit_add_emitter(x64::jit_generator* host,x64::cpu_isa_t host_isa,diff --git a/src/plugins/intel_cpu/src/emitters/utils.cpp b/src/plugins/intel_cpu/src/emitters/utils.cppindex 60403921084..8a1c505b4a9 100644--- a/src/plugins/intel_cpu/src/emitters/utils.cpp+++ b/src/plugins/intel_cpu/src/emitters/utils.cpp@@ -40,4 +40,20 @@ std::string jit_emitter_pretty_name(const std::string& pretty_func) {return end > begin ? pretty_func.substr(begin, end - begin) : pretty_func;}+ov::element::Type get_arithmetic_binary_exec_precision(const std::shared_ptr<ov::Node>& n) {+ std::vector<ov::element::Type> input_precisions;+ for (const auto& input : n->inputs()) {+ input_precisions.push_back(input.get_source_output().get_element_type());+ }++ OPENVINO_ASSERT(std::all_of(input_precisions.begin(),+ input_precisions.end(),+ [&input_precisions](const ov::element::Type& precision) {+ return precision == input_precisions[0];+ }),+ "Binary Eltwise op has unequal input precisions");++ return input_precisions[0];+}+} // namespace ov::intel_cpudiff --git a/src/plugins/intel_cpu/src/emitters/utils.hpp b/src/plugins/intel_cpu/src/emitters/utils.hppindex c94f432a6ee..82b704dad88 100644--- a/src/plugins/intel_cpu/src/emitters/utils.hpp+++ b/src/plugins/intel_cpu/src/emitters/utils.hpp@@ -7,6 +7,7 @@#include <string>#include "openvino/core/except.hpp"+#include "openvino/core/node.hpp"#include "openvino/core/type/element_type.hpp"namespace ov::intel_cpu {@@ -22,4 +23,6 @@ std::string jit_emitter_pretty_name(const std::string& pretty_func);#define OV_CPU_JIT_EMITTER_THROW(...) OPENVINO_THROW(OV_CPU_JIT_EMITTER_NAME, ": ", __VA_ARGS__)#define OV_CPU_JIT_EMITTER_ASSERT(cond, ...) OPENVINO_ASSERT((cond), OV_CPU_JIT_EMITTER_NAME, ": ", __VA_ARGS__)+ov::element::Type get_arithmetic_binary_exec_precision(const std::shared_ptr<ov::Node>& n);+} // namespace ov::intel_cpudiff --git a/src/plugins/intel_cpu/src/node.cpp b/src/plugins/intel_cpu/src/node.cppindex 91ae0d1b8fc..acead3dde7b 100644--- a/src/plugins/intel_cpu/src/node.cpp+++ b/src/plugins/intel_cpu/src/node.cpp@@ -1325,6 +1325,8 @@ const std::vector<impl_desc_type>& Node::getDefaultImplPriority() {impl_desc_type::jit_sse42_dw, impl_desc_type::jit_sse42_1x1, impl_desc_type::jit_sse42,#if defined(OPENVINO_ARCH_ARM64)impl_desc_type::jit_asimd,+#elif defined(OPENVINO_ARCH_RISCV64)+ impl_desc_type::jit_gv,#endifimpl_desc_type::gemm_any, impl_desc_type::gemm_blas, impl_desc_type::gemm_avx512, impl_desc_type::gemm_avx2,impl_desc_type::gemm_avx, impl_desc_type::gemm_sse42, impl_desc_type::gemm_acl, impl_desc_type::acl,diff --git a/src/plugins/intel_cpu/src/nodes/eltwise.cpp b/src/plugins/intel_cpu/src/nodes/eltwise.cppindex e6ac6226112..aa6a5a922eb 100644--- a/src/plugins/intel_cpu/src/nodes/eltwise.cpp+++ b/src/plugins/intel_cpu/src/nodes/eltwise.cpp@@ -46,13 +46,17 @@#if defined(OPENVINO_ARCH_ARM64)# include "cpu/aarch64/cpu_isa_traits.hpp"-# include "executors/aarch64/jit_eltwise.hpp"# include "kernels/aarch64/jit_uni_eltwise_generic.hpp"#elif defined(OPENVINO_ARCH_X86_64)# include "cpu/x64/cpu_isa_traits.hpp"# include "kernels/x64/jit_uni_eltwise_generic.hpp"#endif+#if defined(OPENVINO_ARCH_RISCV64)+# include "kernels/riscv64/cpu_isa_traits.hpp"+# include "kernels/riscv64/jit_uni_eltwise_generic.hpp"+#endif+using namespace dnnl::impl::utils;using namespace dnnl::impl::cpu;@@ -68,24 +72,6 @@ using namespace dnnl::impl::cpu::aarch64;namespace ov::intel_cpu::node {-#if defined(OPENVINO_ARCH_ARM64)-namespace {-bool jitIsSupported(const Node* node,- const float alpha,- const float beta,- const float gamma,- const std::vector<ov::element::Type>& input_precisions = {}) {- return executors::aarch64::JitEltwiseExecutor::isSupported(- node->getAlgorithm(),- input_precisions.empty() ? node->getOriginalInputPrecisions() : input_precisions,- node->getOriginalOutputPrecisions(),- alpha,- beta,- gamma);-}-} // namespace-#endif-Eltwise::BroadcastingPolicy Eltwise::determineBroadcastingPolicy(const std::shared_ptr<ov::Node>& op) {const auto const1 = ov::as_type_ptr<ov::opset1::Constant>(op->get_input_node_shared_ptr(0));const auto const2 = ov::as_type_ptr<ov::opset1::Constant>(op->get_input_node_shared_ptr(1));@@ -681,6 +667,14 @@ public:}#endif // OPENVINO_ARCH_ARM64+#if defined(OPENVINO_ARCH_RISCV64)+ if (mayiuse(ov::intel_cpu::riscv64::gv)) {+ _pKernel.reset(+ new ov::intel_cpu::riscv64::jit_uni_eltwise_generic<ov::intel_cpu::riscv64::gv>(jep, eltwise_data));+ } else {+ OPENVINO_THROW("Can't create jit eltwise kernel");+ }+#endif // OPENVINO_ARCH_RISCV64if (_pKernel) {_pKernel->create_ker();}@@ -748,6 +742,114 @@ public:return _batchDimIdx;}+ static bool isSupportedOp(const Node* node,+ const float alpha,+ const float beta,+ const float gamma,+ const std::vector<ov::element::Type>& input_precisions = {}) {+#if defined(OPENVINO_ARCH_X86_64)+ const auto isISASupportedByJIT = mayiuse(dnnl::impl::cpu::x64::sse41);+#elif defined(OPENVINO_ARCH_ARM64)+ const auto isISASupportedByJIT = mayiuse(dnnl::impl::cpu::aarch64::asimd);+#elif defined(OPENVINO_ARCH_RISCV64)+ const auto isISASupportedByJIT = mayiuse(ov::intel_cpu::riscv64::gv);+#else+ const auto isISASupportedByJIT = false;+#endif+ // if dim rank is greater than the maximum possible, we should not use JIT execution+ if (!isISASupportedByJIT || node->getInputShapeAtPort(0).getRank() > MAX_ELTWISE_DIM_RANK) {+ return false;+ }++ const auto algorithm = node->getAlgorithm();+ if (one_of(algorithm,+ Algorithm::EltwiseLog,+ Algorithm::EltwiseBitwiseLeftShift,+ Algorithm::EltwiseBitwiseRightShift)) {+ return false;+ }++#if defined(OPENVINO_ARCH_X86_64)+ return true;++#elif defined(OPENVINO_ARCH_ARM64)+ if (one_of(algorithm,+ Algorithm::EltwisePowerDynamic,+ Algorithm::EltwiseSoftRelu,+ Algorithm::EltwiseHsigmoid,+ Algorithm::EltwiseErf,+ Algorithm::EltwiseBitwiseAnd,+ Algorithm::EltwiseBitwiseNot,+ Algorithm::EltwiseBitwiseOr,+ Algorithm::EltwiseBitwiseXor)) {+ return false;+ }++ if ((algorithm == Algorithm::EltwiseRelu) && ((alpha != 0.f) || (beta != 0.f) || (gamma != 0.f))) {+ return false;+ }++ const std::set<ov::element::Type> supported_precisions =+ // Divide and Floor (issue #138629) operations are supported for fp32 and fp16 only.+ ((algorithm == Algorithm::EltwiseDivide) || (algorithm == Algorithm::EltwiseFloor))+ ? std::set<ov::element::Type>{ov::element::f16, ov::element::f32}+ : std::set<ov::element::Type>{ov::element::f16,+ ov::element::f32,+ ov::element::i32,+ ov::element::i8,+ ov::element::u8};+#elif defined(OPENVINO_ARCH_RISCV64)+ if (!one_of(algorithm,+ Algorithm::EltwiseAdd,+ Algorithm::EltwiseClamp,+ Algorithm::EltwiseDivide,+ Algorithm::EltwiseExp,+ Algorithm::EltwiseMulAdd,+ Algorithm::EltwiseMultiply,+ Algorithm::EltwisePowerStatic,+ Algorithm::EltwisePrelu,+ Algorithm::EltwiseRelu,+ Algorithm::EltwiseSigmoid,+ Algorithm::EltwiseSubtract)) {+ return false;+ }++ const std::set<ov::element::Type> supported_precisions = {ov::element::f32,+ ov::element::i32,+ ov::element::i8,+ ov::element::u8};+#endif++#if defined(OPENVINO_ARCH_ARM64) || defined(OPENVINO_ARCH_RISCV64)+ const auto check_precisions = [](const std::vector<ov::element::Type>& input_precisions,+ const std::vector<ov::element::Type>& output_precisions,+ const std::set<ov::element::Type>& supported_precisions) {+ if (std::any_of(input_precisions.begin(),+ input_precisions.end(),+ [&supported_precisions](const ov::element::Type& precision) {+ return supported_precisions.find(precision) == supported_precisions.end();+ })) {+ return false;+ }++ if (std::any_of(output_precisions.begin(),+ output_precisions.end(),+ [&supported_precisions](const ov::element::Type& precision) {+ return supported_precisions.find(precision) == supported_precisions.end();+ })) {+ return false;+ }++ return true;+ };++ return check_precisions(input_precisions, node->getOriginalOutputPrecisions(), supported_precisions);+#endif++ // Unsupported architectures should return false:+ return false;+ }+private:std::unique_ptr<jit_uni_eltwise_kernel> _pKernel;size_t _schedulerWorkAmount = 0;@@ -1155,7 +1257,6 @@ static Eltwise::executorPtr buildRefExecutor(const EltwiseKey& key) {key.eltwise_data.front(),key.outBlkDims,key.inpDims);-#case ov::element::i32:return std::make_shared<BitwiseRefExecutor<element_type_traits<ov::element::i32>::value_type>>(key.eltwise_data.front(),@@ -1340,24 +1441,8 @@ void Eltwise::initSupportedPrimitiveDescriptors() {}// if dim rank is greater than the maximum possible, we should use the reference execution-#if defined(OPENVINO_ARCH_ARM64)- bool canUseOptimizedImpl =- mayiuse(dnnl::impl::cpu::aarch64::asimd) && (getInputShapeAtPort(0).getRank() <= MAX_ELTWISE_DIM_RANK);- bool canUseOptimizedShapeAgnosticImpl = isDynamicNode() && canUseOptimizedImpl;-#elif defined(OPENVINO_ARCH_X86_64)- bool canUseOptimizedImpl =- mayiuse(dnnl::impl::cpu::x64::sse41) && getInputShapeAtPort(0).getRank() <= MAX_ELTWISE_DIM_RANK;- // TODO: Add EltwiseLog algorithm support for JIT implementation- canUseOptimizedImpl &= !one_of(getAlgorithm(),- Algorithm::EltwiseLog,- Algorithm::EltwiseBitwiseLeftShift,- Algorithm::EltwiseBitwiseRightShift);-+ bool canUseOptimizedImpl = EltwiseJitExecutor::isSupportedOp(this, getAlpha(), getBeta(), getGamma());bool canUseOptimizedShapeAgnosticImpl = isDynamicNode() && canUseOptimizedImpl;-#else- bool canUseOptimizedImpl = false;- bool canUseOptimizedShapeAgnosticImpl = false;-#endifif (!canUseOptimizedImpl && !fusedWith.empty()) {THROW_CPU_NODE_ERR("uses reference impl, but unexpectedly fused with other ops");@@ -1415,11 +1500,13 @@ void Eltwise::initSupportedPrimitiveDescriptors() {outputPrecision = fusedWith[fusedWith.size() - 1]->getOriginalOutputPrecisionAtPort(0);}-#ifndef OPENVINO_ARCH_ARM64implType = canUseOptimizedShapeAgnosticImpl ? EltwiseImplType::optimizedShapeAgnostic: canUseOptimizedImpl ? EltwiseImplType::optimized: EltwiseImplType::reference;+ const auto useJitExecutor = one_of(implType, EltwiseImplType::optimizedShapeAgnostic, EltwiseImplType::optimized);++#ifdef OPENVINO_ARCH_X86_64if (!hasHardwareSupport(ov::element::bf16)) {bool hasBF16 = false;for (auto& inPrc : inputPrecisions) {@@ -1432,21 +1519,6 @@ void Eltwise::initSupportedPrimitiveDescriptors() {THROW_CPU_NODE_ERR("doesn't support BF16 precision on this target.");}}-# if defined(OV_CPU_WITH_ACL)- const bool useJit = false;-# endif-#elif defined(OPENVINO_ARCH_ARM64)- const bool useJit = canUseOptimizedImpl && jitIsSupported(this, getAlpha(), getBeta(), getGamma());- if (!useJit) {- canUseOptimizedImpl = false;- }-- implType =- (useJit && canUseOptimizedImpl)- ? (canUseOptimizedShapeAgnosticImpl ? EltwiseImplType::optimizedShapeAgnostic : EltwiseImplType::optimized)- : EltwiseImplType::reference;-#else- THROW_CPU_NODE_ERR("Unknown CPU architecture");#endif#if defined(OV_CPU_WITH_ACL)@@ -1460,7 +1532,7 @@ void Eltwise::initSupportedPrimitiveDescriptors() {return forcedPrec;};- const bool useAcl = !useJit;+ const bool useAcl = !useJitExecutor;if (useAcl) {// Use original output precision as a reference point since some eltwise algorithms have non-float inputs (i.e.// EltwiseSelect)@@ -1487,7 +1559,8 @@ void Eltwise::initSupportedPrimitiveDescriptors() {} else {#endif#if defined(OV_CPU_WITH_SHL)- if (ShlEltwiseExecutor::isEltwiseAlgorithmSupported(getAlgorithm())) {+ const bool useSHL = !useJitExecutor;+ if (useSHL && ShlEltwiseExecutor::isEltwiseAlgorithmSupported(getAlgorithm())) {// SHL implementation supports only identical precisions on inputs/outputs and only FP32 for nowconst ov::element::Type forcedPrec = ov::element::f32;for (size_t i = 0; i < inputPrecisions.size(); i++) {@@ -1509,7 +1582,7 @@ void Eltwise::initSupportedPrimitiveDescriptors() {}if (std::find(supportedPrecisions.begin(), supportedPrecisions.end(), prc) ==supportedPrecisions.end()) {- if (prc == ov::element::u32 || prc == ov::element::i64 || prc == ov::element::u64) {+ if (one_of(prc, ov::element::u32, ov::element::i64, ov::element::u64)) {return ov::element::i32;}if (prc == ov::element::f64) {@@ -1544,7 +1617,7 @@ void Eltwise::initSupportedPrimitiveDescriptors() {enum LayoutType : uint8_t { Planar, ChannelsFirst, Blocked };- auto initDesc = [&](LayoutType lt, const bool useEltwiseExecutor = false, const bool useJit = false) -> NodeDesc {+ auto initDesc = [&](LayoutType lt, const bool useEltwiseExecutor = false) -> NodeDesc {auto createMemoryDesc =[lt](const Shape& shape, ov::element::Type prc, size_t offset) -> std::shared_ptr<CpuBlockedMemoryDesc> {const auto& dims = shape.getDims();@@ -1625,15 +1698,8 @@ void Eltwise::initSupportedPrimitiveDescriptors() {config.outConfs.push_back(portConfig);- if (useEltwiseExecutor || useJit) {- impl_desc_type impl_type;-#if defined(OPENVINO_ARCH_ARM64)- if (useJit) {- impl_type = impl_desc_type::jit_asimd;- }-#else- impl_type = impl_desc_type::undef;-#endif+ if (useEltwiseExecutor) {+ impl_desc_type impl_type = impl_desc_type::undef;std::vector<MemoryDescPtr> srcMemoryDescs;srcMemoryDescs.reserve(config.inConfs.size());@@ -1655,13 +1721,19 @@ void Eltwise::initSupportedPrimitiveDescriptors() {return {config, impl_type, !factory->isEmpty() ? factory : nullptr};}impl_desc_type impl_type = impl_desc_type::ref;- if (canUseOptimizedImpl) {+ if (useJitExecutor) {#if defined(OPENVINO_ARCH_ARM64)if (mayiuse(dnnl::impl::cpu::aarch64::asimd)) {impl_type = impl_desc_type::jit_asimd;} else {THROW_CPU_NODE_ERR("not supported architecture");}+#elif defined(OPENVINO_ARCH_RISCV64)+ if (mayiuse(ov::intel_cpu::riscv64::gv)) {+ impl_type = impl_desc_type::jit_gv;+ } else {+ OPENVINO_THROW("not supported architecture");+ }#elif defined(OPENVINO_ARCH_X86_64)if (mayiuse(dnnl::impl::cpu::x64::avx512_core)) {impl_type = impl_desc_type::jit_avx512;@@ -1686,7 +1758,7 @@ void Eltwise::initSupportedPrimitiveDescriptors() {}#if defined(OPENVINO_ARCH_ARM64)- bool isBlockedApplicable = (!useJit) && one_of(getOutputShapeAtPort(0).getRank(), 1u, 3u, 4u, 5u);+ bool isBlockedApplicable = (!useJitExecutor) && one_of(getOutputShapeAtPort(0).getRank(), 1u, 3u, 4u, 5u);#elsebool isBlockedApplicable = one_of(getOutputShapeAtPort(0).getRank(), 1u, 3u, 4u, 5u);#endif@@ -1707,38 +1779,36 @@ void Eltwise::initSupportedPrimitiveDescriptors() {currentInBlkDims.resize(inputNum);#if defined(OV_CPU_WITH_ACL)- if (useAcl || useJit) {- eltwiseAttrs = {algorithm, alpha, beta, gamma};-- auto addDesc = [&initDesc, &useJit](std::vector<NodeDesc>& supportedPrimitiveDescriptors,- const LayoutType layoutType) {- auto nodeDesc = initDesc(layoutType, !useJit, useJit);- if (nodeDesc.getExecutorFactory())- supportedPrimitiveDescriptors.emplace_back(nodeDesc);- };+ eltwiseAttrs = {algorithm, alpha, beta, gamma};- // @todo should be handled in scope of selectPreferPrimitiveDescriptor- if (context->getConfig().modelType == Config::ModelType::CNN) {- if (isChannelsFirstApplicable)- addDesc(supportedPrimitiveDescriptors, ChannelsFirst);- addDesc(supportedPrimitiveDescriptors, Planar);- } else {- addDesc(supportedPrimitiveDescriptors, Planar);- if (isChannelsFirstApplicable)- addDesc(supportedPrimitiveDescriptors, ChannelsFirst);- }+ auto addDesc = [&initDesc, &useAcl](std::vector<NodeDesc>& supportedPrimitiveDescriptors,+ const LayoutType layoutType) {+ auto nodeDesc = initDesc(layoutType, useAcl);+ if (nodeDesc.getExecutorFactory())+ supportedPrimitiveDescriptors.emplace_back(nodeDesc);+ };- canUseEltwiseExecPtr = !supportedPrimitiveDescriptors.empty() && !useJit;- if (!supportedPrimitiveDescriptors.empty())- return;+ // @todo should be handled in scope of selectPreferPrimitiveDescriptor+ if (context->getConfig().modelType == Config::ModelType::CNN) {+ if (isChannelsFirstApplicable)+ addDesc(supportedPrimitiveDescriptors, ChannelsFirst);+ addDesc(supportedPrimitiveDescriptors, Planar);+ } else {+ addDesc(supportedPrimitiveDescriptors, Planar);+ if (isChannelsFirstApplicable)+ addDesc(supportedPrimitiveDescriptors, ChannelsFirst);}++ canUseEltwiseExecPtr = !supportedPrimitiveDescriptors.empty() && useAcl;+ if (!supportedPrimitiveDescriptors.empty())+ return;#endif#if defined(OV_CPU_WITH_SHL)eltwiseAttrs = {algorithm, alpha, beta, gamma};- auto addDesc = [&initDesc](std::vector<NodeDesc>& supportedPrimitiveDescriptors, const LayoutType layoutType) {- auto nodeDesc = initDesc(layoutType, true, false);+ auto addDesc = [&](std::vector<NodeDesc>& supportedPrimitiveDescriptors, const LayoutType layoutType) {+ auto nodeDesc = initDesc(layoutType, useSHL);if (nodeDesc.getExecutorFactory())supportedPrimitiveDescriptors.emplace_back(nodeDesc);};@@ -1747,7 +1817,7 @@ void Eltwise::initSupportedPrimitiveDescriptors() {addDesc(supportedPrimitiveDescriptors, ChannelsFirst);addDesc(supportedPrimitiveDescriptors, Planar);- canUseEltwiseExecPtr = !supportedPrimitiveDescriptors.empty();+ canUseEltwiseExecPtr = !supportedPrimitiveDescriptors.empty() && useSHL;if (!supportedPrimitiveDescriptors.empty())return;#endif@@ -2257,7 +2327,7 @@ bool Eltwise::canFuseParent(const NodePtr& parentNode) const {return false;}const auto& input_precisions = parentNode->getOriginalInputPrecisions();- if (!jitIsSupported(this, getAlpha(), getBeta(), getGamma(), input_precisions)) {+ if (!EltwiseJitExecutor::isSupportedOp(this, getAlpha(), getBeta(), getGamma(), input_precisions)) {return false;}#else@@ -2291,7 +2361,7 @@ bool Eltwise::canFuseConvert(const NodePtr& convertNode) const {}// Convert can be fused into Eltwise only if jit implementation is supported#if defined(OPENVINO_ARCH_ARM64)- return jitIsSupported(this, getAlpha(), getBeta(), getGamma());+ return EltwiseJitExecutor::isSupportedOp(this, getAlpha(), getBeta(), getGamma());#elsereturn false;#endif@@ -2318,24 +2388,16 @@ bool Eltwise::canFuse(const NodePtr& node) const {return true;};-#if defined(OPENVINO_ARCH_ARM64)- if (!mayiuse(dnnl::impl::cpu::aarch64::asimd) || (getInputShapeAtPort(0).getRank() > MAX_ELTWISE_DIM_RANK))- return false;-- if (!jitIsSupported(this, getAlpha(), getBeta(), getGamma())) {+ if (!EltwiseJitExecutor::isSupportedOp(this, getAlpha(), getBeta(), getGamma())) {return false;}++#if defined(OPENVINO_ARCH_ARM64) || defined(OPENVINO_ARCH_RISCV64)const auto eltwise = dynamic_cast<const Eltwise*>(node.get());if ((eltwise == nullptr) ||- (!jitIsSupported(eltwise, eltwise->getAlpha(), eltwise->getBeta(), eltwise->getGamma()))) {+ (!EltwiseJitExecutor::isSupportedOp(eltwise, eltwise->getAlpha(), eltwise->getBeta(), eltwise->getGamma()))) {return false;}-#elif defined(OPENVINO_ARCH_X86_64)- if (!mayiuse(dnnl::impl::cpu::x64::sse41) || getInputShapeAtPort(0).getRank() > MAX_ELTWISE_DIM_RANK) {- return false;- }-#else- return false;#endif// TODO: EltwiseLog is supported only via reference executordiff --git a/src/plugins/intel_cpu/src/nodes/executors/aarch64/jit_eltwise.cpp b/src/plugins/intel_cpu/src/nodes/executors/aarch64/jit_eltwise.cppdeleted file mode 100644index 492bf9d2899..00000000000--- a/src/plugins/intel_cpu/src/nodes/executors/aarch64/jit_eltwise.cpp+++ /dev/null@@ -1,126 +0,0 @@-// Copyright (C) 2023 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#include "jit_eltwise.hpp"--#include <utility>-#include <vector>--namespace ov::intel_cpu::executors::aarch64 {--bool JitEltwiseExecutor::isSupported(const Algorithm& algorithm,- const std::vector<ov::element::Type>& input_precisions,- const std::vector<ov::element::Type>& output_precisions,- const float alpha,- const float beta,- const float gamma) {- const auto is_supported = one_of(algorithm,- Algorithm::EltwiseAbs,- Algorithm::EltwiseAdd,- Algorithm::EltwiseClamp,- Algorithm::EltwiseDivide,- Algorithm::EltwiseElu,- Algorithm::EltwiseEqual,- Algorithm::EltwiseExp,- Algorithm::EltwiseFloor,- Algorithm::EltwiseFloorMod,- Algorithm::EltwiseCeiling,- Algorithm::EltwiseNegative,- Algorithm::EltwiseGeluErf,- Algorithm::EltwiseGeluTanh,- Algorithm::EltwiseGreater,- Algorithm::EltwiseGreaterEqual,- Algorithm::EltwiseHswish,- Algorithm::EltwiseIsFinite,- Algorithm::EltwiseIsInf,- Algorithm::EltwiseIsNaN,- Algorithm::EltwiseLess,- Algorithm::EltwiseLessEqual,- Algorithm::EltwiseLogicalAnd,- Algorithm::EltwiseLogicalOr,- Algorithm::EltwiseLogicalNot,- Algorithm::EltwiseLogicalXor,- Algorithm::EltwiseMaximum,- Algorithm::EltwiseMinimum,- Algorithm::EltwiseMish,- Algorithm::EltwiseMod,- Algorithm::EltwiseMultiply,- Algorithm::EltwiseMulAdd,- Algorithm::EltwiseNotEqual,- Algorithm::EltwisePowerStatic,- Algorithm::EltwisePrelu,- Algorithm::EltwiseRelu,- Algorithm::EltwiseRoundHalfAwayFromZero,- Algorithm::EltwiseRoundHalfToEven,- Algorithm::EltwiseSelect,- Algorithm::EltwiseSigmoid,- Algorithm::EltwiseSoftSign,- Algorithm::EltwiseSqrt,- Algorithm::EltwiseSquaredDifference,- Algorithm::EltwiseSubtract,- Algorithm::EltwiseSwish,- Algorithm::EltwiseTanh);- if (!is_supported) {- return false;- }-- if ((algorithm == Algorithm::EltwiseRelu) && ((alpha != 0.f) || (beta != 0.f) || (gamma != 0.f))) {- return false;- }-- const auto check_precisions = [](const std::vector<ov::element::Type>& input_precisions,- const std::vector<ov::element::Type>& output_precisions,- const std::set<ov::element::Type>& supported_precisions) {- if (std::any_of(input_precisions.begin(),- input_precisions.end(),- [&supported_precisions](const ov::element::Type& precision) {- return supported_precisions.find(precision) == supported_precisions.end();- })) {- return false;- }-- if (std::any_of(output_precisions.begin(),- output_precisions.end(),- [&supported_precisions](const ov::element::Type& precision) {- return supported_precisions.find(precision) == supported_precisions.end();- })) {- return false;- }-- return true;- };-- const std::set<ov::element::Type> supported_precisions =- // Divide and Floor (issue #138629) operations are supported for fp32 and fp16 only.- ((algorithm == Algorithm::EltwiseDivide) || (algorithm == Algorithm::EltwiseFloor))- ? std::set<ov::element::Type>{ov::element::f16, ov::element::f32}- : std::set<ov::element::Type>{ov::element::f16,- ov::element::f32,- ov::element::i32,- ov::element::i8,- ov::element::u8};-- if (!check_precisions(input_precisions, output_precisions, supported_precisions)) {- return false;- }-- return true;-}--JitEltwiseExecutor::JitEltwiseExecutor(ExecutorContext::CPtr context) : EltwiseExecutor(std::move(context)) {}--bool JitEltwiseExecutor::init(const EltwiseAttrs& eltwiseAttrs,- const std::vector<MemoryDescPtr>& srcDescs,- const std::vector<MemoryDescPtr>& dstDescs,- const std::vector<EltwisePostOp>& postOps) {- return true;-}--void JitEltwiseExecutor::exec(const std::vector<MemoryCPtr>& src,- const std::vector<MemoryPtr>& dst,- const void* post_ops_data_) {- exec_func();-}--} // namespace ov::intel_cpu::executors::aarch64diff --git a/src/plugins/intel_cpu/src/nodes/executors/aarch64/jit_eltwise.hpp b/src/plugins/intel_cpu/src/nodes/executors/aarch64/jit_eltwise.hppdeleted file mode 100644index 84c901a9343..00000000000--- a/src/plugins/intel_cpu/src/nodes/executors/aarch64/jit_eltwise.hpp+++ /dev/null@@ -1,41 +0,0 @@-// Copyright (C) 2023 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#pragma once--#include "cpu_types.h"-#include "node.h"-#include "nodes/executors/eltwise.hpp"--namespace ov::intel_cpu::executors::aarch64 {--class JitEltwiseExecutor : public EltwiseExecutor {-public:- explicit JitEltwiseExecutor(const ExecutorContext::CPtr context);-- static bool isSupported(const Algorithm& algorithm,- const std::vector<ov::element::Type>& input_precisions,- const std::vector<ov::element::Type>& output_precisions,- const float alpha,- const float beta,- const float gamma);-- bool init(const EltwiseAttrs& eltwiseAttrs,- const std::vector<MemoryDescPtr>& srcDescs,- const std::vector<MemoryDescPtr>& dstDescs,- const std::vector<EltwisePostOp>& postOps) override;-- void exec(const std::vector<MemoryCPtr>& src,- const std::vector<MemoryPtr>& dst,- const void* post_ops_data_) override;-- [[nodiscard]] impl_desc_type getImplType() const override {- return impl_desc_type::asimd;- }--private:- std::function<void()> exec_func;-};--} // namespace ov::intel_cpu::executors::aarch64diff --git a/src/plugins/intel_cpu/src/nodes/executors/eltwise_list.hpp b/src/plugins/intel_cpu/src/nodes/executors/eltwise_list.hppindex 839179c5037..3d5d0222821 100644--- a/src/plugins/intel_cpu/src/nodes/executors/eltwise_list.hpp+++ b/src/plugins/intel_cpu/src/nodes/executors/eltwise_list.hpp@@ -7,7 +7,6 @@#include "eltwise.hpp"#include "executor.hpp"#if defined(OV_CPU_WITH_ACL)-# include "aarch64/jit_eltwise.hpp"# include "acl/acl_eltwise.hpp"#endif#if defined(OV_CPU_WITH_SHL)diff --git a/src/plugins/intel_cpu/src/nodes/executors/shl/shl.hpp b/src/plugins/intel_cpu/src/nodes/executors/shl/shl.hppindex 50a35a89bb7..e8dd53b3c2d 100644--- a/src/plugins/intel_cpu/src/nodes/executors/shl/shl.hpp+++ b/src/plugins/intel_cpu/src/nodes/executors/shl/shl.hpp@@ -169,7 +169,7 @@ private:struct IShlParams {public:virtual ~IShlParams() = default;- [[nodiscard]] virtual void* get(bool allow_empty) const = 0;+ [[nodiscard]] virtual void* get() const = 0;};template <typename T, typename traits = ShlStructureTraits<T>>@@ -190,8 +190,8 @@ struct ShlParams : public ShlStructure<T>, public IShlParams {setAPI(api);}- [[nodiscard]] void* get(bool allow_empty) const override {- return this->ShlStructure<T, traits>::get(allow_empty);+ [[nodiscard]] void* get() const override {+ return this->ShlStructure<T, traits>::get();}private:diff --git a/src/plugins/intel_cpu/src/nodes/kernels/riscv64/cpu_isa_traits.cpp b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/cpu_isa_traits.cppnew file mode 100644index 00000000000..58210d47fa1--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/cpu_isa_traits.cpp@@ -0,0 +1,96 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "cpu_isa_traits.hpp"++#include "xbyak_riscv/xbyak_riscv_util.hpp"++#include "openvino/core/except.hpp"++#include <csignal>+#include <csetjmp>++using namespace Xbyak_riscv;++namespace ov {+namespace intel_cpu {+namespace riscv64 {++namespace {++struct RVVGenerator : public CodeGenerator {+ RVVGenerator() : CodeGenerator(8) {+ // vsetivli is appeared in RVV 1.0+ vsetivli(a0, 10, SEW::e32);+ ret();+ }+};++static thread_local sigjmp_buf jmpbuf;++static bool can_compile_rvv100() {+#if defined(__linux__)+ __sighandler_t signal_handler = [](int signal) {+ siglongjmp(jmpbuf, 1);+ };++ struct sigaction new_sa, old_sa;+ new_sa.sa_handler = signal_handler;+ sigemptyset(&new_sa.sa_mask);+ new_sa.sa_flags = SA_RESETHAND;+ sigaction(SIGILL, &new_sa, &old_sa);++ bool status = false;+ if (sigsetjmp(jmpbuf, 1) == 0) {+ RVVGenerator gen;+ gen.ready();+ const auto caller = gen.getCode<uint32_t (*)()>();+ status = static_cast<bool>(caller());+ }++ // Restore original signal handler+ sigaction(SIGILL, &old_sa, nullptr);++ return status;+#else+ return false;+#endif+}++} // namespace+++bool mayiuse(const cpu_isa_t cpu_isa) {+ const auto cpu = CPU::getInstance();+ switch (cpu_isa) {+ case g: return cpu.hasExtension(RISCVExtension::I) &&+ cpu.hasExtension(RISCVExtension::M) &&+ cpu.hasExtension(RISCVExtension::A) &&+ cpu.hasExtension(RISCVExtension::F) &&+ cpu.hasExtension(RISCVExtension::D);+ // cpu.hasExtension(RISCVExtension::V) checks only RVV support on the device.+ // To figure out RVV version, we try to execute code with RVV1.0 instructions.+ // If there is no `SEGILL`, the device supports RVV1.0.+ // Otherwise we consider that there is no RVV support+ // [TODO] If needed, support other RVV versions+ case gv: return mayiuse(g) && cpu.hasExtension(RISCVExtension::V) && can_compile_rvv100();+ case isa_all: return false;+ case isa_undef: return true;+ }+ return false;+}++std::string isa2str(cpu_isa_t isa) {+ switch(isa) {+ case cpu_isa_t::isa_undef: return "undef";+ case cpu_isa_t::g: return "g";+ case cpu_isa_t::gv: return "gv";+ case cpu_isa_t::isa_all: return "all";+ default: OPENVINO_THROW("Uknown ISA");+ }+}++} // namespace riscv64+} // namespace intel_cpu+} // namespace ovdiff --git a/src/plugins/intel_cpu/src/nodes/kernels/riscv64/cpu_isa_traits.hpp b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/cpu_isa_traits.hppnew file mode 100644index 00000000000..5c05d933edb--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/cpu_isa_traits.hpp@@ -0,0 +1,41 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <string>++namespace ov {+namespace intel_cpu {+namespace riscv64 {++// Maximum number of features + hints that can be specified via bits+static constexpr int cpu_isa_total_bits = sizeof(unsigned) * 8;++enum cpu_isa_bit_t : unsigned {+ i_bit = 1u << 0,+ m_bit = 1u << 1,+ a_bit = 1u << 2,+ f_bit = 1u << 3,+ d_bit = 1u << 4,+ c_bit = 1u << 5,+ v_bit = 1u << 6, // rvv 1.0++ last_bit = 1u << (cpu_isa_total_bits - 1),+};++enum cpu_isa_t : unsigned {+ isa_undef = 0u,+ g = i_bit | m_bit | a_bit | f_bit | d_bit, // G = IMAFD+ gv = g | v_bit,+ isa_all = ~0u & ~last_bit+};++std::string isa2str(cpu_isa_t isa);++bool mayiuse(const cpu_isa_t cpu_isa);++} // namespace riscv64+} // namespace intel_cpu+} // namespace ovdiff --git a/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_generator.cpp b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_generator.cppnew file mode 100644index 00000000000..fb4fbd926e7--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_generator.cpp@@ -0,0 +1,167 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "jit_generator.hpp"++#include "utils/general_utils.h"++namespace ov {+namespace intel_cpu {+namespace riscv64 {++using namespace Xbyak_riscv;++void jit_generator::preamble() {+ const int frame_size = rnd_up((num_abi_save_gpr_regs + 1) * xlen + num_abi_save_fp_gpr_regs * flen, sp_aligment);+ addi(sp, sp, -frame_size);+ int imm = 0;+ for (const auto& gpr : abi_save_gpr_regs) {+ sd(gpr, sp, imm);+ imm += xlen;+ }+ for (const auto& fp_gpr : abi_save_fp_gpr_regs) {+ fsd(fp_gpr, sp, imm);+ imm += flen;+ }+ sd(ra, sp, imm);+}++void jit_generator::postamble() {+ const int frame_size = rnd_up((num_abi_save_gpr_regs + 1) * xlen + num_abi_save_fp_gpr_regs * flen, sp_aligment);+ int imm = 0;+ for (const auto& gpr : abi_save_gpr_regs) {+ ld(gpr, sp, imm);+ imm += xlen;+ }+ for (const auto& fp_gpr : abi_save_fp_gpr_regs) {+ fld(fp_gpr, sp, imm);+ imm += flen;+ }+ ld(ra, sp, imm);++ addi(sp, sp, frame_size);++ ret();+}++void jit_generator::uni_li(const Reg& rd, size_t value) {+ // We have to decompose pseudo-instruction `li` into several small instructions because+ // the immediate field in RISC-V instructions is limited to 12 or 20 bits:+ // - use `lui` (Load Upper Immediate) for high bits.+ // - use `addi` (Load Upper Immediate) for low bits.+ // - use `slli` to combine parts.++ // Check that value is 32-bit value+ if (static_cast<uint64_t>(static_cast<int64_t>(value << 32) >> 32) == value) {+ const uint32_t value32 = static_cast<uint32_t>(value);+ if (value32 == 0) {+ mv(rd, zero);+ return;+ }++ // Add 0x800 to cancel out the signed extension of ADDIW.+ const auto upper_20 = (value32 + 0x800) >> 12 & 0xFFFFF;+ int32_t lower_12 = static_cast<int32_t>(value32) & 0xFFF;+ // Convert to signed 12-bit+ if (lower_12 > 2047) lower_12 -= 4096;+ if (lower_12 < -2048) lower_12 += 4096;++ if (upper_20 != 0) {+ lui(rd, upper_20);+ }++ if (lower_12 != 0) {+ auto src = upper_20 == 0 ? zero : rd;+ addi(rd, src, lower_12);+ }++ return;+ }++ auto trailing_zero = [](uint64_t value) {+ uint32_t bits = 0;+ if (value == 0)+ return bits;+ while ((value & 1) == 0) {+ bits++;+ value >>= 1;+ }+ return bits;+ };++ int32_t lower_12 = static_cast<int32_t>(static_cast<int64_t>(value << 52) >> 52);+ // Convert to signed 12-bit+ if (lower_12 > 2047) lower_12 -= 4096;+ if (lower_12 < -2048) lower_12 += 4096;++ // Add 0x800 to cancel out the signed extension of ADDI.+ uint64_t upper_52 = (value + 0x800) >> 12;+ const uint32_t shift = 12 + trailing_zero(upper_52);+ upper_52 = static_cast<uint64_t>((static_cast<int64_t>(upper_52 >> (shift - 12)) << shift) >> shift);++ uni_li(rd, upper_52);+ slli(rd, rd, shift);+ if (lower_12 != 0) {+ addi(rd, rd, lower_12);+ }+}++void jit_generator::vfneg_vv(const Xbyak_riscv::VReg& vd, const Xbyak_riscv::VReg& vs, Xbyak_riscv::VM vm) {+ vfsgnjn_vv(vd, vs, vs, vm);+}++Xbyak_riscv::LMUL jit_generator::float2lmul(const float lmul) {+ if (lmul == 0.125f) return LMUL::mf8;+ if (lmul == 0.25f) return LMUL::mf4;+ if (lmul == 0.5f) return LMUL::mf2;+ if (lmul == 1.f) return LMUL::m1;+ if (lmul == 2.f) return LMUL::m2;+ if (lmul == 4.f) return LMUL::m4;+ if (lmul == 8.f) return LMUL::m8;+ OPENVINO_THROW(std::string("not supported vector length multiplier: ") + std::to_string(lmul));+}++float jit_generator::lmul2float(const LMUL lmul) {+ switch (lmul) {+ case LMUL::mf8: return 0.125f;+ case LMUL::mf4: return 0.25f;+ case LMUL::mf2: return 0.5f;+ case LMUL::m1: return 1;+ case LMUL::m2: return 2;+ case LMUL::m4: return 4;+ case LMUL::m8: return 8;+ default: {+ OPENVINO_THROW(std::string("not supported vector length multiplier: ") + std::to_string(static_cast<uint32_t>(lmul)));+ }+ }+}++Xbyak_riscv::SEW jit_generator::bytes2sew(const size_t sew) {+ switch(sew) {+ case 1lu: return SEW::e8;+ case 2lu: return SEW::e16;+ case 4lu: return SEW::e32;+ case 8lu: return SEW::e64;+ default: {+ OPENVINO_THROW(std::string("not supported sew: ") + std::to_string(sew));+ }+ }+}++size_t jit_generator::sew2bytes(const Xbyak_riscv::SEW sew) {+ switch(sew) {+ case SEW::e8: return 1lu;+ case SEW::e16: return 2lu;+ case SEW::e32: return 4lu;+ case SEW::e64: return 8lu;+ default: {+ OPENVINO_THROW(std::string("not supported sew: ") + std::to_string(static_cast<uint32_t>(sew)));+ }+ }+}+++} // namespace riscv64+} // namespace intel_cpu+} // namespace ovdiff --git a/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_generator.hpp b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_generator.hppnew file mode 100644index 00000000000..79cf45087a3--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_generator.hpp@@ -0,0 +1,157 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "xbyak_riscv/xbyak_riscv.hpp"+#include "xbyak_riscv/xbyak_riscv_util.hpp"++#include "openvino/core/except.hpp"+++namespace ov {+namespace intel_cpu {+namespace riscv64 {++#define DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_name) \+ const char *name() const override { return #jit_name; } \+ const char *source_file() const override { return __FILE__; }++// RISCV-64 specific registers mapping+// reg | ABI Name | descripion | saved by+// =====================================================+// 32 integer registers+// x0 | zero | Always zero | ---+// x1 | ra | Return address | Caller+// x2 | sp | Stack pointer | Callee+// x3 | gp | Global pointer | ---+// x4 | tp | Thread poiner | ---+// x5 | t0 | Temp / Alt `ra` | Caller+// x6-7 | t1-2 | Temporaries | Caller+// x8 | s0 / fp | Saved reg / frame ptr | Callee+// x9 | s1 | Saved register | Callee+// x10-11 | a0-1 | Func args / return val | Caller+// x12-17 | a2-7 | Function arguments | Caller+// x18-27 | s2-11 | Saved registers | Callee+// x28-31 | t3-6 | Temporaries | Caller+// =====================================================+// 32 floating-point registers+// f0-7 | ft0-7 | FP Temporaries | Caller+// f8-9 | fs0-1 | FP Saved registers | Callee+// f10-11 | fa0-1 | FP args / return val | Caller+// f12-17 | fa2-7 | FP Function arguments | Caller+// f18-27 | fs2-11 | FP Saved registers | Callee+// f28-31 | ft8-11 | FP Temporaries | Caller++class jit_generator : public Xbyak_riscv::CodeGenerator {+public:+ jit_generator(size_t maxSize = Xbyak_riscv::DEFAULT_MAX_CODE_SIZE,+ void *userPtr = Xbyak_riscv::DontSetProtectRWE,+ Xbyak_riscv::Allocator *allocator = 0)+ : Xbyak_riscv::CodeGenerator(maxSize, userPtr, allocator) {}+ virtual ~jit_generator() {}++ const uint8_t *jit_ker() const {+ OPENVINO_ASSERT(jit_ker_,"jit_ker_ is nullable");+ return jit_ker_;+ }++ template <typename... kernel_args_t>+ void operator()(kernel_args_t... args) const {+ using jit_kernel_func_t = void (*)(const kernel_args_t... args);+ auto *fptr = (jit_kernel_func_t)jit_ker_;+ (*fptr)(std::forward<kernel_args_t>(args)...);+ }++ virtual bool create_kernel() {+ generate();+ jit_ker_ = getCode();+ return jit_ker_;+ }++ void preamble();+ void postamble();++ // Disallow char-based labels completely+ void L(const char *label) = delete;+ void L(Xbyak_riscv::Label &label) {+ Xbyak_riscv::CodeGenerator::L(label);+ }++ jit_generator(const jit_generator &) = delete;+ jit_generator &operator=(const jit_generator &) = delete;++ virtual const char *name() const = 0;+ virtual const char *source_file() const = 0;++ // Callee-saved registers+ static constexpr Xbyak_riscv::Reg abi_save_gpr_regs[] = {Xbyak_riscv::s0, Xbyak_riscv::s1, Xbyak_riscv::s2, Xbyak_riscv::s3,+ Xbyak_riscv::s4, Xbyak_riscv::s5, Xbyak_riscv::s6, Xbyak_riscv::s7,+ Xbyak_riscv::s8, Xbyak_riscv::s9, Xbyak_riscv::s10, Xbyak_riscv::s11};+ static constexpr Xbyak_riscv::FReg abi_save_fp_gpr_regs[] = {Xbyak_riscv::fs0, Xbyak_riscv::fs1, Xbyak_riscv::fs2, Xbyak_riscv::fs3,+ Xbyak_riscv::fs4, Xbyak_riscv::fs5, Xbyak_riscv::fs6, Xbyak_riscv::fs7,+ Xbyak_riscv::fs8, Xbyak_riscv::fs9, Xbyak_riscv::fs10, Xbyak_riscv::fs11};+ // ABI-arguments registers+ static constexpr Xbyak_riscv::Reg abi_param_regs[] = {Xbyak_riscv::a0, Xbyak_riscv::a1, Xbyak_riscv::a2, Xbyak_riscv::a3,+ Xbyak_riscv::a4, Xbyak_riscv::a5, Xbyak_riscv::a6, Xbyak_riscv::a7};++ // load size_t value to GPR safely+ void uni_li(const Xbyak_riscv::Reg& rd, size_t value);++ // negative pseudo-instruction+ void vfneg_vv(const Xbyak_riscv::VReg& vd, const Xbyak_riscv::VReg& vs, Xbyak_riscv::VM vm = Xbyak_riscv::VM::unmasked);++ static Xbyak_riscv::LMUL float2lmul(const float lmul);+ static Xbyak_riscv::SEW bytes2sew(const size_t bytes);+ static float lmul2float(const Xbyak_riscv::LMUL lmul);+ static size_t sew2bytes(const Xbyak_riscv::SEW sew);++protected:+ virtual void generate() = 0;++ virtual const uint8_t* getCodeAddress() const {+ return CodeGenerator::getCode();+ }++ const uint8_t *jit_ker_ = nullptr;++ // In the standard RISC-V calling convention, the stack pointer is always kept 16-byte aligned+ const size_t sp_aligment = 16;+ // FP GP register count+ const size_t fp_gpr_count = 32;+ // GP register count+ const size_t gpr_count = 32;+ // Vector register count+ const size_t vec_count = 32;+ // integer gpr byte size+ const size_t xlen = Xbyak_riscv::CPU::getInstance().getXlen() / 8;+ // fp gpr byte size+ const size_t flen = Xbyak_riscv::CPU::getInstance().getFlen() / 8;+ // vector register byte size+ const size_t vlen = Xbyak_riscv::CPU::getInstance().getVlen() / 8;++ const size_t num_abi_save_gpr_regs+ = sizeof(abi_save_gpr_regs) / sizeof(abi_save_gpr_regs[0]);+ const size_t num_abi_save_fp_gpr_regs+ = sizeof(abi_save_fp_gpr_regs) / sizeof(abi_save_fp_gpr_regs[0]);+ const size_t num_abi_param_regs+ = sizeof(abi_param_regs) / sizeof(abi_param_regs[0]);++private:+ const uint8_t* getCode() {+ ready();+ if (!is_initialized()) return nullptr;+ return getCodeAddress();+ }++ static inline bool is_initialized() {+ // At the moment, Xbyak_riscv does not have GetError()+ // so that return dummy result.+ return true;+ }+};++} // namespace riscv64+} // namespace intel_cpu+} // namespace ovdiff --git a/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_uni_eltwise_generic.cpp b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_uni_eltwise_generic.cppnew file mode 100644index 00000000000..7d866aa8313--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_uni_eltwise_generic.cpp@@ -0,0 +1,548 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "jit_uni_eltwise_generic.hpp"++#include "emitters/plugin/riscv64/jit_eltwise_emitters.hpp"+++namespace ov::intel_cpu {+namespace riscv64 {++using namespace Xbyak_riscv;++#define GET_OFF(field) offsetof(jit_eltwise_call_args_ptrs, field)++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+jit_uni_eltwise_generic<isa>::jit_uni_eltwise_generic(jit_eltwise_params jep, std::vector<EltwiseData> eltwise_data)+ : jit_uni_eltwise_kernel(std::move(jep)),+ jit_generator(),+ eltwise_data_(std::move(eltwise_data)) {}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_uni_eltwise_generic<isa>::generate() {+ static const std::vector<element::Type> exec_precisions_priority = { ov::element::i8, ov::element::u8, element::i32, element::f32 };+ auto const exec_prc =+ eltwise_precision_helper::get_precision(jep_.inputs_number, jep_.src_prc, eltwise_data_, exec_precisions_priority);++ eltwise_emitter = create_eltwise_emitter(eltwise_data_.front(), exec_prc);+ for (size_t i = 1; i < eltwise_data_.size(); ++i) {+ post_op_emitters.push_back(create_eltwise_emitter(eltwise_data_[i], exec_prc));+ }++ // Labels in Xbyak for RISC-V work with absolute addresses which are defined during call `L(label)`:+ // If we store label to the GPR and only then call `L(label)` to define data section,+ // during kernel compilation null-address will be stored to this GPRs since address will be inited later.+ // To use data section, we define it before kernel execution.+ data_section_address = const_cast<uint8_t*>(getCurr());+ emit_data();++ // After data section, we define code section+ code_section_address = const_cast<uint8_t*>(getCurr());+ preamble();++ const auto& jep = jep_;+ const int offset_count = jep.input_size - 1;++ // ptrs initializing+ if (jep.use_runtime_ptrs) {+ auto init_ptrs_with_offsets = [&](Reg reg) {+ for (int j = 0; j < offset_count; j++) {+ ld(reg_tmp_0, reg_offsets, static_cast<int>(j * sizeof(size_t)));+ ld(reg_tmp_1, reg_indexes, static_cast<int>(j * sizeof(size_t)));+ mul(reg_tmp_0, reg_tmp_0, reg_tmp_1);+ add(reg, reg, reg_tmp_0);+ }+ };++ for (size_t i = 0; i < jep.inputs_number; i++) {+ ld(reg_offsets, reg_const_params, GET_OFF(src_offsets) + i * sizeof(size_t));+ ld(src_gpr(i), reg_const_params, GET_OFF(src_ptr[0]) + i * sizeof(size_t));+ init_ptrs_with_offsets(src_gpr(i));+ }++ ld(reg_offsets, reg_const_params, GET_OFF(dst_offsets));+ ld(dst_gpr(), reg_const_params, GET_OFF(dst_ptr));+ init_ptrs_with_offsets(dst_gpr());++ ld(reg_work_amount, reg_const_params, GET_OFF(work_amount));+ } else {+ auto init_ptrs_with_offsets = [&](Reg reg, const std::vector<size_t>& offsets) {+ for (int j = 0; j < offset_count; j++) {+ if (jep_.dims[j] != 1 && offsets[j] != 0) {+ uni_li(reg_tmp_0, static_cast<int>(offsets[j]));+ ld(reg_tmp_1, reg_indexes, static_cast<int>(j * sizeof(size_t)));+ mul(reg_tmp_0, reg_tmp_0, reg_tmp_1);+ add(reg, reg, reg_tmp_0);+ }+ }+ };++ for (size_t i = 0; i < jep.inputs_number; i++) {+ ld(src_gpr(i), reg_const_params, GET_OFF(src_ptr[0]) + i * sizeof(size_t));+ init_ptrs_with_offsets(src_gpr(i), jep.src_offsets[i]);+ }++ ld(dst_gpr(), reg_const_params, GET_OFF(dst_ptr));+ init_ptrs_with_offsets(dst_gpr(), jep.dst_offsets);++ uni_li(reg_work_amount, static_cast<int>(jep.work_amount));+ }++ exec_lmul = compute_exec_lmul(exec_prc);+ exec_sew = bytes2sew(exec_prc.size());+ OPENVINO_ASSERT(lmul2float(exec_lmul) <= lmul2float(get_max_lmul(exec_prc)),+ "Unsupported LMUL configuration for the kernel");++ // We set other values for `current` variables to force first call `update_vlen`+ current_lmul = LMUL::m2;+ current_sew = SEW::e8;++ for (size_t i = 0; i < jep.inputs_number; i++) {+ if (jep.src_size[i] == 1) {+ load_vector(i, src_gpr(i), reg_work_amount, jep_.src_prc[i], exec_prc, true);+ }+ }++ size_t min_src_size = jep.dst_size;+ for (size_t i = 0; i < jep.inputs_number; i++) {+ if (jep.src_size[i] != 1)+ min_src_size = std::min(min_src_size, jep.src_size[i]);+ }++ if (min_src_size == jep.dst_size) {+ Label loop_begin;+ Label loop_end;++ L(loop_begin);+ {+ beqz(reg_work_amount, loop_end);++ // We should call `update_vlen` on each loop iteration to get correct `reg_vlen` in iterations:+ // `rg_vlen` should be valid in in tail loop+ update_vlen(reg_work_amount, exec_sew, exec_lmul, true);++ for (size_t i = 0; i < jep.inputs_number; i++) {+ if (jep.src_size[i] != 1) {+ load_vector(i, src_gpr(i), reg_work_amount, jep_.src_prc[i], exec_prc, false);+ }+ }++ compute_eltwise_op();+ apply_post_ops();++ store_vector(reg_work_amount, exec_prc, jep_.dst_prc);++ sub(reg_work_amount, reg_work_amount, reg_vlen);+ bnez(reg_work_amount, loop_begin);+ }+ L(loop_end);+ }++ if (min_src_size != jep.dst_size) {+ bool is_valid_configuration = true;+ if (jep.dst_size % min_src_size != 0)+ is_valid_configuration = false;++ for (size_t i = 0; i < jep.inputs_number; i++) {+ if (jep.src_size[i] != 1 && jep.src_size[i] != min_src_size && jep.src_size[i] != jep.dst_size)+ is_valid_configuration = false;+ }++ OPENVINO_ASSERT(is_valid_configuration, "Eltwise jitter has invalid configuration for Eltwise node");++ Label loop_begin;+ Label loop_end;+ Label inner_loop_begin;++ L(loop_begin);+ {+ beqz(reg_work_amount, loop_end);++ for (size_t i = 0; i < jep.inputs_number; i++) {+ if (jep.src_size[i] != 1) {+ mv(src_aux_gpr(i), src_gpr(i));+ }+ }++ uni_li(reg_loop_step, min_src_size);+ L(inner_loop_begin);+ {+ // We should call `update_vlen` on each loop iteration to get correct `reg_vlen` in iterations:+ // `rg_vlen` should be valid in in tail loop+ update_vlen(reg_loop_step, exec_sew, exec_lmul, true);++ for (size_t i = 0; i < jep.inputs_number; i++) {+ if (jep.src_size[i] != 1) {+ load_vector(i, src_aux_gpr(i), reg_loop_step, jep_.src_prc[i], exec_prc, false);+ }+ }++ compute_eltwise_op();+ apply_post_ops();++ store_vector(reg_loop_step, exec_prc, jep_.dst_prc);++ sub(reg_loop_step, reg_loop_step, reg_vlen);+ bnez(reg_loop_step, inner_loop_begin);+ }++ const auto reg_tmp = reg_loop_step;+ for (size_t i = 0; i < jep.inputs_number; i++) {+ if (jep.src_size[i] == jep.dst_size) {+ uni_li(reg_tmp, jep.src_prc[i].size() * min_src_size);+ add(src_gpr(i), src_gpr(i), reg_tmp);+ }+ }++ uni_li(reg_loop_step, min_src_size);+ sub(reg_work_amount, reg_work_amount, reg_loop_step);+ j_(loop_begin);+ }++ L(loop_end);+ }++ postamble();+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_uni_eltwise_generic<isa>::update_vlen(const Xbyak_riscv::Reg& gpr_work_amount, Xbyak_riscv::SEW sew, Xbyak_riscv::LMUL lmul, bool force) {+ if (!force && current_lmul == lmul && current_sew == sew)+ return;++ vsetvli(reg_vlen, gpr_work_amount, sew, lmul);+ current_lmul = lmul;+ current_sew = sew;++ const auto byte_shift = static_cast<const uint32_t>(sew2bytes(sew) >> 1);+ slli(reg_bvlen, reg_vlen, byte_shift);+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_uni_eltwise_generic<isa>::load_vector(size_t vec_idx, const Xbyak_riscv::Reg& gpr_ptr, const Xbyak_riscv::Reg& gpr_work_amount,+ const ov::element::Type& src_prc, const ov::element::Type& dst_prc, bool broadcast) {+ // If input data type is I8/U8 and EXEC_LMUL = m1 and EXEC_SEW = e32 (fp32, for example), we have to update parameters of vector registers+ // to load [BVLEN / e32 x LMUL] I8/U8 values to register for the following conversion to exec precision.+ // Since I8/U8 is sew=e8, we should reduce lmul from `EXEC_LMUL = m1` to `EXEC_LMUL / (EXEC_SEW / e8) = m1 / (e32 / e8) = m1/4`.+ // It allow us to load the needed count of I8/U8 values to vector for the further conversion to exec prc.+ const auto needed_lmul = float2lmul(static_cast<float>(src_prc.size()) / static_cast<float>(dst_prc.size()) * lmul2float(exec_lmul));+ const auto needed_sew = bytes2sew(src_prc.size());+ update_vlen(gpr_work_amount, needed_sew, needed_lmul);++ OPENVINO_ASSERT(dst_prc.size() == sew2bytes(exec_sew), "Incompatible execution SEW and dst SEW");+ OPENVINO_ASSERT(one_of(dst_prc, ov::element::f32, ov::element::i32), "Unsupported dst prc");++ switch (src_prc) {+ case ov::element::f32:+ case ov::element::i32: {+ if (broadcast) {+ lw(aux_gpr(0), gpr_ptr);+ vmv_v_x(src_vec(vec_idx), aux_gpr(0));+ } else {+ vle32_v(src_vec(vec_idx), gpr_ptr);+ add(gpr_ptr, gpr_ptr, reg_bvlen);+ }+ break;+ }+ case ov::element::i8:+ case ov::element::u8: {+ if (broadcast) {+ lb(aux_gpr(0), gpr_ptr);+ vmv_v_x(aux_vec(), aux_gpr(0));+ } else {+ vle8_v(aux_vec(), gpr_ptr);+ add(gpr_ptr, gpr_ptr, reg_bvlen);+ }++ update_vlen(gpr_work_amount, exec_sew, exec_lmul);+ if (src_prc.is_signed())+ vsext_vf4(src_vec(vec_idx), aux_vec());+ else+ vzext_vf4(src_vec(vec_idx), aux_vec());+ break;+ }+ default: {+ OPENVINO_THROW("src_prc " + src_prc.to_string() + " is not supported, dst_prc is " + dst_prc.to_string());+ }+ }++ if (one_of(dst_prc, ov::element::f32) && one_of(src_prc, ov::element::i8, ov::element::u8, ov::element::i32))+ vfcvt_f_x_v(src_vec(vec_idx), src_vec(vec_idx)); // int32 -> fp32++ if (one_of(dst_prc, ov::element::i32) && one_of(src_prc, ov::element::f16, ov::element::f32))+ vfcvt_rtz_x_f_v(src_vec(vec_idx), src_vec(vec_idx)); // fp32 -> int32 (round-toward-zero)+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_uni_eltwise_generic<isa>::store_vector(const Xbyak_riscv::Reg& gpr_work_amount, const ov::element::Type& src_prc, const ov::element::Type& dst_prc) {+ OPENVINO_ASSERT(src_prc.size() == sew2bytes(exec_sew), "Incompatible execution SEW and src SEW");+ OPENVINO_ASSERT(one_of(src_prc, ov::element::f32, ov::element::i32), "Unsupported src prc");++ if (one_of(src_prc, ov::element::f32) && one_of(dst_prc, ov::element::i8, ov::element::u8, ov::element::i32))+ vfcvt_rtz_x_f_v(dst_vec(), dst_vec()); // fp32 -> int32 (round-toward-zero)++ if (one_of(src_prc, ov::element::i32) && one_of(dst_prc, ov::element::f16, ov::element::f32))+ vfcvt_f_x_v(dst_vec(), dst_vec()); // int32 -> fp32++ switch (dst_prc) {+ case ov::element::f32:+ case ov::element::i32: {+ vse32_v(dst_vec(), dst_gpr());+ add(dst_gpr(), dst_gpr(), reg_bvlen);+ break;+ }+ case ov::element::i8:+ case ov::element::u8: {+ auto vnclip = [&](const VReg& dst, const VReg& src, float lmul_c, size_t sew) {+ const auto needed_lmul = float2lmul(lmul_c * lmul2float(exec_lmul));+ const auto needed_sew = bytes2sew(sew);+ update_vlen(gpr_work_amount, needed_sew, needed_lmul);+ if (src_prc.is_signed())+ vnclip_wi(dst, src, 0);+ else+ vnclipu_wi(dst, src, 0);+ };+ vnclip(aux_vec(), dst_vec(), 0.5f, 2);+ vnclip(dst_vec(), aux_vec(), 0.25f, 1);++ vse8_v(dst_vec(), dst_gpr());+ add(dst_gpr(), dst_gpr(), reg_bvlen);+ break;+ }+ default: {+ OPENVINO_THROW("dst " + dst_prc.to_string() + " is not supported, src is " + src_prc.to_string());+ }+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+Xbyak_riscv::LMUL jit_uni_eltwise_generic<isa>::compute_exec_lmul(const ov::element::Type& exec_prc) const {+ // TODO: Support any LMUL values+ if (!eltwise_emitter->is_lmul_supported())+ return LMUL::m1;+ for (const auto& post_op_emitter : post_op_emitters) {+ if (!post_op_emitter->is_lmul_supported())+ return LMUL::m1;+ }+ return get_max_lmul(exec_prc);+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+Xbyak_riscv::LMUL jit_uni_eltwise_generic<isa>::get_max_lmul(const ov::element::Type& exec_prc) const {+ OPENVINO_ASSERT(eltwise_emitter, "Eltwise emitter is missed");++ const auto input_count = jep_.inputs_number;+ const auto output_count = 1;+ size_t max_aux_vec_count = eltwise_emitter->aux_vecs_count();+ for (const auto& post_op_emitter : post_op_emitters) {+ max_aux_vec_count = std::max(max_aux_vec_count, post_op_emitter->aux_vecs_count());+ }++ // aux vec is needed for intermediate conversion in load/store+ if (jep_.src_prc[input_count - 1].size() < exec_prc.size() || jep_.dst_prc.size() < exec_prc.size())+ max_aux_vec_count = std::max(max_aux_vec_count, 1lu);++ const auto needed_vec_count = input_count + output_count + max_aux_vec_count + 1; // 1 - mask vec register+ const auto mul = static_cast<size_t>(vec_count / needed_vec_count);+ OPENVINO_ASSERT(mul != 0, "Incorrect configuration!");+ if (mul < 2) return LMUL::m1;+ if (mul < 4) return LMUL::m2;+ if (mul < 8) return LMUL::m4;+ return LMUL::m8;+}++namespace {+struct EltwiseEmitterContext {+ std::shared_ptr<jit_emitter> emitter;+ ov::intel_cpu::riscv64::jit_generator* host;+ ov::intel_cpu::riscv64::cpu_isa_t host_isa;+ const EltwiseData& opData;+ ov::element::Type exec_prc;+};++template <typename T>+struct EltwiseEmitter {+ void operator()(EltwiseEmitterContext& ctx) {+ ctx.emitter = std::make_shared<T>(ctx.host, ctx.host_isa, ctx.exec_prc);+ }+};++template <>+struct EltwiseEmitter<jit_clamp_emitter> {+ void operator()(EltwiseEmitterContext& ctx) {+ ctx.emitter = std::make_shared<jit_clamp_emitter>(ctx.host, ctx.host_isa, ctx.opData.alpha, ctx.opData.beta, ctx.exec_prc);+ }+};++template <>+struct EltwiseEmitter<jit_power_static_emitter> {+ void operator()(EltwiseEmitterContext& ctx) {+ ctx.emitter = std::make_shared<jit_power_static_emitter>(ctx.host, ctx.host_isa, ctx.opData.alpha, ctx.opData.beta, ctx.opData.gamma, ctx.exec_prc);+ }+};++template <>+struct EltwiseEmitter<jit_relu_emitter> {+ void operator()(EltwiseEmitterContext& ctx) {+ ctx.emitter = std::make_shared<jit_relu_emitter>(ctx.host, ctx.host_isa, ctx.opData.alpha, ctx.exec_prc);+ }+};+} // namespace++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+std::shared_ptr<jit_emitter> jit_uni_eltwise_generic<isa>::create_eltwise_emitter(const EltwiseData& data,+ const ov::element::Type& exec_prec) {+ EltwiseEmitterContext ctx = {nullptr, this, isa, data, exec_prec};++ OV_SWITCH(+ intel_cpu,+ EltwiseEmitter,+ ctx,+ data.algo,+ OV_CASE(Algorithm::EltwiseAdd, jit_add_emitter),+ OV_CASE(Algorithm::EltwiseClamp, jit_clamp_emitter),+ OV_CASE(Algorithm::EltwiseDivide, jit_divide_emitter),+ OV_CASE(Algorithm::EltwiseExp, jit_exp_emitter),+ OV_CASE(Algorithm::EltwiseMulAdd, jit_mul_add_emitter),+ OV_CASE(Algorithm::EltwiseMultiply, jit_multiply_emitter),+ OV_CASE(Algorithm::EltwisePowerStatic, jit_power_static_emitter),+ OV_CASE(Algorithm::EltwisePrelu, jit_prelu_emitter),+ OV_CASE(Algorithm::EltwiseRelu, jit_relu_emitter),+ OV_CASE(Algorithm::EltwiseSigmoid, jit_sigmoid_emitter),+ OV_CASE(Algorithm::EltwiseSubtract, jit_subtract_emitter));++ if (!ctx.emitter) {+ OPENVINO_THROW("Unsupported operation type '" + algToString(data.algo) + "' for Eltwise emitter");+ }++ return ctx.emitter;+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_uni_eltwise_generic<isa>::compute_eltwise_op() const {+ OPENVINO_ASSERT(eltwise_emitter, "Eltwise emitter is missed for code emission!");++ std::vector<size_t> in_idxs;+ for (size_t i = 0; i < eltwise_emitter->get_inputs_num(); i++) {+ in_idxs.push_back(src_vec(i).getIdx());+ }++ std::vector<size_t> out_idxs;+ out_idxs.push_back(dst_vec().getIdx());++ const auto max_aux_fp_gpr_available = get_max_aux_fp_gpr_count();+ const auto max_aux_gpr_available = get_max_aux_gpr_count();+ const auto max_aux_vec_available = get_max_aux_vec_count();++ std::vector<size_t> aux_vec_idxs;+ for (size_t i = 0; i < std::min(eltwise_emitter->aux_vecs_count(), max_aux_vec_available); i++) {+ aux_vec_idxs.push_back(aux_vec(i).getIdx());+ }++ std::vector<size_t> aux_gpr_idxs;+ for (size_t i = 0; i < std::min(eltwise_emitter->aux_gprs_count(), max_aux_gpr_available); i++) {+ aux_gpr_idxs.push_back(aux_gpr(i).getIdx());+ }++ std::vector<size_t> aux_fp_gpr_idxs;+ for (size_t i = 0; i < std::min(eltwise_emitter->aux_fp_gprs_count(), max_aux_fp_gpr_available); i++) {+ aux_fp_gpr_idxs.push_back(aux_fp_gpr(i).getIdx());+ }++ eltwise_emitter->emit_code(in_idxs, out_idxs, aux_vec_idxs, aux_gpr_idxs, aux_fp_gpr_idxs);+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_uni_eltwise_generic<isa>::apply_post_ops() const {+ int input_idx = eltwise_emitter->get_inputs_num();+ int eltwise_post_op_idx = 0;+ for (size_t i = 1; i < eltwise_data_.size(); i++) {+ OPENVINO_ASSERT(post_op_emitters[eltwise_post_op_idx], "Post-op emitter is missed for code emission!");+ std::vector<size_t> in_idxs;+ in_idxs.push_back(dst_vec().getIdx());+ for (size_t j = 1; j < post_op_emitters[eltwise_post_op_idx]->get_inputs_num(); j++) {+ in_idxs.push_back(src_vec(input_idx++).getIdx());+ }++ std::vector<size_t> out_idxs;+ out_idxs.push_back(dst_vec().getIdx());++ const auto max_aux_fp_gpr_available = get_max_aux_fp_gpr_count();+ const auto max_aux_gpr_available = get_max_aux_gpr_count();+ const auto max_aux_vec_available = get_max_aux_vec_count();++ std::vector<size_t> aux_vec_idxs;+ for (size_t i = 0; i < std::min(eltwise_emitter->aux_vecs_count(), max_aux_vec_available); i++) {+ aux_vec_idxs.push_back(aux_vec(i).getIdx());+ }++ std::vector<size_t> aux_gpr_idxs;+ for (size_t i = 0; i < std::min(eltwise_emitter->aux_gprs_count(), max_aux_gpr_available); i++) {+ aux_gpr_idxs.push_back(aux_gpr(i).getIdx());+ }++ std::vector<size_t> aux_fp_gpr_idxs;+ for (size_t i = 0; i < std::min(eltwise_emitter->aux_fp_gprs_count(), max_aux_fp_gpr_available); i++) {+ aux_fp_gpr_idxs.push_back(aux_fp_gpr(i).getIdx());+ }++ post_op_emitters[eltwise_post_op_idx]->emit_code(in_idxs, out_idxs, aux_vec_idxs, aux_gpr_idxs, aux_fp_gpr_idxs);++ eltwise_post_op_idx++;+ }+}++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+void jit_uni_eltwise_generic<isa>::emit_data() const {+ OPENVINO_ASSERT(eltwise_emitter, "Eltwise emitter is missed for data emission!");+ eltwise_emitter->emit_data();+ for (size_t i = 0; i < post_op_emitters.size(); i++) {+ OPENVINO_ASSERT(post_op_emitters[i], "Post-op emitter is missed for data emission!");+ post_op_emitters[i]->emit_data();+ }+}++template struct jit_uni_eltwise_generic<cpu_isa_t::gv>;++} // namespace riscv64++namespace {+template <typename T>+struct SupportedPrecisions {+ void operator()(std::set<std::vector<element::Type>>& precisions) {+ precisions = T::get_supported_precisions();+ }+};+} // namespace++using namespace riscv64;++std::set<std::vector<element::Type>> eltwise_precision_helper::get_supported_precisions(const Algorithm& algo) {+ std::set<std::vector<element::Type>> precisions;++ OV_SWITCH(intel_cpu,+ SupportedPrecisions,+ precisions,+ algo,+ OV_CASE(Algorithm::EltwiseAdd, jit_add_emitter),+ OV_CASE(Algorithm::EltwiseClamp, jit_clamp_emitter),+ OV_CASE(Algorithm::EltwiseDivide, jit_divide_emitter),+ OV_CASE(Algorithm::EltwiseExp, jit_exp_emitter),+ OV_CASE(Algorithm::EltwiseMulAdd, jit_mul_add_emitter),+ OV_CASE(Algorithm::EltwiseMultiply, jit_multiply_emitter),+ OV_CASE(Algorithm::EltwisePowerStatic, jit_power_static_emitter),+ OV_CASE(Algorithm::EltwisePrelu, jit_prelu_emitter),+ OV_CASE(Algorithm::EltwiseRelu, jit_relu_emitter),+ OV_CASE(Algorithm::EltwiseSigmoid, jit_sigmoid_emitter),+ OV_CASE(Algorithm::EltwiseSubtract, jit_subtract_emitter));++ if (precisions.empty()) {+ OPENVINO_THROW("Unsupported operation type for Eltwise emitter");+ }++ return precisions;+}++} // ov::intel_cpudiff --git a/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_uni_eltwise_generic.hpp b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_uni_eltwise_generic.hppnew file mode 100644index 00000000000..68c3200c5b0--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/kernels/riscv64/jit_uni_eltwise_generic.hpp@@ -0,0 +1,198 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "jit_generator.hpp"++#include "cpu_isa_traits.hpp"+#include "emitters/plugin/riscv64/jit_emitter.hpp"+#include "nodes/executors/eltwise.hpp"+#include "nodes/kernels/jit_eltwise_common.hpp"+#include "utils/cpu_utils.hpp"+#include "utils/general_utils.h"++namespace ov::intel_cpu::riscv64 {++template <ov::intel_cpu::riscv64::cpu_isa_t isa>+struct jit_uni_eltwise_generic : public jit_uni_eltwise_kernel, jit_generator {+public:+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_eltwise_generic)++ jit_uni_eltwise_generic(jit_eltwise_params jep, std::vector<EltwiseData> eltwise_data);+ jit_uni_eltwise_generic() = default;++ void create_ker() override {+ jit_generator::create_kernel();+ ker_ = (decltype(ker_))jit_ker();+ }++ void generate() override;+++protected:+ const uint8_t* getCodeAddress() const override {+ return code_section_address;+ }++private:+ // Register mapping in the kernel:+ // x0-x4 | system | not used+ // x5 | temp | reg_tmp_0 / reg_work_amount+ // x6 | temp | reg_tmp_1 / reg_vlen+ // x7 | temp | reg_offsets / reg_loop_step+ // x8 | saved | reg_bvlen+ // x9 | saved | dst_gpr+ // x10 | abi | reg_const_params / emitter_aux_gpr+ // x11 | abi | reg_indexes / emitter_aux_gpr+ // x12 | abi | emitter_aux_gpr+ // x13 | abi | emitter_aux_gpr+ // x14 | abi | emitter_aux_gpr+ // x15 | abi | emitter_aux_gpr+ // x16 | abi | emitter_aux_gpr+ // x17 | abi | emitter_aux_gpr+ // x18 | saved | src_gpr+ // x19 | saved | src_gpr+ // x20 | saved | src_gpr+ // x21 | saved | src_gpr+ // x22 | saved | src_gpr+ // x23 | saved | src_gpr+ // x24 | saved | src_gpr+ // x25 | saved | src_aux_gpr+ // x26 | saved | src_aux_gpr+ // x27 | saved | src_aux_gpr+ // x28 | temp | src_aux_gpr+ // x29 | temp | src_aux_gpr+ // x30 | temp | src_aux_gpr+ // x31 | temp | src_aux_gpr++ inline Xbyak_riscv::Reg dst_gpr() const {+ // x9+ return Xbyak_riscv::Reg(9);+ }++ inline Xbyak_riscv::Reg src_gpr(const int idx) const {+ // x18-24+ OPENVINO_ASSERT(idx >= 0 && idx < MAX_ELTWISE_INPUTS, "src reg " + std::to_string(idx) + " is not supported");+ const auto start = 18;+ return Xbyak_riscv::Reg(start + idx);+ }++ inline Xbyak_riscv::Reg src_aux_gpr(const int idx) const {+ // saved registers: x[18 + input_number]-x[18 + input_number + MAX_ELTWISE_INPUTS], in max case x25-x31+ OPENVINO_ASSERT(idx >= 0 && idx < MAX_ELTWISE_INPUTS, "src aux reg " + std::to_string(idx) + " is not supported");+ const auto start = static_cast<size_t>(src_gpr(0).getIdx()) + jep_.inputs_number;+ return Xbyak_riscv::Reg(start + idx);+ }++ inline Xbyak_riscv::Reg aux_gpr(const int idx) const {+ // saved and temp registers: x[18 + 2 * input_number]-x[31] and then abi x10-x17+ const auto saved_start = src_aux_gpr(0).getIdx() + jep_.inputs_number;+ if (saved_start + idx < gpr_count)+ return Xbyak_riscv::Reg(saved_start + idx);+ const auto abi_start = Xbyak_riscv::a0.getIdx();+ const auto new_idx = idx - (gpr_count - saved_start);+ if (abi_start + new_idx < static_cast<size_t>(src_gpr(0).getIdx()))+ return Xbyak_riscv::Reg(abi_start + new_idx);+ OPENVINO_THROW("Cannot allocate aux register for emitter!");+ }++ inline Xbyak_riscv::FReg aux_fp_gpr(const int idx) const {+ OPENVINO_ASSERT(idx >= 0 && idx < static_cast<int>(fp_gpr_count), "Cannot allocate aux fp register for emitter!");+ return Xbyak_riscv::FReg(idx);+ }++ inline Xbyak_riscv::VReg mask_vec() const {+ return Xbyak_riscv::VReg(0);+ }++ inline Xbyak_riscv::VReg dst_vec() const {+ const auto lmul_v = static_cast<int>(lmul2float(exec_lmul));+ // v0 - mask register+ const auto vec_idx = lmul_v == 0 ? 1 : lmul_v;+ return Xbyak_riscv::VReg(vec_idx);+ }++ inline Xbyak_riscv::VReg src_vec(const int idx) const {+ OPENVINO_ASSERT(idx >= 0 && idx < MAX_ELTWISE_INPUTS, "src aux reg " + std::to_string(idx) + " is not supported");+ const auto lmul_v = static_cast<int>(lmul2float(exec_lmul));+ // v0 and v[lmul] - mask and dst registers+ const auto vec_idx = (idx + 2) * (lmul_v == 0 ? 1 : lmul_v);+ OPENVINO_ASSERT(static_cast<size_t>(vec_idx) < (vec_count - lmul_v + 1),+ "src vector reg " + std::to_string(vec_idx) + " is not supported");+ return Xbyak_riscv::VReg(vec_idx);+ }++ inline Xbyak_riscv::VReg aux_vec(const int idx = 0) const {+ const auto vstart = src_vec(jep_.inputs_number + 1).getIdx();+ const auto lmul_v = static_cast<int>(lmul2float(exec_lmul));+ const auto vec_idx = vstart + idx * (lmul_v == 0 ? 1 : lmul_v);+ OPENVINO_ASSERT(static_cast<size_t>(vec_idx) < (vec_count - lmul_v + 1),+ "aux vector reg " + std::to_string(vec_idx) + " is not supported");+ return Xbyak_riscv::VReg(vec_idx);+ }++ inline size_t get_max_aux_fp_gpr_count() const {+ return fp_gpr_count;+ }++ inline size_t get_max_aux_gpr_count() const {+ const auto st_count = gpr_count - (static_cast<size_t>(src_aux_gpr(0).getIdx()) + jep_.inputs_number + 1);+ return st_count + num_abi_param_regs;+ }++ inline size_t get_max_aux_vec_count() const {+ auto lmul_v = static_cast<int>(lmul2float(exec_lmul));+ if (lmul_v == 0) lmul_v = 1;+ const auto single_vec_count = vec_count - (src_vec(0).getIdx() + jep_.inputs_number + 1) * lmul_v;+ return static_cast<size_t>(single_vec_count / lmul_v);+ }++ std::shared_ptr<jit_emitter> create_eltwise_emitter(const EltwiseData& data, const ov::element::Type& exec_prec);++ // Update reg_vlen reg_bvlen using current `work_amount` and target `lmul` and `sew`+ void update_vlen(const Xbyak_riscv::Reg& gpr_work_amount, Xbyak_riscv::SEW sew, Xbyak_riscv::LMUL lmul, bool force = false);++ // Load vector with pointer increment if needed (no broadcasting)+ void load_vector(size_t vec_idx, const Xbyak_riscv::Reg& gpr_ptr, const Xbyak_riscv::Reg& gpr_work_amount,+ const ov::element::Type& src_prc, const ov::element::Type& dst_prc, bool broadcast);+ // Store vector with pointer increment+ void store_vector(const Xbyak_riscv::Reg& gpr_work_amount, const ov::element::Type& src_prc, const ov::element::Type& dst_prc);++ Xbyak_riscv::LMUL compute_exec_lmul(const ov::element::Type& exec_prc) const;+ Xbyak_riscv::LMUL get_max_lmul(const ov::element::Type& exec_prc) const;++ Xbyak_riscv::Reg reg_const_params = Xbyak_riscv::a0;+ Xbyak_riscv::Reg reg_indexes = Xbyak_riscv::a1;++ Xbyak_riscv::Reg reg_tmp_0 = Xbyak_riscv::t0;+ Xbyak_riscv::Reg reg_tmp_1 = Xbyak_riscv::t1;+ Xbyak_riscv::Reg reg_offsets = Xbyak_riscv::t2;+ Xbyak_riscv::Reg reg_work_amount = reg_tmp_0;+ Xbyak_riscv::Reg reg_vlen = reg_tmp_1;+ Xbyak_riscv::Reg reg_loop_step = reg_offsets;+ Xbyak_riscv::Reg reg_bvlen = Xbyak_riscv::x8; // vlen in bytes++ Xbyak_riscv::LMUL current_lmul = Xbyak_riscv::LMUL::m1;+ Xbyak_riscv::SEW current_sew = Xbyak_riscv::SEW::e32;++ // TODO: Support any LMUL values+ Xbyak_riscv::LMUL exec_lmul = Xbyak_riscv::LMUL::m1;+ Xbyak_riscv::SEW exec_sew = Xbyak_riscv::SEW::e32;++ void compute_eltwise_op() const;+ void apply_post_ops() const;+ void emit_data() const;++ const std::vector<EltwiseData> eltwise_data_;+ const std::vector<ov::intel_cpu::Type> ops_list_;++ std::shared_ptr<jit_emitter> eltwise_emitter = nullptr;+ std::vector<std::shared_ptr<jit_emitter>> post_op_emitters;++ uint8_t* data_section_address = nullptr;+ uint8_t* code_section_address = nullptr;+};++} // ov::intel_cpu::riscv64diff --git a/src/plugins/intel_cpu/src/onednn/iml_type_mapper.cpp b/src/plugins/intel_cpu/src/onednn/iml_type_mapper.cppindex b59d89678c6..25d29aa23e5 100644--- a/src/plugins/intel_cpu/src/onednn/iml_type_mapper.cpp+++ b/src/plugins/intel_cpu/src/onednn/iml_type_mapper.cpp@@ -60,6 +60,7 @@ impl_desc_type parse_impl_name(std::string impl_desc_name) {SEARCH_WORD(kleidiai);SEARCH_WORD(shl);SEARCH_WORD(asimd);+ SEARCH_WORD(gv);if ((res & impl_desc_type::avx2) != impl_desc_type::avx2 &&(res & impl_desc_type::avx512) != impl_desc_type::avx512) {SEARCH_WORD(avx);@@ -153,6 +154,8 @@ const char* impl_type_to_string(impl_desc_type type) {CASE(jit_sve512);CASE(shl);CASE(gemm_shl);+ CASE(gv);+ CASE(jit_gv);CASE(kleidiai);CASE(gemm_kleidiai);diff --git a/src/plugins/intel_cpu/src/onednn/iml_type_mapper.h b/src/plugins/intel_cpu/src/onednn/iml_type_mapper.hindex f9766fafea4..70d3ee6c9ee 100644--- a/src/plugins/intel_cpu/src/onednn/iml_type_mapper.h+++ b/src/plugins/intel_cpu/src/onednn/iml_type_mapper.h@@ -51,7 +51,9 @@ enum impl_desc_type : int64_t {// shl backendshl = 1ll << 32,- kleidiai = 1ll << 33,+ gv = 1ll << 33,++ kleidiai = 1ll << 34,// real typesref_any = ref | any,@@ -123,7 +125,9 @@ enum impl_desc_type : int64_t {jit_sve512 = jit | sve512,gemm_shl = gemm | shl,- gemm_kleidiai = gemm | kleidiai+ gemm_kleidiai = gemm | kleidiai,++ jit_gv = jit | gv};std::vector<std::string> extractTypeAndImplName(const std::string& priority);diff --git a/src/plugins/intel_cpu/tests/functional/CMakeLists.txt b/src/plugins/intel_cpu/tests/functional/CMakeLists.txtindex fab83bce7ab..2e3a18c8472 100644--- a/src/plugins/intel_cpu/tests/functional/CMakeLists.txt+++ b/src/plugins/intel_cpu/tests/functional/CMakeLists.txt@@ -9,11 +9,18 @@ if(SUGGEST_OVERRIDE_SUPPORTED)set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-suggest-override")endif()+# To allow test classes call `mayiuse(gv)`+if(RISCV64)+ set(CPU_ISA_TRAITS_RV64 $<TARGET_PROPERTY:openvino_intel_cpu_plugin,SOURCE_DIR>/src/nodes/kernels/riscv64/cpu_isa_traits.hpp+ $<TARGET_PROPERTY:openvino_intel_cpu_plugin,SOURCE_DIR>/src/nodes/kernels/riscv64/cpu_isa_traits.cpp)+endif()+add_library(cpuUtils STATIC$<TARGET_PROPERTY:openvino_intel_cpu_plugin,SOURCE_DIR>/src/utils/rt_info/memory_formats_attribute.hpp$<TARGET_PROPERTY:openvino_intel_cpu_plugin,SOURCE_DIR>/src/utils/rt_info/memory_formats_attribute.cpp$<TARGET_PROPERTY:openvino_intel_cpu_plugin,SOURCE_DIR>/src/utils/precision_support.h- $<TARGET_PROPERTY:openvino_intel_cpu_plugin,SOURCE_DIR>/src/utils/precision_support.cpp)+ $<TARGET_PROPERTY:openvino_intel_cpu_plugin,SOURCE_DIR>/src/utils/precision_support.cpp+ ${CPU_ISA_TRAITS_RV64})set(CPU_UTILS_LINK_LIBRARIES openvino::runtime)set(CPU_UTILS_INCLUDE_PATHS)if(OV_CPU_WITH_ACL)@@ -24,6 +31,9 @@ if(OV_CPU_WITH_DNNL)list(APPEND CPU_UTILS_LINK_LIBRARIES dnnl)list(APPEND CPU_UTILS_INCLUDE_PATHS $<TARGET_PROPERTY:openvino_intel_cpu_plugin,SOURCE_DIR>/thirdparty/onednn/src)endif()+if(RISCV64)+ list(APPEND CPU_UTILS_LINK_LIBRARIES xbyak_riscv)+endif()target_link_libraries(cpuUtils PRIVATE ${CPU_UTILS_LINK_LIBRARIES})target_include_directories(cpuUtils PUBLIC ${CPU_UTILS_INCLUDE_PATHS})diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/activation.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/activation.cppindex 1af2d2d96dd..d0f3a623c1d 100644--- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/activation.cpp+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/activation.cpp@@ -8,6 +8,9 @@#include "utils/cpu_test_utils.hpp"#include "common_test_utils/node_builders/activation.hpp"#include "shared_test_classes/single_op/activation.hpp"+#if defined(OPENVINO_ARCH_RISCV64)+# include "nodes/kernels/riscv64/cpu_isa_traits.hpp"+#endifusing namespace CPUTestUtils;using namespace ov::test::utils;@@ -219,18 +222,27 @@ std::string ActivationLayerCPUTest::getPrimitiveType(const utils::ActivationTypereturn "ref";}return "acl";-#elif defined(OV_CPU_WITH_SHL)+#endif+#if defined(OPENVINO_ARCH_RISCV64)+ if (ov::intel_cpu::riscv64::mayiuse(ov::intel_cpu::riscv64::gv)) {+ if ((activation_type == utils::ActivationTypes::Clamp) ||+ (activation_type == utils::ActivationTypes::Exp) ||+ (activation_type == utils::ActivationTypes::Negative) ||+ (activation_type == utils::ActivationTypes::Relu) ||+ (activation_type == utils::ActivationTypes::PReLu) ||+ (activation_type == utils::ActivationTypes::Sigmoid) )+ return "jit";+ }+#if defined(OV_CPU_WITH_SHL)if ((activation_type == utils::ActivationTypes::Relu) ||(activation_type == utils::ActivationTypes::PReLu) ||(activation_type == utils::ActivationTypes::Exp) ||(activation_type == utils::ActivationTypes::Clamp)) {return "shl";- } else {- return "ref";}-#else- return CPUTestsBase::getPrimitiveType();#endif+#endif+ return CPUTestsBase::getPrimitiveType();}TEST_P(ActivationLayerCPUTest, CompareWithRefs) {diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/eltwise.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/eltwise.cppindex 1fea147aa63..f69a587986d 100644--- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/eltwise.cpp+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/eltwise.cpp@@ -12,6 +12,10 @@#include "openvino/runtime/properties.hpp"#include "utils/cpu_test_utils.hpp"+#if defined(OPENVINO_ARCH_RISCV64)+# include "nodes/kernels/riscv64/cpu_isa_traits.hpp"+#endif+using namespace CPUTestUtils;namespace ov {@@ -271,18 +275,27 @@ std::string EltwiseLayerCPUTest::getPrimitiveType(const utils::EltwiseTypes& elt} else {return "acl";}-#elif defined(OV_CPU_WITH_SHL)+#endif++#if defined(OPENVINO_ARCH_RISCV64)+ if (ov::intel_cpu::riscv64::mayiuse(ov::intel_cpu::riscv64::gv)) {+ if ((eltwise_type == utils::EltwiseTypes::ADD) ||+ (eltwise_type == utils::EltwiseTypes::SUBTRACT) ||+ (eltwise_type == utils::EltwiseTypes::MULTIPLY) ||+ (eltwise_type == utils::EltwiseTypes::DIVIDE)) {+ return "jit";+ }+ }+#if defined(OV_CPU_WITH_SHL)if ((eltwise_type == utils::EltwiseTypes::ADD) ||(eltwise_type == utils::EltwiseTypes::SUBTRACT) ||(eltwise_type == utils::EltwiseTypes::MULTIPLY) ||(eltwise_type == utils::EltwiseTypes::DIVIDE)) {return "shl";- } else {- return "ref";}-#else- return CPUTestsBase::getPrimitiveType();#endif+#endif+ return CPUTestsBase::getPrimitiveType();}TEST_P(EltwiseLayerCPUTest, CompareWithRefs) {diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/riscv64/eltwise.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/riscv64/eltwise.cppnew file mode 100644index 00000000000..bcbaef47124--- /dev/null+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/riscv64/eltwise.cpp@@ -0,0 +1,71 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "custom/single_layer_tests/classes/eltwise.hpp"+#include "utils/cpu_test_utils.hpp"+#include "utils/fusing_test_utils.hpp"+#include "utils/filter_cpu_info.hpp"+#include "nodes/kernels/riscv64/cpu_isa_traits.hpp"++using namespace CPUTestUtils;++namespace ov {+namespace test {+namespace Eltwise {+namespace {++/*+ * The motivation of this test is to validate different input and output precisions of Eltwise Op.+ * If IO data type is not supported by jit emitter, they should be converted+ * to supported types on operation inputs and outputs in JIT kernel+*/++static const std::vector<ov::test::utils::EltwiseTypes> ops() {+ // JIT us supported only when `gv` is available+ if (ov::intel_cpu::riscv64::mayiuse(ov::intel_cpu::riscv64::gv)) {+ return { utils::EltwiseTypes::ADD };+ }+ return {};+}++const std::vector<ov::AnyMap>& config_infer_prc_f32() {+ static const std::vector<ov::AnyMap> additionalConfig = {+ {{ov::hint::inference_precision.name(), ov::element::f32}},+ };+ return additionalConfig;+}++const std::vector<std::vector<ov::Shape>>& inputShapes() {+ static const std::vector<std::vector<ov::Shape>> inputShapes = {+ {{2, 4, 4, 1}},+ {{2, 4, 4, 128}},+ {{2, 4, 4, 131}},+ {{2, 17, 5, 4}},+ {{2, 19, 5, 4}, {1, 19, 1, 1}},+ {{2, 19, 5, 1}, {1, 19, 1, 4}},+ };+ return inputShapes;+}++const auto params_4D_jit = ::testing::Combine(+ ::testing::Combine(+ ::testing::ValuesIn(static_shapes_to_test_representation(inputShapes())),+ ::testing::ValuesIn(ops()),+ ::testing::ValuesIn(secondaryInputTypes()),+ ::testing::ValuesIn(opTypes()),+ ::testing::ValuesIn({ ElementType::i8, ElementType::u8, ElementType::f16, ElementType::i32, ElementType::f32 }),+ ::testing::Values(ov::element::dynamic),+ ::testing::Values(ov::element::dynamic),+ ::testing::Values(ov::test::utils::DEVICE_CPU),+ ::testing::ValuesIn(config_infer_prc_f32())),+ ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D())),+ ::testing::Values(emptyFusingSpec),+ ::testing::Values(false));++INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_jit, EltwiseLayerCPUTest, params_4D_jit, EltwiseLayerCPUTest::getTestCaseName);++} // namespace+} // namespace Eltwise+} // namespace test+} // namespace ovdiff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cppindex 23ff626e516..4cffac67409 100644--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp@@ -6,6 +6,9 @@#include "functional_test_utils/skip_tests_config.hpp"#include "openvino/runtime/system_conf.hpp"#include "utils/precision_support.h"+#if defined(OPENVINO_ARCH_RISCV64)+# include "nodes/kernels/riscv64/cpu_isa_traits.hpp"+#endif#include <string>#include <vector>@@ -451,9 +454,7 @@ std::vector<std::string> disabledTestPatterns() {retVector.emplace_back(R"(nightly_/NmsRotatedOpTest.CompareWithRefs/IS=\(\[\?.\?.5\]_\[\?.\?.\?\]\)_TS=\{\(7.35.5\)_\(7.30.35\)\}_\{\(7.35.5\)_\(7.100.35\)\}_\{\(7.35.5\)_\(7.133.35\)\}__BoxPrc=f16_MaxPrc=i64_ThrPrc=f16_OutPrc=i64_MaxBox=10_IouThr=0.5_ScoreThr=0.4_SortDesc=False_Clockwise=True_ConstIn=\{True,True,True,True,True\}_Device=CPU)");// Accuracy problemretVector.emplace_back(R"(.*InterpolateCubic_Layout_Test.*)");- retVector.emplace_back(R"(.*smoke_EltwiseChain/EltwiseChainTest.CompareWithRefs.*InPRC3=i32_Op0=Div_Op1.*)");retVector.emplace_back(R"(.*nightly_(static|dynamic)/UniqueLayerTestCPU.*dataPrc=i8.*)");- retVector.emplace_back(R"(.*smoke_CompareWithRefs_static.*eltwise_op_type=Div.*model_type=i32.*)");retVector.emplace_back(R"(.*smoke_Interpolate_Basic/InterpolateLayerTest.Inference/IS=\(\[\]\)_TS=\{\(1.4.6.6\)\}_TS=\(1.4.8.8\)_InterpolateMode=cubic_ShapeCalcMode=sizes_CoordinateTransformMode=tf_half_pixel_for_nn_NearestMode=round_prefer_floor_cube_coef=-0.75_Antialias=0_PB=\(0.0.0.0\)_PE=\(0.0.1.1\)_Axes=\(0.1.2.3\)_Scales=\(1.1.1.33333.1.33333\)_netType=f32_trgDev=CPU.*)");retVector.emplace_back(R"(.*smoke_MaxPool_ExplicitPad_CeilRounding.*K\(3.3\)_S\(\d.2\).*PE\(0.2\).*)");// Incorrect number of input or output memory formats@@ -482,6 +483,13 @@ std::vector<std::string> disabledTestPatterns() {retVector.emplace_back(R"(.*proposal_params/.*)");// Quantized models unsupportedretVector.emplace_back(R"(.*Quantized.*)");++ if (!ov::intel_cpu::riscv64::mayiuse(ov::intel_cpu::riscv64::gv)) {+ // Integer division is supported only by JIT Executor which is available on platforms with GV instruction sets.+ // In other cases there might be accuracy problems.+ retVector.emplace_back(R"(.*smoke_EltwiseChain/EltwiseChainTest.CompareWithRefs.*InPRC3=i32_Op0=Div_Op1.*)");+ retVector.emplace_back(R"(.*smoke_CompareWithRefs_static.*eltwise_op_type=Div.*model_type=i32.*)");+ }#endif#if !defined(OPENVINO_ARCH_X86_64)diff --git a/src/plugins/intel_cpu/thirdparty/CMakeLists.txt b/src/plugins/intel_cpu/thirdparty/CMakeLists.txtindex 293b5d384ed..62eafb55cb0 100644--- a/src/plugins/intel_cpu/thirdparty/CMakeLists.txt+++ b/src/plugins/intel_cpu/thirdparty/CMakeLists.txt@@ -184,4 +184,10 @@ if(ENABLE_KLEIDIAI_FOR_CPU)ov_install_static_lib(kleidiai ${OV_CPACK_COMP_CORE})endif()+if(RISCV64)+ set(XBYAK_RISCV_V ON)+ add_subdirectory(xbyak_riscv)+ ov_install_static_lib(xbyak_riscv ${OV_CPACK_COMP_CORE})+endif()+ov_add_onednn()diff --git a/src/plugins/intel_cpu/thirdparty/xbyak_riscv b/src/plugins/intel_cpu/thirdparty/xbyak_riscvnew file mode 160000index 00000000000..0233c991a0c--- /dev/null+++ b/src/plugins/intel_cpu/thirdparty/xbyak_riscv@@ -0,0 +1 @@+Subproject commit 0233c991a0c1608be671dc63d63f450e7a2178ff