|
| 1 | +// RUN: %clangxx -fsycl -fsyntax-only %s |
| 2 | +// |
| 3 | +// This test aims to check that the implementation provides aliases for |
| 4 | +// interoperability with OpenCL in accordance with section C.7.1 Data types of |
| 5 | +// SYCL 2020 specification, revision 6 |
| 6 | + |
| 7 | +#include <sycl/sycl.hpp> |
| 8 | + |
| 9 | +#include <type_traits> |
| 10 | + |
| 11 | +int main() { |
| 12 | + // cl_bool |
| 13 | + // Alias to a conditional data type which can be either true or false. |
| 14 | + // The value true expands to the integer constant 1 and the value false |
| 15 | + // expands to the integer constant 0. |
| 16 | + constexpr sycl::opencl::cl_bool True = true; |
| 17 | + constexpr sycl::opencl::cl_bool False = false; |
| 18 | + static_assert((int)True == 1); |
| 19 | + static_assert((int)False == 0); |
| 20 | + |
| 21 | + // cl_char |
| 22 | + // Alias to a signed 1-bit integer, as defined by the C++ core language. |
| 23 | + static_assert(sizeof(sycl::opencl::cl_char) == 1); |
| 24 | + static_assert(std::is_signed_v<sycl::opencl::cl_char>); |
| 25 | + static_assert(std::is_integral_v<sycl::opencl::cl_char>); |
| 26 | + |
| 27 | + // cl_uchar |
| 28 | + // Alias to an unsigned 1-bit integer, as defined by the C++ core language. |
| 29 | + static_assert(sizeof(sycl::opencl::cl_uchar) == 1); |
| 30 | + static_assert(std::is_unsigned_v<sycl::opencl::cl_uchar>); |
| 31 | + static_assert(std::is_integral_v<sycl::opencl::cl_uchar>); |
| 32 | + |
| 33 | + // cl_short |
| 34 | + // Alias to a signed 2-bit integer, as defined by the C++ core language. |
| 35 | + static_assert(sizeof(sycl::opencl::cl_short) == 2); |
| 36 | + static_assert(std::is_signed_v<sycl::opencl::cl_short>); |
| 37 | + static_assert(std::is_integral_v<sycl::opencl::cl_short>); |
| 38 | + |
| 39 | + // cl_ushort |
| 40 | + // Alias to an unsigned 2-bit integer, as defined by the C++ core language. |
| 41 | + static_assert(sizeof(sycl::opencl::cl_ushort) == 2); |
| 42 | + static_assert(std::is_unsigned_v<sycl::opencl::cl_ushort>); |
| 43 | + static_assert(std::is_integral_v<sycl::opencl::cl_ushort>); |
| 44 | + |
| 45 | + // cl_int |
| 46 | + // Alias to a signed 4-bit integer, as defined by the C++ core language. |
| 47 | + static_assert(sizeof(sycl::opencl::cl_int) == 4); |
| 48 | + static_assert(std::is_signed_v<sycl::opencl::cl_int>); |
| 49 | + static_assert(std::is_integral_v<sycl::opencl::cl_int>); |
| 50 | + |
| 51 | + // cl_uint |
| 52 | + // Alias to an unsigned 4-bit integer, as defined by the C++ core language. |
| 53 | + static_assert(sizeof(sycl::opencl::cl_uint) == 4); |
| 54 | + static_assert(std::is_unsigned_v<sycl::opencl::cl_uint>); |
| 55 | + static_assert(std::is_integral_v<sycl::opencl::cl_uint>); |
| 56 | + |
| 57 | + // cl_long |
| 58 | + // Alias to a signed 8-bit integer, as defined by the C++ core language. |
| 59 | + static_assert(sizeof(sycl::opencl::cl_long) == 8); |
| 60 | + static_assert(std::is_signed_v<sycl::opencl::cl_long>); |
| 61 | + static_assert(std::is_integral_v<sycl::opencl::cl_long>); |
| 62 | + |
| 63 | + // cl_ulong |
| 64 | + // Alias to an unsigned 8-bit integer, as defined by the C++ core language. |
| 65 | + static_assert(sizeof(sycl::opencl::cl_ulong) == 8); |
| 66 | + static_assert(std::is_unsigned_v<sycl::opencl::cl_ulong>); |
| 67 | + static_assert(std::is_integral_v<sycl::opencl::cl_ulong>); |
| 68 | + |
| 69 | + // TODO: how can we check that the type conforms to IEEE 754? |
| 70 | + // There is std::numeric_limits<T>::is_iec559 - is it enough? |
| 71 | + |
| 72 | + // cl_float |
| 73 | + // Alias to a 4-bit floating-point. The float data type must conform to the |
| 74 | + // IEEE 754 single precision storage format. |
| 75 | + static_assert(sizeof(sycl::opencl::cl_float) == 4); |
| 76 | + static_assert(std::is_floating_point_v<sycl::opencl::cl_float>); |
| 77 | + |
| 78 | + // cl_double |
| 79 | + // Alias to a 8-bit floating-point. The double data type must conform to the |
| 80 | + // IEEE 754 double precision storage format. |
| 81 | + static_assert(sizeof(sycl::opencl::cl_double) == 8); |
| 82 | + static_assert(std::is_floating_point_v<sycl::opencl::cl_double>); |
| 83 | + |
| 84 | + // cl_half |
| 85 | + // Alias to a 2-bit floating-point. The half data type must conform to the |
| 86 | + // IEEE 754-2001 half precision storage format. |
| 87 | + static_assert(sizeof(sycl::opencl::cl_half) == 2); |
| 88 | + // TODO: do we need std::is_floating_point to return true for |
| 89 | + // sycl::opencl::cl_half? |
| 90 | + // We alias it to our custom class sycl::half and C++ spec says it is UB |
| 91 | + // to provide specializations for std::is_floating_point type trait |
| 92 | + // static_assert(std::is_floating_point_v<sycl::opencl::cl_half>); |
| 93 | + |
| 94 | + return 0; |
| 95 | +} |
0 commit comments