CUDA OpenGL Interop hangs when using from multiple threads cudaGLMapBufferObject hangs when calling

Hi All,

I have two independent threads and both of them are using CUDA OpenGL interop. My problem is that cudaGLMapBufferObject() hangs when calling from second thread, and after some time blue screen occurs and machien restarts. If CUDA OpenGL inerop is removed from first thread, then the second thread will work fine. could not see such restriction is specified anywhere. Is this a bug of CUDA OpenGL interop?

Code of first thread is as follows,

[codebox]

DWORD WINAPI Thread1( LPVOID lpParameter )

{

HDC hDC =0;

HGLRC hRc = 0;

init( hDC, hRc );

cudaError_t nCudaError = cudaGLSetGLDevice( 0 );

UINT uBufferID = CreateBuffer();

BYTE* pbyInputData = 0;

nCudaError = cudaGLRegisterBufferObject( uBufferID );

nCudaError = cudaGLMapBufferObject( ( void** )&pbyInputData, uBufferID );

//////////////////////////////////////////////////////////////////////////

// My Kernel goes here

//////////////////////////////////////////////////////////////////////////

nCudaError = cudaGLUnmapBufferObject( uBufferID );

nCudaError = cudaGLUnregisterBufferObject( uBufferID );

// Notify second thread to start processing

SetEvent( g_hEvent );

return 0;

}

[/codebox]

Code for second thread is given below,

[codebox]

DWORD WINAPI Thread2( LPVOID lpParameter )

{

HDC hDC =0;

HGLRC hRc = 0;

init( hDC, hRc );

cudaError_t nCudaError = cudaGLSetGLDevice( 0 );

// Wait for first thread to finish using CUDA

WaitForSingleObject( g_hEvent, INFINITE );

UINT uBufferID = CreateBuffer();

BYTE* pbyInputData = 0;

nCudaError = cudaGLRegisterBufferObject( uBufferID );

nCudaError = cudaGLMapBufferObject( ( void** )&pbyInputData, uBufferID );

//////////////////////////////////////////////////////////////////////////

// My Kernel goes here

//////////////////////////////////////////////////////////////////////////

nCudaError = cudaGLUnmapBufferObject( uBufferID );

nCudaError = cudaGLUnregisterBufferObject( uBufferID );

return 0;

}

[/codebox]

This code does not contain any kernel, but the problem can be easily seen without the kernels !

I am using Win XP, CUDA 2.0, NVIDIA GeForce 8600 GTS, Display driver version - 178.28. Please help me to solve the issue.

Hi All,

Full source code for the sample application is attached in this reply. Please have a look.
MultiThreadBuffer.cpp (7.05 KB)

Hi,

Anybody from NVIDIA can aswer this post?

Hi,
I also tried a similar example, where in I had two thread with two independent GL & CUDA contexts for each thread. Looks like on 178.28 it fails, but it ran fine on 180.60, which is the recommended driver for CUDA 2.1.
Give it a shot with 180.60.

Cheers!!!

Okay, it is working fine in driver 180.60. Waiting for the final release of CUDA 2.1 :-)