Best practice to Get gstreamer buffer to GPU memory?

what is the best way to gain accsess to a buffer without using memcpy?

NvBufferMemMap (fd, 0, NvBufferMem_Read,
                        &mapped_ptr) != 0)

using NvBufferMemMap only allows cpu accsess

Hi,
You may try nvivafilter:
https://devtalk.nvidia.com/default/topic/963123/jetson-tx1/video-mapping-on-jetson-tx1/post/4979740/#4979740
https://devtalk.nvidia.com/default/topic/978438/jetson-tx1/optimizing-access-to-image-data-acquired-with-nvcamerasrc/post/5026998/#5026998
https://devtalk.nvidia.com/default/topic/1046218/jetson-tx2/unable-to-overlay-text-when-using-udpsrc-/post/5310313/#5310313
https://devtalk.nvidia.com/default/topic/1022543/jetson-tx2/gstreamer-nvmm-lt-gt-opencv-gpumat/post/5311027/#5311027

Hi,
In our case, we get a cudaEglFrame from the file descriptor. This contains pointers that can be used on GPU and avoids memory copies if the buffer is on shared memory. The steps are:

  1. Get an EGLImage with NvEGLImageFromFd
  2. Get a CUgraphicsResource with cuGraphicsEGLRegisterImage
  3. Get an EglFrame with cuGraphicsResourceGetMappedEglFrame

We provide an out of the box solution for CUDA algorithm integration into GStreamer pipelines called GstCUDA. Please check our wiki page if you are interested on GstCUDA:
https://developer.ridgerun.com/wiki/index.php?title=GstCUDA

Hi,

I have followed your advice and the linked you provided. with the example code

input_params.width = 1000; 
  input_params.height = 1000;
  input_params.layout = NvBufferLayout_Pitch;
  input_params.colorFormat = NvBufferColorFormat_ABGR32;
  input_params.payloadType = NvBufferPayload_SurfArray;
  input_params.nvbuf_tag = NvBufferTag_NONE;


 NvBufferCreateEx (&mobileplugin->conv_dmabuf_fd, &input_params) ;
 





  static EGLDisplay egl_display = EGL_NO_DISPLAY;
    EGLImageKHR egl_image;

    // Init egl_display if not initialized
    if (egl_display == EGL_NO_DISPLAY) {
     
      egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
      if (egl_display == EGL_NO_DISPLAY) {
        flow_ret = GST_FLOW_ERROR;
        goto done;
      }
    }

    // Create an EGLImage from the FD
    egl_image = NvEGLImageFromFd (egl_display, mobileplugin->conv_dmabuf_fd);
    
    if (!egl_image) {
    
      flow_ret = GST_FLOW_ERROR;
      goto done;
    }

but i am getting NvEGLImageFromFd: Failed to create EGLImage from dma-buf fd (1265) error

what am i missing ? what can cause this error?

Hi,
Can you please share a full code so that we can build and run to reproduce the error? Are you on r28.2/TX1?