@@ -231,10 +231,10 @@ convertImpl(T Value) {
231
231
return static_cast <R>(Value);
232
232
}
233
233
234
+ #ifndef __SYCL_DEVICE_ONLY__
234
235
// float to int
235
236
template <typename T, typename R, rounding_mode roundingMode>
236
237
detail::enable_if_t <is_float_to_int<T, R>::value, R> convertImpl (T Value) {
237
- #ifndef __SYCL_DEVICE_ONLY__
238
238
switch (roundingMode) {
239
239
// Round to nearest even is default rounding mode for floating-point types
240
240
case rounding_mode::automatic:
@@ -264,11 +264,62 @@ detail::enable_if_t<is_float_to_int<T, R>::value, R> convertImpl(T Value) {
264
264
assert (!" Unsupported rounding mode!" );
265
265
return static_cast <R>(Value);
266
266
};
267
- #else
268
- // TODO implement device side conversion.
269
- return static_cast <R>(Value);
270
- #endif
271
267
}
268
+ #else
269
+
270
+ template <rounding_mode Mode>
271
+ using RteOrAutomatic = detail::bool_constant<Mode == rounding_mode::automatic ||
272
+ Mode == rounding_mode::rte>;
273
+
274
+ template <rounding_mode Mode>
275
+ using Rtz = detail::bool_constant<Mode == rounding_mode::rtz>;
276
+
277
+ template <rounding_mode Mode>
278
+ using Rtp = detail::bool_constant<Mode == rounding_mode::rtp>;
279
+
280
+ template <rounding_mode Mode>
281
+ using Rtn = detail::bool_constant<Mode == rounding_mode::rtn>;
282
+
283
+ // Convert floating-point type to integer type
284
+ #define __SYCL_GENERATE_CONVERT_IMPL (SPIRVOp, DestType, RoundingMode, \
285
+ RoundingModeCondition) \
286
+ template <typename T, typename R, rounding_mode roundingMode> \
287
+ detail::enable_if_t <is_float_to_int<T, R>::value && \
288
+ std::is_same<R, DestType>::value && \
289
+ RoundingModeCondition<roundingMode>::value, \
290
+ R> \
291
+ convertImpl (T Value) { \
292
+ using OpenCLT = cl::sycl::detail::ConvertToOpenCLType_t<T>; \
293
+ OpenCLT OpValue = cl::sycl::detail::convertDataToType<T, OpenCLT>(Value); \
294
+ return __spirv_Convert##SPIRVOp##_R##DestType##_##RoundingMode (OpValue); \
295
+ }
296
+
297
+ #define __SYCL_GENERATE_CONVERT_IMPL_FOR_ROUNDING_MODE (RoundingMode, \
298
+ RoundingModeCondition) \
299
+ __SYCL_GENERATE_CONVERT_IMPL (FToS, int , RoundingMode, RoundingModeCondition) \
300
+ __SYCL_GENERATE_CONVERT_IMPL(FToS, char , RoundingMode, \
301
+ RoundingModeCondition) \
302
+ __SYCL_GENERATE_CONVERT_IMPL(FToS, short , RoundingMode, \
303
+ RoundingModeCondition) \
304
+ __SYCL_GENERATE_CONVERT_IMPL(FToS, long , RoundingMode, \
305
+ RoundingModeCondition) \
306
+ __SYCL_GENERATE_CONVERT_IMPL(FToU, uint, RoundingMode, \
307
+ RoundingModeCondition) \
308
+ __SYCL_GENERATE_CONVERT_IMPL(FToU, uchar, RoundingMode, \
309
+ RoundingModeCondition) \
310
+ __SYCL_GENERATE_CONVERT_IMPL(FToU, ushort, RoundingMode, \
311
+ RoundingModeCondition) \
312
+ __SYCL_GENERATE_CONVERT_IMPL(FToU, ulong, RoundingMode, RoundingModeCondition)
313
+
314
+ __SYCL_GENERATE_CONVERT_IMPL_FOR_ROUNDING_MODE(rte, RteOrAutomatic)
315
+ __SYCL_GENERATE_CONVERT_IMPL_FOR_ROUNDING_MODE(rtz, Rtz)
316
+ __SYCL_GENERATE_CONVERT_IMPL_FOR_ROUNDING_MODE(rtp, Rtp)
317
+ __SYCL_GENERATE_CONVERT_IMPL_FOR_ROUNDING_MODE(rtn, Rtn)
318
+
319
+ #undef __SYCL_GENERATE_CONVERT_IMPL_FOR_ROUNDING_MODE
320
+ #undef __SYCL_GENERATE_CONVERT_IMPL
321
+
322
+ #endif // __SYCL_DEVICE_ONLY__
272
323
273
324
} // namespace detail
274
325
0 commit comments