Multiple Inference Instance Deployment
VVAS supports running multiple vvas_xinfer instances concurrently on NPU, either within a single GStreamer pipeline using a tee or across multiple independent processes.
Using Single Process
The following is a single VVAS Gstreamer pipeline process running two resnet50 models.
gst-launch-1.0 \
filesrc location=<INPUT>.bgr ! \
rawvideoparse format=bgr width=<INPUT_WIDTH> height=<INPUT_HEIGHT> ! \
tee name=t ! queue ! \
vvas_xabrscaler xclbin-location=/run/media/mmcblk0p1/x_plus_ml.xclbin alpha-r=123.675 alpha-g=116.280 alpha-b=103.530 beta-r=0.017124 beta-g=0.017507 beta-b=0.017429 ! \
vvas_xinfer config-file=/etc/vvas/configs/infer/resnet50_onnxrt_extppe.json ! \
ma1.sink_master vvas_xmetaaffixer name=ma1 ma1.src_master ! \
fakesink -v \
t. ! queue ! \
ma1.sink_slave_0 ma1.src_slave_0 ! vvas_xmetaconvert config-location=/etc/vvas/configs/metaconvert/metaconvert_config.json ! \
vvas_xoverlay ! queue ! \
filesink location=out_1_resnet50.bgr \
t. ! queue ! \
vvas_xabrscaler xclbin-location=/run/media/mmcblk0p1/x_plus_ml.xclbin alpha-r=123.675 alpha-g=116.280 alpha-b=103.530 beta-r=0.017124 beta-g=0.017507 beta-b=0.017429 ! \
vvas_xinfer config-file=/etc/vvas/configs/infer/resnet50_onnxrt_extppe.json ! \
ma2.sink_master vvas_xmetaaffixer name=ma2 ma2.src_master ! \
fakesink -v \
t. ! queue ! \
ma2.sink_slave_0 ma2.src_slave_0 ! vvas_xmetaconvert config-location=/etc/vvas/configs/metaconvert/metaconvert_config.json ! \
vvas_xoverlay ! queue ! \
filesink location=out_2_resnet50.bgr
Note
The JSONs provided below are only samples. Ensure model-path is set to point to your available model before running.
Note
This example uses the same model on each branch. A combination of different models is also supported — simply point each vvas_xinfer instance to a different config file.
Using Multiple Processes
We can run multiple concurrent processes, with identical models running on all, or a different model on each. Here are two example pipelines, each running a ResNet50 model. Spawn these two commands concurrently from two terminals.These two pipelines will run for 500 frames before they exit.
Note
The JSONs provided below are only samples. Ensure model-path is set to point to your available model before running.
gst-launch-1.0 \
multifilesrc location=<INPUT>.nv12 loop=true ! \
rawvideoparse format=nv12 width=<INPUT_WIDTH> height=<INPUT_HEIGHT> ! queue ! \
vvas_xinfer config-file=/etc/vvas/configs/infer/resnet50_vart.json ! queue ! \
vvas_xmetaconvert config-location=/etc/vvas/configs/metaconvert/metaconvert_config.json ! vvas_xoverlay ! queue ! identity eos-after=501 ! \
fakesink -v
Note
The JSONs provided below are only samples. Ensure model-path is set to point to your available model before running.
gst-launch-1.0 \
multifilesrc location=<INPUT>.nv12 loop=true ! \
rawvideoparse format=nv12 width=<INPUT_WIDTH> height=<INPUT_HEIGHT> ! queue ! \
vvas_xinfer config-file=/etc/vvas/configs/infer/resnet50_vart.json ! queue ! \
vvas_xmetaconvert config-location=/etc/vvas/configs/metaconvert/metaconvert_config.json ! vvas_xoverlay ! queue ! identity eos-after=501 ! \
fakesink -v
Spatial Sharing Use Case
When multiple models are deployed simultaneously on NPU hardware, spatial inference/sharing occurs, enabling parallel execution of each model. This setup optimizes performance and efficiency, allowing complex computations to be performed concurrently. It is particularly beneficial for fast processing and real-time data analysis, enhancing application capabilities and improving responsiveness and overall effectiveness.
Note
Spatial sharing can be controlled from user space when using vart runtime for model execution.
To enable spatial sharing, set the vart-config property start-column to different values for each model.
The following Gstreamer pipelines demonstrate the spatial sharing of two ResNet50 models. Each command is executed in the background for 1000 frames.
{
"vart-config" : {
...
"start-column": 0,
...
}
}
Note
The JSONs provided below are only samples. Ensure model-path is set to point to your available model before running.
gst-launch-1.0 \
multifilesrc location=<INPUT>.nv12 loop=true ! \
rawvideoparse format=nv12 width=<INPUT_WIDTH> height=<INPUT_HEIGHT> ! queue ! \
vvas_xinfer config-file=/etc/vvas/configs/infer/resnet50_vart.json ! queue ! \
vvas_xmetaconvert config-location=/etc/vvas/configs/metaconvert/metaconvert_config.json ! vvas_xoverlay ! queue ! identity eos-after=1001 ! \
fakesink -v &
Note
Create resnet50_vart_col4.json by copying resnet50_vart.json and setting start-column to 4.
{
"vart-config" : {
...
"start-column": 4,
...
}
}
Note
The JSONs provided below are only samples. Ensure model-path is set to point to your available model before running.
gst-launch-1.0 \
multifilesrc location=<INPUT>.nv12 loop=true ! \
rawvideoparse format=nv12 width=<INPUT_WIDTH> height=<INPUT_HEIGHT> ! queue ! \
vvas_xinfer config-file=/etc/vvas/configs/infer/resnet50_vart_col4.json ! queue ! \
vvas_xmetaconvert config-location=/etc/vvas/configs/metaconvert/metaconvert_config.json ! vvas_xoverlay ! queue ! identity eos-after=1001 ! \
fakesink -v &
To cross-verify the spatial sharing on the NPU, ensure the GStreamer commands are active and run:
xrt-smi examine -d 0 -r aie-partitions
xrt-smi examine -d 0 -r all # includes all the reported parameters
If needed, you can increase the eos-after value to keep them running for longer time.
In this case, the two ResNet50 models are deployed to different columns (for example, column 0 and column 4), allowing both models to run simultaneously producing best efficiency.
The following is sample output from the xrt-smi examine -d 0 -r aie-partitions command and we can see that two different partition indices are allocated.
Temporal Sharing (Multi-Tenant) Use Case
Temporal inference refers to the process of dynamically swapping out models running on NPU and is required when ML compute requirements (combined for all tenants) are greater than available NPU resources. This limitation highlights the intricacies involved in managing model execution within the constraints of the NPU, emphasizing the need for efficient resource allocation and prioritization during the inference process.
Note
Temporal sharing can be controlled from user space when using vart runtime for model execution.
To enable temporal sharing, set the vart-config property aie-columns-sharing to true and start-column to same value for both models.
The following Gstreamer pipelines demonstrate the temporal sharing of two ResNet50 models. Each command is executed in the background for 1000 frames.
{
"vart-config" : {
...
"aie-columns-sharing": true,
"start-column": 0,
...
}
}
Note
The JSONs provided below are only samples. Ensure model-path is set to point to your available model before running.
gst-launch-1.0 \
multifilesrc location=<INPUT>.nv12 loop=true ! \
rawvideoparse format=nv12 width=<INPUT_WIDTH> height=<INPUT_HEIGHT> ! queue ! \
vvas_xinfer config-file=/etc/vvas/configs/infer/resnet50_vart.json ! queue ! \
vvas_xmetaconvert config-location=/etc/vvas/configs/metaconvert/metaconvert_config.json ! vvas_xoverlay ! queue ! identity eos-after=1001 ! \
fakesink -v &
gst-launch-1.0 \
multifilesrc location=<INPUT>.nv12 loop=true ! \
rawvideoparse format=nv12 width=<INPUT_WIDTH> height=<INPUT_HEIGHT> ! queue ! \
vvas_xinfer config-file=/etc/vvas/configs/infer/resnet50_vart.json ! queue ! \
vvas_xmetaconvert config-location=/etc/vvas/configs/metaconvert/metaconvert_config.json ! vvas_xoverlay ! queue ! identity eos-after=1001 ! \
fakesink -v &
To cross-verify the temporal sharing on the NPU, ensure the GStreamer commands are active and run:
xrt-smi examine -d 0 -r aie-partitions
xrt-smi examine -d 0 -r all # includes all the reported parameters
If needed, you can increase the eos-after value to keep them running for longer time.
The following is the sample output from the xrt-smi examine -d 0 -r aie-partitions command and we can see that same partition index is used for both instances.
Zero Copy Use Case
Zero-copy is supported between Preprocess and Inference, eliminating the need to copy buffers between these stages. Zero-copy is only possible when the hardware (HW) format required by Inference is also supported by Preprocess. Similarly, to enable zero-copy on the output side, PostProcess must be able to handle the HW format produced by Inference. If PostProcess does not support the HW format, additional data copies and conversions will be required, which can increase latency and reduce overall performance.
Refer to VVAS features section to know about formats and layouts requirement for zero copy.
Zero-copy is exclusively supported with the VART inference backend runtime. When using VART, zero-copy is enabled by default. In the provided GStreamer pipeline example, the vvas_xinfer plug-in handles internal pre-processing. The pre-processing output meets the hardware requirements of the NPU, allowing inference to use the same buffer without copying. The same principle applies to the output side as well.
Note
The JSONs provided below are only samples. Ensure model-path is set to point to your available model before running.
gst-launch-1.0 filesrc location=<INPUT>.nv12 \
! rawvideoparse format=nv12 width=<INPUT_WIDTH> height=<INPUT_HEIGHT> ! queue \
! vvas_xinfer config-file=/etc/vvas/configs/infer/resnet50_vart.json ! queue \
! vvas_xmetaconvert config-location=/etc/vvas/configs/metaconvert/metaconvert_config.json \
! vvas_xoverlay ! queue ! filesink location=out_resnet50_vart.nv12 -v
Cascaded (Multi-Level) Inference Use Case
A cascaded pipeline chains two vvas_xinfer elements so that a first model
(for example, an object detector) produces metadata and a second model (for
example, a classifier) runs on each detected region of interest. The first
config sets infer-config inference-level to 1; the second sets it
to 2 so that the second vvas_xinfer consumes the detection tree from the
first. Both stages in the reference workflow use the VART runtime with internal
hardware pre-processing (PPE) inside vvas_xinfer. For metadata layout,
ROI handling, and the attach-ppe-outbuf option, see the multi-level cascaded
inference description in vvas_xinfer.
The following pipeline runs (YOLOX INT8 at level 1, ResNet50 INT8 at level 2)
filesrc and rawvideoparse feed
BGR frames, two vvas_xinfer instances load `yoloxm_int8_vart_zerocopy.json and
resnet50_int8_l2.json, then vvas_xmetaconvert and vvas_xoverlay render
results before the sink.
gst-launch-1.0 -v \
filesrc location=<INPUT>.bgr ! \
rawvideoparse format=bgr width=<INPUT_WIDTH> height=<INPUT_HEIGHT> framerate=30/1 ! \
queue ! \
vvas_xinfer batch-timeout=0 config-file=/etc/vvas/configs/infer/yoloxm_int8_vart_zerocopy.json ! queue ! \
vvas_xinfer batch-timeout=0 config-file=/etc/vvas/configs/infer/resnet50_int8_l2.json ! queue ! \
vvas_xmetaconvert config-location=/etc/vvas/configs/metaconvert/metaconvert_config.json ! \
vvas_xoverlay ! queue ! \
fpsdisplaysink text-overlay=false sync=false \
video-sink="filesink async=false location=<OUTPUT>.bgr" -v
Example Scripts
Additional example scripts are pre-installed on the board at /etc/vvas/examples/:
01_classify_resnet50_int8.sh— ResNet50 INT8 classification02_detect_yoloxm_int8.sh— YOLOx-M INT8 object detection
Each script accepts an NV12 input file, width, and height as arguments:
./script_name.sh <input.nv12> <width> <height>
Note
Before running, update the model paths in the corresponding config JSON files under
/etc/vvas/configs/infer/to match the models available on your board.The example scripts in this section use NV12 as the input format. To use a different format, replace the input file and update the
formatparameter inrawvideoparseaccordingly (for example,format=bgrfor BGR input).