@@ -231,10 +231,10 @@ convertImpl(T Value) {
231231 return static_cast <R>(Value);
232232}
233233
234+ #ifndef __SYCL_DEVICE_ONLY__
234235// float to int
235236template <typename T, typename R, rounding_mode roundingMode>
236237detail::enable_if_t <is_float_to_int<T, R>::value, R> convertImpl (T Value) {
237- #ifndef __SYCL_DEVICE_ONLY__
238238 switch (roundingMode) {
239239 // Round to nearest even is default rounding mode for floating-point types
240240 case rounding_mode::automatic:
@@ -264,11 +264,62 @@ detail::enable_if_t<is_float_to_int<T, R>::value, R> convertImpl(T Value) {
264264 assert (!" Unsupported rounding mode!" );
265265 return static_cast <R>(Value);
266266 };
267- #else
268- // TODO implement device side conversion.
269- return static_cast <R>(Value);
270- #endif
271267}
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__
272323
273324} // namespace detail
274325
0 commit comments