notyou

Ways of accessing vectors in kernel?

Discussion created by notyou on Nov 10, 2011
Latest reply on Nov 12, 2011 by notyou

I've seen two different ways of accessing a vector and I'm not quite sure of the difference between them. Let's say we have a float4 vector. Then in the code I can say:

vector[global_id] = global_id; // assume global_id = 0

and then in other places I see

vector[global_id].x = global_id;

vector[global_id].y = globa_id;

...

 

Will these two do the same thing? If so, is there any reason to use the second method if we write the same data to all locations?

 

Also, if we have something like the above:

// assume vector is a 16 element array

vector[local_id] = local_id // assume local_id = 0

Will this write elements[0-3] with local_id? And then thread 1 writes elements[4-7]?

Or would we have to manually map which elements are executed by each thread?

vector[local_id + X] = local_id // where X is basically making it a loop, in which case we wouldn't be executing 4 items at a time if I'm not mistaken.

Thanks.

-Matt

Outcomes