NVBufSurface and GPU Memory zero Copy Conversion

jetson orin nx
jetpacket 5

hi, I want to implement the conversion from nvbufsurface to GPU memory, such as converting the decoded nvbufsurface from “nvbuf-surface ->surfaceList ->mappedAddr. addr [0] nvbuf-surface ->surfaceList ->mappedAddr. addr [0]” to “void * dev_ptr”, which can be accessed freely by CUDA and TensorRT without deep copying of data.
After converting nvbufsurface to void, it does not affect normal loop decoding

Finally, convert dev_ptr to NVBufSurface and use nvosd to draw the tensorrt output’s rect text on the image. I checked that there is no such case in “~/jetpack dec enc/jetson_dec_5.0.2/build”

  1. NVBufSurface mappedAddr.addr[0] to void*dev_ptr
  2. void dev_ptr to NVBufSurface

Hi,
Not sure which Jetpack version you are using. We would suggest use 6.0GA or 5.1.3. If you are using previous version, please consider upgrade.

We have demonstration to access NvBufSurface through GPU and CPU. Please refer to HandleEGLImage() in

/usr/src/jetson_multimedia_api/samplescommon/algorithm/cuda/NvCudaProc.cpp

And the option in 10_argus_camera_recording sample:

-c        Enable demonstration of CPU processing

hi

I am using Jetpack 5.1

Although HandleEGLImage can use CUDA, I hope to preserve the original data of nvbufsurface to “void *dev_ptr” without copying it, and not affect decoding

I saw an “NvBufSurface2Raw” API that can convert nvbufsurface data into ptr, but it will make a copy. Is there anything that cannot be copied?

Hi,
Please check the sample which demonstrates NvBufSurface + TensorRT:

/usr/src/jetson_multimedia_api/samples/04_video_dec_trt/

If you check the samples and integrate into your use-case , it is optimal performance without additional memory copy.

Hello, thank you for your reply

I have reviewed this sample, but the buffer is related to the nvbufsurface. I hope to keep the decoded data independent of the nvbufsurface and not affect the decoding overlay in the loop. However, the original data still exists, so that I can keep this part of the original data in memory and give it to other modules (asynchronous).

I have found another issue that drawing frames and text on images are different for NVOSD input.
Can I use the CUDA kernel function to write text on top of RGB/BGR images? Can you provide an example, as NVOSD input is different and I need to frequently convert their formats

Hi,
For format conversion, you can call NvBufferTransform() to use hardware converter. The supported coversions are demonstrated in 07 sample:

/usr/src/jetson_multimedia_api/samples/07_video_convert/

If your use-case is not supported, a possible solution is to implement CUDA code to do it. There are some CUDA code in

jetson-utils/cuda at 903fae30ecafaa5ecdfc8e34f4dec2025ad31778 · dusty-nv/jetson-utils · GitHub

You may refer to it for further development.

Hi, I think CUDAFont.cu can meet my needs, but I couldn’t find any examples or tests at git example . Can you share a reference link? Thank you.

Hi,
There is no existing sample exactly fitting the use-case. You would need to check the samples and do development.

Okay, these cases solve my problem. Thank you for your reply

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