Results 1 to 5 of 5

Thread: Single context, multiple devices, where does the memory go?

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    10

    Single context, multiple devices, where does the memory go?

    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

  2. #2
    Senior Member
    Join Date
    Sep 2002
    Location
    Santa Clara
    Posts
    105

    Re: Single context, multiple devices, where does the memory go?

    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.

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    10

    Re: Single context, multiple devices, where does the memory go?

    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?

  4. #4
    Senior Member
    Join Date
    Jul 2009
    Location
    Northern Europe
    Posts
    311

    Re: Single context, multiple devices, where does the memory go?

    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.

  5. #5
    Junior Member
    Join Date
    Mar 2010
    Posts
    3

    Re: Single context, multiple devices, where does the memory go?

    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.

Similar Threads

  1. Replies: 2
    Last Post: 04-26-2010, 08:38 PM
  2. Buffer and context with multi devices
    By matrem in forum OpenCL
    Replies: 2
    Last Post: 12-12-2009, 09:22 AM
  3. cl_mem and devices inside a context...
    By Sarnath in forum OpenCL
    Replies: 4
    Last Post: 07-29-2009, 09:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •