开发者

How to use 3-D array in OpenCL kernel?

I am new to OpenCL. I have worked with OpenCL kernel with 1-D data. But when I tried to pass a 3-D pointer, it fails to b开发者_运维问答uild the kernel. To be specific I'm getting CL_BUILD_PROGRAM_FAILURE. Here's the pseudo code for the kernel I'm trying to build -

__kernel void 3D_Test(__global float ***array)
{

x = get_global_id(0);
y = get_global_id(1);
z = get_global_id(2);

array[x][y][z] = 10.0;

}

Could anyone give me an idea on what's wrong with the code? Thanks in advance!


That's not valid OpenCL C (that's why it doesn't compile), for a 3D array, you will have to use a linearlized version of that array, just create a normal array of appropiate size (sizeX * sizeY * sizeZ) and index it this way:

int index = x + y * sizeX + z * sizeX * sizeY;

Other option is to use a 3D image with clCreateImage3D


You'll have first to ensure in some way your array as enough space, at all levels...

How is your array declared or allocated?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