-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Fix bitselect builtin for integer types (#12598)
This regressed after #11956 as return type wasn't correctly converted from SPIR-V intrinsic back to SYCL types. This PR fixes that. In addition, I'm also adding tests for `sycl::select` builtin that was left unaffected only because we couldn't use SPIR-V intrinsic for its implementation.
- Loading branch information
1 parent
e4113f1
commit a2e1669
Showing
4 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
// RUN: %if preview-breaking-changes-supported %{ %{build} -fpreview-breaking-changes -o %t_preview.out %} | ||
// RUN: %if preview-breaking-changes-supported %{ %{run} %t_preview.out%} | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
template <typename... Ts, typename FuncTy> void TestTypes(FuncTy F) { | ||
(F(Ts{}), ...); | ||
} | ||
|
||
int main() { | ||
sycl::queue q; | ||
|
||
auto Test = [&](auto F, auto Expected, auto... Args) { | ||
#if defined(__GNUC__) || defined(__clang__) | ||
std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
#endif | ||
std::tuple ArgsTuple{Args...}; | ||
auto Result = std::apply(F, ArgsTuple); | ||
static_assert(std::is_same_v<decltype(Expected), decltype(Result)>); | ||
assert(Expected == Result); | ||
|
||
sycl::buffer<bool, 1> ResultBuf{1}; | ||
q.submit([&](sycl::handler &cgh) { | ||
sycl::accessor Result{ResultBuf, cgh}; | ||
cgh.single_task([=]() { | ||
auto R = std::apply(F, ArgsTuple); | ||
static_assert(std::is_same_v<decltype(Expected), decltype(R)>); | ||
Result[0] = Expected == R; | ||
}); | ||
}); | ||
assert(sycl::host_accessor{ResultBuf}[0]); | ||
}; | ||
|
||
auto TestBitSelect = [&](auto type_val) { | ||
using T = decltype(type_val); | ||
auto BitSelect = [](auto... xs) { return sycl::bitselect(xs...); }; | ||
|
||
static_assert(std::is_integral_v<T>, | ||
"Only integer test is implemented here!"); | ||
Test(BitSelect, T{0b0110}, T{0b1100}, T{0b0011}, T{0b1010}); | ||
}; | ||
|
||
TestTypes<signed char, unsigned char, char, long, long long, unsigned long, | ||
unsigned long long>(TestBitSelect); | ||
|
||
auto TestSelect = [&](auto type_val) { | ||
using T = decltype(type_val); | ||
auto Select = [](auto... xs) { return sycl::select(xs...); }; | ||
|
||
Test(Select, T{0}, T{1}, T{0}, true); | ||
Test(Select, T{1}, T{1}, T{0}, false); | ||
}; | ||
|
||
TestTypes<signed char, unsigned char, char>(TestSelect); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters