@@ -192,7 +192,52 @@ inline bool bitwise_comparison_fp32(const half val, const uint32_t exp) {
192
192
return reinterpret_cast <const uint32_t &>(fp32) == exp;
193
193
}
194
194
195
+ constexpr void constexpr_verify_add () {
196
+ constexpr half a{5.0 }, b{2.0 }, ref{7.0 };
197
+ constexpr half result = a + b;
198
+ constexpr half diff = result - ref;
199
+ constexpr auto sign = diff < 0 ? -1 : 1 ;
200
+ static_assert (sign * static_cast <float >(diff) <
201
+ std::numeric_limits<cl::sycl::half>::epsilon (),
202
+ " Constexpr add is wrong" );
203
+ }
204
+
205
+ constexpr void constexpr_verify_sub () {
206
+ constexpr half a{5 .0f }, b{2.0 }, ref{3.0 };
207
+ constexpr half result = a - b;
208
+ constexpr half diff = result - ref;
209
+ constexpr auto sign = diff < 0 ? -1 : 1 ;
210
+ static_assert (sign * static_cast <float >(diff) <
211
+ std::numeric_limits<cl::sycl::half>::epsilon (),
212
+ " Constexpr sub is wrong" );
213
+ }
214
+
215
+ constexpr void constexpr_verify_mul () {
216
+ constexpr half a{5 .0f }, b{2.0 }, ref{10.0 };
217
+ constexpr half result = a * b;
218
+ constexpr half diff = result - ref;
219
+ constexpr auto sign = diff < 0 ? -1 : 1 ;
220
+ static_assert (sign * static_cast <float >(diff) <
221
+ std::numeric_limits<cl::sycl::half>::epsilon (),
222
+ " Constexpr mul is wrong" );
223
+ }
224
+
225
+ constexpr void constexpr_verify_div () {
226
+ constexpr half a{5 .0f }, b{2.0 }, ref{2.5 };
227
+ constexpr half result = a / b;
228
+ constexpr half diff = result - ref;
229
+ constexpr auto sign = diff < 0 ? -1 : 1 ;
230
+ static_assert (sign * static_cast <float >(diff) <
231
+ std::numeric_limits<cl::sycl::half>::epsilon (),
232
+ " Constexpr div is wrong" );
233
+ }
234
+
195
235
int main () {
236
+ constexpr_verify_add ();
237
+ constexpr_verify_sub ();
238
+ constexpr_verify_mul ();
239
+ constexpr_verify_div ();
240
+
196
241
device dev{default_selector ()};
197
242
if (!dev.is_host () && !dev.has_extension (" cl_khr_fp16" )) {
198
243
std::cout << " This device doesn't support the extension cl_khr_fp16"
0 commit comments