opencljoclmultiple-gpu

Using OpenCL for multiple devices (multiple GPU)


Hello fellow StackOverflow Users,

I have this problem : I have one very big image which i want to work on. My first idea is to divide the big image to couple of sub-images and then send this sub-images to different GPUs. I don't use the Image-Object, because I don't work with the RGB-Value, but I'm only using the brightness value to manipulate the image.

My Question are:

  1. Can I use one context with many commandqueues for every device? or should I use one context with one commandqueue for each device ?
  2. Can anyone give me an example or ideas, how I can dynamically change the inputMem-Data (sub-images data) for setting up the kernel arguments to send to the each device ? (I only know how to send the same input data)
  3. For Example, If I have more sub-images than the GPU-number, how can I distribute the sub-images to the GPUs ?
  4. Or maybe another smarter approach?

I'll appreciate every help and ideas. Thank you very much.


Solution

    1. Use 1 context, and many queues. The simple method is one queue per device.
    2. Create 1 program, and a kernel for each device (created from the same program). Then create different buffers (one per device) and set each kernel with each buffer. Now you have different kernels, and you can queue them in parallel with different arguments.
    3. To distribute the jobs, simple use the event system. Checking if a GPU is empty and queing there the next job.

    I can provide more detailed example with code, but as general sketch that should be the way to follow.