Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL][ESIMD] Replace use of intrinsics with spirv functions for addc/subb #13093

Draft
wants to merge 28 commits into
base: sycl
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
608bb81
Replace use of intrinsics with spirv functions for addc/subb
fineg74 Mar 21, 2024
608721d
Restore lowering of esimd intrinsics
fineg74 Apr 23, 2024
52ceded
Refactor implementation
fineg74 Apr 23, 2024
7b90096
Update tests
fineg74 Apr 23, 2024
0e8b39a
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Apr 23, 2024
875bcdb
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Apr 25, 2024
9d9efa7
Remove support for 8/16 bit data
fineg74 Apr 25, 2024
9b953dd
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Apr 25, 2024
9bbb5d2
Merge branch 'addc' of https://github.com/fineg74/llvm into addc
fineg74 Apr 25, 2024
ad0cb74
Fix clang-format issue
fineg74 Apr 25, 2024
a30f641
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Apr 26, 2024
7b60952
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 May 2, 2024
d9a395c
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 May 6, 2024
e596e18
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 May 14, 2024
5cee161
Fix clang-format and a build break
fineg74 May 14, 2024
1f4124f
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 May 29, 2024
43ecf76
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 May 31, 2024
a26049a
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Jul 7, 2024
1a3e5f6
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Jul 17, 2024
6e32c41
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Jul 30, 2024
5d48b4e
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Aug 2, 2024
c6e9852
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Aug 14, 2024
a9eff15
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Aug 23, 2024
5f99e62
Fix test issue
fineg74 Aug 23, 2024
257bad9
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Sep 11, 2024
a2a2b5d
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Oct 17, 2024
b7a027d
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Oct 23, 2024
82702a5
Merge remote-tracking branch 'origin/sycl' into addc
fineg74 Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sycl/include/sycl/__spirv/spirv_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <stddef.h> // for size_t
#include <stdint.h> // for uint32_t
#include <type_traits>
#include <utility> // for pair

// Convergent attribute
#ifdef __SYCL_DEVICE_ONLY__
Expand Down Expand Up @@ -1274,6 +1275,13 @@ extern __DPCPP_SYCL_EXTERNAL
std::enable_if_t<std::is_integral_v<to> && std::is_unsigned_v<to>, to>
__spirv_ConvertPtrToU(from val) noexcept;

template <typename T, int N>
extern __DPCPP_SYCL_EXTERNAL std::pair<__ocl_vec_t<T, N>, __ocl_vec_t<T, N>>
__spirv_IAddCarry(__ocl_vec_t<T, N> src0, __ocl_vec_t<T, N> src1);

