Sharing the GPU between OpenCL capable programs

I’m a beginner so be gentle!

Is there a method to share the GPU between two separate OpenCL capable programs, or more specifically between two separate processes that simultaneously both require the GPU to execute OpenCL kernels? If so, how is this done?

It depends on what do you mean by “share”.

All implementations you are going to find will support multiple host processes using OpenCL simultaneously by time-slicing the GPU. That is, at any given point in time the GPU will be executing the commands from only one of the several host processes and from time to time a different process will be given control over the GPU. This will all be handled automatically by the OpenCL driver.

However, if by sharing you mean that at a given point in time the GPU is executing commands from multiple different processes then you may not be so lucky. It’s going to depend on your hardware vendor. In this case again it will be handled automatically by the driver and there’s nothing you can do from the application to enable it if the hardware/driver doesn’t support it.

If the driver uses time slicing, does this mean that every time the GPU is allocated a time slot from a different host process, the driver is having to move memory between the host and device, i.e. swap the memory from different processes in and out of the GPU? Would this not be quite inefficient?

If the driver uses time slicing, does this mean that every time the GPU is allocated a time slot from a different host process, the driver is having to move memory between the host and device, i.e. swap the memory from different processes in and out of the GPU?

If the two different processes are using a ton of (GPU) memory, then yes, the context switch can cause this sort of traffic. If the GPU has enough memory for the buffers and images from both processes, then this is avoided.

Would this not be quite inefficient?

Yes, it is :slight_smile: Do you have a better idea? (I’m not asking in a sarcastic way, but to make you think a bit why we do this).