【发布时间】:2013-07-14 02:04:38
【问题描述】:
假设我有一个内核来计算两个数组的元素总和。我没有将 a、b 和 c 作为三个参数传递,而是将它们设为结构成员,如下所示:
typedef struct
{
__global uint *a;
__global uint *b;
__global uint *c;
} SumParameters;
__kernel void compute_sum(__global SumParameters *params)
{
uint id = get_global_id(0);
params->c[id] = params->a[id] + params->b[id];
return;
}
如果您使用 PyOpenCL [1] 的 RTFM,则有关于结构的信息,其他人也已经解决了这个问题 [2] [3] [4]。但是我找到的 OpenCL 结构示例都没有指针作为成员。
具体来说,我担心主机/设备地址空间是否匹配,以及主机/设备指针大小是否匹配。有人知道答案吗?
[1]http://documen.tician.de/pyopencl/howto.html#how-to-use-struct-types-with-pyopencl
[2]Struct Alignment with PyOpenCL
[3]http://enja.org/2011/03/30/adventures-in-opencl-part-3-constant-memory-structs/
【问题讨论】:
标签: python struct opencl memory-alignment pyopencl