Module 13 · Lesson 42 of 98

VPI and its pluggable backends

Choose a VPI backend for each image operation, plan an NV12 conversion pipeline, and identify when its output is ready to use.

  • Beginner to advanced
  • 9 min read
  • 15 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM for the written exercises. Running VPI requires a supported NVIDIA system and a compatible VPI installation.

Your place in the module
By the end you can 4 objectives
  • Distinguish VPIImage, VPIImageData, and VPIStream.
  • Select a backend using the operation, format, and platform requirements.
  • Specify the input, intermediate, and output formats for an NV12 camera pipeline.
  • Identify where to check submission and completion status.
Video coming soonVPI and its pluggable backends
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Pixel conversion and a custom CUDA element
  • NV12 shares one interleaved U,V pair across each 2×2 block of luma samples.
  • The Jetson VIC can convert and scale supported surfaces without using CUDA execution units.
  • An appsink sample must stay alive until CUDA has finished accessing its imported surface.
01

Images, streams, and backend selection

4 min read

You built a custom camera pipeline. Now you reach for a library instead, and this lesson answers what VPI offers and how it swaps between CPU, CUDA, and VIC backends.

A camera can deliver a frame in NV12 while the next consumer expects packed RGBA at a smaller resolution. That difference affects both the processing calls and the way the program reads the buffer. NV12 has separate luma and chroma planes, so giving its address to a consumer that reads four channels per pixel produces the wrong interpretation. The producer's format and the consumer's format tell you where an explicit conversion belongs. V4L2 planar YUV formats and V4L2 RGB formats.

VPI is NVIDIA's Vision Programming Interface. Its C API lets a program express image and vision operations using common object types. A The CPU backend uses the host processor. The CUDA backend uses a supported NVIDIA GPU. PVA and VIC are additional backend choices on supported NVIDIA systems, with their own sets of operations. These hardware choices describe VPI on NVIDIA targets. You can complete this lesson's written exercises on the Ubuntu course host without VPI.

VPIImage is an opaque handle to an image. The image has dimensions and a pixel format. You can allocate an image through VPI for an intermediate result or, where the buffer type is supported, create a wrapper around storage supplied by another component. In the wrapper case, the producer still controls the lifetime of that storage. A camera buffer may have to stay checked out from its capture queue while VPI reads it.

VPIImageData is a structure that describes image storage. Its buffer type determines which storage description applies. For a pitch-linear buffer, the description includes plane information such as addresses and row pitches. You can supply a descriptor when wrapping compatible external storage or receive one when locking an image for access. The descriptor represents a particular view of the pixels and the buffer type tells you how the program can access that view. Match each successful image lock with an unlock, and finish stream work that uses an image before accessing its pixels from the host.

VPIStream is the queue for submitted work. Commands submitted to one stream execute in order, so a resize can consume the result of an earlier conversion in that same stream. A stream can carry operations for different enabled backends. The backend argument on each submission says where that operation will execute. This is what pluggable means here. The application can keep its image-and-stream structure when it changes a supported backend choice.

Before choosing an implementation, check that VPI supports the backend on the target, that the algorithm accepts it, and that the stream and participating objects allow it. Then check the algorithm's requirements for formats, dimensions, and parameters. A backend can support an algorithm with a narrower set of formats or options than another backend. If your application offers a fallback, select it explicitly and validate the full operation on that backend. Changing a backend argument alone works when the existing objects and parameters satisfy both implementations.

Submitting a VPI operationIdentifyimagesSource anddestinationhandlesChooseoperationSupplyalgorithmparametersSelectbackendSubmit tostreamCheckreturnedstatusIdentifyimagesSource anddestinationhandlesChooseoperationSupplyalgorithmparametersSelectbackendSubmit tostreamCheckreturnedstatus
The stream orders the work and each submission selects its own backend.
02

Operations and completion

3 min read

Choose the operation by the result you need. With resize, you allocate a destination with the required dimensions and select an interpolation mode supported by the backend. With remap, you supply a mapping from output locations to source coordinates. This lets a rectification step sample a distorted camera image into a corrected view. For a perspective warp, the transform specifies the geometric relationship between the source and the destination. Check the algorithm's interpolation and border options when transformed coordinates can fall outside the source.

Operation What the program supplies and receives
Resize A source image and a destination with the desired dimensions. The selected interpolation controls how the destination is sampled.
Box or Gaussian filter An image and filter parameters. A box filter averages a neighborhood uniformly. A Gaussian filter weights nearby samples more heavily.
Remap or warp An image and a geometric mapping or transform. The output contains pixels sampled at the mapped locations.
Harris corners An image and detector settings. The output contains corner locations that a subsequent stage can use as feature points.
Optical flow Successive frames and the inputs required by the chosen algorithm. Sparse tracking estimates motion at selected points, while dense flow estimates motion across the image at the algorithm's output sampling resolution.
Stereo disparity A rectified left and right image from a stereo pair. The output estimates the horizontal displacement of corresponding image features.

