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
[core] Add preprocessor symbol to enable/disable Xbyak JIT in core (#26712)
Pawel Raasz503375480713
diff --git a/src/core/reference/include/openvino/reference/convert.hpp b/src/core/reference/include/openvino/reference/convert.hppindex 86767988533..926af31dbf5 100644--- a/src/core/reference/include/openvino/reference/convert.hpp+++ b/src/core/reference/include/openvino/reference/convert.hpp@@ -13,6 +13,12 @@#include "openvino/core/type/float16.hpp"#include "openvino/core/type/nf4.hpp"+#if !defined(OS_CHROMEOS) && (defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64))+# define OV_CORE_USE_XBYAK_JIT 1+#else+# define OV_CORE_USE_XBYAK_JIT 0+#endif+namespace ov {template <class ElementIter>@@ -56,7 +62,7 @@ void convert(const TI* arg, TO* out, const size_t count) {std::transform(arg, arg + count, out, detail::convert<TI, TO>);}-#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)+#if OV_CORE_USE_XBYAK_JITtemplate <>void convert<uint8_t, float16>(const uint8_t* arg, float16* out, size_t count);@@ -65,8 +71,6 @@ void convert<float16, float>(const float16* arg, float* out, size_t count);template <>void convert<float, float16>(const float* arg, float16* out, size_t count);template <>-void convert<int32_t, float16>(const int32_t* arg, float16* out, size_t count);-template <>void convert<float, int8_t>(const float* arg, int8_t* out, size_t count);template <>void convert<float16, int8_t>(const float16* arg, int8_t* out, size_t count);@@ -75,7 +79,10 @@ void convert<bfloat16, float16>(const bfloat16* arg, float16* out, size_t count)template <>void convert<bfloat16, float>(const bfloat16* arg, float* out, size_t count);-#endif // OPENVINO_ARCH_X86 || OPENVINO_ARCH_X86_64+#endif // OV_CORE_USE_XBYAK_JIT++template <>+void convert<int32_t, float16>(const int32_t* arg, float16* out, size_t count);// Count how many f32 values is out of normal finite numbers range when converted to f16size_t count_out_of_f16_range(const float* arg, size_t count);diff --git a/src/core/reference/src/op/convert.cpp b/src/core/reference/src/op/convert.cppindex 856ec55a342..18ad7a6f471 100644--- a/src/core/reference/src/op/convert.cpp+++ b/src/core/reference/src/op/convert.cpp@@ -4,15 +4,15 @@#include "openvino/reference/convert.hpp"-#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)+#if OV_CORE_USE_XBYAK_JIT# include "jit_generator.hpp"using namespace ov::runtime;-#endif+#endif // OV_CORE_USE_XBYAK_JITnamespace ov {namespace reference {-#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)+#if OV_CORE_USE_XBYAK_JITnamespace {template <typename src_t, typename dst_t, bool clamp = false>void jit_convert_vec(jit::Generator&, const Xbyak::RegExp&, const Xbyak::RegExp&);@@ -521,19 +521,6 @@ void convert<float, float16>(const float* arg, float16* out, size_t count) {convert_impl(arg, out, count);}-template <>-void convert<int32_t, float16>(const int32_t* arg, float16* out, size_t count) {- for (size_t i = 0; i < count; ++i) {- if (arg[i] > std::numeric_limits<ov::float16>::max()) {- out[i] = std::numeric_limits<ov::float16>::max();- } else if (arg[i] < std::numeric_limits<ov::float16>::lowest()) {- out[i] = std::numeric_limits<ov::float16>::lowest();- } else {- out[i] = static_cast<ov::float16>(arg[i]);- }- }-}-template <>void convert<float, int8_t>(const float* arg, int8_t* out, size_t count) {convert_impl(arg, out, count);@@ -554,10 +541,10 @@ void convert<bfloat16, float>(const bfloat16* arg, float* out, size_t count) {convert_impl(arg, out, count);}-#endif // OPENVINO_ARCH_X86 || OPENVINO_ARCH_X86_64+#endif // OV_CORE_USE_XBYAK_JITvoid convert_from_f32_to_f16_with_clamp(const float* arg, float16* out, size_t count) {-#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)+#if OV_CORE_USE_XBYAK_JITconvert_impl<float, float16, true>(arg, out, count);#else// FIXME CVS-125496: duplicate and stub for ARM, provide optimized solution@@ -570,11 +557,24 @@ void convert_from_f32_to_f16_with_clamp(const float* arg, float16* out, size_t cout[i] = static_cast<ov::float16>(arg[i]);}}-#endif // defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)+#endif // OV_CORE_USE_XBYAK_JIT+}++template <>+void convert<int32_t, float16>(const int32_t* arg, float16* out, size_t count) {+ for (size_t i = 0; i < count; ++i) {+ if (arg[i] > std::numeric_limits<ov::float16>::max()) {+ out[i] = std::numeric_limits<ov::float16>::max();+ } else if (arg[i] < std::numeric_limits<ov::float16>::lowest()) {+ out[i] = std::numeric_limits<ov::float16>::lowest();+ } else {+ out[i] = static_cast<ov::float16>(arg[i]);+ }+ }}void convert_from_bf16_to_f16_with_clamp(const bfloat16* arg, float16* out, size_t count) {-#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)+#if OV_CORE_USE_XBYAK_JITconvert_impl<bfloat16, float16, true>(arg, out, count);#else// FIXME CVS-125496: duplicate and stub for ARM, provide optimized solution@@ -587,20 +587,20 @@ void convert_from_bf16_to_f16_with_clamp(const bfloat16* arg, float16* out, sizeout[i] = static_cast<ov::float16>(arg[i]);}}-#endif // defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)+#endif // OV_CORE_USE_XBYAK_JIT}size_t count_out_of_f16_range(const float* arg, size_t count) {size_t num_out_of_range = 0;-#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)+#if OV_CORE_USE_XBYAK_JITauto converter = jit_count_out_of_range::get<float, float16>();if (converter) {jit_count_out_of_range::args_t args = {arg, &num_out_of_range, count};converter(&args);return num_out_of_range;}-#endif+#endif // OV_CORE_USE_XBYAK_JITfor (size_t i = 0; i < count; ++i) {// if abs value is smaller than the smallest positive fp16, but not zeroif (std::abs(arg[i]) < ov::float16::from_bits(0x0001) && arg[i] != 0.0f) {