|
| 1 | +// RUN: %clangxx -fsycl -fsyntax-only %s |
| 2 | + |
| 3 | +#include <sycl/sycl.hpp> |
| 4 | + |
| 5 | +template <int Dimensions> sycl::range<Dimensions> create_range() { |
| 6 | + return sycl::range<Dimensions>(1); |
| 7 | +} |
| 8 | + |
| 9 | +template <> sycl::range<2> create_range() { return sycl::range<2>(1, 1); } |
| 10 | + |
| 11 | +template <> sycl::range<3> create_range() { return sycl::range<3>(1, 1, 1); } |
| 12 | + |
| 13 | +// Compile only test to check that buffer_allocator type does not get |
| 14 | +// reinterpreted with const keyworkd |
| 15 | +template <typename T, int Dimensions, |
| 16 | + typename Allocator = sycl::buffer_allocator<T>> |
| 17 | +void test_buffer_const_reinterpret() { |
| 18 | + sycl::buffer<T, Dimensions, Allocator> buff(create_range<Dimensions>()); |
| 19 | + sycl::buffer<T const, Dimensions, Allocator> const_buff( |
| 20 | + create_range<Dimensions>()); |
| 21 | + |
| 22 | + auto reinterpret_buff = buff.template reinterpret<T const, Dimensions>( |
| 23 | + create_range<Dimensions>()); |
| 24 | + |
| 25 | + static_assert( |
| 26 | + std::is_same_v<decltype(const_buff), decltype(reinterpret_buff)>); |
| 27 | +} |
| 28 | + |
| 29 | +struct my_struct { |
| 30 | + int my_int = 0; |
| 31 | + float my_float = 0; |
| 32 | + double my_double = 0; |
| 33 | +}; |
| 34 | + |
| 35 | +int main() { |
| 36 | + test_buffer_const_reinterpret<short, 1>(); |
| 37 | + test_buffer_const_reinterpret<int, 1>(); |
| 38 | + test_buffer_const_reinterpret<long, 1>(); |
| 39 | + test_buffer_const_reinterpret<unsigned short, 1>(); |
| 40 | + test_buffer_const_reinterpret<unsigned int, 1>(); |
| 41 | + test_buffer_const_reinterpret<unsigned long, 1>(); |
| 42 | + test_buffer_const_reinterpret<sycl::half, 1>(); |
| 43 | + test_buffer_const_reinterpret<float, 1>(); |
| 44 | + test_buffer_const_reinterpret<double, 1>(); |
| 45 | + test_buffer_const_reinterpret<my_struct, 1>(); |
| 46 | + |
| 47 | + test_buffer_const_reinterpret<short, 2>(); |
| 48 | + test_buffer_const_reinterpret<int, 2>(); |
| 49 | + test_buffer_const_reinterpret<long, 2>(); |
| 50 | + test_buffer_const_reinterpret<unsigned short, 2>(); |
| 51 | + test_buffer_const_reinterpret<unsigned int, 2>(); |
| 52 | + test_buffer_const_reinterpret<unsigned long, 2>(); |
| 53 | + test_buffer_const_reinterpret<sycl::half, 2>(); |
| 54 | + test_buffer_const_reinterpret<float, 2>(); |
| 55 | + test_buffer_const_reinterpret<double, 2>(); |
| 56 | + test_buffer_const_reinterpret<my_struct, 2>(); |
| 57 | + |
| 58 | + test_buffer_const_reinterpret<short, 3>(); |
| 59 | + test_buffer_const_reinterpret<int, 3>(); |
| 60 | + test_buffer_const_reinterpret<long, 3>(); |
| 61 | + test_buffer_const_reinterpret<unsigned short, 3>(); |
| 62 | + test_buffer_const_reinterpret<unsigned int, 3>(); |
| 63 | + test_buffer_const_reinterpret<unsigned long, 3>(); |
| 64 | + test_buffer_const_reinterpret<sycl::half, 3>(); |
| 65 | + test_buffer_const_reinterpret<float, 3>(); |
| 66 | + test_buffer_const_reinterpret<double, 3>(); |
| 67 | + test_buffer_const_reinterpret<my_struct, 3>(); |
| 68 | + |
| 69 | + return 0; |
| 70 | +} |
0 commit comments