|
| 1 | +// RUN: %clangxx -fsycl %s -o %t.out |
| 2 | +// |
| 3 | +// Tests that casting multi_ptr to and from generic compiles for various |
| 4 | +// combinations of valid qualifiers. |
| 5 | + |
| 6 | +#include <sycl/sycl.hpp> |
| 7 | + |
| 8 | +using namespace sycl; |
| 9 | + |
| 10 | +template <typename T, access::address_space AddrSpace, |
| 11 | + sycl::access::decorated IsDecorated> |
| 12 | +void test(queue &Q) { |
| 13 | + T *GlobPtr = malloc_device<T>(1, Q); |
| 14 | + Q.submit([&](handler &CGH) { |
| 15 | + local_accessor<T> LocPtr{1, CGH}; |
| 16 | + CGH.single_task([=]() { |
| 17 | + T X = 0; |
| 18 | + T *InPtr; |
| 19 | + if constexpr (AddrSpace == access::address_space::global_space) |
| 20 | + InPtr = GlobPtr; |
| 21 | + else if constexpr (AddrSpace == access::address_space::local_space) |
| 22 | + InPtr = LocPtr.get_pointer(); |
| 23 | + else |
| 24 | + InPtr = &X; |
| 25 | + |
| 26 | + auto MPtr = address_space_cast<AddrSpace, IsDecorated>(InPtr); |
| 27 | + multi_ptr<T, access::address_space::generic_space, IsDecorated> GenPtr; |
| 28 | + GenPtr = MPtr; |
| 29 | + MPtr = multi_ptr<T, AddrSpace, IsDecorated>{GenPtr}; |
| 30 | + }); |
| 31 | + }).wait(); |
| 32 | +} |
| 33 | + |
| 34 | +template <typename T, access::address_space AddrSpace> |
| 35 | +void testAllDecos(queue &Q) { |
| 36 | + test<T, AddrSpace, sycl::access::decorated::yes>(Q); |
| 37 | + test<T, AddrSpace, sycl::access::decorated::no>(Q); |
| 38 | +} |
| 39 | + |
| 40 | +template <typename T> void testAllAddrSpace(queue &Q) { |
| 41 | + testAllDecos<T, access::address_space::private_space>(Q); |
| 42 | + testAllDecos<T, access::address_space::local_space>(Q); |
| 43 | + testAllDecos<T, access::address_space::global_space>(Q); |
| 44 | +} |
| 45 | + |
| 46 | +template <typename T> void testAllQuals(queue &Q) { |
| 47 | + using UnqualT = std::remove_cv_t<T>; |
| 48 | + testAllAddrSpace<UnqualT>(Q); |
| 49 | + testAllAddrSpace<std::add_const_t<UnqualT>>(Q); |
| 50 | + testAllAddrSpace<std::add_volatile_t<UnqualT>>(Q); |
| 51 | + testAllAddrSpace<std::add_cv_t<UnqualT>>(Q); |
| 52 | +} |
| 53 | + |
| 54 | +int main() { |
| 55 | + queue Q; |
| 56 | + testAllQuals<bool>(Q); |
| 57 | + testAllQuals<char>(Q); |
| 58 | + testAllQuals<short>(Q); |
| 59 | + testAllQuals<int>(Q); |
| 60 | + testAllQuals<long>(Q); |
| 61 | + testAllQuals<long long>(Q); |
| 62 | + testAllQuals<sycl::half>(Q); |
| 63 | + testAllQuals<float>(Q); |
| 64 | + testAllQuals<double>(Q); |
| 65 | + return 0; |
| 66 | +} |
0 commit comments