Skip to content
Skip to content
Modules Inference

Holoscan Inference#

Holoscan Inference runs TensorRT models inside your Holoscan graph. Give InferenceOp one or more models and the tensors each one consumes and produces. It builds or loads a cached TensorRT engine per model and picks the fastest dispatch path that is safe for your configuration. TensorPreprocessorOp turns camera frames into the fixed-shape tensors a model expects, with every step on the GPU.

Package info#

Packageholoscan-inference
GitHub repositorynvidia-holoscan/holoscan-sdk
Version5.0.0
C++ namespaceholoscan::ops
Python namespaceholoscan_inference
Holoscan SDK5.0.0 or later, tested with 5.0.0
RuntimeTensorRT 10.3 or newer and CUDA 13
Platformsx86_64, aarch64
LanguagesC++, Python
LicenseApache-2.0
MaintainerHoloscan Team, NVIDIA
Debian packageholoscan-inference
PyPI packageholoscan-inference-cu13

Operators#

  • InferenceOp runs one or more models and selects a dispatch mode automatically (TensorRT only; CUDA 13 and TensorRT 10.3 or newer required).
  • TensorPreprocessorOp converts, resizes, and normalizes images for a model (GPU input only; use image metadata for multi-plane camera formats).

Quick Start#

Installation#

Configure the NVIDIA repository for your platform using the SDK installation guide, then install the module and its matching Core dependency.

Bash
sudo apt update
sudo apt install holoscan-inference

Use a Python 3.12 or newer virtual environment with CUDA 13.

Bash
python -m pip install holoscan-inference-cu13

No Yocto recipe is published for this SDK 5 module yet. The current Holoscan Yocto layer targets SDK 4.6.

Example Usage#

Run one model with named input and output tensors. These fragments omit tensor producers, consumers, and graph execution.

CMakeLists.txt
find_package(holoscan COMPONENTS inference REQUIRED)
target_link_libraries(my_pipeline PRIVATE holoscan::inference)

holoscan::inference links both operators.

If the SDK is outside CMake's search paths, configure your application with -Dholoscan_DIR=<prefix>/lib/cmake/holoscan, replacing <prefix> with the SDK installation prefix.

C++
#include <holoscan/operators/inference/inference.hpp>
// ...
auto inference = graph.op<holoscan::ops::InferenceOp>(
    "inference", holoscan::ops::InferenceOpParams{
        .model_path_map = {{"detector", "/models/detector.onnx"}},
        .input_map = {{"detector", {"frames"}}},
        .output_map = {{"detector", {"detections"}}},
    });
// ...
Python
from holoscan_inference.operators import InferenceOp
# ...
inference = InferenceOp(
    graph, "inference",
    model_path_map={"detector": "/models/detector.onnx"},
    input_map={"detector": ["frames"]},
    output_map={"detector": ["detections"]},
)
# ...

Importing holoscan alone does not load TensorRT; importing the inference package does.

Docs#

InferenceOp#

InferenceOp runs one or more TensorRT models on named input tensors and publishes named output tensors. For ONNX input it builds and caches an engine; it can also load a prebuilt TensorRT engine. Model-to-tensor maps define which tensors feed each model and where its results appear, including chains in which one model feeds another.

Execution follows the configured model dependencies. Independent models can run concurrently, while dependent work must wait for its inputs. At startup the operator selects a dispatch path for the model count, shape behavior, memory placement, and concurrency settings; eligible paths use CUDA Graph capture and replay to reduce submission overhead.

Parameter Default What it does
model_path_map required Model name to .onnx or .trt path
input_map / output_map required Model name to ordered input or output tensor names
is_engine_path false Treat paths as prebuilt TensorRT engines
enable_fp16 false Build FP16 engines on TensorRT 10
dla_core -1 DLA core to use; -1 disables DLA
parallel_inference true Run independent models in parallel when possible
dynamic_input_dims false Allow input shapes to change between ticks
enable_cuda_graphs true Capture and replay TensorRT work with CUDA Graphs
input_on_cuda / output_on_cuda / transmit_on_cuda true Keep inputs, internal outputs, and emitted tensors on the GPU
cuda_stream_pool / cuda_green_context_pool none Dedicated streams and SM partitions for concurrent models

