typedef cl_float4 cl_float3; cl_platform.h

I 've found some strange strings in cl_platform.h
/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */
typedef cl_float4 cl_float3;
IHMO this is inappropriate way which can lead to wrong code and unpredictable behavior.

What do you mean?

There’s nothing wrong here, cl_float4 is just being given another name (maybe for the sake of readability?)

I mean that


cl_float dot(cl_float3,cl_float3)
cl_float dot(cl_float4,cl_float4)

should do different things on host side.
And


cl_float3 df;
df.w=1.0f;

should give me an error.

They shouldn’t and they won’t. cl_float3 is identical in size, alignment, and behavior to cl_float4.

It’s really just there to let you write self-documenting code. You can just as well use cl_float4 and forget that cl_float3 ever existed. It’s a convenience but the opencl types such as float and double are aligned to powers of 2 (cl_float2, cl_float4, cl_float8, and cl_float16 which are aligned to 8, 16, 32, and 64 bytes respectively).

Typedef is just saying “use this type but call it another name.” What’s being done with “typedef cl_float4 cl_float3” is that you’re being allowed to say your variable is a type of cl_float3 but to the machine, it still sees it as a cl_float4. No matter what you call it, the machine will still treat it the same.

The OpenCL specification http://www.khronos.org/registry/cl/spec … f#page=143 goes in to detail about it at section 6.1.5 (which should be the page that url opens up on)