Skip to content

[SYCL] vec convert of long long types correction. #1734

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
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
52 changes: 29 additions & 23 deletions sycl/include/CL/sycl/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,11 @@ using Rtp = detail::bool_constant<Mode == rounding_mode::rtp>;
template <rounding_mode Mode>
using Rtn = detail::bool_constant<Mode == rounding_mode::rtn>;

// convert signed and unsigned types with an equal size and diff names
// convert types with an equal size and diff names
template <typename T, typename R, rounding_mode roundingMode, typename OpenCLT,
typename OpenCLR>
detail::enable_if_t<!std::is_same<T, R>::value &&
(is_sint_to_sint<T, R>::value ||
is_uint_to_uint<T, R>::value) &&
std::is_same<OpenCLT, OpenCLR>::value,
R>
detail::enable_if_t<
!std::is_same<T, R>::value && std::is_same<OpenCLT, OpenCLR>::value, R>
convertImpl(T Value) {
return static_cast<R>(Value);
}
Expand All @@ -330,12 +327,11 @@ convertImpl(T Value) {
#define __SYCL_GENERATE_CONVERT_IMPL(DestType) \
template <typename T, typename R, rounding_mode roundingMode, \
typename OpenCLT, typename OpenCLR> \
detail::enable_if_t<!std::is_same<T, R>::value && \
is_sint_to_sint<T, R>::value && \
detail::enable_if_t<is_sint_to_sint<T, R>::value && \
!std::is_same<OpenCLT, OpenCLR>::value && \
(std::is_same<OpenCLR, DestType>::value || \
std::is_same<OpenCLR, signed char>::value && \
std::is_same<DestType, char>::value) && \
!std::is_same<OpenCLT, OpenCLR>::value, \
std::is_same<DestType, char>::value), \
R> \
convertImpl(T Value) { \
OpenCLT OpValue = cl::sycl::detail::convertDataToType<T, OpenCLT>(Value); \
Expand All @@ -346,18 +342,16 @@ __SYCL_GENERATE_CONVERT_IMPL(char)
__SYCL_GENERATE_CONVERT_IMPL(short)
__SYCL_GENERATE_CONVERT_IMPL(int)
__SYCL_GENERATE_CONVERT_IMPL(long)
__SYCL_GENERATE_CONVERT_IMPL(longlong)

#undef __SYCL_GENERATE_CONVERT_IMPL

// unsigned to unsigned
#define __SYCL_GENERATE_CONVERT_IMPL(DestType) \
template <typename T, typename R, rounding_mode roundingMode, \
typename OpenCLT, typename OpenCLR> \
detail::enable_if_t<!std::is_same<T, R>::value && \
is_uint_to_uint<T, R>::value && \
std::is_same<OpenCLR, DestType>::value && \
!std::is_same<OpenCLT, OpenCLR>::value, \
detail::enable_if_t<is_uint_to_uint<T, R>::value && \
!std::is_same<OpenCLT, OpenCLR>::value && \
std::is_same<OpenCLR, DestType>::value, \
R> \
convertImpl(T Value) { \
OpenCLT OpValue = cl::sycl::detail::convertDataToType<T, OpenCLT>(Value); \
Expand All @@ -374,16 +368,23 @@ __SYCL_GENERATE_CONVERT_IMPL(ulong)
// unsigned to (from) signed
template <typename T, typename R, rounding_mode roundingMode, typename OpenCLT,
typename OpenCLR>
detail::enable_if_t<is_sint_to_from_uint<T, R>::value, R> convertImpl(T Value) {
detail::enable_if_t<is_sint_to_from_uint<T, R>::value &&
is_standard_type<OpenCLT>::value &&
is_standard_type<OpenCLR>::value,
R>
convertImpl(T Value) {
return static_cast<R>(Value);
}

// sint to float
#define __SYCL_GENERATE_CONVERT_IMPL(SPIRVOp, DestType) \
template <typename T, typename R, rounding_mode roundingMode, \
typename OpenCLT, typename OpenCLR> \
detail::enable_if_t< \
is_sint_to_float<T, R>::value && std::is_same<R, DestType>::value, R> \
detail::enable_if_t<is_sint_to_float<T, R>::value && \
(std::is_same<OpenCLR, DestType>::value || \
std::is_same<OpenCLR, _Float16>::value && \
std::is_same<DestType, half>::value), \
R> \
convertImpl(T Value) { \
OpenCLT OpValue = cl::sycl::detail::convertDataToType<T, OpenCLT>(Value); \
return __spirv_Convert##SPIRVOp##_R##DestType(OpValue); \
Expand All @@ -399,8 +400,11 @@ __SYCL_GENERATE_CONVERT_IMPL(SToF, double)
#define __SYCL_GENERATE_CONVERT_IMPL(SPIRVOp, DestType) \
template <typename T, typename R, rounding_mode roundingMode, \
typename OpenCLT, typename OpenCLR> \
detail::enable_if_t< \
is_uint_to_float<T, R>::value && std::is_same<R, DestType>::value, R> \
detail::enable_if_t<is_uint_to_float<T, R>::value && \
(std::is_same<OpenCLR, DestType>::value || \
std::is_same<OpenCLR, _Float16>::value && \
std::is_same<DestType, half>::value), \
R> \
convertImpl(T Value) { \
OpenCLT OpValue = cl::sycl::detail::convertDataToType<T, OpenCLT>(Value); \
return __spirv_Convert##SPIRVOp##_R##DestType(OpValue); \
Expand All @@ -417,9 +421,11 @@ __SYCL_GENERATE_CONVERT_IMPL(UToF, double)
RoundingModeCondition) \
template <typename T, typename R, rounding_mode roundingMode, \
typename OpenCLT, typename OpenCLR> \
detail::enable_if_t<!std::is_same<T, R>::value && \
is_float_to_float<T, R>::value && \
std::is_same<R, DestType>::value && \
detail::enable_if_t<is_float_to_float<T, R>::value && \
!std::is_same<OpenCLT, OpenCLR>::value && \
(std::is_same<OpenCLR, DestType>::value || \
std::is_same<OpenCLR, _Float16>::value && \
std::is_same<DestType, half>::value) && \
RoundingModeCondition<roundingMode>::value, \
R> \
convertImpl(T Value) { \
Expand Down
9 changes: 9 additions & 0 deletions sycl/test/basic_tests/vec_convert_i_to_i.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,14 @@ int main() {
test<ulong, int, 8, rounding_mode::automatic>(
ulong8{3000000000, 2147483647, 100, 150, 2147483648, 1000, 0, 1},
int8{-1294967296, 2147483647, 100, 150, -2147483648, 1000, 0, 1});

test<longlong, ulonglong, 1, rounding_mode::automatic>(
longlong{1},
ulonglong{1});

test<ulonglong, longlong, 1, rounding_mode::automatic>(
ulonglong{1},
longlong{1});

return 0;
}