Skip to content

Commit

Permalink
Fix for test failure on AMD CPU.
Browse files Browse the repository at this point in the history
vec operator should also apply isnan for sycl::half
  • Loading branch information
oleksandr-pavlyk committed Oct 28, 2024
1 parent 63c82fc commit cd783e0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ template <typename argT1, typename argT2, typename resT> struct MaximumFunctor
}
else if constexpr (std::is_floating_point_v<argT1> ||
std::is_same_v<argT1, sycl::half>)
return (std::isnan(in1) || in1 > in2) ? in1 : in2;
else
{
const bool choose_first = (std::isnan(in1) || (in1 > in2));
return (choose_first) ? in1 : in2;
}
else {
return (in1 > in2) ? in1 : in2;
}
}

template <int vec_sz>
Expand All @@ -87,11 +91,17 @@ template <typename argT1, typename argT2, typename resT> struct MaximumFunctor
sycl::vec<resT, vec_sz> res;
#pragma unroll
for (int i = 0; i < vec_sz; ++i) {
if constexpr (std::is_floating_point_v<argT1>)
res[i] =
(sycl::isnan(in1[i]) || in1[i] > in2[i]) ? in1[i] : in2[i];
else
res[i] = (in1[i] > in2[i]) ? in1[i] : in2[i];
const auto &v1 = in1[i];
const auto &v2 = in2[i];
if constexpr (std::is_floating_point_v<argT1> ||
std::is_same_v<argT1, sycl::half>)
{
const bool choose_first = (std::isnan(v1) || (v1 > v2));
res[i] = (choose_first) ? v1 : v2;
}
else {
res[i] = (v1 > v2) ? v1 : v2;
}
}
return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ template <typename argT1, typename argT2, typename resT> struct MinimumFunctor
}
else if constexpr (std::is_floating_point_v<argT1> ||
std::is_same_v<argT1, sycl::half>)
return (std::isnan(in1) || in1 < in2) ? in1 : in2;
else
{
const bool choose_first = sycl::isnan(in1) || (in1 < in2);
return (choose_first) ? in1 : in2;
}
else {
return (in1 < in2) ? in1 : in2;
}
}

template <int vec_sz>
Expand All @@ -87,11 +91,17 @@ template <typename argT1, typename argT2, typename resT> struct MinimumFunctor
sycl::vec<resT, vec_sz> res;
#pragma unroll
for (int i = 0; i < vec_sz; ++i) {
if constexpr (std::is_floating_point_v<argT1>)
res[i] =
(sycl::isnan(in1[i]) || in1[i] < in2[i]) ? in1[i] : in2[i];
else
res[i] = (in1[i] < in2[i]) ? in1[i] : in2[i];
const auto &v1 = in1[i];
const auto &v2 = in2[i];
if constexpr (std::is_floating_point_v<argT1> ||
std::is_same_v<argT1, sycl::half>)
{
const bool choose_first = sycl::isnan(v1) || (v1 < v2);
res[i] = (choose_first) ? v1 : v2;
}
else {
res[i] = (v1 < v2) ? v1 : v2;
}
}
return res;
}
Expand Down

0 comments on commit cd783e0

Please sign in to comment.