View Full Version : "clDevicePointer" function needed!

06-02-2010, 01:31 AM
A function to retrieve the device memory pointer in order to use in
other OpenCL buffers. This gives the possibility to pass graph or
other structures relying heavily on pointers by keeping their

Example thread about the feature:

Special note: a similar function already exists in CUDA.

05-30-2011, 02:16 AM
I agree. I have an object that has a list of objects that have lists of
objects. Flattening this is going to be such a pain.

Doing this with a bunch of buffers containing references to each other
would be so much better. This structure is only written once, so
the performance hit would be negligible.

These kind of hierarchial structures are common so some way to handle them
would be beneficial to paraller computing.
You can only do so much with just arrays.

I realize that buffers move around and so on, so the system
should really know that this is a buffer, not just a memory address.

something like (in OpenCL-C)

struct Blaa{
int resurgence;
float revorbitance;
Buffer minions; // This a buffer object

struct Minion{
Buffer henchmen; // Our structure is multidimensional

kernel addMinion(global Blaa* blaa,global Minion* minion){
if(blaa.minions.size < blaa.minions.capacity){ // The size of the buffer is static
bufferAppend(blaa.minions,minion); // system function

kernel commandMinion(global Blaa* blaa,int index){
commandMinion( (Minion*)minions.address[index] );

I hope that gives you the idea.
Henchman could also have a buffer member and so on.
This would allow arbitrarily complex hierarchies to be built.

At the moment i can't see a way to do something like
this that doesn't involve flattening the entire data structure
or implementing my own malloc against a buffer i would use as general memory.
Are there better ways since, as someone said in the other thread,
just getting the address that a certain buffer happens to be
in is not safe?

05-31-2011, 01:49 PM
I third this!

06-03-2011, 07:20 PM
Why not use indices instead of pointers? This way they are independent of buffer location, devices, address spaces, etc. The same index could be applied to multiple buffers. Index size can be chosen based on data size in order to optimize its storage (i.e. 8, 16, 32, or 64 bit -- or even encoded into a large field as an arbitrary number of bits). The index can also be in terms of structure size, or in terms of bytes (or something else).

09-30-2011, 03:37 AM
for the same reason that one wants to use a linked list: constant-time insertion and removal anywhere in the list.

09-30-2011, 06:49 AM
for the same reason that one wants to use a linked list: constant-time insertion and removal anywhere in the list.

You can do that with offsets as well. Offsets and pointers are fundamentally the same thing.