How to pass and efficiently access multi-dimensional array

Dear all,

I need to pass a multi-dimensional (4/5-D) array to OpenCL, besides to efficiently access such array in the future for further processing. In particular, I need to do that in order to elaborate some complex 4/5-D data.

Please, could you give me some information or suggestions concerning such stuff?

Thank you in advance.

Best Regards

OpenCL 1.x supports 2D and 3D images and OpenCL 1.2 adds 1D images, and clEnqueueNDRangeKernel supports 1D, 2D, and 3D workgroups. Of course all of these ultimately map to linear memory, so it’s just abstractions. Everything could have been done with 1D only.

So your 4D and 5D problems can be decomposed into 1D, 2D, or 3D problems for OpenCL. The runtime doesn’t really care which. Your choice should be informed by how you access data; you want to keep accesses within a workgroup adjacent if possible, to maximize memory bandwidth.

address = dim4 * dim3pitch + dim3 * dim2pitch + dim2 * dim1pitch + dim1 * dim0pitch + dim0

For 2D/3D dim0pitch is rowpitch and dim1pitch is slicepitch.

Thank you very much,

the solution you suggested works nicely!

Thanks again.