2013-06-22 73 views
3

我想將一個cl_mem緩衝區數組傳遞到一個內核中,但這似乎是不可行的。任何人都知道這裏有什麼意義?如果實際上不可行,那麼當我想將許多緩衝區對象傳入內核時,我該如何實現該目標?非常感謝。如何將一個cl_mem緩衝區數組傳遞給OpenCL設備

+0

除了clEnqueueNDRangeKernel()? –

+0

clEnqueueNDRangeKernel是什麼意思?它只是啓動內核,而不是將參數傳遞給內核。我使用clSetKernelArg將參數傳遞給內核,不是嗎? – acekiller

回答

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的包裝這樣做,您可能需要一個String concatenator方法來將實際參數放入內核字符串中。你也可以使用二維參數。它不應該是C/C++封裝中的字符串問題。

相關問題