get_global_id(0) changes when moving from float * to float4 * in kernel


I’m running the following code from “OpenCL in action”:

__kernel void id_check(__global float *output) { 

   /* Access work-item/work-group information */
   size_t global_id_0 = get_global_id(0);
   size_t global_id_1 = get_global_id(1);
   size_t global_size_0 = get_global_size(0);
   size_t offset_0 = get_global_offset(0);
   size_t offset_1 = get_global_offset(1);
   size_t local_id_0 = get_local_id(0);
   size_t local_id_1 = get_local_id(1);

   /* Determine array index */
   int index_0 = global_id_0 - offset_0;
   int index_1 = global_id_1 - offset_1;
   int index = index_1 * global_size_0 + index_0;
   /* Set float data */
   float f = global_id_0 * 10.0f + global_id_1 * 1.0f;
   f += local_id_0 * 0.1f + local_id_1 * 0.01f;

   output[index] = f;

If I change the input to: __global float4 *output,

The indexes of global_id are changed.

Can you tell why ?

The code of the host is the same. So the host divides data to cores as it did before.
So the value of get_global_id(0) should not change.


The output of the float4 version shows that the kernel works fine but that it is probably the way you display the result which is wrong.

You are right !

The line that puts the data in the output buffer is:
output[index] = f;

If the output changes to ‘float4 *’ it should be handled accordingly.