Results 1 to 5 of 5

Thread: Passing arrays of complex structures

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    7

    Passing arrays of complex structures

    Hi,

    Could someone please give an advice on how to pass arrays of structures that contain members that contain other arrays of structs? To be more more clear, here's what I am trying to do:

    typedef struct
    {
    int p;
    coef* t1;
    coef* t2;
    mydata* data;
    ...
    ...
    } CL_ThreadData;


    __kernel void calc(__global CL_ThreadData* tData)
    {
    ...
    //Do some calc
    //Mask off tData by thread_ID
    printf("ID of data[0] is %d",tData[get_global_id(0)].data[0].id);
    }


    On the host side I create an array of CL_ThreadData for 16 threads, initialize it, move it to device mem via clCreateBuffer and pass entire thing via SetArg() to the kernel.

  2. #2
    Junior Member
    Join Date
    May 2009
    Posts
    11

    Re: Passing arrays of complex structures

    this doesnt seem to work on current sdk implementations.

    you have to copy the whole array to the gpu memory instead of passing it as a kernel parameter.
    (this also makes sense because of the limited stack size on gpus).

  3. #3
    Junior Member
    Join Date
    Jun 2009
    Posts
    7

    Re: Passing arrays of complex structures

    Thank you for your reply. This was for CPU SDK, but you are correct that if this were to run on GPU I would need to be more sensitive to the parameter stack. If I am not mistaken, the current CPU reports a limit of 256MB for the max size of passed args.

    So I can just create a separate buffer using clCreateBuffer for each of those arrays and just reference it in the kernel code?

  4. #4
    Junior Member
    Join Date
    Jul 2009
    Posts
    11

    Re: Passing arrays of complex structures

    Yes

  5. #5
    Senior Member
    Join Date
    Jul 2009
    Location
    Northern Europe
    Posts
    311

    Re: Passing arrays of complex structures

    Remember that you can access buffers however you want in the kernel. You can access them as structs, but it is up to you to make sure the data is packed as you expect. If you are passing lots of data you should always do it through cl_mem objects to avoid stack limitations.

Similar Threads

  1. How to pass complex structures to kernel?
    By chanakya.sun in forum OpenCL
    Replies: 2
    Last Post: 07-22-2011, 04:21 AM

Posting Permissions

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