PDA

View Full Version : Single context, multiple devices, where does the memory go?



gigurra
10-23-2009, 08:17 AM
I have set up a context containing 4 GPU devices.

When I create a buffer object with clCreateBuffer(....) I specify
which context to place the memory in, however...

Will the buffer be stored as 1 copy on each device,
or will it be a single buffer that spans all 4?

I know I can use clCreateContext on a specific device and
then assign memory on that device explicitly, but that is not
what I'm after here.

All help greatly appreciated :)

affie
10-24-2009, 07:11 AM
The OpenCL implementation handles the allocation & management of memory objects. When you create a buffer, it is possible that the implementation may not allocate memory on any device. When you enqueue a command that uses the memory object to a device, the implementation will make sure that there is a data store allocated on the device, make sure the data store allocated on the device has the latest bits before enqueuing the command.

This is why you need to use events to ensure correct synchronization of data when a memory object is to be used by commands executing in multiple queues or in an out-of-order queue.

gigurra
10-28-2009, 11:03 AM
Thank you for the answer

Now, let's say I have a context on 4 devices.
I create a buffer on this context to hold a set of floats.

Now I create a command queue on each device.

If I enqueue a write to buffer on the first queue.

I assume at this point I have only written memory on the first device?
I mean there is no actual "target device" in the enqueueWriteBuffer function...


"the device has the latest bits before enqueuing the command."
Not quite sure I understand what you mean by this. "Has the latest bits",
what does this mean?

dbs2
10-29-2009, 12:51 AM
If you enqueue a write to the buffer on queueA(deviceA) then OpenCL will use that device to do the write. However, if you then use the buffer on queueB(deviceB) in the same context, OpenCL will recognize that deviceA has the most recent data and will move it over to deviceB before using it. In short, as long as you use events to ensure that no two devices are trying to access the same memory object at the same time, OpenCL will make sure that each use of the memory object has the most recent data, regardless of which device last used it.

Dr.Synth
04-04-2010, 04:04 AM
very informative bits of information on this thread, thanks all! i too was just wondering where the mem is allocated since the device id is never mentioned with clCreateBuffer.