Pointer to pointer to global memory

Hello,

I was wondering if it was possible (I know already it is not indispensable), to store the address of a usual pointer to global memory in another pointer.

For example, would it be OpenCL compliant to write something like this?

__kernel SomeKernel(__global int *p)

{

__global int **q = &p;

}

I guess not, but I would like to be sure.

This seems to compile with Nvidia drivers, but not some others.

Thank you for your answer.

OpenCL has the more abstract concept of memory objects compared to C4CUDA. This becomes quite obvious if you consider that CL memory objects are created context-, not device-wise, an can be shared between multiple devices. Pointers, however, are device-specific and would only reflect one view on a shared memory object, but would be completely meaningless on another device.

From what I understand, an OpenCL runtime is not even required to bind a memory object to a certain address between different kernel invocations, in principle it could store it on disc and restore it before another kernel execution somewhere else.

For that reason, there are only pointers that exist for the time a kernel is executed (so these pointers are device-specific and valid only for a a short time), and there is no support for storing pointers to global memory. You might somehow get it working by casting pointers through size_t to unsigned long long (and vice versa), but don’t be surprised if you don’t get what you expected.

Regards,
Markus

I have seen this from other people coding CUDA or OCL on NV platforms. Everybody wants pointers to data in other memory objects or somewhere else in VRAM. Pointers are needed in very little percentage of cases. Indexers are more safe and they bring the same performance. (Indexers BY DEFINITION compile to pointer arithmetic, so they are the same speed) Difference is that you need not worry about pointers being valid or not over time. Indexers are always true and valid for buffers.