I am trying to create a MFC application in which I can open image and run various image-processing algorithms - sort of a mini-photoshop.
I think, if I want to open multiple images, I need to create multiple OpenGL contexts - one for each window/image.
Can I do that using CUDA? I am trying to use the OpenGL PBO (as in the postProcessGL example in the SDK).
Currently, my first image opens and runs fine, but when I try to open another image, creating the PBO fails and crashes the program.
What might be a better way, if there is one?
The Programming Guids states “A CUDA context may interoperate with only 1 Direct3D device…”, but it does not talk about any such limit on the OpenGL notes.
Adding the CUDA_SAFE_CALL does not let me create the second window (= GL context) on release 169. I AM using release 169 and I started this code only AFTER installing release 169. I have NOT tried it on the earlier releases.
So my observations are on release 169.
And I am using PBO not VBO, if that makes any difference in this matter.
Hey I also found that the CUT_CHECK_ERROR_GL() macro can create problems when called during the OnDestroy() operation.
If I opened multiple windows with the code posted below, closing one of the child windows would crash my entire app without any error. (There was the message ‘invalid memory at 0xxxxxx’ in the console which didnt help a lot)
After I remarked the CUT_CHECK_ERROR_GL() macro my program runs and shuts down smoothly.
Interestingly, I have the same macro in the CreatePBO and CreateTexture functions (which are same as those in the postProcessGL example). Those calls do not create any problem.
So I assume that I am not closing down OpenGL properly and hence the macro is finding some error but before it can tell me what it found, something is killing it. What might I be doing wrong?
The first time I make this call, errRegisterBuffer gets the value ‘cudaSuccess’. But every subsequent new window I create, it gets the value 10208. I am not sure what it means as the cudaError_t enum does not define this code (at least not explicitly)
That explains why CUDA_SAFE_CALL fails. But, once I remove that macro, everything runs fine. (which I understand could be dangerous, but it runs!)
Every new window I create has its own instance of the pbo and its own data to render. I do not understand what I am doing wrong here. :mellow: I would certainly appreciate any help.
Here is a brief overview of the sequence of events the program follows :
I follow a similar procedure as in postProcessGL sample -
For every new window (document in MFC) -
create and register a PBO (in doc)
1.1. Use glGenBuffer() to create the PBO
1.2. Register PBO using cudaGLRegisterBufferObject().
Process the PBO (in view)
Display the PBO (in view)
(Currently I am just writing to the PBO independent of what it already has and hence I do not have source and destination PBOs as in postProcessGL.)
My guess is that there’s something wrong with PBO generated in multiple threads. The glew library that comes with CUDA is not multi-threaded. You’ll have to build your own multi-threaded version of glew. Instructions are on the glew site (http://glew.sourceforge.net/).Let me know if you’re still getting the crash after installing multi-threaded glew.
I just noticed / “Solved” a similar issue with multiple windows and cuda-glbuffer registration (my version of the driver is the linux-64bit 169.12) and oh boy, was I checking for the answer a long time with this.
So what I was doing is the following in pseudo-code:
and for some reason the last registration failed (with the usual unspecified driver error)!
Well, here’s the solution:
What is going on here?
cuda has one context per thread
GL creates here two contexts for the same thread (one for each window)
First glGenBuffers()-call gives handle == 1 because it’s the first buffer of the context.
Second glGenBuffers()-call gives also handle == 1, because it’s also the first buffer of the context, because it’s a new context.
Cuda-register checks if handle == 1 has been registered already and returns an error because it has been registered (cuda context is not changed between windows)
Adding the dummy glGenBuffers()-call increments the result-handle to 2 and cuda works a-ok.
Is this even close? Does someone know a nicer solution? Is this fixed in some later driver / cuda - version? I have cuda 1.1, since 2.0 still seems to be in beta stage.
Has anybody found a real resolve to this problem? I need to either use multiple windows or subwindows and both give me the unspecified driver error when I try to Map buffer objects. I tried removing the CUDA_SAFE_CALL, but it didn’t help. I am using Cuda2.0b2 on XP