# Accessing the DMA buffer from cuda kernel without the use of EGL image

**URL:** <https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938>\
**Category:** Jetson Nano\
**Tags:** opengl\
**Created:** [October 27, 2023, 3:37pm UTC](https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938 "2023-10-27T15:37:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cnt.aureliano](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@cnt.aureliano](https://forums.developer.nvidia.com/u/cnt.aureliano)\
**Post date:** [October 27, 2023, 3:37pm UTC](https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938/1 "2023-10-27T15:37:45Z")

</div>

Hi,

Using the [https://docs.nvidia.com/jetson/l4t-multimedia/l4t\_mm\_12\_camera\_v4l2\_cuda.html](https://docs.nvidia.com/jetson/l4t-multimedia/l4t_mm_12_camera_v4l2_cuda.html). I can create a dma buffer generated using NvBufferCreateEx so the v4l2 driver can use to capture images. Now if I wanted to access this data in cuda kernel the provided sample uses egl image to do so, is it possible to access the dma buffer pointer without the use of EGL image.

This is the same question as [https://forums.developer.nvidia.com/t/how-to-access-dma-buffer-from-cuda-device/198656](https://forums.developer.nvidia.com/t/how-to-access-dma-buffer-from-cuda-device/198656). the accepted answer doesn’t confirm if that’s possible without the use EGL.

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [October 30, 2023, 1:27am UTC](https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938/3 "2023-10-30T01:27:40Z")

</div>

Hi,  
The case is not supported. For accessing DAM buffer(NvBuffer), it has to be mapped to EGLImage and then get CUDA pointer. If using DAM buffer is not a hard requirement in you ruse-case, you can allocate CUDA buffer for capturing frame data. This is demonstrated in

> /usr/src/jetson\_multimedia\_api/samples/v4l2cuda

---

<div class="post-metadata">

**Author:** ![cnt.aureliano](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@cnt.aureliano](https://forums.developer.nvidia.com/u/cnt.aureliano)\
**Post date:** [November 1, 2023, 12:05pm UTC](https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938/4 "2023-11-01T12:05:11Z")

</div>

Thank you for your reply,

I saw the sample provided which uses the MMAP and UserPtr memory methods.  
Since I want to reduce the memory copy from the driver image capture to Cuda kernels, I am opting to use the DAM buffer.  
Do you think, It’s better to use DMA method rather than using MMAP then copy the memory to Gpu space ?  
if that’s the case, is it possible to create EGLImageKHR without a Egldisplay using : NvEGLImageFromFd(NULL, DMA\_buf\_fd);

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [November 1, 2023, 12:29pm UTC](https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938/5 "2023-11-01T12:29:19Z")

</div>

Hi,  
Not sure if setting to NULL works. But if there’s no display output, setting to EGL\_NO\_DISPLAYshall work fine.

---

<div class="post-metadata">

**Author:** ![cnt.aureliano](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@cnt.aureliano](https://forums.developer.nvidia.com/u/cnt.aureliano)\
**Post date:** [November 7, 2023, 4:19pm UTC](https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938/7 "2023-11-07T16:19:04Z")

</div>

Hello @DaneLLL

Thank you for your response, I was wondering if you have any idea why I get the following error : “ **nvbuf\_utils: dmabuf\_fd 0 mapped entry NOT found** ” in “**egl\_image = NvEGLImageFromFd(EGL\_NO\_DISPLAY, buf\_fd)**;”

P.S : The Buf\_fd corresponds to one of the camera buffers (NvBufferTag\_CAMERA) and not a renderer buffer like the one used in 12\_camera\_v4l2\_cuda example.

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [November 8, 2023, 3:55am UTC](https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938/8 "2023-11-08T03:55:27Z")

</div>

Hi,  
Do you run in headless mode? It shall work when `export DISPLAY=:0` is not set.

---

<div class="post-metadata">

**Author:** ![cnt.aureliano](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@cnt.aureliano](https://forums.developer.nvidia.com/u/cnt.aureliano)\
**Post date:** [November 8, 2023, 11:56am UTC](https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938/9 "2023-11-08T11:56:32Z")

</div>

How do you run the 12\_camera\_v4l2\_cuda in headless mode ?  
and if I run this sample when `export DISPLAY=:0` is not set I get the same error of my current code :  
`nvbuf_utils: dmabuf_fd 0 mapped entry NOT found ` and `nvbuf_utils: Can not get HW buffer from FD ... Exiting...`

Any ideas ?

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [November 8, 2023, 12:16pm UTC](https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938/10 "2023-11-08T12:16:55Z")

</div>

Hi,  
Default 12\_camera\_v4l2\_cuda cannot run in headless mode. Please remove `NvEglRenderer` and try.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [November 22, 2023, 12:17pm UTC](https://forums.developer.nvidia.com/t/accessing-the-dma-buffer-from-cuda-kernel-without-the-use-of-egl-image/270938/11 "2023-11-22T12:17:49Z")

</div>

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