cudaGraphicsMapResources each frame or just once when cuda-opengl interop ? which better?

both work, and saw demos diff:
some call cudaGraphicsMapResources after cudaGraphicsGLRegisterImage which only 1 time before the render-loop;
some call cudaGraphicsMapResources each frame, and cudaCreateSurfaceObject, cudaDestroySurfaceObject, cudaGraphicsUnmapResources all are called each frame.

ppt from nvidia years ago do Map and Unmap EveryFrame, but it seems that not Map&Unmap everyFrame also works, and as Map&Unmap is heavy SO is it also OK to do Map&Unmap NOT everyFrame but with Register&Unregister in the init&release?

AFAIK it is undefined behavior to not do map and unmap every frame. That is:

  • when you want to access the data from OpenGL side, you must unmap it first (if it was previously mapped).
  • when you want to access the data from the CUDA side, you must map it first (if it has not been previously mapped, since the last unmap operation, or creation operation)
  • there is no guarantee that the address returned by the map operation will be the same, from one frame to the next.

I won’t be able to point you at documentation or justification or recent training material for this. You can find GTC material that covers guides for CUDA/Graphics interop. Do as you wish, of course.

Yes, I acknowledge in many cases it appears to work if you don’t follow this guide.

thanks! so map everyFrame is the right way.
and is Map & Unmap Async? need to call cudaStreamSynchronize(0) after them?

moreover, need to call cudaStreamSynchronize(0) or cudaDeviceSynchronize after the Kernel?

as far as I know, map and unmap are synchronous.

I don’t understand the other question.

If you are asking can you launch a kernel followed by an unmap, without an intervening sync call, I believe the answer is yes. That is safe.

And if that is what you were asking about here, I can say that I for one had no idea you were talking there about in the context of CUDA graphics interop where you are launching a kernel followed by an unmap call.

There is such a concept as multi-GPU interop which is more arcane. None of my response apply to that case.

Mixing Graphics and Compute with Multiple GPUs - Part 1 (
This is enough if:
— You can use the map/unmap hints
— map/unmap is CPU asynchronous
— You are afraid of multiple threads
— You developed the whole application

sure, map/unmap may be cpu synchronous or asynchronous. that isn’t the way I interpreted the question. The point is, with respect to GPU activity, it is synchronous. The unmap operation will not begin until the previous kernel call is complete. And if that is the case, then an intervening sync would be unnecessary and superfluous. And again, I am mostly speaking from the perspective of single GPU interop. If you are now asking about multi-GPU interop, please disregard all of my comments.

And if you are concerned about something else, then you have given no indication from what I can see, of what your actual concern is.

Good luck!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.