Skip to content

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

[Snippets][CPU][RV64] Implement load/store + convert fusion (#36156)

Arseniy Obolenskiy206e79f17261
diff --git a/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_conversion_helpers.cpp b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_conversion_helpers.cpp
new file mode 100644
index 00000000000..ca3135e77a9
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_conversion_helpers.cpp
@@ -0,0 +1,303 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "jit_conversion_helpers.hpp"
+
+#include <cstddef>
+#include <nodes/kernels/riscv64/cpu_isa_traits.hpp>
+#include <nodes/kernels/riscv64/jit_generator.hpp>
+#include <utility>
+
+#include "emitters/plugin/riscv64/jit_emitter.hpp"
+#include "emitters/utils.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "utils/general_utils.h"
+#include "xbyak_riscv/xbyak_riscv.hpp"
+#include "xbyak_riscv/xbyak_riscv_csr.hpp"
+
+namespace ov::intel_cpu::riscv64::jit_conversion {
+namespace {
+
+std::pair<Xbyak_riscv::SEW, Xbyak_riscv::LMUL> get_vtype_for_element_size(const ov::element::Type& type) {
+ switch (type.size()) {
+ case 4UL:
+ return {Xbyak_riscv::SEW::e32, Xbyak_riscv::LMUL::m1};
+ case 2UL:
+ return {Xbyak_riscv::SEW::e16, Xbyak_riscv::LMUL::mf2};
+ case 1UL:
+ return {Xbyak_riscv::SEW::e8, Xbyak_riscv::LMUL::mf4};
+ default:
+ OV_CPU_JIT_EMITTER_THROW("Unsupported precision size for vtype setup: ", type);
+ }
+}
+
+bool requires_zvfh(const ov::element::Type& input_type, const ov::element::Type& output_type) {
+ return input_type != output_type && any_of(ov::element::f16, input_type, output_type);
+}
+
+} // namespace
+
+bool is_supported_convert_precision(const ov::element::Type& precision) {
+ return any_of(precision, ov::element::f32, ov::element::i32, ov::element::f16, ov::element::i8, ov::element::u8);
+}
+
+void validate_convert_precision(const ov::element::Type& input_type, const ov::element::Type& output_type) {
+ OV_CPU_JIT_EMITTER_ASSERT(is_supported_convert_precision(input_type) && is_supported_convert_precision(output_type),
+ "Unsupported conversion: ",
+ input_type,
+ " -> ",
+ output_type);
+ OV_CPU_JIT_EMITTER_ASSERT(
+ !requires_zvfh(input_type, output_type) || mayiuse(ov::intel_cpu::riscv64::cpu_isa_t::gv_zvfh),
+ "Unsupported Zvfh conversion: ",
+ input_type,
+ " -> ",
+ output_type);
+}
+
+Xbyak_riscv::SEW byte_size_to_sew(size_t byte_size) {
+ switch (byte_size) {
+ case 1UL:
+ return Xbyak_riscv::SEW::e8;
+ case 2UL:
+ return Xbyak_riscv::SEW::e16;
+ case 4UL:
+ return Xbyak_riscv::SEW::e32;
+ default:
+ OV_CPU_JIT_EMITTER_THROW("Unsupported memory access byte size: ", byte_size);
+ }
+}
+
+void emit_convert_process(ov::intel_cpu::riscv64::jit_generator_t* h,
+ const Xbyak_riscv::VReg& src,
+ const Xbyak_riscv::VReg& dst,
+ const ov::element::Type& input_type,
+ const ov::element::Type& output_type,
+ arithmetic_mode mode,
+ const Xbyak_riscv::Reg& avl) {
+ const auto is_saturation = mode == arithmetic_mode::saturation;
+ h->csrr(avl, Xbyak_riscv::CSR::vl);
+
+ const auto set_type_for = [&](const ov::element::Type& type) {
+ const auto [sew, lmul] = get_vtype_for_element_size(type);
+ set_vector_length(h, 0, sew, {}, lmul, &avl);
+ };
+ const auto move_if_needed = [&](const Xbyak_riscv::VReg& from, const Xbyak_riscv::VReg& to) {
+ if (from.getIdx() != to.getIdx()) {
+ h->vmv_v_v(to, from);
+ }
+ };
+ const auto narrow_i32_to_i8 = [&](const Xbyak_riscv::VReg& from, const Xbyak_riscv::VReg& to) {
+ set_type_for(ov::element::i16);
+ if (is_saturation) {
+ h->vnclip_wi(to, from, 0);
+ } else {
+ h->vnsra_wi(to, from, 0);
+ }
+ set_type_for(ov::element::i8);
+ if (is_saturation) {
+ h->vnclip_wi(to, to, 0);
+ } else {
+ h->vnsra_wi(to, to, 0);
+ }
+ };
+ const auto narrow_i32_to_u8 = [&](const Xbyak_riscv::VReg& from, const Xbyak_riscv::VReg& to) {
+ set_type_for(ov::element::i16);
+ if (is_saturation) {
+ h->vnclipu_wi(to, from, 0);
+ } else {
+ h->vnsrl_wi(to, from, 0);
+ }
+ set_type_for(ov::element::i8);
+ if (is_saturation) {
+ h->vnclipu_wi(to, to, 0);
+ } else {
+ h->vnsrl_wi(to, to, 0);
+ }
+ };
+ const auto widen_f16_to_f32 = [&](const Xbyak_riscv::VReg& from, const Xbyak_riscv::VReg& to) {
+ set_type_for(ov::element::f16);
+ h->vfwcvt_f_f_v(to, from);
+ set_type_for(ov::element::f32);
+ };
+ const auto narrow_f32_to_f16 = [&](const Xbyak_riscv::VReg& from, const Xbyak_riscv::VReg& to) {
+ set_type_for(ov::element::f16);
+ h->vfncvt_f_f_w(to, from);
+ };
+ const auto widen_i8_to_i32 = [&](const Xbyak_riscv::VReg& from, const Xbyak_riscv::VReg& to, const bool is_signed) {
+ set_type_for(ov::element::i32);
+ if (is_signed) {
+ h->vsext_vf4(to, from);
+ } else {
+ h->vzext_vf4(to, from);
+ }
+ };
+ const auto saturate_i32_to_u8 = [&](const Xbyak_riscv::VReg& from, const Xbyak_riscv::VReg& to) {
+ set_type_for(ov::element::i32);
+ move_if_needed(from, to);
+ h->vfcvt_f_x_v(to, to);
+ h->vfcvt_xu_f_v(to, to);
+ narrow_i32_to_u8(to, to);
+ };
+
+ if (input_type == output_type) {
+ set_type_for(input_type);
+ move_if_needed(src, dst);
+ return;
+ }
+
+ if (output_type == ov::element::f32) {
+ if (input_type == ov::element::f16) {
+ widen_f16_to_f32(src, dst);
+ } else if (input_type == ov::element::i32) {
+ set_type_for(ov::element::i32);
+ h->vfcvt_f_x_v(dst, src);
+ set_type_for(ov::element::f32);
+ } else if (input_type == ov::element::i8) {
+ widen_i8_to_i32(src, dst, true);
+ h->vfcvt_f_x_v(dst, dst);
+ set_type_for(ov::element::f32);
+ } else if (input_type == ov::element::u8) {
+ widen_i8_to_i32(src, dst, false);
+ h->vfcvt_f_xu_v(dst, dst);
+ set_type_for(ov::element::f32);
+ } else {
+ OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
+ }
+ return;
+ }
+
+ if (output_type == ov::element::f16) {
+ if (input_type == ov::element::f32) {
+ narrow_f32_to_f16(src, dst);
+ } else if (input_type == ov::element::i32) {
+ set_type_for(ov::element::i32);
+ h->vfcvt_f_x_v(dst, src);
+ if (is_saturation) {
+ set_type_for(ov::element::f32);
+ }
+ narrow_f32_to_f16(dst, dst);
+ } else if (input_type == ov::element::i8) {
+ widen_i8_to_i32(src, dst, true);
+ h->vfcvt_f_x_v(dst, dst);
+ if (is_saturation) {
+ set_type_for(ov::element::f32);
+ }
+ narrow_f32_to_f16(dst, dst);
+ } else if (input_type == ov::element::u8) {
+ widen_i8_to_i32(src, dst, false);
+ h->vfcvt_f_xu_v(dst, dst);
+ if (is_saturation) {
+ set_type_for(ov::element::f32);
+ }
+ narrow_f32_to_f16(dst, dst);
+ } else {
+ OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
+ }
+ return;
+ }
+
+ if (output_type == ov::element::i32) {
+ if (input_type == ov::element::f32) {
+ set_type_for(ov::element::f32);
+ if (is_saturation) {
+ h->vfcvt_x_f_v(dst, src);
+ } else {
+ h->vfcvt_rtz_x_f_v(dst, src);
+ }
+ set_type_for(ov::element::i32);
+ } else if (input_type == ov::element::f16) {
+ widen_f16_to_f32(src, dst);
+ if (is_saturation) {
+ h->vfcvt_x_f_v(dst, dst);
+ } else {
+ h->vfcvt_rtz_x_f_v(dst, dst);
+ }
+ set_type_for(ov::element::i32);
+ } else if (any_of(input_type, ov::element::i8, ov::element::u8)) {
+ widen_i8_to_i32(src, dst, input_type == ov::element::i8);
+ } else {
+ OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
+ }
+ return;
+ }
+
+ if (output_type == ov::element::i8) {
+ if (input_type == ov::element::f32) {
+ set_type_for(ov::element::f32);
+ if (is_saturation) {
+ h->vfcvt_x_f_v(dst, src);
+ } else {
+ h->vfcvt_rtz_x_f_v(dst, src);
+ }
+ set_type_for(ov::element::i32);
+ narrow_i32_to_i8(dst, dst);
+ } else if (input_type == ov::element::f16) {
+ widen_f16_to_f32(src, dst);
+ if (is_saturation) {
+ h->vfcvt_x_f_v(dst, dst);
+ } else {
+ h->vfcvt_rtz_x_f_v(dst, dst);
+ }
+ set_type_for(ov::element::i32);
+ narrow_i32_to_i8(dst, dst);
+ } else if (input_type == ov::element::i32) {
+ narrow_i32_to_i8(src, dst);
+ } else if (input_type == ov::element::u8) {
+ if (is_saturation) {
+ widen_i8_to_i32(src, dst, false);
+ narrow_i32_to_i8(dst, dst);
+ } else {
+ set_type_for(ov::element::i8);
+ move_if_needed(src, dst);
+ }
+ } else {
+ OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
+ }
+ return;
+ }
+
+ if (output_type == ov::element::u8) {
+ if (input_type == ov::element::f32) {
+ set_type_for(ov::element::f32);
+ if (is_saturation) {
+ h->vfcvt_xu_f_v(dst, src);
+ } else {
+ h->vfcvt_rtz_x_f_v(dst, src);
+ }
+ set_type_for(ov::element::i32);
+ narrow_i32_to_u8(dst, dst);
+ } else if (input_type == ov::element::f16) {
+ widen_f16_to_f32(src, dst);
+ if (is_saturation) {
+ h->vfcvt_xu_f_v(dst, dst);
+ } else {
+ h->vfcvt_rtz_x_f_v(dst, dst);
+ }
+ set_type_for(ov::element::i32);
+ narrow_i32_to_u8(dst, dst);
+ } else if (input_type == ov::element::i32) {
+ if (is_saturation) {
+ saturate_i32_to_u8(src, dst);
+ } else {
+ narrow_i32_to_u8(src, dst);
+ }
+ } else if (input_type == ov::element::i8) {
+ if (is_saturation) {
+ widen_i8_to_i32(src, dst, true);
+ saturate_i32_to_u8(dst, dst);
+ } else {
+ set_type_for(ov::element::i8);
+ move_if_needed(src, dst);
+ }
+ } else {
+ OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
+ }
+ return;
+ }
+
+ OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
+}
+
+} // namespace ov::intel_cpu::riscv64::jit_conversion
diff --git a/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_conversion_helpers.hpp b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_conversion_helpers.hpp
new file mode 100644
index 00000000000..54f4bd331d8
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_conversion_helpers.hpp
@@ -0,0 +1,33 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <nodes/kernels/riscv64/jit_generator.hpp>
+
+#include "openvino/core/type/element_type.hpp"
+#include "xbyak_riscv/xbyak_riscv.hpp"
+
+namespace ov::intel_cpu::riscv64 {
+
+enum class arithmetic_mode : uint8_t { saturation, truncation };
+
+namespace jit_conversion {
+
+bool is_supported_convert_precision(const ov::element::Type& precision);
+void validate_convert_precision(const ov::element::Type& input_type, const ov::element::Type& output_type);
+Xbyak_riscv::SEW byte_size_to_sew(size_t byte_size);
+
+void emit_convert_process(ov::intel_cpu::riscv64::jit_generator_t* h,
+ const Xbyak_riscv::VReg& src,
+ const Xbyak_riscv::VReg& dst,
+ const ov::element::Type& input_type,
+ const ov::element::Type& output_type,
+ arithmetic_mode mode,
+ const Xbyak_riscv::Reg& avl);
+
+} // namespace jit_conversion
+} // namespace ov::intel_cpu::riscv64
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.cpp
index ed0333b3235..bf44c911c4b 100644
--- 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.cpp
@@ -11,10 +11,10 @@
#include <cstdlib>
#include <memory>
#include <set>
-#include <utility>
#include <vector>
#include "common/utils.hpp"
+#include "emitters/plugin/riscv64/jit_conversion_helpers.hpp"
#include "emitters/plugin/riscv64/jit_emitter.hpp"
#include "emitters/utils.hpp"
#include "nodes/kernels/riscv64/cpu_isa_traits.hpp"
@@ -39,23 +39,6 @@ using namespace Xbyak_riscv;
#define CONST_1_F 0x3f800000 // 1.F
-static std::pair<SEW, LMUL> getVTypeForElementSize(const ov::element::Type& type) {
- switch (type.size()) {
- case 4UL:
- return {SEW::e32, LMUL::m1};
- case 2UL:
- return {SEW::e16, LMUL::mf2};
- case 1UL:
- return {SEW::e8, LMUL::mf4};
- default:
- OV_CPU_JIT_EMITTER_THROW("Unsupported precision size for vtype setup: ", type);
- }
-}
-
-static bool requires_zvfh(const ov::element::Type& input_type, const ov::element::Type& output_type) {
- return input_type != output_type && any_of(ov::element::f16, input_type, output_type);
-}
-
/// ABS ///
jit_abs_emitter::jit_abs_emitter(ov::intel_cpu::riscv64::jit_generator_t* host,
ov::intel_cpu::riscv64::cpu_isa_t host_isa,
@@ -152,20 +135,7 @@ jit_convert_saturation_emitter::jit_convert_saturation_emitter(ov::intel_cpu::ri
input_type = convert->get_input_element_type(0);
output_type = convert->get_output_element_type(0);
- const bool is_supported_input =
- any_of(input_type, ov::element::f32, ov::element::f16, ov::element::i32, ov::element::i8, ov::element::u8);
- const bool is_supported_output =
- any_of(output_type, ov::element::f32, ov::element::f16, ov::element::i32, ov::element::i8, ov::element::u8);
- OV_CPU_JIT_EMITTER_ASSERT(is_supported_input && is_supported_output,
- "Unsupported conversion: ",
- input_type,
- " -> ",
- output_type);
- OV_CPU_JIT_EMITTER_ASSERT(!requires_zvfh(input_type, output_type) || mayiuse(cpu_isa_t::gv_zvfh),
- "Unsupported Zvfh conversion: ",
- input_type,
- " -> ",
- output_type);
+ jit_conversion::validate_convert_precision(input_type, output_type);
}
size_t jit_convert_saturation_emitter::get_inputs_num() const {
@@ -190,170 +160,9 @@ void jit_convert_saturation_emitter::emit_isa(const std::vector<size_t>& in_vec_
const std::vector<size_t>& out_vec_idxs) const {
auto src = VReg(in_vec_idxs[0]);
auto dst = VReg(out_vec_idxs[0]);
- auto avl = Reg(aux_gpr_idxs[0]);
- h->csrr(avl, CSR::vl);
-
- const auto set_type_for = [&](const ov::element::Type& type) {
- const auto [sew, lmul] = getVTypeForElementSize(type);
- set_vector_length(h, 0, sew, aux_gpr_idxs, lmul, &avl);
- };
- const auto move_if_needed = [&](const VReg& from, const VReg& to) {
- if (from.getIdx() != to.getIdx()) {
- h->vmv_v_v(to, from);
- }
- };
-
- const auto narrow_i32_to_i8 = [&](const VReg& from, const VReg& to) {
- set_type_for(ov::element::i16);
- h->vnclip_wi(to, from, 0);
- set_type_for(ov::element::i8);
- h->vnclip_wi(to, to, 0);
- };
- const auto narrow_i32_to_u8 = [&](const VReg& from, const VReg& to) {
- set_type_for(ov::element::i16);
- h->vnclipu_wi(to, from, 0);
- set_type_for(ov::element::i8);
- h->vnclipu_wi(to, to, 0);
- };
- const auto widen_f16_to_f32 = [&](const VReg& from, const VReg& to) {
- set_type_for(ov::element::f16);
- h->vfwcvt_f_f_v(to, from);
- set_type_for(ov::element::f32);
- };
- const auto narrow_f32_to_f16 = [&](const VReg& from, const VReg& to) {
- set_type_for(ov::element::f16);
- h->vfncvt_f_f_w(to, from);
- };
- const auto widen_i8_to_i32 = [&](const VReg& from, const VReg& to, const bool is_signed) {
- set_type_for(ov::element::i32);
- if (is_signed) {
- h->vsext_vf4(to, from);
- } else {
- h->vzext_vf4(to, from);
- }
- };
- const auto saturate_i32_to_u8 = [&](const VReg& from, const VReg& to) {
- // Convert through FP32 to clamp negatives to 0 before narrowing to unsigned.
- set_type_for(ov::element::i32);
- move_if_needed(from, to);
- h->vfcvt_f_x_v(to, to);
- h->vfcvt_xu_f_v(to, to);
- narrow_i32_to_u8(to, to);
- };
-
- if (input_type == output_type) {
- set_type_for(input_type);
- move_if_needed(src, dst);
- return;
- }
-
- if (output_type == ov::element::f32) {
- if (input_type == ov::element::f16) {
- widen_f16_to_f32(src, dst);
- } else if (input_type == ov::element::i32) {
- set_type_for(ov::element::i32);
- h->vfcvt_f_x_v(dst, src);
- set_type_for(ov::element::f32);
- } else if (input_type == ov::element::i8) {
- widen_i8_to_i32(src, dst, true);
- h->vfcvt_f_x_v(dst, dst);
- set_type_for(ov::element::f32);
- } else if (input_type == ov::element::u8) {
- widen_i8_to_i32(src, dst, false);
- h->vfcvt_f_xu_v(dst, dst);
- set_type_for(ov::element::f32);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
- }
- return;
- }
-
- if (output_type == ov::element::f16) {
- if (input_type == ov::element::f32) {
- narrow_f32_to_f16(src, dst);
- } else if (input_type == ov::element::i32) {
- set_type_for(ov::element::i32);
- h->vfcvt_f_x_v(dst, src);
- set_type_for(ov::element::f32);
- narrow_f32_to_f16(dst, dst);
- } else if (input_type == ov::element::i8) {
- widen_i8_to_i32(src, dst, true);
- h->vfcvt_f_x_v(dst, dst);
- set_type_for(ov::element::f32);
- narrow_f32_to_f16(dst, dst);
- } else if (input_type == ov::element::u8) {
- widen_i8_to_i32(src, dst, false);
- h->vfcvt_f_xu_v(dst, dst);
- set_type_for(ov::element::f32);
- narrow_f32_to_f16(dst, dst);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
- }
- return;
- }
-
- if (output_type == ov::element::i32) {
- if (input_type == ov::element::f32) {
- set_type_for(ov::element::f32);
- h->vfcvt_x_f_v(dst, src);
- set_type_for(ov::element::i32);
- } else if (input_type == ov::element::f16) {
- widen_f16_to_f32(src, dst);
- h->vfcvt_x_f_v(dst, dst);
- set_type_for(ov::element::i32);
- } else if (any_of(input_type, ov::element::i8, ov::element::u8)) {
- widen_i8_to_i32(src, dst, input_type == ov::element::i8);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
- }
- return;
- }
-
- if (output_type == ov::element::i8) {
- if (input_type == ov::element::f32) {
- set_type_for(ov::element::f32);
- h->vfcvt_x_f_v(dst, src);
- set_type_for(ov::element::i32);
- narrow_i32_to_i8(dst, dst);
- } else if (input_type == ov::element::f16) {
- widen_f16_to_f32(src, dst);
- h->vfcvt_x_f_v(dst, dst);
- set_type_for(ov::element::i32);
- narrow_i32_to_i8(dst, dst);
- } else if (input_type == ov::element::i32) {
- narrow_i32_to_i8(src, dst);
- } else if (input_type == ov::element::u8) {
- widen_i8_to_i32(src, dst, false);
- narrow_i32_to_i8(dst, dst);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
- }
- return;
- }
-
- if (output_type == ov::element::u8) {
- if (input_type == ov::element::f32) {
- set_type_for(ov::element::f32);
- h->vfcvt_xu_f_v(dst, src);
- set_type_for(ov::element::i32);
- narrow_i32_to_u8(dst, dst);
- } else if (input_type == ov::element::f16) {
- widen_f16_to_f32(src, dst);
- h->vfcvt_xu_f_v(dst, dst);
- set_type_for(ov::element::i32);
- narrow_i32_to_u8(dst, dst);
- } else if (input_type == ov::element::i32) {
- saturate_i32_to_u8(src, dst);
- } else if (input_type == ov::element::i8) {
- widen_i8_to_i32(src, dst, true);
- saturate_i32_to_u8(dst, dst);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
- }
- return;
- }
-
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
+ OV_CPU_JIT_EMITTER_ASSERT(!aux_gpr_idxs.empty(), "Convert saturation emitter expects one auxiliary GPR register");
+ const auto avl = Reg(aux_gpr_idxs.front());
+ jit_conversion::emit_convert_process(h, src, dst, input_type, output_type, arithmetic_mode::saturation, avl);
}
/// ConvertTruncation ///
@@ -367,20 +176,7 @@ jit_convert_truncation_emitter::jit_convert_truncation_emitter(ov::intel_cpu::ri
input_type = convert->get_input_element_type(0);
output_type = convert->get_output_element_type(0);
- const bool is_supported_input =
- any_of(input_type, ov::element::f32, ov::element::f16, ov::element::i32, ov::element::i8, ov::element::u8);
- const bool is_supported_output =
- any_of(output_type, ov::element::f32, ov::element::f16, ov::element::i32, ov::element::i8, ov::element::u8);
- OV_CPU_JIT_EMITTER_ASSERT(is_supported_input && is_supported_output,
- "Unsupported conversion: ",
- input_type,
- " -> ",
- output_type);
- OV_CPU_JIT_EMITTER_ASSERT(!requires_zvfh(input_type, output_type) || mayiuse(cpu_isa_t::gv_zvfh),
- "Unsupported Zvfh conversion: ",
- input_type,
- " -> ",
- output_type);
+ jit_conversion::validate_convert_precision(input_type, output_type);
}
size_t jit_convert_truncation_emitter::get_inputs_num() const {
@@ -405,159 +201,9 @@ void jit_convert_truncation_emitter::emit_isa(const std::vector<size_t>& in_vec_
const std::vector<size_t>& out_vec_idxs) const {
auto src = VReg(in_vec_idxs[0]);
auto dst = VReg(out_vec_idxs[0]);
- auto avl = Reg(aux_gpr_idxs[0]);
- h->csrr(avl, CSR::vl);
-
- const auto set_type_for = [&](const ov::element::Type& type) {
- const auto [sew, lmul] = getVTypeForElementSize(type);
- set_vector_length(h, 0, sew, aux_gpr_idxs, lmul, &avl);
- };
- const auto move_if_needed = [&](const VReg& from, const VReg& to) {
- if (from.getIdx() != to.getIdx()) {
- h->vmv_v_v(to, from);
- }
- };
-
- const auto truncate_i32_to_i8 = [&](const VReg& from, const VReg& to) {
- set_type_for(ov::element::i16);
- h->vnsra_wi(to, from, 0);
- set_type_for(ov::element::i8);
- h->vnsra_wi(to, to, 0);
- };
- const auto truncate_i32_to_u8 = [&](const VReg& from, const VReg& to) {
- set_type_for(ov::element::i16);
- h->vnsrl_wi(to, from, 0);
- set_type_for(ov::element::i8);
- h->vnsrl_wi(to, to, 0);
- };
- const auto widen_f16_to_f32 = [&](const VReg& from, const VReg& to) {
- set_type_for(ov::element::f16);
- h->vfwcvt_f_f_v(to, from);
- set_type_for(ov::element::f32);
- };
- const auto narrow_f32_to_f16 = [&](const VReg& from, const VReg& to) {
- set_type_for(ov::element::f16);
- h->vfncvt_f_f_w(to, from);
- };
- const auto widen_i8_to_i32 = [&](const VReg& from, const VReg& to, const bool is_signed) {
- set_type_for(ov::element::i32);
- if (is_signed) {
- h->vsext_vf4(to, from);
- } else {
- h->vzext_vf4(to, from);
- }
- };
-
- if (input_type == output_type) {
- set_type_for(input_type);
- move_if_needed(src, dst);
- return;
- }
-
- if (output_type == ov::element::f32) {
- if (input_type == ov::element::f16) {
- widen_f16_to_f32(src, dst);
- } else if (input_type == ov::element::i32) {
- set_type_for(ov::element::i32);
- h->vfcvt_f_x_v(dst, src);
- set_type_for(ov::element::f32);
- } else if (input_type == ov::element::i8) {
- widen_i8_to_i32(src, dst, true);
- h->vfcvt_f_x_v(dst, dst);
- set_type_for(ov::element::f32);
- } else if (input_type == ov::element::u8) {
- widen_i8_to_i32(src, dst, false);
- h->vfcvt_f_xu_v(dst, dst);
- set_type_for(ov::element::f32);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
- }
- return;
- }
-
- if (output_type == ov::element::f16) {
- if (input_type == ov::element::f32) {
- narrow_f32_to_f16(src, dst);
- } else if (input_type == ov::element::i32) {
- set_type_for(ov::element::i32);
- h->vfcvt_f_x_v(dst, src);
- narrow_f32_to_f16(dst, dst);
- } else if (input_type == ov::element::i8) {
- widen_i8_to_i32(src, dst, true);
- h->vfcvt_f_x_v(dst, dst);
- narrow_f32_to_f16(dst, dst);
- } else if (input_type == ov::element::u8) {
- widen_i8_to_i32(src, dst, false);
- h->vfcvt_f_xu_v(dst, dst);
- narrow_f32_to_f16(dst, dst);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
- }
- return;
- }
-
- if (output_type == ov::element::i32) {
- if (input_type == ov::element::f32) {
- set_type_for(ov::element::f32);
- h->vfcvt_rtz_x_f_v(dst, src);
- set_type_for(ov::element::i32);
- } else if (input_type == ov::element::f16) {
- widen_f16_to_f32(src, dst);
- h->vfcvt_rtz_x_f_v(dst, dst);
- set_type_for(ov::element::i32);
- } else if (any_of(input_type, ov::element::i8, ov::element::u8)) {
- widen_i8_to_i32(src, dst, input_type == ov::element::i8);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
- }
- return;
- }
-
- if (output_type == ov::element::i8) {
- if (input_type == ov::element::f32) {
- set_type_for(ov::element::f32);
- h->vfcvt_rtz_x_f_v(dst, src);
- set_type_for(ov::element::i32);
- truncate_i32_to_i8(dst, dst);
- } else if (input_type == ov::element::f16) {
- widen_f16_to_f32(src, dst);
- h->vfcvt_rtz_x_f_v(dst, dst);
- set_type_for(ov::element::i32);
- truncate_i32_to_i8(dst, dst);
- } else if (input_type == ov::element::i32) {
- truncate_i32_to_i8(src, dst);
- } else if (input_type == ov::element::u8) {
- set_type_for(ov::element::i8);
- move_if_needed(src, dst);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
- }
- return;
- }
-
- if (output_type == ov::element::u8) {
- if (input_type == ov::element::f32) {
- set_type_for(ov::element::f32);
- h->vfcvt_rtz_x_f_v(dst, src);
- set_type_for(ov::element::i32);
- truncate_i32_to_u8(dst, dst);
- } else if (input_type == ov::element::f16) {
- widen_f16_to_f32(src, dst);
- h->vfcvt_rtz_x_f_v(dst, dst);
- set_type_for(ov::element::i32);
- truncate_i32_to_u8(dst, dst);
- } else if (input_type == ov::element::i32) {
- truncate_i32_to_u8(src, dst);
- } else if (input_type == ov::element::i8) {
- set_type_for(ov::element::i8);
- move_if_needed(src, dst);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
- }
- return;
- }
-
- OV_CPU_JIT_EMITTER_THROW("Unsupported conversion: ", input_type, " -> ", output_type);
+ OV_CPU_JIT_EMITTER_ASSERT(!aux_gpr_idxs.empty(), "Convert truncation emitter expects one auxiliary GPR register");
+ const auto avl = Reg(aux_gpr_idxs.front());
+ jit_conversion::emit_convert_process(h, src, dst, input_type, output_type, arithmetic_mode::truncation, avl);
}
/// CEIL ///
diff --git a/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_load_store_emitters.cpp b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_load_store_emitters.cpp
new file mode 100644
index 00000000000..0754c1a1c6b
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_load_store_emitters.cpp
@@ -0,0 +1,189 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "jit_load_store_emitters.hpp"
+
+#include <cstddef>
+#include <nodes/kernels/riscv64/cpu_isa_traits.hpp>
+#include <nodes/kernels/riscv64/jit_generator.hpp>
+#include <vector>
+
+#include "emitters/plugin/riscv64/jit_conversion_helpers.hpp"
+#include "emitters/plugin/riscv64/jit_emitter.hpp"
+#include "emitters/utils.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "xbyak_riscv/xbyak_riscv.hpp"
+
+namespace ov::intel_cpu::riscv64 {
+namespace {
+
+bool needs_aux_vec_for_conversion(const ov::element::Type& src_prc, const ov::element::Type& dst_prc) {
+ return src_prc != dst_prc && src_prc.size() < dst_prc.size();
+}
+
+bool needs_conversion(const ov::element::Type& src_prc, const ov::element::Type& dst_prc) {
+ return src_prc != dst_prc;
+}
+
+} // namespace
+
+jit_load_emitter::jit_load_emitter(ov::intel_cpu::riscv64::jit_generator_t* host,
+ ov::intel_cpu::riscv64::cpu_isa_t host_isa,
+ ov::element::Type src_prc,
+ ov::element::Type dst_prc,
+ size_t load_num,
+ size_t byte_offset,
+ arithmetic_mode mode,
+ ov::element::Type exec_prc,
+ emitter_in_out_map in_out_type)
+ : jit_emitter(host, host_isa, exec_prc, in_out_type),
+ load_num_(load_num),
+ byte_offset_(byte_offset),
+ src_prc_(src_prc),
+ dst_prc_(dst_prc),
+ mode_(mode) {
+ jit_conversion::validate_convert_precision(src_prc_, dst_prc_);
+}
+
+size_t jit_load_emitter::get_inputs_num() const {
+ return 1;
+}
+
+void jit_load_emitter::emit_impl(const std::vector<size_t>& in_idxs, const std::vector<size_t>& out_idxs) const {
+ if (host_isa_ == ov::intel_cpu::riscv64::gv) {
+ emit_isa<ov::intel_cpu::riscv64::gv>(in_idxs, out_idxs);
+ } else {
+ OV_CPU_JIT_EMITTER_THROW("Unsupported isa.");
+ }
+}
+
+template <ov::intel_cpu::riscv64::cpu_isa_t isa>
+void jit_load_emitter::emit_isa(const std::vector<size_t>& in_idxs, const std::vector<size_t>& out_idxs) const {
+ auto src = Xbyak_riscv::Reg(in_idxs[0]);
+ auto dst = Xbyak_riscv::VReg(out_idxs[0]);
+ const auto needs_aux_vec = needs_aux_vec_for_conversion(src_prc_, dst_prc_);
+ OV_CPU_JIT_EMITTER_ASSERT(!needs_aux_vec || !aux_vec_idxs.empty(),
+ "Widening load conversion requires an auxiliary vector register");
+ auto data = needs_aux_vec ? Xbyak_riscv::VReg(aux_vec_idxs.front()) : dst;
+
+ const auto byte_size = src_prc_.size();
+ set_vector_length(h, load_num_, jit_conversion::byte_size_to_sew(byte_size), aux_gpr_idxs);
+
+ if (byte_offset_ == 0) {
+ if (byte_size == 1) {
+ h->vle8_v(data, src);
+ } else if (byte_size == 2) {
+ h->vle16_v(data, src);
+ } else {
+ h->vle32_v(data, src);
+ }
+ } else {
+ OV_CPU_JIT_EMITTER_ASSERT(!aux_gpr_idxs.empty(), "Static byte offset requires an auxiliary GPR");
+ auto tmp_gpr = Xbyak_riscv::Reg(aux_gpr_idxs.front());
+ h->uni_li(tmp_gpr, byte_offset_);
+ h->add(tmp_gpr, src, tmp_gpr);
+ if (byte_size == 1) {
+ h->vle8_v(data, tmp_gpr);
+ } else if (byte_size == 2) {
+ h->vle16_v(data, tmp_gpr);
+ } else {
+ h->vle32_v(data, tmp_gpr);
+ }
+ }
+
+ if (needs_conversion(src_prc_, dst_prc_)) {
+ OV_CPU_JIT_EMITTER_ASSERT(!aux_gpr_idxs.empty(), "Load conversion requires an auxiliary GPR");
+ const auto avl = Xbyak_riscv::Reg(aux_gpr_idxs.front());
+ jit_conversion::emit_convert_process(h, data, dst, src_prc_, dst_prc_, mode_, avl);
+ }
+}
+
+size_t jit_load_emitter::aux_gprs_count() const {
+ return (load_num_ > 31 || byte_offset_ != 0 || needs_conversion(src_prc_, dst_prc_)) ? 1 : 0;
+}
+
+size_t jit_load_emitter::aux_vecs_count() const {
+ return needs_aux_vec_for_conversion(src_prc_, dst_prc_) ? 1 : 0;
+}
+
+jit_store_emitter::jit_store_emitter(ov::intel_cpu::riscv64::jit_generator_t* host,
+ ov::intel_cpu::riscv64::cpu_isa_t host_isa,
+ ov::element::Type src_prc,
+ ov::element::Type dst_prc,
+ size_t store_num,
+ size_t byte_offset,
+ arithmetic_mode mode,
+ ov::element::Type exec_prc,
+ emitter_in_out_map in_out_type)
+ : jit_emitter(host, host_isa, exec_prc, in_out_type),
+ store_num_(store_num),
+ byte_offset_(byte_offset),
+ src_prc_(src_prc),
+ dst_prc_(dst_prc),
+ mode_(mode) {
+ jit_conversion::validate_convert_precision(src_prc_, dst_prc_);
+}
+
+size_t jit_store_emitter::get_inputs_num() const {
+ return 1;
+}
+
+void jit_store_emitter::emit_impl(const std::vector<size_t>& in_idxs, const std::vector<size_t>& out_idxs) const {
+ if (host_isa_ == ov::intel_cpu::riscv64::gv) {
+ emit_isa<ov::intel_cpu::riscv64::gv>(in_idxs, out_idxs);
+ } else {
+ OV_CPU_JIT_EMITTER_THROW("Unsupported isa.");
+ }
+}
+
+template <ov::intel_cpu::riscv64::cpu_isa_t isa>
+void jit_store_emitter::emit_isa(const std::vector<size_t>& in_idxs, const std::vector<size_t>& out_idxs) const {
+ auto src = Xbyak_riscv::VReg(in_idxs[0]);
+ auto dst = Xbyak_riscv::Reg(out_idxs[0]);
+ auto data = src;
+
+ if (needs_conversion(src_prc_, dst_prc_)) {
+ OV_CPU_JIT_EMITTER_ASSERT(!aux_vec_idxs.empty(), "Store conversion requires an auxiliary vector register");
+ OV_CPU_JIT_EMITTER_ASSERT(!aux_gpr_idxs.empty(), "Store conversion requires an auxiliary GPR");
+ data = Xbyak_riscv::VReg(aux_vec_idxs.front());
+ set_vector_length(h, store_num_, jit_conversion::byte_size_to_sew(src_prc_.size()), aux_gpr_idxs);
+ const auto avl = Xbyak_riscv::Reg(aux_gpr_idxs.front());
+ jit_conversion::emit_convert_process(h, src, data, src_prc_, dst_prc_, mode_, avl);
+ }
+
+ const auto byte_size = dst_prc_.size();
+ set_vector_length(h, store_num_, jit_conversion::byte_size_to_sew(byte_size), aux_gpr_idxs);
+
+ if (byte_offset_ == 0) {
+ if (byte_size == 1) {
+ h->vse8_v(data, dst);
+ } else if (byte_size == 2) {
+ h->vse16_v(data, dst);
+ } else {
+ h->vse32_v(data, dst);
+ }
+ } else {
+ OV_CPU_JIT_EMITTER_ASSERT(!aux_gpr_idxs.empty(), "Static byte offset requires an auxiliary GPR");
+ auto tmp_gpr = Xbyak_riscv::Reg(aux_gpr_idxs.front());
+ h->uni_li(tmp_gpr, byte_offset_);
+ h->add(tmp_gpr, dst, tmp_gpr);
+ if (byte_size == 1) {
+ h->vse8_v(data, tmp_gpr);
+ } else if (byte_size == 2) {
+ h->vse16_v(data, tmp_gpr);
+ } else {
+ h->vse32_v(data, tmp_gpr);
+ }
+ }
+}
+
+size_t jit_store_emitter::aux_gprs_count() const {
+ return (store_num_ > 31 || byte_offset_ != 0 || needs_conversion(src_prc_, dst_prc_)) ? 1 : 0;
+}
+
+size_t jit_store_emitter::aux_vecs_count() const {
+ return needs_conversion(src_prc_, dst_prc_) ? 1 : 0;
+}
+
+} // namespace ov::intel_cpu::riscv64
diff --git a/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_load_store_emitters.hpp b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_load_store_emitters.hpp
new file mode 100644
index 00000000000..5308ac8426c
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/plugin/riscv64/jit_load_store_emitters.hpp
@@ -0,0 +1,78 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstddef>
+#include <nodes/kernels/riscv64/cpu_isa_traits.hpp>
+#include <nodes/kernels/riscv64/jit_generator.hpp>
+#include <vector>
+
+#include "emitters/plugin/riscv64/jit_conversion_helpers.hpp"
+#include "emitters/plugin/riscv64/jit_emitter.hpp"
+#include "openvino/core/type/element_type.hpp"
+
+namespace ov::intel_cpu::riscv64 {
+
+class jit_load_emitter : public jit_emitter {
+public:
+ jit_load_emitter(ov::intel_cpu::riscv64::jit_generator_t* host,
+ ov::intel_cpu::riscv64::cpu_isa_t host_isa,
+ ov::element::Type src_prc,
+ ov::element::Type dst_prc,
+ size_t load_num,
+ size_t byte_offset,
+ arithmetic_mode mode = arithmetic_mode::saturation,
+ ov::element::Type exec_prc = ov::element::f32,
+ emitter_in_out_map in_out_type = emitter_in_out_map::gpr_to_vec);
+
+ size_t get_inputs_num() const override;
+
+private:
+ void emit_impl(const std::vector<size_t>& in_idxs, const std::vector<size_t>& out_idxs) const override;
+
+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>
+ void emit_isa(const std::vector<size_t>& in_idxs, const std::vector<size_t>& out_idxs) const;
+
+ size_t aux_gprs_count() const override;
+ size_t aux_vecs_count() const override;
+
+ size_t load_num_ = 0;
+ size_t byte_offset_ = 0;
+ ov::element::Type src_prc_;
+ ov::element::Type dst_prc_;
+ arithmetic_mode mode_ = arithmetic_mode::saturation;
+};
+
+class jit_store_emitter : public jit_emitter {
+public:
+ jit_store_emitter(ov::intel_cpu::riscv64::jit_generator_t* host,
+ ov::intel_cpu::riscv64::cpu_isa_t host_isa,
+ ov::element::Type src_prc,
+ ov::element::Type dst_prc,
+ size_t store_num,
+ size_t byte_offset,
+ arithmetic_mode mode = arithmetic_mode::saturation,
+ ov::element::Type exec_prc = ov::element::f32,
+ emitter_in_out_map in_out_type = emitter_in_out_map::vec_to_gpr);
+
+ size_t get_inputs_num() const override;
+
+private:
+ void emit_impl(const std::vector<size_t>& in_idxs, const std::vector<size_t>& out_idxs) const override;
+
+ template <ov::intel_cpu::riscv64::cpu_isa_t isa>
+ void emit_isa(const std::vector<size_t>& in_idxs, const std::vector<size_t>& out_idxs) const;
+
+ size_t aux_gprs_count() const override;
+ size_t aux_vecs_count() const override;
+
+ size_t store_num_ = 0;
+ size_t byte_offset_ = 0;
+ ov::element::Type src_prc_;
+ ov::element::Type dst_prc_;
+ arithmetic_mode mode_ = arithmetic_mode::saturation;
+};
+
+} // namespace ov::intel_cpu::riscv64
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/riscv64/cpu_generator.cpp b/src/plugins/intel_cpu/src/emitters/snippets/riscv64/cpu_generator.cpp
index c1583c5c40b..0c04e2e283a 100644
--- a/src/plugins/intel_cpu/src/emitters/snippets/riscv64/cpu_generator.cpp
+++ b/src/plugins/intel_cpu/src/emitters/snippets/riscv64/cpu_generator.cpp
@@ -98,6 +98,8 @@
#include "snippets/op/vector_buffer.hpp"
#include "snippets/target_machine.hpp"
#include "transformations/snippets/common/op/fused_mul_add.hpp"
+#include "transformations/snippets/common/op/load_convert.hpp"
+#include "transformations/snippets/common/op/store_convert.hpp"
#include "utils.hpp"
#include "utils/general_utils.h"
#include "xbyak_riscv/xbyak_riscv.hpp"
@@ -284,7 +286,15 @@ CPUTargetMachine::CPUTargetMachine(ov::intel_cpu::riscv64::cpu_isa_t host_isa, o
jitters[snippets::op::LoadReorder::get_type_info_static()] = emitter_factory.from_expr<jit_load_memory_emitter>();
jitters[snippets::op::BroadcastLoad::get_type_info_static()] =
emitter_factory.from_expr<jit_load_broadcast_emitter>();
+ jitters[intel_cpu::LoadConvertSaturation::get_type_info_static()] =
+ emitter_factory.from_expr<jit_load_memory_emitter>();
+ jitters[intel_cpu::LoadConvertTruncation::get_type_info_static()] =
+ emitter_factory.from_expr<jit_load_memory_emitter>();
jitters[snippets::op::Store::get_type_info_static()] = emitter_factory.from_expr<jit_store_memory_emitter>();
+ jitters[intel_cpu::StoreConvertSaturation::get_type_info_static()] =
+ emitter_factory.from_expr<jit_store_memory_emitter>();
+ jitters[intel_cpu::StoreConvertTruncation::get_type_info_static()] =
+ emitter_factory.from_expr<jit_store_memory_emitter>();
jitters[snippets::op::Fill::get_type_info_static()] = emitter_factory.from_expr<jit_fill_emitter>();
// reductions
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/riscv64/jit_memory_emitters.cpp b/src/plugins/intel_cpu/src/emitters/snippets/riscv64/jit_memory_emitters.cpp
index 082956773c5..c5e7c01795f 100644
--- a/src/plugins/intel_cpu/src/emitters/snippets/riscv64/jit_memory_emitters.cpp
+++ b/src/plugins/intel_cpu/src/emitters/snippets/riscv64/jit_memory_emitters.cpp
@@ -11,7 +11,9 @@
#include <nodes/kernels/riscv64/jit_generator.hpp>
#include <vector>
+#include "emitters/plugin/riscv64/jit_conversion_helpers.hpp"
#include "emitters/plugin/riscv64/jit_emitter.hpp"
+#include "emitters/plugin/riscv64/jit_load_store_emitters.hpp"
#include "emitters/snippets/jit_snippets_call_args.hpp"
#include "emitters/snippets/utils/utils.hpp"
#include "emitters/utils.hpp"
@@ -24,10 +26,11 @@
#include "snippets/op/memory_access.hpp"
#include "snippets/op/store.hpp"
#include "snippets/utils/utils.hpp"
+#include "transformations/snippets/common/op/load_convert.hpp"
+#include "transformations/snippets/common/op/store_convert.hpp"
#include "utils.hpp"
#include "utils/general_utils.h"
#include "xbyak_riscv/xbyak_riscv.hpp"
-#include "xbyak_riscv/xbyak_riscv_csr.hpp"
namespace ov::intel_cpu::riscv64 {
@@ -65,32 +68,25 @@ jit_memory_emitter::jit_memory_emitter(jit_generator_t* h,
if (ov::snippets::utils::is_dynamic_value(compiled_byte_offset)) {
is_offset_runtime = true;
// Compiled byte offset is zero to manually `add` runtime offset before operation and `sub` after to reset
- // pointer in the register
+ // pointer in the register.
compiled_byte_offset = 0;
OV_CPU_JIT_EMITTER_ASSERT(buffer_cluster_id != SIZE_MAX, "Incorrect buffer offset in call_args");
}
}
-jit_load_memory_emitter::jit_load_memory_emitter(jit_generator_t* h, cpu_isa_t isa, const ExpressionPtr& expr)
- : jit_memory_emitter(h, isa, expr, emitter_in_out_map::gpr_to_vec) {
- bool is_supported_precision =
- any_of(src_prc, ov::element::f32, ov::element::i32, ov::element::f16, ov::element::i8, ov::element::u8) &&
- src_prc == dst_prc;
- OV_CPU_JIT_EMITTER_ASSERT(is_supported_precision, "Unsupported precision pair.");
-
- const auto load = ov::as_type_ptr<snippets::op::Load>(expr->get_node());
- OV_CPU_JIT_EMITTER_ASSERT(load != nullptr, "Expects Load expression");
- count = load->get_count();
- byte_size = src_prc.size();
- OV_CPU_JIT_EMITTER_ASSERT(any_of(byte_size, 1UL, 2UL, 4UL),
- "Only 1-, 2- or 4-byte element loads are supported, got: ",
- byte_size);
+size_t jit_memory_emitter::aux_gprs_count() const {
+ // for runtime arguments
+ return is_offset_runtime ? 1 : 0;
}
-size_t jit_memory_emitter::aux_gprs_count() const {
- // One auxiliary register is needed for runtime offsets and for operations that
- // cannot be encoded directly in immediates (large VL or static byte offsets).
- return (is_offset_runtime || count > 31 || compiled_byte_offset != 0) ? 1 : 0;
+std::vector<size_t> jit_memory_emitter::get_available_aux_gprs() const {
+ OV_CPU_JIT_EMITTER_ASSERT(!is_offset_runtime || !aux_gpr_idxs.empty(),
+ "If offset is dynamic, memory emitter needs at least one aux gpr!");
+ auto available_aux_gprs = aux_gpr_idxs;
+ if (is_offset_runtime) {
+ available_aux_gprs.pop_back();
+ }
+ return available_aux_gprs;
}
void jit_memory_emitter::emit_code_impl(const std::vector<size_t>& in_idxs,
@@ -113,140 +109,61 @@ void jit_memory_emitter::emit_code_impl(const std::vector<size_t>& in_idxs,
}
if (is_offset_runtime) {
- // load the runtime offset from args.buffer_offsets[buffer_cluster_id]
const auto offset = GET_OFF(buffer_offsets) + buffer_cluster_id * sizeof(size_t);
- // RV64 uses 64-bit size_t
h->ld(aux_gpr, reg_runtime_params, static_cast<int32_t>(offset));
- // bump the pointer
h->add(data_reg, data_reg, aux_gpr);
}
emit_impl(in_idxs, out_idxs);
if (is_offset_runtime) {
- // subtract back so we leave the pointer unchanged for the caller
h->sub(data_reg, data_reg, aux_gpr);
}
emitter_postamble();
}
-void jit_load_memory_emitter::emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
- if (host_isa_ == ov::intel_cpu::riscv64::gv) {
- emit_isa<ov::intel_cpu::riscv64::gv>(in, out);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Doesn't support isa ", host_isa_);
- }
-}
+jit_load_memory_emitter::jit_load_memory_emitter(jit_generator_t* h, cpu_isa_t isa, const ExpressionPtr& expr)
+ : jit_memory_emitter(h, isa, expr, emitter_in_out_map::gpr_to_vec) {
+ const auto load = ov::as_type_ptr<snippets::op::Load>(expr->get_node());
+ OV_CPU_JIT_EMITTER_ASSERT(load != nullptr, "Expects Load expression");
+ count = load->get_count();
-template <cpu_isa_t isa>
-void jit_load_memory_emitter::emit_isa(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
- auto src = Xbyak_riscv::Reg(in[0]);
- auto dst = Xbyak_riscv::VReg(out[0]);
+ const auto mode = ov::is_type<ov::intel_cpu::LoadConvertTruncation>(expr->get_node()) ? arithmetic_mode::truncation
+ : arithmetic_mode::saturation;
+ load_emitter = std::make_unique<jit_load_emitter>(h, isa, src_prc, dst_prc, count, compiled_byte_offset, mode);
+}
- // Set vector configuration for the load
- auto sew = Xbyak_riscv::SEW::e32;
- if (byte_size == 1) {
- sew = Xbyak_riscv::SEW::e8;
- } else if (byte_size == 2) {
- sew = Xbyak_riscv::SEW::e16;
- } else {
- OV_CPU_JIT_EMITTER_ASSERT(byte_size == 4, "Unsupported load byte_size: ", byte_size);
- }
- set_vector_length(h, count, sew, aux_gpr_idxs);
-
- // Load vector data from memory
- if (compiled_byte_offset == 0) {
- if (byte_size == 1) {
- h->vle8_v(dst, src);
- } else if (byte_size == 2) {
- h->vle16_v(dst, src);
- } else {
- h->vle32_v(dst, src);
- }
- } else {
- // Use temporary register to calculate address with offset
- auto tmp_gpr = Xbyak_riscv::Reg(aux_gpr_idxs.empty() ? Xbyak_riscv::t0.getIdx() : aux_gpr_idxs[0]);
- h->addi(tmp_gpr, src, static_cast<int32_t>(compiled_byte_offset));
- if (byte_size == 1) {
- h->vle8_v(dst, tmp_gpr);
- } else if (byte_size == 2) {
- h->vle16_v(dst, tmp_gpr);
- } else {
- h->vle32_v(dst, tmp_gpr);
- }
- }
+void jit_load_memory_emitter::emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
+ OV_CPU_JIT_EMITTER_ASSERT(load_emitter != nullptr, "Load CPU emitter isn't initialized!");
+ load_emitter->emit_code({in[0]}, {out[0]}, aux_vec_idxs, get_available_aux_gprs(), {});
}
void jit_load_memory_emitter::emit_data() const {
- // No additional data emission needed for basic load
+ load_emitter->emit_data();
}
jit_store_memory_emitter::jit_store_memory_emitter(jit_generator_t* h, cpu_isa_t isa, const ExpressionPtr& expr)
: jit_memory_emitter(h, isa, expr, emitter_in_out_map::vec_to_gpr) {
- bool is_supported_precision =
- any_of(dst_prc, ov::element::f32, ov::element::i32, ov::element::f16, ov::element::i8, ov::element::u8) &&
- src_prc == dst_prc;
- OV_CPU_JIT_EMITTER_ASSERT(is_supported_precision, "Unsupported precision pair.");
-
const auto store = ov::as_type_ptr<snippets::op::Store>(expr->get_node());
OV_CPU_JIT_EMITTER_ASSERT(store != nullptr, "Expects Store expression");
count = store->get_count();
- byte_size = dst_prc.size();
- OV_CPU_JIT_EMITTER_ASSERT(any_of(byte_size, size_t(1), size_t(2), size_t(4)),
- "Only 1-, 2- or 4-byte element stores are supported, got: ",
- byte_size);
+
+ const auto mode = ov::is_type<ov::intel_cpu::StoreConvertTruncation>(expr->get_node())
+ ? arithmetic_mode::truncation
+ : arithmetic_mode::saturation;
+ store_emitter = std::make_unique<jit_store_emitter>(h, isa, src_prc, dst_prc, count, compiled_byte_offset, mode);
}
void jit_store_memory_emitter::emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
- if (host_isa_ == ov::intel_cpu::riscv64::gv) {
- emit_isa<ov::intel_cpu::riscv64::gv>(in, out);
- } else {
- OV_CPU_JIT_EMITTER_THROW("Doesn't support isa ", host_isa_);
- }
+ OV_CPU_JIT_EMITTER_ASSERT(store_emitter != nullptr, "Store CPU emitter isn't initialized!");
+ store_emitter->emit_code({in[0]}, {out[0]}, aux_vec_idxs, get_available_aux_gprs(), {});
}
-template <cpu_isa_t isa>
-void jit_store_memory_emitter::emit_isa(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
- auto src = Xbyak_riscv::VReg(in[0]);
- auto dst = Xbyak_riscv::Reg(out[0]);
-
- // Set vector configuration for the store
- auto sew = Xbyak_riscv::SEW::e32;
- if (byte_size == 1) {
- sew = Xbyak_riscv::SEW::e8;
- } else if (byte_size == 2) {
- sew = Xbyak_riscv::SEW::e16;
- } else {
- OV_CPU_JIT_EMITTER_ASSERT(byte_size == 4, "Unsupported store byte_size: ", byte_size);
- }
- set_vector_length(h, count, sew, aux_gpr_idxs);
-
- // Store vector data to memory
- if (compiled_byte_offset == 0) {
- if (byte_size == 1) {
- h->vse8_v(src, dst);
- } else if (byte_size == 2) {
- h->vse16_v(src, dst);
- } else {
- h->vse32_v(src, dst);
- }
- } else {
- // Use temporary register to calculate address with offset
- auto tmp_gpr = Xbyak_riscv::Reg(aux_gpr_idxs.empty() ? Xbyak_riscv::t0.getIdx() : aux_gpr_idxs[0]);
- h->addi(tmp_gpr, dst, static_cast<int32_t>(compiled_byte_offset));
- if (byte_size == 1) {
- h->vse8_v(src, tmp_gpr);
- } else if (byte_size == 2) {
- h->vse16_v(src, tmp_gpr);
- } else {
- h->vse32_v(src, tmp_gpr);
- }
- }
+void jit_store_memory_emitter::emit_data() const {
+ store_emitter->emit_data();
}
-/* ============== jit_load_broadcast_emitter =============== */
-
jit_load_broadcast_emitter::jit_load_broadcast_emitter(ov::intel_cpu::riscv64::jit_generator_t* h,
ov::intel_cpu::riscv64::cpu_isa_t isa,
const ov::snippets::lowered::ExpressionPtr& expr)
@@ -262,6 +179,10 @@ jit_load_broadcast_emitter::jit_load_broadcast_emitter(ov::intel_cpu::riscv64::j
byte_size = src_prc.size();
}
+size_t jit_load_broadcast_emitter::aux_gprs_count() const {
+ return jit_memory_emitter::aux_gprs_count() + (compiled_byte_offset == 0 ? 1 : 2);
+}
+
void jit_load_broadcast_emitter::emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
if (host_isa_ == ov::intel_cpu::riscv64::gv) {
emit_isa<ov::intel_cpu::riscv64::gv>(in, out);
@@ -274,54 +195,37 @@ template <cpu_isa_t isa>
void jit_load_broadcast_emitter::emit_isa(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
auto src_gpr = Xbyak_riscv::Reg(in[0]);
auto dst_vreg = Xbyak_riscv::VReg(out[0]);
-
- auto sew = Xbyak_riscv::SEW::e32;
- if (byte_size == 4) {
- sew = Xbyak_riscv::SEW::e32;
- } else if (byte_size == 2) {
- sew = Xbyak_riscv::SEW::e16;
- } else if (byte_size == 1) {
- sew = Xbyak_riscv::SEW::e8;
- } else {
- OV_CPU_JIT_EMITTER_THROW("Unsupported byte size: ", byte_size);
+ const auto available_aux_gprs = get_available_aux_gprs();
+ set_vector_length(h,
+ ov::intel_cpu::riscv64::utils::get_snippet_lanes(),
+ jit_conversion::byte_size_to_sew(byte_size),
+ available_aux_gprs);
+
+ OV_CPU_JIT_EMITTER_ASSERT(!available_aux_gprs.empty(), "Broadcast load requires an auxiliary GPR");
+ auto tmp_gpr = Xbyak_riscv::Reg(available_aux_gprs[0]);
+ auto addr_gpr = src_gpr;
+
+ if (compiled_byte_offset != 0) {
+ OV_CPU_JIT_EMITTER_ASSERT(available_aux_gprs.size() > 1,
+ "Broadcast load with static byte offset requires two auxiliary GPRs");
+ addr_gpr = Xbyak_riscv::Reg(available_aux_gprs[1]);
+ h->uni_li(addr_gpr, compiled_byte_offset);
+ h->add(addr_gpr, src_gpr, addr_gpr);
}
- set_vector_length(h, ov::intel_cpu::riscv64::utils::get_snippet_lanes(), sew, aux_gpr_idxs);
-
- // Load scalar from memory and broadcast to vector register
- // First load the scalar value into a temporary GPR
- auto tmp_gpr = Xbyak_riscv::Reg(aux_gpr_idxs.empty() ? Xbyak_riscv::t0.getIdx() : aux_gpr_idxs[0]);
-
- // Calculate effective address if there's an offset
- if (compiled_byte_offset == 0) {
- if (byte_size == 1) {
- if (src_prc == ov::element::u8) {
- h->lbu(tmp_gpr, src_gpr, 0);
- } else {
- h->lb(tmp_gpr, src_gpr, 0);
- }
- } else if (byte_size == 2) {
- h->lhu(tmp_gpr, src_gpr, 0);
+
+ if (byte_size == 1) {
+ if (src_prc == ov::element::u8) {
+ h->lbu(tmp_gpr, addr_gpr, 0);
} else {
- h->lw(tmp_gpr, src_gpr, 0);
+ h->lb(tmp_gpr, addr_gpr, 0);
}
+ } else if (byte_size == 2) {
+ h->lhu(tmp_gpr, addr_gpr, 0);
} else {
- auto addr_gpr = Xbyak_riscv::Reg(aux_gpr_idxs.size() > 1 ? aux_gpr_idxs[1] : Xbyak_riscv::t1.getIdx());
- h->addi(addr_gpr, src_gpr, static_cast<int32_t>(compiled_byte_offset));
- if (byte_size == 1) {
- if (src_prc == ov::element::u8) {
- h->lbu(tmp_gpr, addr_gpr, 0);
- } else {
- h->lb(tmp_gpr, addr_gpr, 0);
- }
- } else if (byte_size == 2) {
- h->lhu(tmp_gpr, addr_gpr, 0);
- } else {
- h->lw(tmp_gpr, addr_gpr, 0);
- }
+ h->lw(tmp_gpr, addr_gpr, 0);
}
- // Move scalar to vector register and broadcast
- h->vmv_v_x(dst_vreg, tmp_gpr); // Broadcast scalar to all elements
+ h->vmv_v_x(dst_vreg, tmp_gpr);
}
void jit_load_broadcast_emitter::emit_data() const {
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/riscv64/jit_memory_emitters.hpp b/src/plugins/intel_cpu/src/emitters/snippets/riscv64/jit_memory_emitters.hpp
index 480ed3566d0..6be907082a8 100644
--- a/src/plugins/intel_cpu/src/emitters/snippets/riscv64/jit_memory_emitters.hpp
+++ b/src/plugins/intel_cpu/src/emitters/snippets/riscv64/jit_memory_emitters.hpp
@@ -11,6 +11,7 @@
#include <vector>
#include "emitters/plugin/riscv64/jit_emitter.hpp"
+#include "emitters/plugin/riscv64/jit_load_store_emitters.hpp"
#include "openvino/core/type/element_type.hpp"
#include "snippets/lowered/expression.hpp"
@@ -31,6 +32,8 @@ public:
const std::vector<size_t>& pool_gpr_idxs) const override;
protected:
+ std::vector<size_t> get_available_aux_gprs() const;
+
ov::element::Type src_prc;
ov::element::Type dst_prc;
@@ -59,10 +62,7 @@ private:
void emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const override;
void emit_data() const override;
- template <ov::intel_cpu::riscv64::cpu_isa_t isa>
- void emit_isa(const std::vector<size_t>& in, const std::vector<size_t>& out) const;
-
- size_t byte_size = 0;
+ std::unique_ptr<jit_load_emitter> load_emitter = nullptr;
};
class jit_store_memory_emitter : public jit_memory_emitter {
@@ -77,11 +77,9 @@ public:
private:
void emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const override;
+ void emit_data() const override;
- template <ov::intel_cpu::riscv64::cpu_isa_t isa>
- void emit_isa(const std::vector<size_t>& in, const std::vector<size_t>& out) const;
-
- size_t byte_size = 0;
+ std::unique_ptr<jit_store_emitter> store_emitter = nullptr;
};
class jit_load_broadcast_emitter : public jit_memory_emitter {
@@ -95,6 +93,8 @@ public:
}
private:
+ size_t aux_gprs_count() const override;
+
void emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const override;
void emit_data() const override;
diff --git a/src/plugins/intel_cpu/src/extension.cpp b/src/plugins/intel_cpu/src/extension.cpp
index 573b5c3438e..88705d388ad 100644
--- a/src/plugins/intel_cpu/src/extension.cpp
+++ b/src/plugins/intel_cpu/src/extension.cpp
@@ -107,7 +107,7 @@
#include "transformations/cpu_opset/common/op/read_value_with_subgraph.hpp"
#include "transformations/cpu_opset/common/op/sdpa.hpp"
#include "transformations/cpu_opset/common/op/swish_cpu.hpp"
-#if defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_ARM64)
+#if defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_ARM64) || defined(OPENVINO_ARCH_RISCV64)
# include "transformations/snippets/common/op/load_convert.hpp"
# include "transformations/snippets/common/op/store_convert.hpp"
#endif
@@ -168,6 +168,12 @@ private:
# define OP_EXTENSION_ARM64(x)
#endif
+#if defined(OPENVINO_ARCH_RISCV64)
+# define OP_EXTENSION_RISCV64(x) x,
+#else
+# define OP_EXTENSION_RISCV64(x)
+#endif
+
#if defined(SNIPPETS_DEBUG_CAPS)
# define OP_EXTENSION_SNIPPETS_DEBUG_CAPS(x) x,
#else
@@ -222,6 +228,10 @@ OPENVINO_CREATE_EXTENSIONS(std::vector<ov::Extension::Ptr>({
OP_EXTENSION_ARM64(std::make_shared<ov::OpExtension<ov::intel_cpu::StoreConvertTruncation>>())
OP_EXTENSION_ARM64(std::make_shared<ov::OpExtension<ov::intel_cpu::aarch64::GemmCPU>>())
OP_EXTENSION_ARM64(std::make_shared<ov::OpExtension<ov::intel_cpu::aarch64::GemmCopyB>>())
+ OP_EXTENSION_RISCV64(std::make_shared<ov::OpExtension<ov::intel_cpu::LoadConvertSaturation>>())
+ OP_EXTENSION_RISCV64(std::make_shared<ov::OpExtension<ov::intel_cpu::LoadConvertTruncation>>())
+ OP_EXTENSION_RISCV64(std::make_shared<ov::OpExtension<ov::intel_cpu::StoreConvertSaturation>>())
+ OP_EXTENSION_RISCV64(std::make_shared<ov::OpExtension<ov::intel_cpu::StoreConvertTruncation>>())
// clang-format on
std::make_shared<TypeRelaxedExtension<ov::op::v1::Add>>(),
std::make_shared<TypeRelaxedExtension<ov::op::v1::AvgPool>>(),
diff --git a/src/plugins/intel_cpu/src/nodes/subgraph.cpp b/src/plugins/intel_cpu/src/nodes/subgraph.cpp
index 700a6d4d83b..03c1cf57eba 100644
--- a/src/plugins/intel_cpu/src/nodes/subgraph.cpp
+++ b/src/plugins/intel_cpu/src/nodes/subgraph.cpp
@@ -37,6 +37,7 @@
#include "snippets/pass/positioned_pass.hpp"
#include "snippets/shape_types.hpp"
#include "transformations/cpu_opset/common/pass/convert_to_swish_cpu.hpp"
+#include "transformations/snippets/common/pass/lowered/fuse_load_store_and_convert.hpp"
#include "transformations/snippets/common/pass/mul_add_to_fma.hpp"
#include "transformations/snippets/common/shape_inference.hpp"
#include "utils/general_utils.h"
@@ -69,6 +70,7 @@
# include "emitters/snippets/riscv64/cpu_generator.hpp"
# include "executors/riscv64/subgraph.hpp"
# include "openvino/core/except.hpp"
+# include "snippets/lowered/pass/insert_loops.hpp"
#else
# include "emitters/snippets/cpu_runtime_configurator.hpp"
# include "snippets/lowered/pass/insert_perf_count_verbose.hpp"
@@ -83,7 +85,6 @@
#endif
#if defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_ARM64)
# include "snippets/pass/propagate_precision.hpp"
-# include "transformations/snippets/common/pass/lowered/fuse_load_store_and_convert.hpp"
#endif
#if defined(OPENVINO_ARCH_X86_64)
@@ -680,7 +681,7 @@ Subgraph::DataFlowPasses Subgraph::getDataFlowPasses() {
Subgraph::ControlFlowPasses
Subgraph::getControlFlowPasses() { // NOLINT(readability-convert-member-functions-to-static)
ControlFlowPasses backend_passes;
-#if defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_ARM64) || defined(SNIPPETS_DEBUG_CAPS)
+#if defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_ARM64) || defined(OPENVINO_ARCH_RISCV64)
using PassPosition = ov::snippets::pass::PassPosition;
using Place = PassPosition::Place;
#endif
@@ -748,6 +749,9 @@ Subgraph::getControlFlowPasses() { // NOLINT(readability-convert-member-functio
SNIPPETS_REGISTER_PASS_RELATIVE_ARM64(Place::After,
ov::snippets::lowered::pass::InsertLoops,
ov::intel_cpu::pass::FuseLoadStoreConvert);
+ SNIPPETS_REGISTER_PASS_RELATIVE_RISCV64(Place::After,
+ ov::snippets::lowered::pass::InsertLoops,
+ ov::intel_cpu::pass::FuseLoadStoreConvert);
SNIPPETS_REGISTER_PASS_RELATIVE_X86_64(Place::Before,
ov::snippets::lowered::pass::InsertBuffers,
ov::intel_cpu::pass::InsertBrgemmCopyBuffers);