|
triton_cpp v1.2.1
Header-only C++ wrapper for NVIDIA Triton Inference Server clients
|
Wrapper for Triton C++ Client Libraries
This repository provides a header-only C++ wrapper around the official Triton C++ client libraries for making interaction with a Triton Inference Server easier in ROS 2 and standalone CMake projects.
The wrapper does not host neural networks itself. A Triton Inference Server with a compatible exported model repository must be available at runtime.
🚀 Quick Start • 💻 Development • 📝 Documentation
Set TRITON_CLIENT_DIR to the Triton client installation prefix when it is not installed at /opt/tritonclient.
Clone and install the package:
After installation, link your CMake target to the package:
Alternatively, add this repository directly to your CMake project:
For ROS 2 workspaces, add this repository to the workspace and declare:
The full constructor signature is:
| Parameter | Type | Default | Description |
|---|---|---|---|
model_name | string | — | Name of the model to load from the Triton server |
model_version | string | — | Version of the model (e.g. "1") |
server_url | string | — | gRPC URL of the Triton server (e.g. "127.0.0.1:8001") |
shm | bool | — | Use host/system shared memory for Triton input and output transport (see Use host shared memory) |
variable_input_size | bool | false | Allow input shapes to change between inference calls (see Variable input size) |
retry_connection | bool | false | Retry connecting to the server until it becomes available (see Retry connection) |
client_timeout_s | double | 0.0 | Client-side inference timeout in seconds; 0.0 disables it (see Inference timeout) |
cuda_input_shm | bool | false | Require Triton CUDA shared memory for input tensors. Construction fails with an informative error if it is unavailable. |
Transport combinations:
shm=false, cuda_input_shm=false: standard Triton transport for inputs and outputsshm=true, cuda_input_shm=false: system shared memory for inputs and outputsshm=false, cuda_input_shm=true: CUDA shared memory for inputs, standard Triton transport for outputsshm=true, cuda_input_shm=true: CUDA shared memory for inputs, system shared memory for outputsvariable_input_size=true cannot be combined with either shm=true or cuda_input_shm=trueBy default, triton_cpp provides the input and output as a serialized Protobuf stream to the server. If the server and client run on the same machine, using shared memory is much more efficient.
--ipc=shareable --shm-size=2gb, or in docker-compose.yml --ipc=container:triton-triton-server-1, replacing triton-triton-server-1 with the name of the container running triton, or in docker-compose.yml /dev/shm in both containers and observe whether files containing data buffers are created while inference is running.Shared-memory regions are registered with Triton using per-client unique names, so multiple independent TritonInterface instances can use SHM safely at the same time, even when they point to the same Triton server.
When SHM is enabled, tensor offsets inside each shared region are aligned using max(type_alignment, 8) to avoid misaligned accesses for mixed datatypes (for example FP32, INT64, and BOOL) in the same packed buffer.
If your input tensors are already on GPU memory, cuda_input_shm=true avoids copying them back to host memory before sending them to Triton.
Notes:
shm=truetriton_cpp build, construction fails with an informative errorgetInputTensor(...) access is not available for CUDA-backed input buffersusesCudaInputSharedMemory()getInputTensorDevice(...)copyInputTensorToDevice(...)Example:
getInputTensorDevice(...) and copyInputTensorToDevice(...) can be combined in the same integration, depending on whether individual inputs already reside on the GPU or originate in host memory.
By default (variable_input_size = false) input buffers are allocated once during initInOutputs() and reused on every infer() call, which is the most efficient mode.
Set variable_input_size = true when the number of elements in an input tensor changes between calls. In this mode the Triton client reallocates the input memory on every infer() call, so there is a small per-call overhead.
Note:
variable_input_size = truecannot be combined withshm = trueorcuda_input_shm = true. If you try, theTritonInterfaceconstructor throwsstd::invalid_argument.
By default (retry_connection = false) the constructor throws std::runtime_error immediately if it cannot reach the server or fetch the model configuration.
Set retry_connection = true to have the constructor keep retrying (with a 1-second delay between attempts) until the server is reachable and the model is loaded. This is useful when the client node may start before the Triton server is fully ready (e.g. inside a Docker Compose stack).
TritonInterface supports an optional client-side inference timeout via the constructor argument client_timeout_s:
client_timeout_s == 0.0: timeout disabledclient_timeout_s > 0.0: failed/blocked inference requests return with an error after the timeoutclient_timeout_s < 0.0: invalid (throws)Implementation details are found in the Source Code Documentation.
The source code in this repository is licensed under Apache-2.0, see [LICENSE](LICENSE). Container images provided by this repository may contain third-party software shipped with their own license terms.
In particular, the NVIDIA Triton C++ client libraries are licensed under the BSD 3-Clause License (license source).
Development and maintenance of this repository are supported by the following projects. We acknowledge the funding of the respective institutions.
| Project | Funding Institution | Grant Number |
|---|---|---|
| AIGGREGATE | 🇪🇺 European Union | 101202457 |
| autotech.agil | 🇩🇪 Federal Ministry for Research, Technology and Space (BMFTR) | 1IS22088A |
Funded by the European Union. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Climate, Infrastructure and Environment Executive Agency (CINEA). Neither the European Union nor CINEA can be held responsible for them.