IntelPython / dpctl

Python SYCL bindings and SYCL-based Python Array API library
https://intelpython.github.io/dpctl/
Apache License 2.0
101 stars 30 forks source link

Design support for reduced precision types in dpctl #72

Open diptorupd opened 4 years ago

diptorupd commented 4 years ago

We should support reduced precision types that are supported in Sycl.

PokhodenkoSA commented 3 years ago

Links:

oleksandr-pavlyk commented 3 years ago

The scope of the support matters. The main purpose of supporting in dpctl is to be able to submit kernels that take reduced precision arguments.

In addition to standard C/C++ types, SYCL supports std::byte and sycl::half (assuming device supports it). See tables 4.105 and 5.1 in the SYCL 2020 provisional standard. bfloa16 is not presently supported. Reference to an extension proposal would be good to record in this issue.

Anyhow, for dpctl to support any additional type, we need Python class representing the type, say dpctl.types.c_half and dpctl.types.c_bfloat16, whose purpose in life is to hold the value, and designate its type. It should have a constructor to convert from other floating point types, i.e. Python floats, ctypes.c_float, ctypes.c_double, etc., and allow to get the reference to the value.

DPCTL's SyclQueue.submit will then recognize this class, and call KernelSetArg with the proper enum value.

oleksandr-pavlyk commented 3 years ago

Here is example of using ctypes to convert a single ctype.c_float value input into a ctypes.c_short encoding the bits of the corresponding float16 value. https://gamedev.stackexchange.com/questions/28023/python-float-32bit-to-half-float-16bit

I wonder is this could be a start of implementing our own float16 type object.

diptorupd commented 8 months ago

@oleksandr-pavlyk Is the issue still relevant? If not I will suggest it to be closed.