3

我想将一组 cl_mem 缓冲区传递到一个内核中,但这似乎不可行。有人知道这里有什么意义吗?如果它实际上是不可行的,那么当我想将许多缓冲区对象传递给内核时,我该如何实现这个目标?非常感谢。

4

1 回答 1

0

对于内核,例如

 kernelString = "__kernel void advect(" +
                "     __global float *x,"+
                "     __global float *y,"+
                "     __global float *z,"+
                "     __global float *vx,"+
                "     __global float *vy,"+
                "     __global float *vz,"+
                "     ... many arguments,"+
                "     __global float *x2,"+
                "     __global float *y2,"+
                "     __global float *z2,"+
                "     __global float *vx2,"+
                "     __global float *vy2,"+
                "     __global float *vz2)"+
                "{"+
                "..."+
                "}"+

而不是

    CL.clSetKernelArg(kernel0, 0, Sizeof.cl_mem, Pointer.to(girisDizisi0Buf));
    CL.clSetKernelArg(kernel0, 1, Sizeof.cl_mem, Pointer.to(girisDizisi1Buf));
    CL.clSetKernelArg(kernel0, 2, Sizeof.cl_mem, Pointer.to(girisDizisi2Buf));
    CL.clSetKernelArg(kernel0, 3, Sizeof.cl_mem, Pointer.to(girisDizisi3Buf));
    CL.clSetKernelArg(kernel0, 4, Sizeof.cl_mem, Pointer.to(girisDizisi4Buf));
    CL.clSetKernelArg(kernel0, 5, Sizeof.cl_mem, Pointer.to(girisDizisi5Buf));

您可以在循环中对数组执行相同操作

 for(int i=0;i<max;i++)
 {
      CL.clSetKernelArg(kernel0, i, Sizeof.cl_mem, Pointer.to(BufferYourArray[i]));
 }

如果您在 java 的包装器中执行此操作,您可能需要一个字符串连接器方法来将实际参数放入内核字符串中。您也可以使用二维参数。它不应该是 C/C++ 包装器中的字符串问题。

于 2013-06-22T11:20:20.390 回答