When to call cudaMapResources?

I had hoped I could cache the Pitch and and Address just once but I seem to have to call cudaMapResources() every time I run a kernel.

  1. Is that expected?
  2. Is there a faster way as it takes 2ms on my machine.

Thanks

So am I asking just a dumbass question, or is there really not an answer?

Help!

I’m using cudaGraphicsMapResources only to map OpenGL textures to cudaArrays so I’m not sure whether it is identical to your situation or not but I guess all mappings should behave the same. In my case I call it just once when I need to access the data and then I call hundreds of different kernels that use this mapped array. So no, you shouldn’t be required to call the mapping function before each kernel.

OK. So does your OpenGL texture change ever? I’m drawing some stuff into an offscreen texture using DirectX (FBO in OpenGL speak) and then wanting to run some CUDA on the result. Is it your understanding I don’t need to cudaMapResources() the texture more than once - even if I scribble new pixel values in there?

When you call cudaMapResources then you transfer the ownership of your texture from DX/GL to CUDA so in case you want to render something into it again then you have to call cudaUnmapResources to set the ownership back to DX/GL. What I meant is that you don’t have to call the mapping function before each kernel (unless it is the only kernel you call after you render something into the texture…which seems to be your case)