Copy OpenCL image or buffer object to CUDA surface

Hi,

I am developing an application using

  1. OpenCV with OpenCL support and
  2. the Video Codec SDK, creating a CUDA encoding session (analog to the NvEncoder sample)

So far I am required to read the OpenCL image or buffer objects processed by my OpenCV code back into RAM, in order to feed them into the CUDA surfaces for the video encoder, which of course is wasting quite some time, especially on bigger frames. I would like to save this extra up- and download by copying the data directly in VRAM (or even reference the OpenCL image/buffer in case this is possible). I have no idea how I could accomplish this, can anybody help me with that? Any hints, samples, reference implementations?

Thanks!

Not possible. CUDA and OpenCL are not interoperable on the device side of activity. Of course you can interoperate on the host side by moving data to the host, as you’ve already pointed out.

Would taking the OpenGL-detour help? I understand there are means of OpenCL/OpenGL interop as well as OpenGL/CUDA interop. Maybe copying OpenCL image to OpenGL buffer and OpenGL buffer to CUDA surface would still be a lot faster than reading back into RAM, right (I’m talking about a 6.1 megapixel RGB24 camera image here)? Although getting the first part done may be tricky since OpenCV hides the OpenCL part from the user pretty well.

Any thoughts on that would be appreciated.

It might be possible with OpenGL as the intermediary. I haven’t studied it. Maybe someone else will know.