CUDA and Linux DMA-BUF


Is it possible to export an fd from CUDA, that is a valid DMA-BUF handle? The reason for specifically needing a DMA-BUF handle is that I don’t have control over the consuming application.

I’ve tried using cuMemExportToShareableHandle and importing the resulting fd with eglCreateImage(EGL_LINUX_DMA_BUF_EXT) in a test app, but I just get the following error:

In eglCreateImage: could not bind to DMA buffer

I get the same error with a completely invalid fd (0).

Are the fd’s produced by cuMemExportToShareableHandle meant to be valid DMA-BUF handles? If it’s not possible to do directly, can I use EGLStreams to port a frame in, and export that EGLImage using the EGL_MESA_image_dma_buf_export extension (that’s quite the hoop jumping though)?

I’m using a 1060 6GB, with the 495.44 linux drivers and CUDA 11.5.

Thanks & Regards

It is a hoop jump, but the last hoop (EGL_MESA_image_dma_buf_export) does not seem to work yet, even though the extension is advertised.

Try this example code (not written by me), maybe it works for you (which I doubt).