Display with CUDA Options to display with CUDA

I need to display the results of calculations I did with CUDA into the screen.
I have a dll that uses CUDA and calculates the results. This dll copies the data from video memory into CPU memory which its address is passed by the dll interface.
The program that use this dll is written in C# and uses opengl.
Each time I want to draw the results I create recreate the vertex buffer in opengl in the C# program.
It would be much faster if I could simply draw the results I calculated in CUDA from the GPU memory, without copying it into CPU memory and then back into GPU memory.
Is there a way to do it when I have my application divided into a dll and a C# program?
The C# program is the GUI.

Thank you.

Yes that is possible, use the CUDA<->GL or DX interoperability

Perhaps we misunderstood each other.

I know that I can use OpenGL and DirectX with CUDA.

For instance, to map a pointer in CUDA into a vertex buffer of DirectX.

The problem I have is that my application is devided into two programs.

One is a dll written in CPP, in which all the CUDA calculations are done.

The other is an executable written in C#, which is the GUI and somehow need to display what the dll program calculates in CUDA.

What I am doing now is to calculate the results in CUDA, the C# program then calls a function of a dll with pointers to CPU memory.

The dll copies the CUDA results into this CPU memory.

Then the GUI creates a new vertex buffer by the results it has in the CPU memory.

Which means I calculate in CUDA into GPU, copy GPU into CPU, copy CPU into GPU and then disply from GPU.

I want it instead to be: calculate CUDA into GPU, display from GPU.

Can I do this?

Is this simply a matter of passing a pointer to an OpenGL interface into a call of a dll interface function?

How do I do this?

You can create a pixel buffer object and let your CUDA kernel write into it. Then you can display it. That’s was wumpus meant by CUDA<->GL or DX interoperability. So you can get rid of the copies to and from CPU.
The boxFilter Example in the SDK makes the interoperability very clear.

While I have not done this myself, you should be able to pass the VBO id from your C# code to a function inside your .dll that does CUDA work. That function should then do the straightforward interop - register, map, calculate, unmap, unregister. Once the function returns control to your C# code, you should be able to issue OpenGL calls using the updated VBO.

Try it and let us know how it goes.

Paulius

Mesher,
What library are you using to deal with OpenGL through C#? I was trying something what Paulius mentioned in the last post, but I got stuck when the .Net gl wrapper did not let me use the pbo the way i wanted.

A small snippet of code would be awesome! Thanks.

I read the boxFilter example, it seems almost the same as mapping vertexBuffer into CUDA memory.
So I don’t see what is the difference?
My solution to my problem is to send the window handle DWORD from the C# executable to my dll.
Then use this handle to create a direct3DDevice and draw into it with directX.
After I fill a directX vertex buffer using CUDA.
The problem is even greater because the window procedure is called in a different thread then the GPGPU calculation function.
So I will need to use some sort of a mutex for this to work properly.