template <typename T, int N>
extern __DPCPP_SYCL_EXTERNAL std::pair<__ocl_vec_t<T, N>, __ocl_vec_t<T, N>>
__spirv_ISubBorrow(__ocl_vec_t<T, N> src0, __ocl_vec_t<T, N> src1);
template <typename RetT, typename... ArgsT>
extern __DPCPP_SYCL_EXTERNAL __spv::__spirv_TaskSequenceINTEL *
__spirv_TaskSequenceCreateINTEL(RetT (*f)(ArgsT...), int Pipelined = -1,
Expand Down
214 changes: 89 additions & 125 deletions sycl/include/sycl/ext/intel/esimd/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1720,131 +1720,95 @@ bfn(T src0, T src1, T src2) {

/// @} sycl_esimd_logical

/// Performs add with carry of 2 unsigned 32-bit vectors.
/// @tparam N size of the vectors
/// @param carry vector that is going to hold resulting carry flag
/// @param src0 first term
/// @param src1 second term
/// @return sum of 2 terms, carry flag is returned through \c carry parameter
template <int N>
__ESIMD_API __ESIMD_NS::simd<uint32_t, N>
addc(__ESIMD_NS::simd<uint32_t, N> &carry, __ESIMD_NS::simd<uint32_t, N> src0,
__ESIMD_NS::simd<uint32_t, N> src1) {
std::pair<__ESIMD_DNS::vector_type_t<uint32_t, N>,
__ESIMD_DNS::vector_type_t<uint32_t, N>>
Result = __esimd_addc<uint32_t, N>(src0.data(), src1.data());

carry = Result.first;
return Result.second;
}

/// Performs add with carry of a unsigned 32-bit vector and scalar.
/// @tparam N size of the vectors
/// @param carry vector that is going to hold resulting carry flag
/// @param src0 first term
/// @param src1 second term
/// @return sum of 2 terms, carry flag is returned through \c carry parameter
template <int N>
__ESIMD_API __ESIMD_NS::simd<uint32_t, N>
addc(__ESIMD_NS::simd<uint32_t, N> &carry, __ESIMD_NS::simd<uint32_t, N> src0,
uint32_t src1) {
__ESIMD_NS::simd<uint32_t, N> Src1V = src1;
return addc(carry, src0, Src1V);
}

/// Performs add with carry of a unsigned 32-bit scalar and vector.
/// @tparam N size of the vectors
/// @param carry vector that is going to hold resulting carry flag
/// @param src0 first term
/// @param src1 second term
/// @return sum of 2 terms, carry flag is returned through \c carry parameter
template <int N>
__ESIMD_API __ESIMD_NS::simd<uint32_t, N>
addc(__ESIMD_NS::simd<uint32_t, N> &carry, uint32_t src0,
__ESIMD_NS::simd<uint32_t, N> src1) {
__ESIMD_NS::simd<uint32_t, N> Src0V = src0;
return addc(carry, Src0V, src1);
}

/// Performs add with carry of a unsigned 32-bit scalars.
/// @tparam N size of the vectors
/// @param carry scalar that is going to hold resulting carry flag
/// @param src0 first term
/// @param src1 second term
/// @return sum of 2 terms, carry flag is returned through \c carry parameter
__ESIMD_API uint32_t addc(uint32_t &carry, uint32_t src0, uint32_t src1) {
__ESIMD_NS::simd<uint32_t, 1> CarryV = carry;
__ESIMD_NS::simd<uint32_t, 1> Src0V = src0;
__ESIMD_NS::simd<uint32_t, 1> Src1V = src1;
__ESIMD_NS::simd<uint32_t, 1> Res = addc(CarryV, Src0V, Src1V);
carry = CarryV[0];
return Res[0];
}

/// Performs substraction with borrow of 2 unsigned 32-bit vectors.
/// @tparam N size of the vectors
/// @param borrow vector that is going to hold resulting borrow flag
/// @param src0 first term
/// @param src1 second term
/// @return difference of 2 terms, borrow flag is returned through \c borrow
/// parameter
template <int N>
__ESIMD_API __ESIMD_NS::simd<uint32_t, N>
subb(__ESIMD_NS::simd<uint32_t, N> &borrow, __ESIMD_NS::simd<uint32_t, N> src0,
__ESIMD_NS::simd<uint32_t, N> src1) {
std::pair<__ESIMD_DNS::vector_type_t<uint32_t, N>,
__ESIMD_DNS::vector_type_t<uint32_t, N>>
Result = __esimd_subb<uint32_t, N>(src0.data(), src1.data());

borrow = Result.first;
return Result.second;
}

/// Performs substraction with borrow of unsigned 32-bit vector and scalar.
/// @tparam N size of the vectors
/// @param borrow vector that is going to hold resulting borrow flag
/// @param src0 first term
/// @param src1 second term
/// @return difference of 2 terms, borrow flag is returned through \c borrow
/// parameter
template <int N>
__ESIMD_API __ESIMD_NS::simd<uint32_t, N>
subb(__ESIMD_NS::simd<uint32_t, N> &borrow, __ESIMD_NS::simd<uint32_t, N> src0,
uint32_t src1) {
__ESIMD_NS::simd<uint32_t, N> Src1V = src1;
return subb(borrow, src0, Src1V);
}

/// Performs substraction with borrow of unsigned 32-bit scalar and vector.
/// @tparam N size of the vectors
/// @param borrow vector that is going to hold resulting borrow flag
/// @param src0 first term
/// @param src1 second term
/// @return difference of 2 terms, borrow flag is returned through \c borrow
/// parameter
template <int N>
__ESIMD_API __ESIMD_NS::simd<uint32_t, N>
subb(__ESIMD_NS::simd<uint32_t, N> &borrow, uint32_t src0,
__ESIMD_NS::simd<uint32_t, N> src1) {
__ESIMD_NS::simd<uint32_t, N> Src0V = src0;
return subb(borrow, Src0V, src1);
}

/// Performs substraction with borrow of 2 unsigned 32-bit scalars.
/// @tparam N size of the vectors
/// @param borrow scalar that is going to hold resulting borrow flag
/// @param src0 first term
/// @param src1 second term
/// @return difference of 2 terms, borrow flag is returned through \c borrow
/// parameter
__ESIMD_API uint32_t subb(uint32_t &borrow, uint32_t src0, uint32_t src1) {
__ESIMD_NS::simd<uint32_t, 1> BorrowV = borrow;
__ESIMD_NS::simd<uint32_t, 1> Src0V = src0;
__ESIMD_NS::simd<uint32_t, 1> Src1V = src1;
__ESIMD_NS::simd<uint32_t, 1> Res = subb(BorrowV, Src0V, Src1V);
borrow = BorrowV[0];
return Res[0];
}
#if defined(__SYCL_DEVICE_ONLY__)
#define __ESIMD_ADDC_IMPL(T) \
std::pair<__ESIMD_DNS::vector_type_t<T, N>, \
__ESIMD_DNS::vector_type_t<T, N>> \
Result = __spirv_IAddCarry<T, N>(src0.data(), src1.data()); \
carry = Result.second; \
return Result.first;
#else
#define __ESIMD_ADDC_IMPL(T) return 0;
#endif // __SYCL_DEVICE_ONLY__

#define __ESIMD_ADDC(T) \
template <int N> \
__ESIMD_API __ESIMD_NS::simd<T, N> addc(__ESIMD_NS::simd<T, N> &carry, \
__ESIMD_NS::simd<T, N> src0, \
__ESIMD_NS::simd<T, N> src1) { \
__ESIMD_ADDC_IMPL(T) \
} \
template <int N> \
__ESIMD_API __ESIMD_NS::simd<T, N> addc( \
__ESIMD_NS::simd<T, N> &carry, __ESIMD_NS::simd<T, N> src0, T src1) { \
__ESIMD_NS::simd<T, N> Src1V = src1; \
return addc(carry, src0, Src1V); \
} \
template <int N> \
__ESIMD_API __ESIMD_NS::simd<T, N> addc( \
__ESIMD_NS::simd<T, N> &carry, T src0, __ESIMD_NS::simd<T, N> src1) { \
__ESIMD_NS::simd<T, N> Src0V = src0; \
return addc(carry, Src0V, src1); \
} \
__ESIMD_API T addc(T &carry, T src0, T src1) { \
__ESIMD_NS::simd<T, 1> CarryV = carry; \
__ESIMD_NS::simd<T, 1> Src0V = src0; \
__ESIMD_NS::simd<T, 1> Src1V = src1; \
__ESIMD_NS::simd<T, 1> Res = addc(CarryV, Src0V, Src1V); \
carry = CarryV[0]; \
return Res[0]; \
}

__ESIMD_ADDC(uint32_t)
__ESIMD_ADDC(uint64_t)

#undef __ESIMD_ADDC
#undef __ESIMD_ADDC_IMPL

#if defined(__SYCL_DEVICE_ONLY__)
#define __ESIMD_SUBB_IMPL(T) \
std::pair<__ESIMD_DNS::vector_type_t<T, N>, \
__ESIMD_DNS::vector_type_t<T, N>> \
Result = __spirv_ISubBorrow<T, N>(src0.data(), src1.data()); \
borrow = Result.second; \
return Result.first;
#else
#define __ESIMD_SUBB_IMPL(T) return 0;
#endif // __SYCL_DEVICE_ONLY__

#define __ESIMD_SUBB(T) \
template <int N> \
__ESIMD_API __ESIMD_NS::simd<T, N> subb(__ESIMD_NS::simd<T, N> &borrow, \
__ESIMD_NS::simd<T, N> src0, \
__ESIMD_NS::simd<T, N> src1) { \
__ESIMD_SUBB_IMPL(T) \
} \
template <int N> \
__ESIMD_API __ESIMD_NS::simd<T, N> subb( \
__ESIMD_NS::simd<T, N> &borrow, __ESIMD_NS::simd<T, N> src0, T src1) { \
__ESIMD_NS::simd<T, N> Src1V = src1; \
return subb(borrow, src0, Src1V); \
} \
template <int N> \
__ESIMD_API __ESIMD_NS::simd<T, N> subb( \
__ESIMD_NS::simd<T, N> &borrow, T src0, __ESIMD_NS::simd<T, N> src1) { \
__ESIMD_NS::simd<T, N> Src0V = src0; \
return subb(borrow, Src0V, src1); \
} \
__ESIMD_API T subb(T &borrow, T src0, T src1) { \
__ESIMD_NS::simd<T, 1> BorrowV = borrow; \
__ESIMD_NS::simd<T, 1> Src0V = src0; \
__ESIMD_NS::simd<T, 1> Src1V = src1; \
__ESIMD_NS::simd<T, 1> Res = subb(BorrowV, Src0V, Src1V); \
borrow = BorrowV[0]; \
return Res[0]; \
} // namespace ext::intel::esimd

__ESIMD_SUBB(uint32_t)
__ESIMD_SUBB(uint64_t)

#undef __ESIMD_SUBB
#undef __ESIMD_SUBB_IMPL

/// rdtsc - get the value of timestamp counter.
/// @return the current value of timestamp counter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,6 @@ __ESIMD_INTRIN __ESIMD_DNS::vector_type_t<T, N> __esimd_dpasw_nosrc0(
__ESIMD_DNS::vector_type_t<T1, N1> src1,
__ESIMD_DNS::vector_type_t<T2, N2> src2) __ESIMD_INTRIN_END;

template <typename T, int N>
__ESIMD_INTRIN std::pair<__ESIMD_DNS::vector_type_t<T, N>,
__ESIMD_DNS::vector_type_t<T, N>>
__esimd_addc(__ESIMD_DNS::vector_type_t<T, N> src0,
__ESIMD_DNS::vector_type_t<T, N> src1) __ESIMD_INTRIN_END;

template <typename T, int N>
__ESIMD_INTRIN std::pair<__ESIMD_DNS::vector_type_t<T, N>,
__ESIMD_DNS::vector_type_t<T, N>>
__esimd_subb(__ESIMD_DNS::vector_type_t<T, N> src0,
__ESIMD_DNS::vector_type_t<T, N> src1) __ESIMD_INTRIN_END;

template <uint8_t FuncControl, typename T, int N>
__ESIMD_INTRIN __ESIMD_raw_vec_t(T, N)
__esimd_bfn(__ESIMD_raw_vec_t(T, N) src0, __ESIMD_raw_vec_t(T, N) src1,
Expand Down
Loading
Loading