CUDA programming
Hi All
I would like to ask if it is possible to run CUDA with Unity ?
As alternative to CUDA check out Unity's compute shaders:
https://docs.unity3d.com/$$anonymous$$anual/ComputeShaders.html
Answer by ermal · Aug 12, 2016 at 01:48 AM
Yes, it is, but you have to develop a DLL native plugin to do this.
I'm currently successfully doing OpenGL (GLCore) and D3D11 interop with CUDA from Unity textures.
All CUDA mapping, unmapping and registering/unregistering of textures and OpenGL/Direct3D objects has to be done from the render thread.
It took me a while to figure this out, but essentially you have to get the native texture pointers from your Unity code into your native CUDA DLL.
Would you $$anonymous$$d sharing some sample code to help us get started quicker? Thanks!
Do you have a sample code showing how to update the texture because I am mapping the texture with cuda using nativeplugin dll but the texture is´not updating its data though cuda$$anonymous$$emcpy is returning no error ..would you $$anonymous$$d share a sample. Thanks anyway
Thanks, this has really helped me. I'm freeing my CUDA resources via GL.IssuePluginEvent and now things are much more stable. Were there any resources you came across that helped you figure this out or was it your own discovery?
I'm able to free resources as needed at runtime but I'm still trying to figure out the best way to get everything cleaned up when the application is shutting down. It seems that somehow I need to know which GL.IssuePluginEvent is going to be the last one and then on that call I could set the eventId parameter to some special value like -1. Perhaps if there's still one more render call after OnApplicationQuit I could set some flag from there.
Your answer
![](https://koobas.hobune.stream/wayback/20220612084253im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Jobs not running in working threads 0 Answers
Passing local variables to struct 1 Answer
How to remove as intersections on parallel lines? 0 Answers
Forcing NavMeshAgent to follow Parallel to the player 0 Answers
Paralel Scene Loading for Adventure Game 0 Answers