Skip to content

Commit

Permalink
is_sycl{ => _scalar}_floating_point
Browse files Browse the repository at this point in the history
  • Loading branch information
fknorr committed Dec 27, 2024
1 parent 2063674 commit e6abee4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 39 deletions.
30 changes: 13 additions & 17 deletions tests/common/common_vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ bool check_vector_size(sycl::vec<vecType, numOfElems> vector) {
* @brief Helper function to check vector values are correct.
*/
template <typename vecType, int numOfElems>
bool check_vector_values(sycl::vec<vecType, numOfElems> vector,
vecType* vals) {
bool check_vector_values(sycl::vec<vecType, numOfElems> vector, vecType* vals) {
for (int i = 0; i < numOfElems; i++) {
if ((vals[i] != vector[i])) {
return false;
Expand All @@ -72,14 +71,12 @@ bool check_vector_values(sycl::vec<vecType, numOfElems> vector,
* for division result are accurate enough
*/
template <typename vecType, int numOfElems>
typename std::enable_if<is_sycl_floating_point<vecType>::value, bool>::type
check_vector_values_div(sycl::vec<vecType, numOfElems> vector,
vecType *vals) {
typename std::enable_if_t<is_sycl_scalar_floating_point_v<vecType>, bool>
check_vector_values_div(sycl::vec<vecType, numOfElems> vector, vecType* vals) {
for (int i = 0; i < numOfElems; i++) {
vecType vectorValue = vector[i];
if (vals[i] == vectorValue)
continue;
const vecType ulpsExpected = 2.5; // Min Accuracy for x / y
if (vals[i] == vectorValue) continue;
const vecType ulpsExpected = 2.5; // Min Accuracy for x / y
const vecType difference = sycl::fabs(vectorValue - vals[i]);
// using sycl functions to get ulp because it used in kernel
const vecType differenceExpected = ulpsExpected * get_ulp_sycl(vals[i]);
Expand All @@ -95,9 +92,8 @@ check_vector_values_div(sycl::vec<vecType, numOfElems> vector,
* @brief Helper function to check that vector values for division are correct
*/
template <typename vecType, int numOfElems>
typename std::enable_if<!is_sycl_floating_point<vecType>::value, bool>::type
check_vector_values_div(sycl::vec<vecType, numOfElems> vector,
vecType *vals) {
typename std::enable_if_t<!is_sycl_scalar_floating_point_v<vecType>, bool>::type
check_vector_values_div(sycl::vec<vecType, numOfElems> vector, vecType* vals) {
return check_vector_values(vector, vals);
}

Expand All @@ -123,7 +119,8 @@ bool check_single_vector_op(vectorType vector1, lambdaFunc lambda) {

template <typename sourceType, typename targetType>
static constexpr bool if_FP_to_non_FP_conv_v =
is_sycl_floating_point<sourceType>::value && !is_sycl_floating_point<targetType>::value;
is_sycl_scalar_floating_point<sourceType>::value &&
!is_sycl_scalar_floating_point<targetType>::value;

template <typename vecType, int N, typename convertType>
sycl::vec<convertType, N> convert_vec(sycl::vec<vecType, N> inputVec) {
Expand Down Expand Up @@ -196,7 +193,7 @@ sycl::vec<convertType, N> rtn(sycl::vec<vecType, N> inputVec) {
// values instead.
template <typename vecType, int N, typename convertType>
void handleFPToUnsignedConv(sycl::vec<vecType, N>& inputVec) {
if constexpr (is_sycl_floating_point<vecType>::value &&
if constexpr (is_sycl_scalar_floating_point<vecType>::value &&
std::is_unsigned_v<convertType>) {
for (size_t i = 0; i < N; ++i) {
vecType elem = inputVec[i];
Expand Down Expand Up @@ -247,7 +244,7 @@ bool check_vector_convert_result_impl(sycl::vec<vecType, N> inputVec,
sycl::vec<convertType, N> expectedVec;
switch (mode) {
case sycl::rounding_mode::automatic:
if constexpr (is_sycl_floating_point<vecType>::value) {
if constexpr (is_sycl_scalar_floating_point<vecType>::value) {
expectedVec = rte<vecType, N, convertType>(inputVec);
} else {
expectedVec = rtz<vecType, N, convertType>(inputVec);
Expand Down Expand Up @@ -291,9 +288,8 @@ bool check_vector_convert_result(sycl::vec<vecType, N> inputVec) {
template <typename vecType, int N, typename convertType>
bool check_vector_convert_modes(sycl::vec<vecType, N> inputVec) {
bool flag = true;
flag &=
check_vector_convert_result<vecType, N, convertType,
sycl::rounding_mode::automatic>(inputVec);
flag &= check_vector_convert_result<vecType, N, convertType,
sycl::rounding_mode::automatic>(inputVec);
#if SYCL_CTS_ENABLE_FULL_CONFORMANCE
flag &= check_vector_convert_result<vecType, N, convertType,
sycl::rounding_mode::rte>(inputVec);
Expand Down
2 changes: 1 addition & 1 deletion tests/group_functions/group_functions_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ template <typename T>
inline auto get_op_types() {
#if SYCL_CTS_ENABLE_FULL_CONFORMANCE
static const auto types = []() {
if constexpr (is_sycl_floating_point_v<T>) {
if constexpr (is_sycl_scalar_floating_point_v<T>) {
// Bitwise operations are not defined for floating point types.
return named_type_pack<sycl::plus<T>, sycl::multiplies<T>,
sycl::logical_and<T>, sycl::logical_or<T>,
Expand Down
15 changes: 8 additions & 7 deletions tests/marray_basic/marray_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ struct operators_helper {
// similar to native::divide we can skip checking them.
template <typename OpT, typename ElemT>
struct skip_result_check
: std::bool_constant<
(std::is_same_v<OpT, op_div> || std::is_same_v<OpT, op_assign_div>) &&
is_sycl_floating_point_v<ElemT>> {};
: std::bool_constant<(
std::is_same_v<OpT, op_div> ||
std::is_same_v<
OpT, op_assign_div>)&&is_sycl_scalar_floating_point_v<ElemT>> {};

template <typename OpT, typename ElemT>
constexpr bool skip_result_check_v = skip_result_check<OpT, ElemT>::value;
Expand All @@ -67,10 +68,10 @@ bool are_equal_ignore_division(const T1& lhs, const T1& rhs) {
// similar to native::divide we can skip checking them here.
constexpr bool is_div =
std::is_same_v<OpT, op_div> || std::is_same_v<OpT, op_assign_div>;
constexpr bool is_sycl_floating_point = std::is_same_v<ElemT, float> ||
std::is_same_v<ElemT, double> ||
std::is_same_v<ElemT, sycl::half>;
if constexpr (is_div && is_sycl_floating_point) return true;
constexpr bool is_sycl_scalar_floating_point =
std::is_same_v<ElemT, float> || std::is_same_v<ElemT, double> ||
std::is_same_v<ElemT, sycl::half>;
if constexpr (is_div && is_sycl_scalar_floating_point) return true;
return value_operations::are_equal(lhs, rhs);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/math_builtin_api/math_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ bool verify(sycl_cts::util::logger& log, T a, T b, float accuracy,
AccuracyMode accuracy_mode, const std::string& comment);

template <typename T>
std::enable_if_t<is_sycl_floating_point_v<T>, bool>
verify(sycl_cts::util::logger& log, T value, sycl_cts::resultRef<T> r,
float accuracy, AccuracyMode accuracy_mode, const std::string& comment) {
std::enable_if_t<is_sycl_scalar_floating_point_v<T>, bool> verify(
sycl_cts::util::logger& log, T value, sycl_cts::resultRef<T> r,
float accuracy, AccuracyMode accuracy_mode, const std::string& comment) {
const T reference = r.res;

if (!r.undefined.empty())
Expand Down
10 changes: 5 additions & 5 deletions tests/reduction/identity_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ AccumulatorT get_identity() {
}

/** minimum (floating point) */
template <typename AccumulatorT, typename OperatorT,
std::enable_if_t<
std::is_same_v<OperatorT, sycl::minimum<AccumulatorT>> &&
is_sycl_floating_point_v<AccumulatorT>,
bool> = true>
template <
typename AccumulatorT, typename OperatorT,
std::enable_if_t<std::is_same_v<OperatorT, sycl::minimum<AccumulatorT>> &&
is_sycl_scalar_floating_point_v<AccumulatorT>,
bool> = true>
AccumulatorT get_identity() {
return std::numeric_limits<AccumulatorT>::infinity();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/reduction/reduction_without_identity_param_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ template <typename VariableT, bool UseCombineFlagT, bool UsePropertyFlag,
void run_test_for_all_reductions_types(FunctorT functor, RangeT& range,
sycl::queue& queue,
const std::string& type_name) {
if constexpr (is_sycl_floating_point<VariableT>::value &&
if constexpr (is_sycl_scalar_floating_point<VariableT>::value &&
(std::is_same<FunctorT, sycl::bit_and<VariableT>>::value ||
std::is_same<FunctorT, sycl::bit_or<VariableT>>::value ||
std::is_same<FunctorT, sycl::bit_xor<VariableT>>::value)) {
Expand Down
10 changes: 5 additions & 5 deletions util/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ using has_atomic_support = contains<T, int, unsigned int, long, unsigned long,
* @brief Checks whether T is a floating-point sycl type
*/
template <typename T>
using is_sycl_floating_point =
using is_sycl_scalar_floating_point =
#if SYCL_CTS_ENABLE_HALF_TESTS
std::bool_constant<std::is_floating_point_v<T> ||
std::is_same_v<std::remove_cv_t<T>, sycl::half>>;
Expand All @@ -59,8 +59,8 @@ using is_sycl_floating_point =
#endif

template <typename T>
inline constexpr bool is_sycl_floating_point_v{
is_sycl_floating_point<T>::value};
inline constexpr bool is_sycl_scalar_floating_point_v{
is_sycl_scalar_floating_point<T>::value};

template <typename T>
using is_nonconst_rvalue_reference =
Expand Down Expand Up @@ -410,10 +410,10 @@ using is_legal_operator = std::bool_constant<
std::is_same_v<std::remove_cv_t<T>, bool>) ||
(std::is_same_v<OperatorT, sycl::minimum<T>> && std::is_integral_v<T>) ||
(std::is_same_v<OperatorT, sycl::minimum<T>> &&
is_sycl_floating_point_v<T>) ||
is_sycl_scalar_floating_point_v<T>) ||
(std::is_same_v<OperatorT, sycl::maximum<T>> && std::is_integral_v<T>) ||
(std::is_same_v<OperatorT, sycl::maximum<T>> &&
is_sycl_floating_point_v<T>)>;
is_sycl_scalar_floating_point_v<T>)>;

/**
Checks whether \p T and \p OperatorT form a valid SYCL operator. */
Expand Down

0 comments on commit e6abee4

Please sign in to comment.