Skip to content

[ESIMD]Move addc and subb functions out of experimental namespace #10589

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

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
126 changes: 126 additions & 0 deletions sycl/include/sycl/ext/intel/esimd/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,132 @@ ESIMD_INLINE ESIMD_NODEBUG T0 reduce(simd<T1, SZ> v, BinaryOperation op) {
}
}

/// 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];
}

/// @} sycl_esimd_math

} // namespace ext::intel::esimd
Expand Down
92 changes: 42 additions & 50 deletions sycl/include/sycl/ext/intel/experimental/esimd/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,77 +497,69 @@ imul(T &rmd, T0 src0, T1 src1) {
}

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;
__SYCL_DEPRECATED(
"Please use sycl::ext::intel::esimd::addc(carry, src0, src1);")
__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) {
return __ESIMD_NS::addc(carry, src0, src1);
}

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);
__SYCL_DEPRECATED(
"Please use sycl::ext::intel::esimd::addc(carry, src0, src1);")
__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) {
return __ESIMD_NS::addc(carry, src0, src1);
}

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);
__SYCL_DEPRECATED(
"Please use sycl::ext::intel::esimd::addc(carry, src0, src1);")
__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) {
return __ESIMD_NS::addc(carry, src0, src1);
}

__SYCL_DEPRECATED(
"Please use sycl::ext::intel::esimd::addc(carry, src0, src1);")
__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];
return __ESIMD_NS::addc(carry, src0, src1);
}

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;
__SYCL_DEPRECATED(
"Please use sycl::ext::intel::esimd::subb(borrow, src0, src1);")
__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) {
return __ESIMD_NS::subb(borrow, src0, src1);
}

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);
__SYCL_DEPRECATED(
"Please use sycl::ext::intel::esimd::subb(borrow, src0, src1);")
__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) {
return __ESIMD_NS::subb(borrow, src0, src1);
}

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);
__SYCL_DEPRECATED(
"Please use sycl::ext::intel::esimd::subb(borrow, src0, src1);")
__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) {
return __ESIMD_NS::subb(borrow, src0, src1);
}

__SYCL_DEPRECATED(
"Please use sycl::ext::intel::esimd::subb(borrow, src0, src1);")
__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];
return __ESIMD_NS::subb(borrow, src0, src1);
}

/// Integral quotient (vector version)
Expand Down
3 changes: 1 addition & 2 deletions sycl/test-e2e/ESIMD/addc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

using namespace sycl;
using namespace sycl::ext::intel::esimd;
namespace iesimd = sycl::ext::intel::experimental::esimd;

template <int N, bool AIsVector, bool BIsVector> bool test(sycl::queue Q) {
static_assert(AIsVector || BIsVector || N == 1,
Expand Down Expand Up @@ -84,7 +83,7 @@ template <int N, bool AIsVector, bool BIsVector> bool test(sycl::queue Q) {
using ResType = std::conditional_t<AIsVector || BIsVector,
simd<uint32_t, N>, uint32_t>;
ResType Carry = 0;
ResType Res = iesimd::addc(Carry, A, B);
ResType Res = addc(Carry, A, B);

if constexpr (AIsVector || BIsVector) {
Carry.copy_to(CarryMatrixPtr + (ValuesToTrySize * AI + BI) * N);
Expand Down
3 changes: 1 addition & 2 deletions sycl/test-e2e/ESIMD/subb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

using namespace sycl;
using namespace sycl::ext::intel::esimd;
namespace iesimd = sycl::ext::intel::experimental::esimd;

template <int N, bool AIsVector, bool BIsVector> bool test(sycl::queue Q) {
static_assert(AIsVector || BIsVector || N == 1,
Expand Down Expand Up @@ -85,7 +84,7 @@ template <int N, bool AIsVector, bool BIsVector> bool test(sycl::queue Q) {
using ResType = std::conditional_t<AIsVector || BIsVector,
simd<uint32_t, N>, uint32_t>;
ResType Borrow = 0;
ResType Res = iesimd::subb(Borrow, A, B);
ResType Res = subb(Borrow, A, B);

if constexpr (AIsVector || BIsVector) {
Borrow.copy_to(BorrowMatrixPtr + (ValuesToTrySize * AI + BI) * N);
Expand Down