Is there a possibility to iterate over the built-in vector types
(float4, uint16, etc.) ?
As far as I’ve seen in the “quick reference card” it is only possible
to access the elements using either “v.x; v.y; … v.w;” or
“v.s0, v.s1, …”.
Is it possible to access all elements of a float16 by simply incrementing
an index? Or do I have to access all elements manually?
The vector types are not arrays, you cannot index them nor take pointers to their members.
If you need to add two vectors together, OpenCL handles that automatically for you. For example
float4 a; float4 b; float4 c; c = a+b;
this would be equivalent to:
float4 a; float4 b; float4 c; c.x = a.x + b.x; c.y = a.y + b.y; c.z = a.z + b.z; c.w = a.w + b.w;
Check out the handy dandy ‘cheat sheet’ for OpenCL on math operations that support the vector types. Saves quite a bit of lines of code I find
Thanks. I am aware of how the built-in vector types work and
that they are not comparable to arrays. But I have to pass
lots of uint-arrays with a length of 16 into a kernel and thought that
using uint16 types on the device could be helpful.
As each element has to be accessed individually I was hoping that
there would be a smart way to access all single elements of a “type16”
vector without having to write at least 16 lines of code.
Apparently there isn’t so I’ll have to use arrays instead.
Vectors are useful when you want to do the same thing to all elements simultaneously. If you are doing operations on individual elements then you aren’t using the vector hardware effectively and the language doesn’t try to support operations that cannot be done efficiently.