I am new to OpenCL programming and my input is a 3D array. I am calculating the index as:
int gidX = get_global_id(0)?1:get_global_id(0);
int gidY = get_global_id(1)?1:get_global_id(1);
int gidZ = get_global_id(2)?1:get_global_id(2);
int index = gidX + (gidY*SizeX) + (gidZ*SizeY*SizeZ);
Is this the right way to do it? How do I use the local thread ids with 3d arrays? I had used it with 2d arrays as:
int tid = get_local_id(0);
int gid = get_global_id(0);
int index = tid + gid*width;
And, is there a way I could use image3d_t type for my 3D volume?
Thanks,
Sayan
It depends how you have your 3D array linearized to memory.. but Rick’s answer coded as an inline function would work fine. The other optimization you may want are prefetching to local memory when possible.