Using async_work_group_copy with a custom data type

时光怂恿深爱的人放手 提交于 2020-01-03 02:55:07

问题


I need to copy some data from __global to __local in openCL using async_work_group_copy. The issue is, I'm not using a built-in data type.

The code snip of what I have tried is as follows:

typedef struct Y
{
    ...
} Y;

typedef struct X
{
    Y y[MAXSIZE];
} X;

kernel void krnl(global X* restrict x){ 
    global const Y* l = x[a].y;

    local Y* l2;

    size_t sol2 = sizeof(l);

    async_work_group_copy(l2, l, sol2, 0);
}

where 'a' is just a vector of int. This code does not work, specifically because the gen_type is not a built-in one. The specs (1.2) says:

We use the generic type name gentype to indicate the built-in data types ... as the type for the arguments unless otherwise stated.

so how do I otherwisely state this data type?


回答1:


OpenCL async_work_group_copy() is designed to copy N elements of a basic data type. However it does not really know what is being copied. So you can tell it to copy N bytes, containing any type inside (including structs). Similar to memcpy().

You can do:

kernel void krnl(global X* restrict x){ 
    global const Y* l = x[a].y;
    local Y l2;

    size_t sol2 = sizeof(Y);

    async_work_group_copy((local char *)&l2, (global char *)l, sol2, 0);
}

However, remember that you need to declare local memory explicitly in side the kernel, or dinamically from the API side and pass a pointer to local memory. You can't just create a local pointer without any initialization and copy there. (see my code)



来源:https://stackoverflow.com/questions/37981455/using-async-work-group-copy-with-a-custom-data-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!