Skip to content

Commit 0bfffd6

Browse files
[SYCL][ESIMD][EMU] Half-type support - __esimd_convertvector_to/from (#6239)
* [SYCL][ESIMD][EMU] Half-type support - __esimd_convertvector_to/from
1 parent bd80f34 commit 0bfffd6

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

sycl/include/sycl/ext/intel/esimd/detail/elem_type_traits.hpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,20 @@ __esimd_convertvector_to(vector_type_t<StdTy, N> Val)
166166
// element_type_traits<WrapperTy>::use_native_cpp_ops is false.
167167
#else
168168
{
169-
// TODO implement for host
170-
__ESIMD_UNSUPPORTED_ON_HOST;
169+
vector_type_t<__raw_t<WrapperTy>, N> Output = 0;
170+
171+
if constexpr (std::is_same_v<WrapperTy, sycl::half>) {
172+
for (int i = 0; i < N; i += 1) {
173+
// 1. Convert Val[i] to float (x) using c++ static_cast
174+
// 2. Convert x to half (using float2half)
175+
// 3. Output[i] = half_of(x)
176+
Output[i] = ::sycl::detail::float2Half(static_cast<float>(Val[i]));
177+
}
178+
} else {
179+
__ESIMD_UNSUPPORTED_ON_HOST;
180+
}
181+
182+
return Output;
171183
}
172184
#endif // __SYCL_DEVICE_ONLY__
173185

@@ -179,8 +191,20 @@ __esimd_convertvector_from(vector_type_t<__raw_t<WrapperTy>, N> Val)
179191
// element_type_traits<WrapperTy>::use_native_cpp_ops is false.
180192
#else
181193
{
182-
// TODO implement for host
183-
__ESIMD_UNSUPPORTED_ON_HOST;
194+
vector_type_t<StdTy, N> Output;
195+
196+
if constexpr (std::is_same_v<WrapperTy, sycl::half>) {
197+
for (int i = 0; i < N; i += 1) {
198+
// 1. Convert Val[i] to float y(using half2float)
199+
// 2. Convert y to StdTy using c++ static_cast
200+
// 3. Store in Output[i]
201+
Output[i] = static_cast<StdTy>(::sycl::detail::half2Float(Val[i]));
202+
}
203+
} else {
204+
__ESIMD_UNSUPPORTED_ON_HOST;
205+
}
206+
207+
return Output;
184208
}
185209
#endif // __SYCL_DEVICE_ONLY__
186210

0 commit comments

Comments
 (0)