14
14
#include < string>
15
15
#include < type_traits>
16
16
17
- // Debug prints are hidden under macro to reduce amount of output in CI runs
18
- // and thus speed up tests. However, they are useful when debugging the test
19
- // locally and can be quickly turned on in there.
20
- #ifdef ENABLE_DEBUG_OUTPUT
21
-
22
17
template <typename T> std::string to_string () { return " unknown type" ; }
23
18
template <> std::string to_string<std::byte>() { return " std::byte" ; }
24
19
template <> std::string to_string<char >() { return " char" ; }
@@ -36,33 +31,25 @@ template <> std::string to_string<unsigned long long>() {
36
31
}
37
32
template <> std::string to_string<bool >() { return " bool" ; }
38
33
39
- #define DEBUG_PRINT (x ) std::cout << x << std::endl;
40
-
41
- #else
42
- #define DEBUG_PRINT (x )
43
- #endif
44
-
45
34
template <typename T>
46
- void check_vectors_equal (sycl::vec<T, 4 > a, sycl::vec<T, 4 > b) {
47
- bool all_good =
35
+ bool check_vectors_equal (sycl::vec<T, 4 > a, sycl::vec<T, 4 > b,
36
+ const std::string &fail_message) {
37
+ bool result =
48
38
a.x () == b.x () && a.y () == b.y () && a.z () == b.z () && a.w () == b.w ();
49
- if (!all_good) {
50
- DEBUG_PRINT (" host and device results mismatch:" );
51
- DEBUG_PRINT (
52
- " \t {" << static_cast <int >(a.x ()) << " , " << static_cast <int >(a.y ())
53
- << " , " << static_cast <int >(a.z ()) << " , "
54
- << static_cast <int >(a.w ()) << " } vs {" << static_cast <int >(b.x ())
55
- << " , " << static_cast <int >(b.y ()) << " , "
56
- << static_cast <int >(b.z ()) << " , " << static_cast <int >(b.w ())
57
- << " }" );
39
+ if (!result) {
40
+ std::cout << fail_message << std::endl;
41
+ std::cout << " \t {" << static_cast <int >(a.x ()) << " , "
42
+ << static_cast <int >(a.y ()) << " , " << static_cast <int >(a.z ())
43
+ << " , " << static_cast <int >(a.w ()) << " } vs {"
44
+ << static_cast <int >(b.x ()) << " , " << static_cast <int >(b.y ())
45
+ << " , " << static_cast <int >(b.z ()) << " , "
46
+ << static_cast <int >(b.w ()) << " }" << std::endl;
58
47
}
59
- assert (all_good);
60
- }
61
48
62
- template <typename From, typename To> void check_convert () {
63
- DEBUG_PRINT (" checking vec<" << to_string<From>() << " , 4>::convert<"
64
- << to_string<To>() << " >()" );
49
+ return result;
50
+ }
65
51
52
+ template <typename From, typename To> bool check_convert () {
66
53
sycl::vec<From, 4 > input;
67
54
if constexpr (std::is_signed_v<From>) {
68
55
input = sycl::vec<From, 4 >{static_cast <From>(37 ), static_cast <From>(0 ),
@@ -84,66 +71,84 @@ template <typename From, typename To> void check_convert() {
84
71
auto acc = buf.get_host_access ();
85
72
auto deviceResult = acc[0 ];
86
73
87
- // Host and device results must match.
88
- check_vectors_equal (hostResult, deviceResult) ;
74
+ std::string test =
75
+ " (vec< " + to_string<From>() + " , 4>::convert< " + to_string<To>() + " >) " ;
89
76
77
+ // Host and device results must match.
78
+ bool host_and_device_match = check_vectors_equal (
79
+ hostResult, deviceResult, " host and device results do not match " + test);
90
80
// And they should match with a reference, which is for integer conversions
91
81
// can be computed with a simple static_cast.
92
82
// Strictly speaking, integer conversions are underspecified in the SYCL 2020
93
83
// spec, but `static_cast` implementation matches SYCL-CTS, so we will leave
94
84
// it here for now as well.
95
85
// See https://github.com/KhronosGroup/SYCL-Docs/issues/492
96
- assert (deviceResult.x () == static_cast <To>(input.x ()));
97
- assert (deviceResult.y () == static_cast <To>(input.y ()));
98
- assert (deviceResult.z () == static_cast <To>(input.z ()));
99
- assert (deviceResult.w () == static_cast <To>(input.w ()));
86
+ sycl::vec<To, 4 > reference{
87
+ static_cast <To>(input.x ()), static_cast <To>(input.y ()),
88
+ static_cast <To>(input.z ()), static_cast <To>(input.w ())};
89
+ bool device_matches_reference = check_vectors_equal (
90
+ deviceResult, reference, " device results don't match reference " + test);
91
+ bool host_matches_reference = check_vectors_equal (
92
+ hostResult, reference, " host resutls don't match reference " + test);
93
+
94
+ return host_and_device_match && device_matches_reference &&
95
+ host_matches_reference;
100
96
}
101
97
102
98
template <class T >
103
99
constexpr auto has_unsigned_v =
104
100
std::is_integral_v<T> && !std::is_same_v<T, bool > &&
105
101
!std::is_same_v<T, sycl::byte> && !std::is_same_v<T, std::byte>;
106
102
107
- template <typename From, typename To> void check_signed_unsigned_convert_to () {
108
- check_convert<From, To>();
103
+ template <typename From, typename To> bool check_signed_unsigned_convert_to () {
104
+ bool pass = true ;
105
+ pass &= check_convert<From, To>();
109
106
if constexpr (has_unsigned_v<To>)
110
- check_convert<From, std::make_unsigned_t <To>>();
107
+ pass &= check_convert<From, std::make_unsigned_t <To>>();
111
108
if constexpr (has_unsigned_v<From>)
112
- check_convert<std::make_unsigned_t <From>, To>();
109
+ pass &= check_convert<std::make_unsigned_t <From>, To>();
113
110
if constexpr (has_unsigned_v<To> && has_unsigned_v<From>)
114
- check_convert<std::make_unsigned_t <From>, std::make_unsigned_t <To>>();
111
+ pass &=
112
+ check_convert<std::make_unsigned_t <From>, std::make_unsigned_t <To>>();
113
+ return pass;
115
114
}
116
115
117
- template <typename From> void check_convert_from () {
118
- check_signed_unsigned_convert_to<From, sycl::byte>();
116
+ template <typename From> bool check_convert_from () {
117
+ bool pass = true ;
118
+ pass &= check_signed_unsigned_convert_to<From, sycl::byte>();
119
119
// FIXME: enable test cases below once compilation issues for them are fixed
120
120
// check_signed_unsigned_convert_to<From, std::byte>();
121
- check_signed_unsigned_convert_to<From, std::int8_t >();
122
- check_signed_unsigned_convert_to<From, std::int16_t >();
123
- check_signed_unsigned_convert_to<From, std::int32_t >();
124
- check_signed_unsigned_convert_to<From, std::int64_t >();
125
- check_signed_unsigned_convert_to<From, bool >();
126
- check_signed_unsigned_convert_to<From, char >();
127
- check_signed_unsigned_convert_to<From, signed char >();
128
- check_signed_unsigned_convert_to<From, short >();
129
- check_signed_unsigned_convert_to<From, int >();
130
- check_signed_unsigned_convert_to<From, long >();
131
- check_signed_unsigned_convert_to<From, long long >();
121
+ pass &= check_signed_unsigned_convert_to<From, std::int8_t >();
122
+ pass &= check_signed_unsigned_convert_to<From, std::int16_t >();
123
+ pass &= check_signed_unsigned_convert_to<From, std::int32_t >();
124
+ pass &= check_signed_unsigned_convert_to<From, std::int64_t >();
125
+ pass &= check_signed_unsigned_convert_to<From, bool >();
126
+ pass &= check_signed_unsigned_convert_to<From, char >();
127
+ pass &= check_signed_unsigned_convert_to<From, signed char >();
128
+ pass &= check_signed_unsigned_convert_to<From, short >();
129
+ pass &= check_signed_unsigned_convert_to<From, int >();
130
+ pass &= check_signed_unsigned_convert_to<From, long >();
131
+ pass &= check_signed_unsigned_convert_to<From, long long >();
132
+
133
+ return pass;
132
134
}
133
135
134
136
int main () {
135
- check_convert_from<sycl::byte>();
137
+ bool pass = true ;
138
+ pass &= check_convert_from<sycl::byte>();
136
139
// FIXME: enable test cases below once compilation issues for them are fixed
137
140
// check_convert_from<std::byte>();
138
- check_convert_from<std::int8_t >();
139
- check_convert_from<std::int16_t >();
140
- check_convert_from<std::int32_t >();
141
- check_convert_from<std::int64_t >();
142
- check_convert_from<char >();
143
- check_convert_from<signed char >();
144
- check_convert_from<short >();
145
- check_convert_from<int >();
146
- check_convert_from<long >();
147
- check_convert_from<long long >();
148
- check_convert_from<bool >();
141
+ pass &= check_convert_from<std::int8_t >();
142
+ pass &= check_convert_from<std::int16_t >();
143
+ pass &= check_convert_from<std::int32_t >();
144
+ pass &= check_convert_from<std::int64_t >();
145
+ pass &= check_convert_from<char >();
146
+ pass &= check_convert_from<signed char >();
147
+ pass &= check_convert_from<short >();
148
+ pass &= check_convert_from<int >();
149
+ pass &= check_convert_from<long >();
150
+ pass &= check_convert_from<long long >();
151
+ pass &= check_convert_from<bool >();
152
+
153
+ return static_cast <int >(!pass);
149
154
}
0 commit comments