OpenCL: using struct as kernel argument

梦想的初衷 提交于 2019-12-02 04:25:59

It is not safe to declare structs in OpenCL if you are not using the OpenCL datatypes. And also, alignment may be an issue, force a packet alignment in the Host/Device compiler.

You should declare your structs as:

[Host]

typedef struct __attribute__ ((packed)) _st_foo
{
    cl_int aaa;
    cl_int bbb;
     .....
    cl_int zzz;
}st_foo;

[Device]

typedef struct __attribute__ ((packed)) _st_foo
{
    int aaa;
    int bbb;
     .....
    int zzz;
};

Aditionally, if you just want a single parameter, not an array of structs, then just pass it in as:

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