-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libclc] Fix int<->float conversion builtins #126905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libclc] Fix int<->float conversion builtins #126905
Conversation
While working on moving the conversion builtins to the CLC library in 25c0554 it was discovered that many weren't passing the OpenCL-CTS tests. As it happens, the clspv-specific code for conversion implementations between integer and floating-point types was more correct. However: * The clspv code was generating 'sat' conversions to floating-point types, which are not legal * The clspv code around rtn/rtz conversions needed tweaking as it wasn't validating when sizeof(dst) > sizeof(src), e.g., int -> double. With this commit, the CTS failures seen before have been resolved. This also assumes that the new implementations are correct also for clspv. If this is the case, then 'clc' and 'clspv' modes are mutually exclusive and we can simplify the build process for conversions by not building clc-clspv-convert.cl. Note that there are still outstanding failures in 'rtz' and 'rtp' rounding modes between float->half, double->half, and double->float (i.e., floating-point types when sizeof(src) > sizeof(dst)). These will be looked at separately.
CC @rjodinchr. I remember you saying you're OOO so no pressure, but perhaps you could verify this commit with clspv? For clarity, the remaining failures I see are in
Looks like a problem with rounding to near zero to me. Does anyone else see this? |
Do we really need to generate source for this? It's harder to reason about. It looks like the sign bit of the input isn't preserved on underflow to 0 |
Perhaps we could simply check in the generated source? It shouldn't change all that often. We might want to split it up into separate files as it's massive. This sort of thing should really be in an issue ticket, but I had a brief look at the remaining failures yesterday. For some context: _CLC_DEF _CLC_OVERLOAD half __clc_convert_half_rtp(float x) {
half r = __clc_convert_half(x);
float y = __clc_convert_float(r);
half sel = __clc_select(r, __clc_nextafter(r, (half)INFINITY), __clc_convert_short(y < x));
return sel;
} At least it's nice and small. Since the first two conversions are just I do pass the OpenCL-CTS for nextafter in the same (admittedly janky) configuration so I may have crossed some wires somewhere. Anyway, I ran the full OpenCL-CTS with this PR overnight and the only remaining failures are those six I listed above. |
See #127469 for the fix for the other conversion builtins. |
While working on moving the conversion builtins to the CLC library in 25c0554 it was discovered that many weren't passing the OpenCL-CTS tests.
As it happens, the clspv-specific code for conversion implementations between integer and floating-point types was more correct. However:
With this commit, the CTS failures seen before have been resolved.
This also assumes that the new implementations are correct also for clspv. If this is the case, then 'clc' and 'clspv' modes are mutually exclusive and we can simplify the build process for conversions by not building clc-clspv-convert.cl.