-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I have written a CUBLAS wrapper in Python using ctypes.  CUBLAS uses
the CUDA runtime API whereas PyCUDA uses the driver API.  Thankfully
both are compatible nowadays and so mixing the two is in and of itself
not an issue.  My wrapper is along the lines of:

class Cublas(object):
    def __init__(self, ...):
        ...
        cublasInit(byref(self._handle))

    def __del__(self):
        cublasDestroy(self._handle)

where handle is a CUBLAS V2 API handle.  Issues arise, however, if
there is an uncaught exception.  In this case Python fires off the
atexit handlers (which cause the CUDA context to be popped) before
garbage collecting objects.  However, if there is no active context
then cublasDestroy will segfault.

My current workaround is to put an if statement which checks to see if
pycuda.autoinit.context is None and if not then call cublasDestroy.
However, I am interested if there is a more elegant solution.  Having
to explicitly .pop() a context is something of a nusiance.  Can PyCUDA
not do that on its own when the object is GC'ed?

Regards, Freddie.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlB0F1AACgkQ/J9EM/uoqVeDewCePLtt0FidOSuPd1qBSRz1tJCo
8gkAnROXZglwtt+8uoBilkA9pvYizDf1
=IgIt
-----END PGP SIGNATURE-----

_______________________________________________
PyCUDA mailing list
[email protected]
http://lists.tiker.net/listinfo/pycuda

Reply via email to