OpenCL local_work_size问题

时间:2011-07-26 14:15:26

标签: opencl

我有一个大小为n的向量(在主程序启动之前未知),我想尝试工作组大小。但是,除非我将local_work_size设置为一个精确划分n的数字,否则我只能在下面的fprop中得到0个值。

内核:

__kernel void palt(__global double *fprop, __global const double *fcoll,
                   __global const int *nn, const uint max_size)
{
    size_t l = get_global_id(0);

    if( l > max_size ) return;

    fprop[l] = fcoll[nn[l]];

}

主机代码:

int block_sz_p = 128;
const int max_size = ns*imax;

// set the parameters for the propagation operator
errNum = clSetKernelArg(propagation_kernel, 0, sizeof(cl_mem), &fpd);
errNum |= clSetKernelArg(propagation_kernel, 1, sizeof(cl_mem), &fcd);
errNum |= clSetKernelArg(propagation_kernel, 2, sizeof(cl_mem), &nnd);
errNum |= clSetKernelArg(propagation_kernel, 3, sizeof(int), (void *) &max_sz);
checkErr(errNum, "clSetKernelArg(propagation)");

// specify the work group size/dim
const size_t work_dim = 3;  
const size_t global_work_size_propagation[] = {imax*ns, 1, 1};
const size_t local_work_size_propagation[] = {block_sz_p, 1, 1};

// propagation
clEnqueueNDRangeKernel(queue, propagation_kernel, work_dim, NULL, 
                       global_work_size_propagation, local_work_size_propagation,
                       0, NULL, &event);

clWaitForEvents(1, &event); 
clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START, 
                        sizeof(cl_ulong), &start, NULL);
clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END, 
                        sizeof(cl_ulong), &end, NULL);
tker2 = (end-start);

这里发生了什么?

1 个答案:

答案 0 :(得分:1)

您应检查CL错误,clEnqueueNDRangeKernel和其他调用返回错误代码(其他人通过引用返回错误代码)。

我认为问题是当全局工作组大小不能被本地工作组大小整除时,不支持并产生CL错误:

  

CL_INVALID_WORK_GROUP_SIZE如果指定了local_work_size,并且 global_work_size指定的工作项数量不能按local_work_size 给出的工作组大小平均分配,或者与为内核使用的工作组大小不匹配程序源中的属性((reqd_work_group_size(X,Y,Z)))限定符。

来自clEnqueueNDRangeKernel man page

相关问题