Segmentation fault

Hi,

I am using CUDA from python via python’s ctypes interface. Strangely, when I upgraded to 3.2 I get a segmentation fault when any of my programs end. This also seems to occur in 3.1 but not in 3.0. A minimal example to replicate the behaviour is as follows:

import ctypes
libcublas = ctypes.cdll.LoadLibrary(‘libcublas.so’)
libcublas.cublasInit()
libcublas.cublasShutdown()

Any help is greatly appreciated.

Hi,

I am using CUDA from python via python’s ctypes interface. Strangely, when I upgraded to 3.2 I get a segmentation fault when any of my programs end. This also seems to occur in 3.1 but not in 3.0. A minimal example to replicate the behaviour is as follows:

import ctypes
libcublas = ctypes.cdll.LoadLibrary(‘libcublas.so’)
libcublas.cublasInit()
libcublas.cublasShutdown()

Any help is greatly appreciated.

Did you ever find the solution to this problem? I am having the same problem with python 2.6.4. All the code executed just fine, but when python exits, there is a segmentation fault. this is a simple test case that triggers it:

test.py:

import ctypes

mcQueenyDll = ctypes.CDLL(“/home/tsarvey/csec/ctypes_test/_test.so”)
mcQueenyDll.test_func()
print ‘done’

test.cu (compiled to _test.so):

extern “C” void test_func()
{
int *dev_a;

// allocate the memory on the GPU (array of 2 ints)
cudaMalloc( (void**)&dev_a, 2 * sizeof(int) );
cudaFree( dev_a );   

}

output:

done
Segmentation Fault

Well I’m not really sure why this happened, but it seems to have something to do with python cleaning up after the CUDA C call. If you use pycuda to do some initialization it works, at least for me. Again, I’m not really sure why.

Put this in your imports:

import pycuda.autoinit