# nvidia/dcgm architecture

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

- Interactive diagram: https://gitdiagram.com/nvidia/dcgm
- Repository: https://github.com/nvidia/dcgm
- Video tour (about a minute): https://gitdiagram.com/nvidia/dcgm/video

## Overview

##### Major system components
- Core Daemon & Host Engine – This is the central part that manages GPU health monitoring, diagnostics, and alerts. Look at directories like “hostengine”, “dcgmi”, and parts of “modules”.
- Common Libraries – Under “common” and “dcgmlib”, these encapsulate shared code for low-level GPU operations, error handling, logging, threading, and interprocess communication.
- Modules – Found under the “modules” directory (with subdirectories such as diag, health, introspect, nvswitch, policy, sysmon, vgpu, etc.). Each module extends DCGM functionality (e.g., diagnostics, profiling, or policy management) and integrates with the core daemon.
- Build & Packaging Infrastructure – The “dcgmbuild” directory along with CMake lists, Dockerfiles, build scripts (build.sh, various cmake scripts) indicate a controlled build and packaging environment.
- SDK & Examples – The “sdk” and “sdk_samples” folders contain API samples and helper libraries that allow third-party integrations using C, Python, or even Go.
- Testing & Verification – Directories like “testing”, “common/tests”, “nvml-injection/tests”, and extensive Python test scripts show that there is a robust test framework set up.
- Additional Tools – Tools such as “nvml-injection”, “cublas_proxy”, “nvvs”, and various “scripts” assist in running diagnostics, GPU tests, or validating GPU telemetry.

##### Interactions and dependencies
- The host engine (central daemon) uses the common libraries (error handling, logging, low-level GPU communication) and loads various modules to perform specialized tasks.
- The modules interact with DCGM core (often through “dcgmlib” or “modules/common”) and interface externally (for example, through command-line tools like “dcgmi” and system services).
- The build system is layered – Docker is used to create a reproducible build environment, and a set of CMake scripts ties together the many components from common libraries up through modules and testing frameworks.
- The SDK and sample applications wrap the core functionality and allow integration with external monitoring systems such as Kubernetes with dcgm-exporter.

##### Architectural patterns and design principles
- Modularity and separation of concerns: the project is divided into specific directories that cater to distinct functionalities (core, modules, testing, sdk, build).
- Reuse of common libraries (e.g., “common”, “dcgmlib”) across modules and tools.
- Extensive use of CMake to configure, build, and package various parts of the system.
- Support for cross-compiling and multi-node scenarios — evidenced by toolchain files and a “multi-node” directory.

##### Relevant technologies and frameworks
- C++ as the primary language, with heavy reliance on CMake and Docker for reproducibility.
- Integration of scripting (Bash, Python) for builds, tests, and diagnostics.
- Use of vendor-specific libraries and extensions for CUDA and NVML/NVS.
- Testing frameworks spanning both C++ (unit tests) and Python (extensive integration test scripts).

##### Additional elements
- Labels that clearly denote versioning (if applicable) and build configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Components"
        CORE["Core Daemon & Host Engine"]:::daemon
        DCGMI["DCGMI CLI"]:::daemon
    end

    subgraph "Common Libraries"
        COMMON["Common Libraries"]:::lib
        DCGMLIB["DCGM Library"]:::lib
    end

    subgraph "Modules"
        MODULES["Modules Suite (diag, health, introspect, nvswitch, policy, sysmon, vgpu)"]:::modules
    end

    subgraph "Build & Packaging Infrastructure"
        BUILD["Build & Packaging (dcgmbuild, CMake, Docker)"]:::build
    end

    subgraph "SDK & Examples"
        SDK["SDK (nvidia)"]:::sdk
        SDK_SAMPLES["SDK Samples (c_src)"]:::sdk
    end

    subgraph "Testing & Verification"
        TESTS["Test Framework (C++ & Python)"]:::tests
    end

    subgraph "Additional Tools"
        TOOLS["Additional Tools"]:::tools
        NVML["NVML Injection"]:::tools
        NVVS["NVVS Tool"]:::tools
        SCRIPTS["Diagnostic Scripts"]:::tools
    end

    %% Relationships
    %% Core Components depend on Common Libraries
    CORE -->|"uses"| COMMON
    CORE -->|"uses"| DCGMLIB

    %% Modules interact with Core and Common Libraries
    MODULES -->|"integrates"| CORE
    MODULES -->|"depends_on"| COMMON

    %% SDK & Examples build on Core functionality
    SDK -->|"wraps"| CORE
    SDK_SAMPLES -->|"wraps"| CORE

    %% Build & Packaging orchestrates all components
    BUILD --> CORE
    BUILD --> COMMON
    BUILD --> DCGMLIB
    BUILD --> MODULES
    BUILD --> SDK
    BUILD --> SDK_SAMPLES
    BUILD --> TESTS
    BUILD --> TOOLS

    %% Testing targets Core, Modules, and Common Libraries
    TESTS --> CORE
    TESTS --> MODULES
    TESTS --> COMMON

    %% Additional Tools support Core and Common Libraries
    TOOLS --> CORE
    TOOLS --> COMMON
    NVML --> CORE
    NVVS --> CORE
    SCRIPTS --> CORE

    %% Bidirectional relationship between Core Components and Modules
    CORE <-->|"communicates"| MODULES

    %% Click Events
    click CORE "https://github.com/nvidia/dcgm/blob/master/hostengine/src/main.cpp"
    click DCGMI "https://github.com/nvidia/dcgm/blob/master/dcgmi/main_dcgmi.cpp"
    click COMMON "https://github.com/nvidia/dcgm/blob/master/common/CMakeLists.txt"
    click DCGMLIB "https://github.com/nvidia/dcgm/blob/master/dcgmlib/src/DcgmApi.cpp"
    click MODULES "https://github.com/nvidia/dcgm/tree/master/modules"
    click BUILD "https://github.com/nvidia/dcgm/blob/master/dcgmbuild/README.md"
    click SDK "https://github.com/nvidia/dcgm/tree/master/sdk/nvidia"
    click SDK_SAMPLES "https://github.com/nvidia/dcgm/tree/master/sdk_samples/c_src"
    click TESTS "https://github.com/nvidia/dcgm/blob/master/testing/CMakeLists.txt"
    click TOOLS "https://github.com/nvidia/dcgm/blob/master/cublas_proxy/cublas_proxy.cpp"
    click NVML "https://github.com/nvidia/dcgm/blob/master/nvml-injection/src/InjectedNvml.cpp"
    click NVVS "https://github.com/nvidia/dcgm/blob/master/nvvs/CMakeLists.txt"
    click SCRIPTS "https://github.com/nvidia/dcgm/blob/master/scripts/gather-dcgm-logs.sh"

    %% Styles
    classDef daemon fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef lib fill:#66ccff,stroke:#333,stroke-width:2px;
    classDef modules fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef build fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef sdk fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef tests fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef tools fill:#ccffff,stroke:#333,stroke-width:2px;
```
