Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Triton inference server Server JetsonCommonHeader

From Leeroopedia
Revision as of 13:58, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Triton_inference_server_Server_JetsonCommonHeader.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

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");
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment