Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 build 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!

like image 979
andromida Avatar asked Jul 18 '11 18:07

andromida


1 Answers

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

like image 160
Dr. Snoopy Avatar answered Sep 30 '22 14:09

Dr. Snoopy