Discussion:
[PyCUDA] Shutting down PyCUDA
Thomas Unterthiner
2014-10-06 09:42:33 UTC
Permalink
Hi again!

How do you completely shut down PyCUDA? After running the following lines:

from pycuda import driver as pycuda_drv
pycuda_drv.init()
device = pycuda_drv.Device(0)
ctx = device.make_context()

I can see a new process listed when using `nvidia-smi` on GPU 0 (as
expected). However, this process does not go away after:

from pycuda.tools import clear_context_caches
clear_context_caches()
ctx.pop()

# make sure the context is gone:
del(ctx)
del(device)
import gc
gc.collect()


So it seems like the context is still alive on the GPU. Grepping for
"cuCtxDestroy" in the pycuda source also yields no results. So I am
assuming the underlying cuda context is never deleted. Is this by design
(i.e., is there are reason for this), or was there just never a need to
do this before?

Cheers

Thomas
Andreas Kloeckner
2014-10-09 00:05:28 UTC
Permalink
Post by Thomas Unterthiner
Hi again!
from pycuda import driver as pycuda_drv
pycuda_drv.init()
device = pycuda_drv.Device(0)
ctx = device.make_context()
I can see a new process listed when using `nvidia-smi` on GPU 0 (as
from pycuda.tools import clear_context_caches
clear_context_caches()
ctx.pop()
del(ctx)
del(device)
import gc
gc.collect()
So it seems like the context is still alive on the GPU. Grepping for
"cuCtxDestroy" in the pycuda source also yields no results. So I am
assuming the underlying cuda context is never deleted. Is this by design
(i.e., is there are reason for this), or was there just never a need to
do this before?
You're the first one to ask for this. In fact, PyCUDA still uses the
context management functions from CUDAs 1.x days that are by now
deprecated (I think). This was a terrible interface, and the resulting
context management code was scary and brittle.

So from my perspective, I'd very much support ripping out and
modernizing the context management bit of PyCUDA's code. If you've got a
bit of spare time, I'd love to review a patch.

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 810 bytes
Desc: not available
URL: <http://lists.tiker.net/pipermail/pycuda/attachments/20141008/b40c2e22/attachment.sig>
Loading...