|
triton_cpp v1.2.1
Header-only C++ wrapper for NVIDIA Triton Inference Server clients
|
Synchronous, typed interface to one model served by Triton. More...
#include <triton_interface.hpp>
Public Member Functions | |
| TritonInterface (const std::string &model_name, const std::string &model_version, const std::string &server_url, bool shm, bool variable_input_size=false, bool retry_connection=false, double client_timeout_s=0.0, bool cuda_input_shm=false) | |
| Connect to Triton and query metadata for one model. | |
| void | initInOutputs (std::optional< std::map< std::string, std::vector< int64_t > > > special_output_shapes, std::optional< std::map< std::string, std::vector< int64_t > > > special_input_shapes=std::nullopt) |
| Creates all input and output buffers for the model, based on the model metadata. | |
| void | infer () |
| Run synchronous inference with the data currently stored in the input buffers. | |
| template<typename T > | |
| VectorType< T > | getInputTensor (const std::string &name, int64_t rows) |
| Get a view to the InputBuffer, interpreted as a Vector. | |
| template<typename T > | |
| MatrixType< T > | getInputTensor (const std::string &name, int64_t rows, int64_t cols) |
| Get a view to the InputBuffer, interpreted as a Matrix. | |
| template<typename T , typename... DimType> | |
| TensorType< T, sizeof...(DimType)+3 > | getInputTensor (const std::string &name, int64_t dim0, int64_t dim1, int64_t dim2, DimType... dims) |
| Get a view to the InputBuffer, interpreted as a Tensor of rank >=3. | |
| std::pair< uint8_t *, std::size_t > | getInputTensor (const std::string &name) |
| Get the raw input buffer. | |
| bool | usesCudaInputSharedMemory () const |
| Whether input tensors are currently backed by Triton CUDA shared memory. | |
| std::pair< uint8_t *, std::size_t > | getInputTensorDevice (const std::string &name) |
| Get the device pointer for a CUDA shared-memory-backed input tensor. | |
| void | copyInputTensorToDevice (const std::string &name, const void *host_data, std::size_t bytes) |
| Copy host data into a CUDA shared-memory-backed input tensor. | |
| template<typename T > | |
| VectorType< const T > | getOutputTensor (const std::string &name, int64_t rows) const |
| Get a view to the OutputBuffer, interpreted as a Vector. | |
| template<typename T > | |
| MatrixType< const T > | getOutputTensor (const std::string &name, int64_t rows, int64_t cols) const |
| Get a view to the OutputBuffer, interpreted as a Matrix. | |
| template<typename T , typename... DimType> | |
| TensorType< const T, sizeof...(DimType)+3 > | getOutputTensor (const std::string &name, int64_t dim0, int64_t dim1, int64_t dim2, DimType... dims) const |
| Get a view to the OutputBuffer, interpreted as a Tensor of rank >=3. | |
| std::pair< const uint8_t *, std::size_t > | getOutputTensor (const std::string &name) const |
| Get the raw output buffer and its size. | |
| std::string | getModelInfo () const |
| Get a description of the model's in and outputs as human-readable text. | |
| std::size_t | nInputs () const |
| Get the number of inputs. | |
| std::size_t | nOutputs () const |
| Get the number of outputs. | |
| std::vector< int64_t > | getInputShape (const std::string &name) const |
| Get the Input Shape of a tensor. | |
| std::vector< int64_t > | getOutputShape (const std::string &name) const |
| Get the Output Shape of a tensor. | |
Lifetime | |
| TritonInterface (const TritonInterface &)=delete | |
| Copy construction is disabled because the interface owns registrations and buffers. | |
| TritonInterface & | operator= (const TritonInterface &)=delete |
| Copy assignment is disabled because the interface owns registrations and buffers. | |
| TritonInterface (TritonInterface &&)=delete | |
| Move construction is disabled to keep registered buffer addresses stable. | |
| TritonInterface & | operator= (TritonInterface &&)=delete |
| Move assignment is disabled to keep registered buffer addresses stable. | |
| ~TritonInterface () | |
| Unregister shared-memory regions owned by this interface. | |
Synchronous, typed interface to one model served by Triton.
The interface owns the Triton gRPC client, model input/output descriptors, and optional system or CUDA shared-memory registrations. Call initInOutputs() before accessing tensors or performing inference.
Definition at line 36 of file triton_interface.hpp.
|
inline |
Connect to Triton and query metadata for one model.
| model_name | Name of the served model. |
| model_version | Model version, such as "1". |
| server_url | Triton gRPC endpoint, such as "127.0.0.1:8001". |
| shm | Use POSIX shared memory for inputs and outputs. |
| variable_input_size | Recreate standard input buffers when callers request new shapes. |
| retry_connection | Retry client creation and model metadata queries once per second. |
| client_timeout_s | Per-inference client timeout in seconds; zero disables the timeout. |
| cuda_input_shm | Use CUDA IPC shared memory for inputs. Outputs still follow shm. |
| std::invalid_argument | for incompatible options or a negative timeout. |
| std::runtime_error | if the server connection, model query, or requested CUDA support fails. |
Definition at line 52 of file triton_interface.hpp.
References triton_cpp::LocalCudaSharedMemorySupported().
|
delete |
Copy construction is disabled because the interface owns registrations and buffers.
|
delete |
Move construction is disabled to keep registered buffer addresses stable.
|
inline |
Unregister shared-memory regions owned by this interface.
Definition at line 137 of file triton_interface.hpp.
|
inline |
Copy host data into a CUDA shared-memory-backed input tensor.
| name | Name of the input tensor. |
| host_data | Pointer to the host buffer to copy from. |
| bytes | Number of bytes to copy. Must exactly match the input tensor size. |
| std::invalid_argument | if the tensor is not CUDA-backed, the byte size does not match, or triton_cpp was built without CUDA SHM support. |
| std::runtime_error | if the underlying CUDA copy fails. |
Definition at line 376 of file triton_interface.hpp.
References triton_cpp::throw_on_cuda_error().
|
inline |
Get the Input Shape of a tensor.
| name | name of the input tensor |
| std::invalid_argument | if the input name is not found in the model metadata |
Definition at line 512 of file triton_interface.hpp.
|
inline |
Get the raw input buffer.
| name | name of the input |
| std::invalid_argument | if variable input size is enabled and this input has not been created yet, or if the input is not host-mappable. |
Definition at line 333 of file triton_interface.hpp.
|
inline |
Get a view to the InputBuffer, interpreted as a Tensor of rank >=3.
| T | Scalar data type |
| name | name of the input |
| dim0 | size of the tensor. |
| dim1 | size of the tensor. |
| dim2 | size of the tensor. |
| dims | size of the tensor (arbitrary count). |
| std::invalid_argument | if the size of the input buffer does not match the requested size |
Definition at line 305 of file triton_interface.hpp.
|
inline |
Get a view to the InputBuffer, interpreted as a Vector.
| T | Scalar data type |
| name | name of the input |
| rows | size of the vector. |
| std::invalid_argument | if the size of the input buffer does not match the requested size |
Definition at line 247 of file triton_interface.hpp.
|
inline |
Get a view to the InputBuffer, interpreted as a Matrix.
| T | Scalar data type |
| name | name of the input |
| rows | size of the matrix. |
| cols | size of the matrix. |
| std::invalid_argument | if the size of the input buffer does not match the requested size |
Definition at line 275 of file triton_interface.hpp.
|
inline |
Get the device pointer for a CUDA shared-memory-backed input tensor.
| name | Name of the input tensor. |
| std::invalid_argument | if the input is not backed by CUDA shared memory. |
Definition at line 358 of file triton_interface.hpp.
|
inline |
Get a description of the model's in and outputs as human-readable text.
Definition at line 489 of file triton_interface.hpp.
|
inline |
Get the Output Shape of a tensor.
| name | name of the output tensor |
| std::invalid_argument | if the output name is not found in the model metadata |
Definition at line 527 of file triton_interface.hpp.
|
inline |
Get the raw output buffer and its size.
| name | Name of the output tensor. |
| std::out_of_range | if name is unknown when shared memory is enabled. |
Definition at line 469 of file triton_interface.hpp.
|
inline |
Get a view to the OutputBuffer, interpreted as a Tensor of rank >=3.
| T | Scalar data type |
| name | name of the output |
| dim0 | size of the tensor. |
| dim1 | size of the tensor. |
| dim2 | size of the tensor. |
| dims | size of the tensor (arbitrary count). |
| std::invalid_argument | if the size of the output buffer does not match the requested size |
Definition at line 450 of file triton_interface.hpp.
References getOutputTensor().
|
inline |
Get a view to the OutputBuffer, interpreted as a Vector.
| T | Scalar data type |
| name | name of the output |
| rows | size of the vector. |
| std::invalid_argument | if the size of the input buffer does not match the requested size |
Definition at line 405 of file triton_interface.hpp.
References getOutputTensor().
Referenced by getOutputTensor(), getOutputTensor(), and getOutputTensor().
|
inline |
Get a view to the OutputBuffer, interpreted as a Matrix.
| T | Scalar data type |
| name | name of the output |
| rows | size of the matrix. |
| cols | size of the matrix. |
| std::invalid_argument | if the size of the output buffer does not match the requested size |
Definition at line 426 of file triton_interface.hpp.
References getOutputTensor().
|
inline |
Run synchronous inference with the data currently stored in the input buffers.
Returned output views remain valid until the next call to infer().
| std::runtime_error | if Triton rejects or fails the inference request. |
Definition at line 222 of file triton_interface.hpp.
|
inline |
Creates all input and output buffers for the model, based on the model metadata.
| special_output_shapes | Some models don't know their output shape, i.e. it is given as -1. In this case, you must provide the correct shape here. |
| special_input_shapes | Some models don't know their input shape, i.e. it is given as -1. In this case, you must provide the correct shape here. |
| std::invalid_argument | if a provided input or output name is unknown. |
| std::runtime_error | if shared-memory setup was requested but initialization fails. |
Definition at line 148 of file triton_interface.hpp.
|
inline |
Get the number of inputs.
Definition at line 496 of file triton_interface.hpp.
|
inline |
Get the number of outputs.
Definition at line 503 of file triton_interface.hpp.
|
delete |
Copy assignment is disabled because the interface owns registrations and buffers.
|
delete |
Move assignment is disabled to keep registered buffer addresses stable.
|
inline |
Whether input tensors are currently backed by Triton CUDA shared memory.
Definition at line 349 of file triton_interface.hpp.