Problem with cudaGLRegisterBufferObject problem in multi-threading application


I found that the usage of cudaGLRegisterBufferObject in the second thread will fail. I packed the operation of CUDA-OpenGL interoperation in a thread. When the thread is executed for the first time, all things work well. However, when it is executed for the second time, cudaGLRegisterBufferObject will fail.

Some code piece is as follows:
//first time execution: all things work well.
HANDLE hThread = (HANDLE)_beginthreadex( NULL, 0, &runTest, NULL, 0, 0);
WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );hThread = NULL;

//second time execution: cudaGLRegisterBufferObject will fail.
hThread = (HANDLE)_beginthreadex( NULL, 0, &runTest, NULL, 0, 0 );
WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );hThread = NULL;

Please try the attached to see if you can succeed, which is revised from the simpleGL example of CUDA SDK. The CUDA-related operations are kept.

My test environment is as follows:

GPU model: G80 (GeForce 8800 GTX)
PC configuration: Core Duo 2 E6600 (2.4G/4M/1066) + 2G DDR 667 (1G*2)
Dev environment: MS VS .net 2003

CUDA version: 1.0 (for both toolkit and SDK)
Display driver: 162.01

Hope that more explanation or solution may be given. Thanks in advance.

Has anybody encountered the similar problem?

Have you fixed this problem?

Because actually I’m facing this kind of issue as well. I create my VBOS from thread1, then update it many times from a thread 2 (at a higher frequency), and I delete the VBOs at the end from the thread 1. If I want to relaunch all of this a second time from my application, it fails on cudaGLRegisterBufferObject as well. It’s like cudaGLUnregisterBufferObject does not work.

Anyone knows how fixing this? Because it means I have to completely quit the application to be able to run this function again, I can’t launch it more than once, which is pretty annoying as you can guess…

Currently CUDA is only safe to use in the thread that initializes it, in which case, the thread that does the first CUDA function call. A relaunched thread is a different thread.
You may be able to work around this by creating the CUDA thread and suspend/resume it instead of terminate/relaunch.

This (inability to register a second buffer from another thread) is a known bug and it will be fixed in an upcoming CUDA driver.


Thanks for your quick answers guys.

Paulius> So it would be fixed in the next release (any approximate ETA about a developer or normal release by the way?). October? November? Later?

asadafag> actually I’ve got an application with a menu, and I launch different plugins from this menu. When I press escape, I want to quit the current plugin and clean everything properly. In this way I can switch between plugins. Plugins can be on different threads.
So my problem is that I can launch my CUDA plugin once. Then I exit it, and I can then launch every other plugin that doesn’t use any mapping done by CUDA. But if I want to launch my CUDA plugin again, it fails on cudaGLRegisterBufferObject. What I mean is I can’t really use a suspend/resume approach, it’s not what I want here. It’s not urgent, I can wait the fix from NVIDIA. I don’t need to fake it in the meantime.