Seg-fault with CUDA 3.1

Hi everyone,

I seem to be running into a seg-fault with the CUDA 3.1 beta, that I cannot reproduce with CUDA 3.0. The code below tries to just initialize CUDA and CUBLAS (Thanks to Dan Price from EMP for sharing this).

#include "cuda.h"

#include "cublas.h"

#include <stdio.h>

#define MSG() printf("%s:%d\n", __FILE__, __LINE__);

int main(int argc, char** argv)

{   

	struct{

		void operator()(CUresult r)	  { if(r) exit(r); }

		void operator()(cublasStatus r)  { if(r) exit(r); }

	}CheckError;

	CUcontext cuContext;

	MSG();

	CheckError(  cuInit(0)					   );

	MSG();

	CheckError(  cuCtxCreate(&cuContext, 0, 0)   );

	MSG();

	CheckError(  cublasInit()					);

	MSG();

	CheckError(  cuCtxDetach(cuContext)		  );

	MSG();

	return 0;

}

Running it in gdb gives the following output and stack-trace.

(gdb) r

Starting program: /home/sandeep/res 

[Thread debugging using libthread_db enabled]

test.cu:15

test.cu:17

test.cu:19

[New Thread 0x7ffff4339700 (LWP 5803)]

test.cu:21

test.cu:23

Program received signal SIGSEGV, Segmentation fault.

std::_Rb_tree_rebalance_for_erase (__z=<value optimized out>, __header=@0x6985a0) at ../../../../libstdc++-v3/src/tree.cc:386

386				   if ((__w->_M_right == 0 || 

(gdb) bt

#0  std::_Rb_tree_rebalance_for_erase (__z=<value optimized out>, __header=@0x6985a0) at ../../../../libstdc++-v3/src/tree.cc:386

#1  0x00007ffff4354659 in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#2  0x0000003db3210238 in ?? () from /lib64/libc.so.6

#3  0x00007ffff433e790 in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#4  0x0000000100000000 in ?? ()

#5  0x000000010000083a in ?? ()

#6  0x0000000000000028 in ?? ()

#7  0x00007ffff4f4c838 in ?? ()

#8  0x00007fffffffdc30 in ?? ()

#9  0x000000000062bdd0 in ?? ()

#10 0x000000000062bdb0 in ?? ()

#11 0x00007ffff456f968 in pthread_mutex_unlock () at forward.c:184

#12 0x0000000000696af0 in ?? ()

#13 0x000000000062bdd0 in ?? ()

#14 0x0000000000000004 in ?? ()

#15 0x00007ffff434a22c in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#16 0x00007ffff456f998 in pthread_mutex_unlock () at forward.c:184

#17 0x000000000062bdb0 in ?? ()

#18 0x00007ffff456f960 in pthread_mutex_unlock () at forward.c:184

#19 0x00007ffff456f998 in pthread_mutex_unlock () at forward.c:184

#20 0x00007ffff456f998 in pthread_mutex_unlock () at forward.c:184

#21 0x00007ffff434db5b in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#22 0x00007ffff434e27a in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#23 0x00007ffff4343198 in __cudaUnregisterFatBinary () from /usr/local/cuda/lib64/libcudart.so.3

#24 0x0000003db3236960 in __cxa_finalize (d=0x7ffff7fe42a0) at cxa_finalize.c:56

#25 0x00007ffff4f8ae66 in sqrtf () at w_sqrtf.c:33

#26 0x0000000000000000 in ?? ()

The seg-fault doesn’t appear if I don’t call cublasInit() . I’ve tested this with Fedora 10 (64-bit) Linux. Thanks in advance for the suggestions to resolve this.

Thanks,

Sandeep.

I think you need to call cublasShutdown before calling cuCtxDetach. From the CUBLAS 3.0 documentation: cublasShutdown “releases CPU‐side resources used by the CUBLAS library.”

I can reproduce this behavior. I’ve tried adding cublasShutdown(), and it didn’t help.

I’ll investigate this further. Thanks for the report, Sandeep!

–Cliff

I can confirm that this was indeed a bug, and it will be fixed in the final 3.1 release.
Thanks again for bringing this to our attention!

–Cliff

Thanks for the prompt response, Cliff! … We’ll be awaiting the fix then.