Load the same fields from YAML with InferenceOpParams::from_yaml(path) for one operator per file, or from_yaml_node(node, config_dir) when one file configures several operators.

Remarks. This module requires CUDA 13 and TensorRT 10.3 or newer. The first run builds a TensorRT engine next to each .onnx file; later runs reuse it. The cache name includes the GPU, TensorRT version, and build settings, so configuration changes trigger a rebuild. Plan for the initial build time and a writable model directory. Tensor names, order, dimensions, and dtypes must agree with the model's bindings.

Dispatch without tuning#

InferenceOp picks one of seven dispatch modes when it starts, based on the configuration you already gave it. There is no opt-in.

Mode Models Shapes Concurrency
kFast 1 static —
kSeqFast N static sequential
kParFast N static parallel, one CUDA stream per model
kDynFast 1 dynamic —
kDynSeqFast N dynamic sequential
kDynParFast N dynamic parallel
kStandard N any work queue, always available

The fast modes need TensorRT models, device-resident inputs, and no chained models. When a setting rules out a faster mode, InferenceOp uses a safe one and logs the reason with a suggested fix. CUDA Graphs are on by default. Add a green-context pool to give each concurrent model its own SM partition.

See the full InferenceOp parameter reference for engine, batching, memory, and execution settings.

TensorPreprocessorOp#

TensorPreprocessorOp converts camera images into fixed-shape model input tensors entirely on the GPU. It first converts YUV to RGB when needed, then uses bilinear interpolation to resize to the requested dimensions. For F32 output it computes (pixel / 255 - mean[channel]) / std[channel]; U8 output skips that normalization. Finally it writes interleaved NHWC or planar NCHW storage, optionally adding a batch dimension of one.

The pipeline uses NPP operations on the Holoscan CUDA stream. The input_kind selects a bare tensor or a full image payload; the image path preserves the plane and color metadata needed to interpret camera buffers.

Parameter What it sets
input_port_name, output_port_name Input and output tensor names
input_kind tensor or image; use image to retain per-frame camera metadata
input_pix_fmt RGB24, YUYV, NV12, or I420 input format
input_width, input_height, input_planes Dimensions and plane offsets/strides for a flat NV12 or I420 tensor
output_width, output_height Required resize dimensions
output_pix_fmt, output_layout rgb_u8 or rgb_fp32, and nchw or nhwc
prepend_batch_dim Add a leading batch dimension of 1
normalize_mean, normalize_std Three RGB channel constants; used for rgb_fp32 output
yuv_matrix, yuv_range Color conversion; currently only full-range YUV is supported, and BT.709 is supported only for NV12
memory_kind CUDA device or managed memory

Remarks. Input must be GPU-accessible U8 image data; host input is rejected. For NV12 or I420 from Holoscan Camera, set input_kind: image so plane layout travels with each frame. Mean and standard deviation are RGB channel constants and affect only F32 output; standard deviations must be nonzero. This operator resizes to the requested shape, so choose dimensions appropriate for the model's expected aspect ratio. See the preprocessor reference for format, colorimetry, and stride constraints.

Examples#

The module includes eight example configurations, from a single model to concurrent dynamic-shape models with CUDA Graphs and isolation.

Configuration Scenario
01_single_model One TensorRT model on GPU-resident tensors
02_multi_model_independent Two independent models, run sequentially
03_multi_model_chained One model’s output feeds another model’s input
04_multi_model_concurrent Two independent models on dedicated streams
05_multi_model_concurrent_graphs Concurrent models with CUDA Graphs
06_multi_model_concurrent_isolated Concurrent models with a green-context pool
07_dynamic_shape_single One model with changing input dimensions
08_dynamic_shape_concurrent_isolated Dynamic shapes, concurrency, CUDA Graphs, and isolation together
All modules