sharing cuda contexts and the use of cuCtxAttach()

I have 3 threads A, B, and C.

Thread A creates a context. Can’t I simultaneously use this context created by A, inside thread B and C. I tried some samples and looks like it fails. Isn’t there any way to share a context between multiple threads simultaneously(that is without the popping and pushing)?

But I am confused as to why we have cuCtxAttach(). My understanding was that multiple threads can attach to any context using cuCtxAttach and use it irrespective of whether that same context is used simultaneously in some other thread. Can someone explain the use of this function to me?

Thanks for taking time for this.

There was another thread similar to this, but the question was unanswered

  • bump. sorry. can someone help me with this*

Pushing and popping is the only way. cuCtxAttach is a function that you should never really have to use.

Right. Thanks tmurray. I was wondering what’s the actual use of cuCtxAttach! It still isn’t clear to me as to why we have these functions. The manuals aren’t very clear about their use. By any chance are these functions available, so that in future implementations nvidia plans to support other multiple host threads to attach to a single context and use it simultaneously?

It’s ludicrously special purpose; it’s basically for picking the most opportune time to do teardown of a CUDA context (a library can tell if it’s the only user or if there is another user of the context).

Right. Thanks