The vpiSubmit* family queues these operations. For example, vpiSubmitRescale takes a stream, a backend, source and destination images, and resampling options. vpiSubmitConvertImageFormat takes source and destination images that describe the formats on either side of the conversion. Some algorithms require a VPIPayload created before submission. A payload can hold algorithm configuration and working resources, such as those needed for a specific image size. Keep it alive while its queued operations can still use it.

Check the VPIStatus from each call that returns one against VPI_SUCCESS. A successful submission means VPI accepted the command. The output becomes available when the work completes. If a submission fails, report the operation, requested backend, and relevant formats and dimensions. Skip stages that depend on the failed submission. Any previously accepted work still needs to finish before you recycle the buffers it references.

To consume a result on the host, call vpiStreamSync and check its status before accessing the output. This waits for submitted work on that stream to complete and gives the application a point to detect failures from asynchronous execution. For a producer and consumer already ordered in the same stream, you can submit both and synchronize at the point where the host needs the result. If you measure only the time spent inside the submission call, you measure submission overhead. A measurement that includes the wait also includes execution of the work pending on that stream.

From submission to host accessSubmitoperationChecksubmissionWait forstreamCheckcompletionAccessoutputSubmitoperationChecksubmissionWait forstreamCheckcompletionAccessoutput
Submission status and completion status answer different questions.
Going deeperExplore the mechanism

The Programmable Vision Accelerator (PVA) is a dedicated vision processor present only on some NVIDIA Jetson modules, such as Jetson AGX Xavier and Jetson AGX Orin. A compatible VPI release can use it for supported vision operations. The supported combinations depend on the release and target. Check the algorithm's PVA entry for limits such as image size, format, or allowed parameters before assigning the work to that processor.

VIC, the Video Image Compositor, provides hardware offload for supported image operations such as scaling and format conversion. A VIC stage can handle a supported camera pre-processing operation while leaving CUDA execution resources available for other work. For a sequence that scales on VIC and processes the result on CUDA, check that the intermediate image is usable by both stages. Hardware offload identifies where the operation executes. Whether the stages can share the existing storage depends on the image representation and supported buffer types at that boundary.

03

Planning the NV12 conversion pipeline

3 min read

NV12 stores a full-resolution luma plane and a chroma plane with interleaved U and V samples. In each two-by-two group of luma samples, the pixels share one U and one V sample. Packed RGB stores three channels per pixel. Packed RGBA adds an alpha channel. Each plane can have padding at the end of a row, so use the producer's metadata for pitch and plane placement when describing the frame. A row pitch is the byte distance between the starts of adjacent rows. V4L2 planar YUV formats and V4L2 RGB formats.

The format contract also includes the interpretation of sample values. For YUV input, check the producer's color encoding and quantization range and make sure the VPI input representation reflects them. Two buffers can have the same NV12 plane layout and require different conversion coefficients or range handling. A range mismatch can make blacks look gray or crush dark detail even when plane addresses and pitches are correct. At the output, follow the consumer's channel order and alpha requirements. NV12 supplies no alpha samples, so check how the chosen conversion populates that channel if the consumer uses it.

Suppose your input is an NV12 camera frame and your consumer wants smaller RGBA pixels. Where the selected VPI implementation supports the required format and layouts, resize into an NV12 intermediate at the consumer's resolution. Then submit format conversion into an RGBA output image of that same resolution. This order keeps the intermediate in a subsampled format and converts only the pixels needed at the output size. Check the resize constraints on NV12 dimensions, including the chroma sampling requirements. If the desired resize implementation requires a packed format, consider conversion before resize and check support for each of those operations. The order can affect the resulting pixels because luma and chroma are sampled on different grids.

NV12 to RGBANV12 cameraframeResizeSmallerNV12 imageConvertformatRGBA outputNV12 cameraframeResizeSmallerNV12 imageConvertformatRGBA output
This example scales in NV12, then converts into RGBA at the consumer's resolution.

For wrapped input, wait until the camera producer has finished writing the frame before submitting work that reads it. Then keep the input buffer valid and prevent the producer from overwriting it until VPI finishes the queued reads. A buffer shared across components still has access ordering requirements. With one VPI stream and a host consumer, a checked vpiStreamSync after both operations is a straightforward completion point. After successful completion, obtain the appropriate view of the RGBA output for the consumer and return the input to capture when its reads have finished. DMA buffer sharing and synchronization.

If the result has scrambled rows, compare the plane pitches and placement reported by the producer with the descriptor you supplied. If geometry is correct and colors are wrong, inspect the format, channel order, encoding, and range. If intermittent corruption appears when frames travel through the pipeline continuously, check when capture buffers return to the producer. These symptoms can have other causes, but each check tests a distinct requirement of the pipeline.

The next lesson, NPP for image primitives, follows the same need for conversion, resizing, and filtering and asks how to request those operations with NVIDIA's CUDA image primitives.

Key takeaways

  • A VPI submission selects a backend for one operation.
  • Operations in one VPI stream execute in submission order.
  • NV12 uses a luma plane and an interleaved chroma plane, while packed RGB and RGBA use a single plane.
  • A wrapped camera buffer must remain valid until queued work that uses it has finished.
Reflect
  1. Explain to a colleague, in two sentences: distinguish VPIImage, VPIImageData, and VPIStream.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close