Discussion:
[PyCUDA] Multithreading with a single context per process
Emanuel Rietveld
2018-03-05 21:45:51 UTC
Permalink
If I understand correctly, the current PyCUDA multithreading examples
assume you create a separate context for each thread.

If I want to use CUDA 4.0+'s one-context-per-process model instead,
how would I do that in PyCUDA?

I think you'd call cudaSetDevice instead of cuCtxCreate? Does the
equivalent exist in PyCUDA? If it does not, can I add it?

I need to share memory between threads.

Cheers,

Emanuel
Andreas Kloeckner
2018-03-05 22:11:44 UTC
Permalink
Post by Emanuel Rietveld
If I understand correctly, the current PyCUDA multithreading examples
assume you create a separate context for each thread.
If I want to use CUDA 4.0+'s one-context-per-process model instead,
how would I do that in PyCUDA?
I think you'd call cudaSetDevice instead of cuCtxCreate? Does the
equivalent exist in PyCUDA? If it does not, can I add it?
Yes, in fact that would be very welcome. PyCUDA has some complicated and
brittle logic in place to manage CUDA's context stacks that I've been
meaning to rip out. Here's an example:

https://github.com/inducer/pycuda/blob/master/src/cpp/cuda.hpp#L525

Patches that get rid of all that code and simplify it would be very
welcome.

Andreas

Loading...