OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1722 Discussions

Opencl implementation of convert_char()

uttam_k_
Beginner
1,170 Views

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?

0 Kudos
3 Replies
Alexey_B_Intel1
Employee
1,170 Views

Because the implementations for CPU and GPU are different and OpenCL specification doesn't specify the behavior. Here is the quote from the spec:

6.2.3.3 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
implementation-defined.

0 Kudos
uttam_k_
Beginner
1,170 Views

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?

Regards,

uttam

0 Kudos
Alexey_B_Intel1
Employee
1,170 Views

Hi uttam,

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.

Thanks,
Alexey

0 Kudos
Reply