Results 1 to 5 of 5

Thread: One device, many contexts

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    14

    One device, many contexts

    Is it the intent of the OpenCL specification to allow a device to be part of more than one context, or should a device that is already part of an existing context be marked as "unavailable" and cause "clCreateContext()" to fail when an application asks for it to be included in a new context as well?

    Also, if OpenCL should not fail "clCreateContext()" when one or more of the listed devices are already part of context(s), then what about "clCreateContextWithType()" when there are no other available devices of the selected type?

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: One device, many contexts

    Is it the intent of the OpenCL specification to allow a device to be part of more than one context
    Yes, this is intentional. I'll give an example of why this is useful: let's say that you write an application that uses OpenCL to perform some computation. Let's also say that your application is linked against a library that also uses OpenCL to accelerate some operations. Isn't it nice that the library and the main application can both use OpenCL simultaneously? They don't need to worry whether the other party is already using certain device; in fact, they don't even need to know that the other is using OpenCL at all!

    Also, if OpenCL should not fail "clCreateContext()" when one or more of the listed devices are already part of context(s), then what about "clCreateContextWithType()" when there are no other available devices of the selected type?
    No difference. The OpenCL driver makes sure that multiple contexts, even multiple processes, can use the same device "simultaneously".
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    14

    Re: One device, many contexts

    Thank you, this was very informative.

    I can now see why using the same device with multiple contexts is important.

    I think that using the same device with multiple processes "simultaneously" is dangerous for security, unless of course the device is a CPU. Multiple threads of the same process - certainly, but not multiple processes of possibly different users. GPUs have no memory-protection, so it would be open to abuse such as spying on other users, or even modifying their data. Of course, a driver could transparently back up and restore the whole GPU memory when used by different processes, but that can be unreasonably expensive.

  4. #4
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: One device, many contexts

    You will find that modern GPUs have MMUs (shameless plug).

    Useless trivia: I think the first GPU with an MMU was the 3dlabs P10 back in 2002.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  5. #5
    Junior Member
    Join Date
    Nov 2009
    Posts
    14

    Re: One device, many contexts

    Very interesting.

    I just wondered, since GPUs with MMUs are starting to appear, one important feature that goes with it is the ability to preempt a kernel: what if two users use the same GPU and one's kernel takes very long - suppose it already ran for an hour, or suppose it has a bug causing an infinite loop, it is important for the operating-system to be able to stop that kernel and resume it later, allowing the second user to proceed.

    Any such plans?

Similar Threads

  1. multiple contexts and devices
    By brdavs in forum OpenCL
    Replies: 1
    Last Post: 01-24-2013, 02:02 PM
  2. eglBindTexImage with two contexts
    By stumcd in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 07-28-2010, 07:51 AM

Posting Permissions

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