I am using Intel core i7 6820HQ CPU and integrated graphics 530 to run an opencl application.
When I perform convert_char() on overflowed results, I get different results in CPU and GPU.
E.g convert_char(271.125) on CPU overflows and rounds up whereas in GPU it clamps to 255. ofcourse by doing convert_char_sat() i got the right results on both platforms.
But can someone explain why it works differently on different platforms?
Because the implementations for CPU and GPU are different and OpenCL specification doesn't specify the behavior. Here is the quote from the spec:
220.127.116.11 Out-of-Range Behavior and Saturated Conversions
When the conversion operand is either greater than the greatest representable destination value or
less than the least representable destination value, it is said to be out-of-range. The result of outof-range conversion is determined by the conversion rules specified by the C99 specification in
section 6.3. When converting from a floating-point type to integer type, the behavior is
hi @Alexey Bader
Thanks for the reply/
I did see the specification for the conversion rules. I was just wondering why Intel would implement it like that. Is it documented somewhere?
Based on the premise that OpenCL should conform to functional correctness across different platforms, Isn't this behaviour a bug?
To get bitwise matching results from different OpenCL devices I would avoid using features that are mentioned by OpenCL specification as "implementation defined" or "undefined behaviour". Typically "implementation defined" operations implemented differently by different HW i.e. implementation on CPU and GPU devices of the same "implementation defined" feature might be different.
If your algorithm cares about results of conversion from float to int with overflow, you shouldn't use convert_char built-in function.