Implementation:Triton inference server Server JetsonCommonHeader
| Knowledge Sources | |
|---|---|
| Domains | Edge_Inference, Utilities |
| Last Updated | 2026-02-13 17:00 GMT |
Overview
Shared utility header providing error-checking macros and type conversion helpers for Jetson C API example applications.
Description
common.h provides reusable macros for Triton C API error handling in the Jetson example applications. It defines RETURN_IF_ERR, THROW_IF_ERR, and FAIL_IF_ERR macros that wrap TRITONSERVER_Error handling, plus helper functions for data type conversion. These reduce boilerplate code across Jetson example files.
Usage
Included by Jetson C API examples (e.g., people_detection.cc) to simplify error handling patterns when using the Triton in-process C API.
Code Reference
Source Location
- Repository: Triton Inference Server
- File: docs/examples/jetson/concurrency_and_dynamic_batching/common.h
- Lines: 1-106
Signature
#ifndef TRITON_EXAMPLE_COMMON_H
#define TRITON_EXAMPLE_COMMON_H
#include <tritonserver.h>
#define RETURN_IF_ERR(X) \
do { \
TRITONSERVER_Error* err__ = (X); \
if (err__ != nullptr) { return err__; } \
} while (false)
#define THROW_IF_ERR(X) \
do { \
TRITONSERVER_Error* err__ = (X); \
if (err__ != nullptr) { \
throw std::runtime_error(TRITONSERVER_ErrorMessage(err__)); \
} \
} while (false)
#define FAIL_IF_ERR(X, MSG) \
do { \
TRITONSERVER_Error* err__ = (X); \
if (err__ != nullptr) { \
std::cerr << "error: " << (MSG) << ": " \
<< TRITONSERVER_ErrorMessage(err__) << std::endl; \
exit(1); \
} \
} while (false)
#endif // TRITON_EXAMPLE_COMMON_H
Import
#include "common.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| X | TRITONSERVER_Error* | Yes | Error return from Triton C API call |
Outputs
| Name | Type | Description |
|---|---|---|
| (macros) | control flow | Return/throw/exit on error, pass-through on success |
Usage Examples
Using Error Macros
#include "common.h"
TRITONSERVER_Error* SetupServer(const char* model_repo) {
TRITONSERVER_ServerOptions* options = nullptr;
RETURN_IF_ERR(TRITONSERVER_ServerOptionsNew(&options));
RETURN_IF_ERR(TRITONSERVER_ServerOptionsSetModelRepositoryPath(
options, model_repo));
return nullptr;
}
int main() {
FAIL_IF_ERR(SetupServer("/models"), "Failed to setup server");
}