Array of pointers in device memory

Just wondering,

How do I go about creating a cl_mem object which appears as an array of pointers to the kernel?

I understand that a “cl_mem” argument appears as a “pointer” argument in the kernel…

What if this cl_mem object contains an array of cl_mem objects??? Will it appear as array of pointers to the kernel?

How do I go about this?

In OpenCL 1.0, a cl_mem object cannot contain cl_mem objects. So a pointer to pointers cannot be passed as an argument to a kernel. T

Thanks for the answer.

Well, Is there a reason why you mention “1.0”?

Is there any consideration for array of pointers?

People often need to copy complex data-structures on to GPUs or other HPC devices. Wondering, why OpenCL is not considerate about these requirements?

I’m new to this and a bit confused.

Does this mean we cant pass multi-dimensional arrays to the GPU?

Not just array of pointers… Even true heterogeneous computing (simultaneously harnessing CPU and GPU power) is NOT possible with this spec.

You can absolutely pass multi-dimensional arrays to kernels. When you pass in a buffer, it is just a bunch of data that you can use however you want inside the kernel. What you can not do is pass in an array of cl_mem objects (buffers or images).

With regards to “true” heterogeneous computation, the OpenCL spec allows you to execute kernels on any supported device in your system. So this is “true” heterogeneous computation, but it is not, is “automatic” heterogeneous computation. (E.g., the developer will still have to determine how to split the work across the supported devices, but OpenCL will allow them to all be used together.)

You can absolutely pass multi-dimensional arrays to kernels. When you pass in a buffer, it is just a bunch of data that you can use however you want inside the kernel. What you can not do is pass in an array of cl_mem objects (buffers or images).

I think I differ here. CL_MEM can hold data… that is uni-dimensional. In CUDA, I could technically create an “int **a” on the device… So, “a” points to an array of pointers each of which point to an array of integers… I cant replicate that with OpenCL.

But arrays like int “a[100][100]” can be replicated once we know if it is row_major or column_major.

With regards to “true” heterogeneous computation, the OpenCL spec allows you to execute kernels on any supported device in your system

Not really. The spec does NOT spell out the Platform layer. Each vendor comes out with his own version of clFindDevices and so on…

Therez no device manager layer outlined by the spec at all. Thus true heterogeneous computing is still out of reach.

Best REgards,
Sarnath

Just to clarify, is it allowable under the 1.0 standard that separate kernel executions passed the same cl_mem object may provide to the kernel different pointer values for this object? The spec does not seem to explicitly specify one way or the other.

(If the pointer values passed for cl_mem objects were guaranteed to always be the same, then it should be possible to arrange for pointer-based data structures to persist between kernel calls.)

It is certainly possible that separate kernel executions passed the same cl_mem object may result in different pointer values for this memory object in the kernel. Consider for example if memory usage results in memory objects being punted from the device’s memory. In this case, there is no guarantee that the cl_mem object will be the same pointer value across multiple kernel executions.