Skip to content

Commit 6f0bb25

Browse files
authored
[SYCL][libdevice] Add SIMD emulation APIs for imf libdevice (#6327)
* [SYCL][libdevice] Add SIMD emulation APIs for imf libdevice * Add __imf_vcmp* functions part1 * add __imf_vset* APIs * Add __imf_vsadu2/4 __imf_vsads2/4 * Add all SIMD APIs * fix incorrect __devicelib_imf_vhaddu2 name * Fix bug in __imf_vcmplt4 Signed-off-by: jinge90 <[email protected]>
1 parent 0f30535 commit 6f0bb25

File tree

7 files changed

+1889
-4
lines changed

7 files changed

+1889
-4
lines changed

libdevice/cmake/modules/ImfSrcConcate.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(imf_fp32_fallback_src_list imf_utils/integer_misc.cpp
22
imf_utils/half_convert.cpp
33
imf_utils/float_convert.cpp
4+
imf_utils/simd_emulate.cpp
45
imf/imf_inline_fp32.cpp)
56

67
set(imf_fp64_fallback_src_list imf_utils/double_convert.cpp

libdevice/cmake/modules/SYCLLibdevice.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ set(imf_fallback_fp32_deps device.h device_imf.hpp imf_half.hpp
123123
imf_utils/integer_misc.cpp
124124
imf_utils/float_convert.cpp
125125
imf_utils/half_convert.cpp
126+
imf_utils/simd_emulate.cpp
126127
imf/imf_inline_fp32.cpp)
127128
set(imf_fallback_fp64_deps device.h device_imf.hpp imf_half.hpp
128129
imf_utils/double_convert.cpp

libdevice/device_imf.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "device.h"
1313
#include "imf_half.hpp"
1414
#include <cstddef>
15+
#include <limits>
1516
#include <type_traits>
16-
1717
#ifdef __LIBDEVICE_IMF_ENABLED__
1818

1919
#if !defined(__SPIR__) && !defined(__LIBDEVICE_HOST_IMPL__)
@@ -458,12 +458,21 @@ static inline int __popcll(unsigned long long int x) {
458458
#endif
459459
}
460460

461-
static inline unsigned int __abs(int x) { return x < 0 ? -x : x; }
462-
463-
static inline unsigned long long int __abs(long long int x) {
461+
template <typename T>
462+
static inline typename std::make_unsigned<T>::type __abs(T x) {
463+
static_assert((std::is_signed<T>::value && std::is_integral<T>::value),
464+
"__abs can only accept signed integral type.");
464465
return x < 0 ? -x : x;
465466
}
466467

468+
template <typename T> static inline void __swap(T &x, T &y) {
469+
static_assert(std::is_integral<T>::value,
470+
"__swap can only accept integral type.");
471+
T tmp = x;
472+
x = y;
473+
y = tmp;
474+
}
475+
467476
template <typename Ty1, typename Ty2>
468477
static inline Ty2 __get_bytes_by_index(Ty1 x, size_t idx) {
469478
static_assert(!std::is_signed<Ty1>::value && !std::is_signed<Ty2>::value,

0 commit comments

Comments
 (0)