NvMediaImage Surfaces to CUDA Consumer on dGPU (nvm_egldgpu)

The NvMedia dGPU sample application, nvm_egldgpu, demonstrates how to use NvMediaEglstream APIs to post NvMediaImage surfaces to dGPU, which can be processed by CUDA APIs running on dGPU.
The application supports a single image producer and a single CUDA consumer. It can run with a single process for producer and consumer or with two different processes. The image producer must be on Tegra and the CUDA consumer must be on iGPU or dGPU. Single-process and cross-process operation work for both combinations.
The image producer reads image data from an input file and posts it to the CUDA consumer through EGLStream. The image producer accepts YUV420 or RAW formats as input.
In FIFO mode, if the input to the image producer bit matches the output of the CUDA consumer, then the test is successful. In mailbox mode, the number of frames acquired by the consumer depends on the speed at which the producer and consumer are running. You cannot compare input and output files directly in mailbox mode.

Single-Process Operation

The application can run in single-process mode, that is, with the image producer thread and CUDA consumer thread run in a single process. First, the application creates an EGLStream object using EGLStreamCreate()by passing the EGLDisplay handle corresponding to the iGPU. The image producer interacts with the EGLStream object, and eglGetStreamFileDescriptorKHR()is used to get a file descriptor corresponding to the EGLStream object. Then eglCreateStreamFromFileDescriptorKHR() creates another EGLStream object named EGLStream_dGPU by passing the EGLDisplay handle corresponding to dGPU. The CUDA consumer interacts with this eglStream_dGPU object.

Cross-Process Operation

The application can also run in cross-process mode, that is, with the image producer and CUDA consumer running in different processes. First, the consumer process creates an EGLStream object with EGLStreamCreate()by passing the EGLDisplay handle corresponding to the dGPU. The CUDA consumer interacts with this EGLStream object. Then it uses eglGetStreamFileDescriptorKHR()to get a file descriptor corresponding to the EGLStream object. The consumer process sends this file descriptor through a socket to the producer process. The producer process creates an EGLStream object using eglCreateStreamFromFileDescriptorKHR() by passing the EGLDisplay handle corresponding to iGPU. The image producer interacts with this EGLStream object.

Command Line Options

The application command syntax is:
./nvm_egldgpu [options]
This table describes the command line options. Only the –f and –fr options are required; the rest are optional.
Option
Description
Default
-h
Prints a help menu for the application.
N/A
-v <level>
Logging level. Value may be:
0 = Errors
1 = Warnings
2 = Info
3 = Debug
If no level is provided, uses 3 (Debug). If the option is not provided, uses 0 (Errors).
If the option is omitted, 0. If the option is used, but <level> is not provided, 3.
-f <file>
Specifies the input filename. The file must be in YUV420p or RAW.
N/A
-fr <W>x<H>
Specifies the input file resolution. <W> is the input image width, and <H> is the input image height; for example:
‑fr 640x480
N/A
-st <type>
Specifies the file type. Value may be:
420p
RAW
For RAW, the application assumes 12 bits per pixel and GRBG RAW pixel order (effectively, each pixel takes 2 bytes of space out of which only 12 bits are valid).
420p
-bl
Makes the producer use a block linear surface. Block linear is only supported for iGPU.
Producer uses a pitch linear surface.
-n <frames>
Number of frames the appolication is to produce.
All frames in the file.
--fifo
Specifies FIFO mode for EGLStream.
Mailbox mode
--crossproc <x>
Specifies cross-process operation for the producer and consumer. Value may be:
prod
con
Single-process mode
-s <file>
Makes the CUDA consumer save output to <file>.
CUDA consumer acquires and releases the surface but writes no output.
--dgpu <b>
Specifies where the Consumer is running. Value may be:
1: Consumer is running on dGPU
0: Consumer is on iGPU
1
--useblit
Uses blit path before posting the surfaces to EGLStream.
N/A

Example Commands

This topic shows how to perform common tasks with nvm_egldgpu.
To test an image producer and CUDA consumer from a single process
Enter the command:
./nvm_egldgpu -f test.yuv -s cuda.yuv --fifo -fr 1920x1080
This command tests an image producer and CUDA consumer from a single process in FIFO mode for YUV420 planar input of size 1920×1080 on dGPU. The CUDA consumer output is written to the cuda.yuv file.
Enter the command:
./nvm_egldgpu -f test.yuv -s cuda.yuv --fifo -fr 1920x1080 --dgpu 0
This command tests an image producer and CUDA a consumer from a single process in FIFO mode for YUV420 planar input of size 1920×1080 on iGPU. The CUDA consumer output is written to the cuda.yuv file.
To test an image producer and CUDA consumer from two different processes
1. Run the consumer:
./nvm_egldgpu --crossproc con -s cuda.yuv --fifo
2. Run the producer:
./nvm_egldgpu --crossproc prod -f test1.yuv -fr 1920x1080 --fifo