Open diptorupd opened 4 years ago
"e"
) is supported in module struct
starting from Python 3.6 (https://docs.python.org/3/library/struct.html#format-characters)class c_half(ctypes._SimpleCData):
_type_ = "e"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: class must define a '_type_' attribute which must be
a single character string containing one of 'cbBhHiIlLdfuzZqQPXOv?g'.
Links:
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.
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.
@oleksandr-pavlyk Is the issue still relevant? If not I will suggest it to be closed.
We should support reduced precision types that are supported in Sycl.