【发布时间】:2017-04-11 14:32:45
【问题描述】:
我正在尝试通过识别 3d 体积位置和组 ID 来计算每个组的本地总和。
我的想法是将空间分组并使用 atomic_add 来计算 local_sum。 但是因为我是并行计算的新手,所以很难找到代码和指令之间的相关性。 我当前的内核是这样的:
__kernel void TestAtomicAddLocal(__global *int src, int3 size, __global int *res)
{
int x = get_global_id(0);
int y = get_global_id(1);
int z = get_global_id(2);
if( x >= vol_dim.x || y >= vol_dim.y || z >= vol_dim.z ){ return; }
int id = x + y * vol_dim.x + z * vol_dim.x * vol_dim.y;
// local mem shared by all work items in work group,
//so this can be accessed by all items in current workgroup
__local int local_sum;
local_sum= 0;
// use global_id to access the value of input array
int local_offset = atomic_add(&local_sum, src[id]);
barrier(CLK_LOCAL_MEM_FENCE);
int global_offset = atomic_add(&num_verts[0], local_sum);
barrier(CLK_GLOBAL_MEM_FENCE);
}
对于主机部分,我的设置是
enqueueNDrangeKernel( cq, kn_testAtomicAddLocal, 3, 0, cl::size3(256,256,256), cl::size3(64, 64, 64), 0, 0, 0);
对于 kenrnel 参数,*src 为 cl_mem,大小为 256*256*256*sizeof(cl_int),大小为 4 * sizeof(cl_int),*res 为 cl_mem,大小为 4*sizeof(int)。
然后我得到错误 CL_OUT_OF_RESOURCE 和 CL_INVALID_GROUP_SIZE,据我了解,我的设备最大组大小为 1024,但这里总组 = (256/64)^3 = 64
【问题讨论】:
标签: opencl