Hi Freddie,

Freddie Witherden <[email protected]> writes:
> 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?

First off, why are you making a new CUBLAS wrapper instead of making
scikits.cuda better?

http://pypi.python.org/pypi/scikits.cuda/

Second, as an answer to your question: pycuda.autoinit is by no means a
required part of PyCUDA. Just do your own initialization (and also
initialize PyCUDA), and tell your users to call your init instead of
PyCUDA's.

Andreas


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

Reply via email to