How can I get gpu memory from deepstream buffer in gstreamer plugin in python?

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU)
GPU (T4)
• DeepStream Version
6.0.1
• JetPack Version (valid for Jetson only)
• TensorRT Version
8.2.1.8
• NVIDIA GPU Driver Version (valid for GPU only)
470.57.02
• Issue Type( questions, new requirements, bugs)
questions
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

Hi.
I want to get gpu memory using python deepstream api in python gstreamer plugin.

There are pyds.get_nvds_buf_surface method in API, but it return cpu numpy array.

I can get gpu memory by using c gstreamer plugin and c++ deepstream api in deepstream 4.
But I want to change from C to python by using python gstreamer plugin and python deepstream api in deepstream 6.

I used NvBufSurface in c++, and there pyds.NvBufSurface in API.
But, there are no sample for using pyds.NvBufSurface.
I tried like using in c++, but it failed.

I think image is already in gpu nvmm memory. How can I get gpu memory from deepstream buffer in gstreamer plugin?

My Gstreamer pipeline

gst-launch-1.0 
    uridecodebin uri=file:///sample_video/1.mp4 !
    nvvideoconvert nvbuf-memory-type=0 !
    "video/x-raw(memory:NVMM),format=RGBA" !
    m.sink_0 nvstreammux name=m nvbuf-memory-type=0 width=1920 height=1080 batch-size=1 !
    gsttestplugin !
    fakesink sync=1

My Python Gstreamer plugin (gsttestplugin)

import gi
gi.require_version("Gst", "1.0")
gi.require_version("GstBase", "1.0")
from gi.repository import GObject, Gst, GstBase

import pyds

class GstTestPlugin(GstBase.BaseTransform):
    GST_PLUGIN_NAME = "gsttestplugin"

    __gstmetadata__ = (
        "TestPlugin",
        "Plugin",
        "Test Plugin",
        "Test",
    )

    __gsttemplates__ = (
        Gst.PadTemplate.new(
            "src",
            Gst.PadDirection.SRC,
            Gst.PadPresence.ALWAYS,
            Gst.Caps.new_any(),
        ),
        Gst.PadTemplate.new(
            "sink",
            Gst.PadDirection.SINK,
            Gst.PadPresence.ALWAYS,
            Gst.Caps.new_any(),
        ),
    )

    def __init__(self):
        super(GstTestPlugin, self).__init__()

    def do_transform_ip(self, buffer: Gst.Buffer) -> Gst.FlowReturn:
        res, map_info = buffer.map(Gst.MapFlags.READ)
        if not res:
            return Gst.FlowReturn.ERROR

        surf = pyds.NvBufSurface.cast(hash(map_info.data))
        print(surf.gpuId, surf.batchSize)

        buffer.unmap(map_info)

        return Gst.FlowReturn.OK

GObject.type_register(GstTestPlugin)
__gstelementfactory__ = (
    GstTestPlugin.GST_PLUGIN_NAME,
    Gst.Rank.NONE,
    GstTestPlugin,
)

Log

Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Traceback (most recent call last):
  File "/opt/nvidia/deepstream/deepstream/lib/gst-plugins/python/gsttestplugin.py", line 41, in do_transform_ip
    surf = pyds.NvBufSurface.cast(hash(map_info.data))
TypeError: cast(): incompatible function arguments. The following argument types are supported:
    1. (self: capsule) -> pyds.NvBufSurface
    2. (self: int) -> pyds.NvBufSurface

Invoked with: -6714784618403796263
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
Caught SIGSEGV
New clock: GstSystemClock
exec gdb failed: No such file or directory
Spinning.  Please run 'gdb gst-launch-1.0 835' to continue debugging, Ctrl-C to quit, or Ctrl-\ to dump core.
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:01.272463991
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
^C

My Using Code in C api in deepstream 4.0

GstMapInfo in_map_info;
NvBufSurface* in_surf = nullptr;
memset(&in_map_info, 0, sizeof(in_map_info));

if (!gst_buffer_map(inbuf, &in_map_info, GST_MAP_READ))
    return GST_FLOW_ERROR;

in_surf = reinterpret_cast<NvBufSurface*>(in_map_info.data);

gst_buffer_unmap(inbuf, &in_map_info);

We have not released DS 6.0.1, how can you use such version?

Oh, DS version is 6.0.

Please use get-nvds-buf-surface API: gst_element_send_nvevent_new_stream_reset — Deepstream Deepstream Version: 6.1.1 documentation

There is sample code in deepstream_python_apps/deepstream_imagedata-multistream.py at master · NVIDIA-AI-IOT/deepstream_python_apps (github.com)

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