# nvidia/tensorrt architecture

> Architecture diagram of the GitHub repository nvidia/tensorrt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nvidia/tensorrt
- Repository: https://github.com/nvidia/tensorrt

## Overview

##### Main System Components
- Core Inference Engine Components:
- TensorRT Libraries: Represent the dependency on prebuilt TensorRT GA binaries (the “TRT_LIB_DIR”), which your code extends.
- ONNX Parser: The module (under “parsers”) that converts ONNX models into TensorRT networks.
- Plugin System:
- Python Bindings and Packaging:
- The “python” folder and its packaging subdirectories. These wrap and expose the C++ APIs into Python. Show these as a separate component that communicates with the C++ layers.
- Demo Applications & Samples:
- The “demo”, “quickstart”, and “samples” directories. These are client applications that demonstrate usage of TensorRT capabilities and how to leverage plugins and parsers.
- Build and Configuration Infrastructure:
- The “cmake” directory (with toolchains, modules, etc.) and Docker scripts (“docker” directory) which manage the multi-platform build (including cross-compilation for aarch64) and containerized environment.
- Auxiliary Tools:
- Tools such as “tools/Polygraphy”, “tools/onnx-graphsurgeon”, and additional testing utilities which help in debugging, validating and benchmarking the inference models.
- External Dependencies & System Requirements:
- Dependencies like CUDA, cuDNN, and third-party libraries (cub, protobuf) should be shown as externally provided resources that flow into the build and runtime environments.

##### Relationships and Data Flow
- That the Python layer interacts with the underlying C++ libraries.
- That demo applications and sample projects “consume” the libraries and plugins to execute inference.
- External systems and dependencies (e.g., CUDA, cuDNN, ONNX, Docker) feeding data into or being required by these modules.

##### Architectural Patterns and Design Principles
- Modular design: The clear separation between core engine components, plugins, parsers, and language bindings.
- Extensibility: Highlight the plugin architecture that allows new operations to be added without touching the core.
- Cross-platform and portability: Note the use of toolchain files in “cmake/toolchains” and Docker files that encapsulate both native and cross-compiled environments.
- Layered Architecture: At the bottom is the hardware-related libraries (CUDA, cuDNN) and prebuilt libraries, followed by the core inference modules and plugins, then the user-facing Python bindings and demo applications at the top.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    EXTERNAL["CUDA, cuDNN & ThirdParty"]:::external

    %% Build & Configuration Layer
    subgraph "Build & Configuration"
        BUILD["Build Scripts/Toolchain (CMake)"]:::build
        DOCKER["Containerization (Docker)"]:::build
    end

    %% Core Engine & Extensions Layer
    subgraph "Core Engine & Extensions"
        TRT["TensorRT Core Engine"]:::core
        ONNX["ONNX Parser"]:::parser
        PLUGIN["Plugin System"]:::plugin
    end

    %% Python Bindings Layer
    subgraph "Language Bindings"
        PY["Python Bindings"]:::python
    end

    %% Demo Applications & Samples
    subgraph "Client Applications"
        DEMO["Demos"]:::app
        QS["Quickstart Guides"]:::app
        SAMP["Samples"]:::app
    end

    %% Auxiliary Tools Layer
    subgraph "Auxiliary Tools"
        POLY["Polygraphy"]:::aux
        OGS["ONNX Graph Surgeon"]:::aux
    end

    %% Relationships and Data Flow
    EXTERNAL -->|feeds| BUILD
    EXTERNAL -->|feeds| DOCKER

    BUILD -->|compiles| TRT
    BUILD -->|compiles| ONNX
    BUILD -->|compiles| PLUGIN
    BUILD -->|supports| POLY
    BUILD -->|supports| OGS

    ONNX -->|converts| TRT
    TRT -->|extended_by| PLUGIN
    TRT -->|exposed_to| PY

    PY -->|consumed_by| DEMO
    PY -->|consumed_by| QS
    PY -->|consumed_by| SAMP

    %% Class Definitions (Colors)
    classDef external fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef build fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef parser fill:#F4A460,stroke:#333,stroke-width:2px;
    classDef plugin fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef python fill:#FFFFE0,stroke:#333,stroke-width:2px;
    classDef app fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef aux fill:#E6E6FA,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click TRT "https://github.com/nvidia/tensorrt/blob/release/10.9/include/NvInfer*.h"
    click ONNX "https://github.com/nvidia/tensorrt/tree/release/10.9/parsers/onnx"
    click PLUGIN "https://github.com/nvidia/tensorrt/tree/release/10.9/plugin"
    click PY "https://github.com/nvidia/tensorrt/tree/release/10.9/python"
    click DEMO "https://github.com/nvidia/tensorrt/tree/release/10.9/demo"
    click QS "https://github.com/nvidia/tensorrt/tree/release/10.9/quickstart"
    click SAMP "https://github.com/nvidia/tensorrt/tree/release/10.9/samples"
    click BUILD "https://github.com/nvidia/tensorrt/tree/release/10.9/cmake"
    click DOCKER "https://github.com/nvidia/tensorrt/tree/release/10.9/docker"
    click POLY "https://github.com/nvidia/tensorrt/tree/release/10.9/tools/Polygraphy"
    click OGS "https://github.com/nvidia/tensorrt/tree/release/10.9/tools/onnx-graphsurgeon"
```
