Results 1 to 3 of 3

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

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    21

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

    Hello,

    I'm running the following code from "OpenCL in action":

    Code :
    __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.

    Thanks,
    Zvika
    Attached Images Attached Images

  2. #2
    Senior Member
    Join Date
    Oct 2012
    Posts
    102
    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.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    21
    Quote Originally Posted by utnapishtim View Post
    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.
    Thanks,
    Zvika

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •