fixstars / clpy

OpenCL backend for CuPy
Other
152 stars 13 forks source link

Support half #265

Open vorj opened 4 years ago

vorj commented 4 years ago

Related to #264 .

We should support half type regardless of whether the environment supports cl_khr_fp16 or not.

LWisteria commented 4 years ago

@vorj Do you mean that you want to implement all half operations with software functions? How much do you need it? I think it's reasonable to give up half support if the device doesn't support the extensions for it.

vorj commented 4 years ago

@LWisteria

Do you mean that you want to implement all half operations with software functions?

Yes, and I think that we can implement almost of them like float_to_half(float_operation(half_to_float(half_value))) . The exception is nextafter , but this has been already implemented.

I think it's reasonable to give up half support if the device doesn't support the extensions for it.

I thought so when we had no idea to solve the issue, but now I have an idea, and it's worth to try to get ClPy's features closer to CuPy's ones I think.

ybsh commented 4 years ago

Talked with @LWisteria about who should work on this issue . We agreed that this task is more appropriate for an intern, considering this task seems to require a fair amount of time, and I'm not currently very sure if I can spare as much time. I will continue the performance improvement issue: https://github.com/fixstars/clpy/issues/153

LWisteria commented 4 years ago

@vorj OK, I understand that you want to use Ultima to convert a + b where a and b are half to f2h(h2f(a)+h2f(b)), right?

Then, how will you deal rounding errors etc? f2h(h2f(a)+h2f(b)) does not exactly match native a+b.

vorj commented 4 years ago

@LWisteria

I understand that you want to use Ultima to convert a + b where a and b are half to f2h(h2f(a)+h2f(b)), right?

Yes, that's it.

how will you deal rounding errors etc?

That's the problem. I'm still thinking about it. Well, I have a question. Although currently we calculate sqrt(int8_value) as f2h(sqrt(i2f(int8_value))) , does the casting in this situation have no problem?

Or we can use some open source software implementation of half as an alternative option. However, even this option requires member function support to ultima, and I don't know the half implementation supporting for not only arithmetic operator but also mathmatical functions since my investigation is insufficient.