Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
8 years ago

Structure Padding or Memory Transferring

I have develop a C code to do some calculations on some data made of structures. It works perfectly on CPU with C code. I have then implemented the same code with OpenCL and it is outputting wrong results and by debugging on CPU I can see it's reading wrong values from the structures. I have developed different codes on OpenCl even big codes and didn't have this problem. I am using doubles to avoid precision differences but the problem here is that the data looks getting transferred wrongly. I have no idea why is this happening. What suggestions would you guys give me? I have done already structure packaging correctly I guess. Looks like the memory allocation might be giving some problems but I am not sure why. I am running just 1 work-item and no use of local memory only global. Before I was trying a similar code and it was not giving so many problems. I am thinking it's a problem of memory allocation but I have always done like this in other codes.

Sorry if I am not posting any code but I can't share it because of my job.

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Without seeing the code, it would be pretty difficult to guess what the problem is.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Let's start with memory allocation. This is how I allocate memory for structures:

    d_orders_size = sizeof(SimpleOrder) * orders->size();

    d_orders = (SimpleOrder*)_aligned_malloc(d_orders_size, 64);

    for (int i = 0; i < orders->size(); i++)

    {

    d_orders[i] = orders->at(i);

    }

    This is the definition of the structure:

    struct SimpleOrder {

    cl_double a;

    cl_int b;

    enum anEnum c;

    cl_int d;

    cl_int e;

    cl_int padding[10];

    };

    So it's size of 64 bytes.

    Is there any problem with these two parts?

    The rest of the OpenCL code is the same as the C version so I don't see why there should be any problem since it's a one work item kernel.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have just realized I was passing the wrong buffer to a function inside the kernel... Sorry for wasting a thread here. Thanks it can be closed.