kunzmi / managedCuda

ManagedCUDA aims an easy integration of NVidia's CUDA in .net applications written in C#, Visual Basic or any other .net language.
Other
450 stars 80 forks source link

OpenGL interop resource Error #98

Open chenw11 opened 3 years ago

chenw11 commented 3 years ago

Referring to the provided ManagedCUDA example FluidsGLCSharp, I initialized a CudaGraphicsInteropResourceCollection as cuda_pbo_resource in the class constructor: CtxInit However, I got the following error when tried to access the object from a different CPU thread. This method is an override method that constantly updates during the runtime: OpenglERROR I tried to set the CUDA context to current thread using ctx.SetCurrent(), but the error retain the same. The only situation I can get it to work is placing the MapAllResources() right after the cuda_pbo_resource.Add() like the following: CtxWorkingCase Seem like the OpenGL interop resource is not available for global share. Is there a way to set its property? The current bug info of this error is difficult to track the problem. Thanks in advance for your help.

kunzmi commented 3 years ago

It's been a while that I worked with OpenGL/Cuda interop but I can remember that together with multi-threading on CPU this ended up in a nightmare. My solution was to run all graphics and Cuda on a specific CPU thread. So instead of having api calls done directly on multiple host threads, I invoked them on a specific thread for Cuda/OpenGL. Of course this solution has performance draw backs, but for me it worked out fine... Maybe this can help you, too.