Using async_work_group_copy with a custom data type

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 08:04:19

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)

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