cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

blelump
Journeyman III

Casting double to float

is this possible?

Hi,

Assume that such simple kernel is given:

#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
__kernel void sum(__global const double2 *a,__global const float2 *b,__global float2 *c){
    size_t id = get_global_id(0);
    c[id]=a[id]+b[id];

}



Running it on CPU works fine [implicit double to float cast performs] whereas on GPU it behaves quite unexpected. I suppose that implicit cast cannot be done in this case so I tried an explicit cast like

#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
__kernel void sum(__global const double2 *a,__global const float2 *b,__global float2 *c){

    size_t id = get_global_id(0);
    c[id].x = (float)a[id].x+b[id].x;
    c[id].y = (float)a[id].y+b[id].y;

    //or even:

    float2 aa;
    aa.x = a[id].x;
    aa.x = a[id].x;
    c[id].x = aa.x+b[id].x;
    c[id].y = aa.y+b[id].y;

}



Both solutions are wrong - cause CL complier error or an undefined data as a result of such sum. I've also tried to use the to_float2(double2) function, but compliler complains that source and destination have different size. Does anyone have an idea why or how to avoid such issue? Is this possible at all to cast double -> float?

0 Likes
6 Replies

The 2.01 release only supports double math operations and IO, not casts/conversions.
0 Likes

Originally posted by: MicahVillmow The 2.01 release only supports double math operations and IO, not casts/conversions.


Ok, thanks for pointing that. May I expect support for such operation in a future release ? If so, then when?

0 Likes

new version of SDK is coming soon. maybe with double and image support.

0 Likes

New version of SDK [2.1] is available already, but I assume nothing has changed in this case? Actually that's not what I expected. Besides that I cannot find any information that it is a bug though. Perhaps I am missing something?

0 Likes

blelump,
Our double support did not change much for the 2.1 release. Conversions between double and other types will be fully supported in our next release.
0 Likes

Originally posted by: MicahVillmow blelump, Our double support did not change much for the 2.1 release. Conversions between double and other types will be fully supported in our next release.


Ok, thank you.

0 Likes