Skip to content

Commit 5033754

Browse files
authored
[core] Add preprocessor symbol to enable/disable Xbyak JIT in core (openvinotoolkit#26712)
### Details: - When OV built with defined symbol `OS_CHROMEOS` (defined by ChromOS enviroment or user) the Xbyak JIT code will be disabled - Temporary use standard implementation instead Xbyak code to enable use OpenVINO on ChromOS. - Optimized version using intrinsic code in next PR. ### Tickets: - CVS-152707
1 parent a683ae6 commit 5033754

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

src/core/reference/include/openvino/reference/convert.hpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
#include "openvino/core/type/float16.hpp"
1414
#include "openvino/core/type/nf4.hpp"
1515

16+
#if !defined(OS_CHROMEOS) && (defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64))
17+
# define OV_CORE_USE_XBYAK_JIT 1
18+
#else
19+
# define OV_CORE_USE_XBYAK_JIT 0
20+
#endif
21+
1622
namespace ov {
1723

1824
template <class ElementIter>
@@ -56,7 +62,7 @@ void convert(const TI* arg, TO* out, const size_t count) {
5662
std::transform(arg, arg + count, out, detail::convert<TI, TO>);
5763
}
5864

59-
#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
65+
#if OV_CORE_USE_XBYAK_JIT
6066

6167
template <>
6268
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);
6571
template <>
6672
void convert<float, float16>(const float* arg, float16* out, size_t count);
6773
template <>
68-
void convert<int32_t, float16>(const int32_t* arg, float16* out, size_t count);
69-
template <>
7074
void convert<float, int8_t>(const float* arg, int8_t* out, size_t count);
7175
template <>
7276
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)
7579
template <>
7680
void convert<bfloat16, float>(const bfloat16* arg, float* out, size_t count);
7781

78-
#endif // OPENVINO_ARCH_X86 || OPENVINO_ARCH_X86_64
82+
#endif // OV_CORE_USE_XBYAK_JIT
83+
84+
template <>
85+
void convert<int32_t, float16>(const int32_t* arg, float16* out, size_t count);
7986

8087
// Count how many f32 values is out of normal finite numbers range when converted to f16
8188
size_t count_out_of_f16_range(const float* arg, size_t count);

src/core/reference/src/op/convert.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
#include "openvino/reference/convert.hpp"
66

7-
#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
7+
#if OV_CORE_USE_XBYAK_JIT
88
# include "jit_generator.hpp"
99

1010
using namespace ov::runtime;
11-
#endif
11+
#endif // OV_CORE_USE_XBYAK_JIT
1212

1313
namespace ov {
1414
namespace reference {
15-
#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
15+
#if OV_CORE_USE_XBYAK_JIT
1616
namespace {
1717
template <typename src_t, typename dst_t, bool clamp = false>
1818
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) {
521521
convert_impl(arg, out, count);
522522
}
523523

524-
template <>
525-
void convert<int32_t, float16>(const int32_t* arg, float16* out, size_t count) {
526-
for (size_t i = 0; i < count; ++i) {
527-
if (arg[i] > std::numeric_limits<ov::float16>::max()) {
528-
out[i] = std::numeric_limits<ov::float16>::max();
529-
} else if (arg[i] < std::numeric_limits<ov::float16>::lowest()) {
530-
out[i] = std::numeric_limits<ov::float16>::lowest();
531-
} else {
532-
out[i] = static_cast<ov::float16>(arg[i]);
533-
}
534-
}
535-
}
536-
537524
template <>
538525
void convert<float, int8_t>(const float* arg, int8_t* out, size_t count) {
539526
convert_impl(arg, out, count);
@@ -554,10 +541,10 @@ void convert<bfloat16, float>(const bfloat16* arg, float* out, size_t count) {
554541
convert_impl(arg, out, count);
555542
}
556543

557-
#endif // OPENVINO_ARCH_X86 || OPENVINO_ARCH_X86_64
544+
#endif // OV_CORE_USE_XBYAK_JIT
558545

559546
void convert_from_f32_to_f16_with_clamp(const float* arg, float16* out, size_t count) {
560-
#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
547+
#if OV_CORE_USE_XBYAK_JIT
561548
convert_impl<float, float16, true>(arg, out, count);
562549
#else
563550
// 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 c
570557
out[i] = static_cast<ov::float16>(arg[i]);
571558
}
572559
}
573-
#endif // defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
560+
#endif // OV_CORE_USE_XBYAK_JIT
561+
}
562+
563+
template <>
564+
void convert<int32_t, float16>(const int32_t* arg, float16* out, size_t count) {
565+
for (size_t i = 0; i < count; ++i) {
566+
if (arg[i] > std::numeric_limits<ov::float16>::max()) {
567+
out[i] = std::numeric_limits<ov::float16>::max();
568+
} else if (arg[i] < std::numeric_limits<ov::float16>::lowest()) {
569+
out[i] = std::numeric_limits<ov::float16>::lowest();
570+
} else {
571+
out[i] = static_cast<ov::float16>(arg[i]);
572+
}
573+
}
574574
}
575575

576576
void convert_from_bf16_to_f16_with_clamp(const bfloat16* arg, float16* out, size_t count) {
577-
#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
577+
#if OV_CORE_USE_XBYAK_JIT
578578
convert_impl<bfloat16, float16, true>(arg, out, count);
579579
#else
580580
// 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, size
587587
out[i] = static_cast<ov::float16>(arg[i]);
588588
}
589589
}
590-
#endif // defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
590+
#endif // OV_CORE_USE_XBYAK_JIT
591591
}
592592

593593
size_t count_out_of_f16_range(const float* arg, size_t count) {
594594
size_t num_out_of_range = 0;
595595

596-
#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
596+
#if OV_CORE_USE_XBYAK_JIT
597597
auto converter = jit_count_out_of_range::get<float, float16>();
598598
if (converter) {
599599
jit_count_out_of_range::args_t args = {arg, &num_out_of_range, count};
600600
converter(&args);
601601
return num_out_of_range;
602602
}
603-
#endif
603+
#endif // OV_CORE_USE_XBYAK_JIT
604604
for (size_t i = 0; i < count; ++i) {
605605
// if abs value is smaller than the smallest positive fp16, but not zero
606606
if (std::abs(arg[i]) < ov::float16::from_bits(0x0001) && arg[i] != 0.0f) {

0 commit comments

Comments
 (0)