有人在 JOCL 中进行矩阵乘法时遇到这种错误吗?
Exception in thread "main" org.jocl.CLException: CL_INVALID_KERNEL_ARGS
at org.jocl.CL.checkResult(CL.java:787)
at org.jocl.CL.clEnqueueNDRangeKernel(CL.java:20802)
at org.jocl.samples.JOCLSample.main(JOCLSample.java:147)
我编辑了他们的示例 HelloJOCL.java 来进行矩阵乘法计算以及 matrixMul.cl(内核代码)。这是导致错误的内核参数:
// Create the kernel
cl_kernel kernel = clCreateKernel(program, "matrixMul", null);
long time = nanoTime();
// Set the arguments for the kernel
clSetKernelArg(kernel, 0,
Sizeof.cl_mem, Pointer.to(memObjects[0]));
clSetKernelArg(kernel, 1,
Sizeof.cl_mem, Pointer.to(memObjects[1]));
clSetKernelArg(kernel, 2,
Sizeof.cl_mem, Pointer.to(memObjects[2]));
工作项维度代码:
// Set the work-item dimensions
long global_work_size[] = new long[]{n};
long local_work_size[] = new long[]{1};
// Execute the kernel
clEnqueueNDRangeKernel(commandQueue, kernel, 1, null,
global_work_size, null, 0, null, null);
和内核代码:
private static String programSource =
"__kernel void "+
"matrixMul(__global float* C,"+
" __global float* A,"+
" __global float* B,"+
" int wA, int wB)"+
"{"+
"int x = get_global_id(0);"+
"int y = get_global_id(1);"+
"float value = 0;"+
"for (int k = 0; k < wA; ++k)"+
"{"+
" float elementA = A[y * wA + k];"+
" float elementB = B[k * wB + x];"+
" value += elementA * elementB;"+
"}"+
"C[y * wA + x] = value;"+
"}";