Thomas Unterthiner
2014-09-24 08:58:51 UTC
Hi!
I have a program that makes extensive use of pycuda, but also calls out
to a C library which also uses CUDA internally (it does not share any
state or memory with the pycuda code, and uses the CUDA runtime API).
However, after the call to the C library ends, all my PyCUDA calls fail
with a "LogicError: cuFuncSetBlockShape failed: invalid handle". (The
same call with the same parameters worked fine before calling out to the
C library).
I have tried explicitly initializing/shutting down the PyCUDA contexts,
but I still can't get stuff to work. The relevant parts of my program
look as follows:
# initialize PyCUDA
def init_pycuda(gpu_id):
import pycuda.driver as cuda
global __pycuda_context, __pycuda_device
pycuda_drv.init()
__pycuda_device = pycuda_drv.Device(gpu_id)
__pycuda_context = __pycuda_device.make_context()
import scikits.cuda.misc
scikits.cuda.misc.init()
init_pycuda(0)
use_pycuda()
# trying to shut down PyCUDA
import scikits.cuda.misc
from pycuda.tools import clear_context_caches
cuda_memory_pool.free_held()
cuda_hostmemory_pool.free_held()
scikits.cuda.misc.shutdown()
__pycuda_context.pop()
clear_context_caches()
__pycuda_context = None
__pycuda_device = None
# ... now I'm calling out to the other library
call_external_library()
init_pycuda(0)
use_pycuda() # this will now fail with a LogicError
As said before, the C library uses the CUDA runtime API, so it uses
cudaSetDevice to initialize and calls cudaDeviceReset at the end. Is
there something I'm overlooking wrt. how to (de)initializing PyCUDA?
Cheers
Thomas
I have a program that makes extensive use of pycuda, but also calls out
to a C library which also uses CUDA internally (it does not share any
state or memory with the pycuda code, and uses the CUDA runtime API).
However, after the call to the C library ends, all my PyCUDA calls fail
with a "LogicError: cuFuncSetBlockShape failed: invalid handle". (The
same call with the same parameters worked fine before calling out to the
C library).
I have tried explicitly initializing/shutting down the PyCUDA contexts,
but I still can't get stuff to work. The relevant parts of my program
look as follows:
# initialize PyCUDA
def init_pycuda(gpu_id):
import pycuda.driver as cuda
global __pycuda_context, __pycuda_device
pycuda_drv.init()
__pycuda_device = pycuda_drv.Device(gpu_id)
__pycuda_context = __pycuda_device.make_context()
import scikits.cuda.misc
scikits.cuda.misc.init()
init_pycuda(0)
use_pycuda()
# trying to shut down PyCUDA
import scikits.cuda.misc
from pycuda.tools import clear_context_caches
cuda_memory_pool.free_held()
cuda_hostmemory_pool.free_held()
scikits.cuda.misc.shutdown()
__pycuda_context.pop()
clear_context_caches()
__pycuda_context = None
__pycuda_device = None
# ... now I'm calling out to the other library
call_external_library()
init_pycuda(0)
use_pycuda() # this will now fail with a LogicError
As said before, the C library uses the CUDA runtime API, so it uses
cudaSetDevice to initialize and calls cudaDeviceReset at the end. Is
there something I'm overlooking wrt. how to (de)initializing PyCUDA?
Cheers
Thomas