|
10 | 10 |
|
11 | 11 | #define SYCL_SIMPLE_SWIZZLES
|
12 | 12 | #include <CL/sycl.hpp>
|
13 |
| -using namespace cl::sycl; |
14 | 13 |
|
15 |
| -void check_vectors(int4 a, int4 b, int4 c, int4 gold) { |
16 |
| - int4 result = a * (int4)b.y() + c; |
| 14 | +void check_vectors(cl::sycl::int4 a, cl::sycl::int4 b, cl::sycl::int4 c, |
| 15 | + cl::sycl::int4 gold) { |
| 16 | + cl::sycl::int4 result = a * (cl::sycl::int4)b.y() + c; |
17 | 17 | assert((int)result.x() == (int)gold.x());
|
18 | 18 | assert((int)result.y() == (int)gold.y());
|
19 |
| - assert((int)result.w() == (int)gold.w()); |
20 | 19 | assert((int)result.z() == (int)gold.z());
|
| 20 | + assert((int)result.w() == (int)gold.w()); |
| 21 | +} |
| 22 | + |
| 23 | +template <typename From, typename To> void check_convert() { |
| 24 | + cl::sycl::vec<From, 4> vec{1, 2, 3, 4}; |
| 25 | + cl::sycl::vec<To, 4> result = vec.template convert<To>(); |
| 26 | + assert((int)result.x() == (int)vec.x()); |
| 27 | + assert((int)result.y() == (int)vec.y()); |
| 28 | + assert((int)result.z() == (int)vec.z()); |
| 29 | + assert((int)result.w() == (int)vec.w()); |
| 30 | +} |
| 31 | + |
| 32 | +template <typename From, typename To> void check_signed_unsigned_convert_to() { |
| 33 | + check_convert<From, To>(); |
| 34 | + check_convert<From, cl::sycl::detail::make_unsigned_t<To>>(); |
| 35 | + check_convert<cl::sycl::detail::make_unsigned_t<From>, To>(); |
| 36 | + check_convert<cl::sycl::detail::make_unsigned_t<From>, |
| 37 | + cl::sycl::detail::make_unsigned_t<To>>(); |
| 38 | +} |
| 39 | + |
| 40 | +template <typename From> void check_convert_from() { |
| 41 | + check_signed_unsigned_convert_to<From, int8_t>(); |
| 42 | + check_signed_unsigned_convert_to<From, int16_t>(); |
| 43 | + check_signed_unsigned_convert_to<From, int32_t>(); |
| 44 | + check_signed_unsigned_convert_to<From, int64_t>(); |
| 45 | + check_signed_unsigned_convert_to<From, half>(); |
| 46 | + check_signed_unsigned_convert_to<From, float>(); |
| 47 | + check_signed_unsigned_convert_to<From, double>(); |
21 | 48 | }
|
22 | 49 |
|
23 | 50 | int main() {
|
24 |
| - int4 a = {1, 2, 3, 4}; |
25 |
| - const int4 b = {10, 20, 30, 40}; |
26 |
| - const int4 gold = {21, 42, 90, 120}; |
27 |
| - const int2 a_xy = a.xy(); |
| 51 | + cl::sycl::int4 a = {1, 2, 3, 4}; |
| 52 | + const cl::sycl::int4 b = {10, 20, 30, 40}; |
| 53 | + const cl::sycl::int4 gold = {21, 42, 90, 120}; |
| 54 | + const cl::sycl::int2 a_xy = a.xy(); |
28 | 55 | check_vectors(a, b, {1, 2, 30, 40}, gold);
|
29 | 56 | check_vectors(a, b, {a.x(), a.y(), b.z(), b.w()}, gold);
|
30 | 57 | check_vectors(a, b, {a.x(), 2, b.z(), 40}, gold);
|
@@ -82,5 +109,14 @@ int main() {
|
82 | 109 | assert((std::is_same<cl::sycl::vec<unsigned long, 8>, cl::sycl::ulong8>::value));
|
83 | 110 | assert((std::is_same<cl::sycl::vec<unsigned long, 16>, cl::sycl::ulong16>::value));
|
84 | 111 |
|
| 112 | + // Check convert() from and to various types. |
| 113 | + check_convert_from<int8_t>(); |
| 114 | + check_convert_from<int16_t>(); |
| 115 | + check_convert_from<int32_t>(); |
| 116 | + check_convert_from<int64_t>(); |
| 117 | + check_convert_from<half>(); |
| 118 | + check_convert_from<float>(); |
| 119 | + check_convert_from<double>(); |
| 120 | + |
85 | 121 | return 0;
|
86 | 122 | }
|
0 commit comments