Declaring Half precision floating point memory in SYCL

I would like to know and understand how can one declare half-precision buffers and pointers in SYCL namely in the following ways -

  • Via the buffer class.
  • Using malloc_device() function.

Also, suppose I have an existing fp32 matrix/array on the host side. How can I copy its contents to fp16 memory on the GPU side?

TIA

For half-precision, you can just use sycl::half as the template parameter for either of these.

accHalf[i] = static_cast<sycl::half>(accFloat[i]);

For copying, you’ll need to convert the data from fp32 to fp16, which you could probably do using a kernel to perform the conversion. This seems to be a well documented problem with solutions, see this thread.