I have a vector of size n (unknown before the main program is launched), and I want to experiment with the work-group sizes. However, unless I set the local_work_size to a number that exactly divides n, I only get 0 values in fprop below.
Kernel:
__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]];
}
Host code:
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);
What’s going on here?
You should check for CL errors, clEnqueueNDRangeKernel and other calls return a error code (others return the error code by reference).
I assume the problem is when the global workgroup size isn’t divisible by the local workgroup size, which is not supported and generates a CL error:
From the clEnqueueNDRangeKernel man page.