# pcie-bench/pcie-model architecture

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

- Interactive diagram: https://gitdiagram.com/pcie-bench/pcie-model
- Repository: https://github.com/pcie-bench/pcie-model

## Overview

##### Main Components
- PCIe Model (model/pcie.py): Handles calculations regarding PCIe specifications.
- Memory Bandwidth Model (model/mem_bw.py): Calculates bandwidth for memory read/write PCIe transactions.
- NIC Models:
⁃ Simple NIC (model/simple_nic.py): Models the basic data transactions of a simple network interface controller.
⁃ Niantic NIC (model/niantic.py): Models a modern, more realistic 10Gb/s NIC including batched DMA transactions.
- Additional Utilities (model/util.py) and any smaller supporting parts (model/eth.py might be for Ethernet-related behavior).

- Sample Application Layer – Represented by the two top-level sample programs:
- pcie_bw.py: Provides an interface to calculate and plot PCIe bandwidth at the TLP layer. This also relies on the memory bandwidth model.
- nic_bw.py: Demonstrates bandwidth estimation for NICs using both the simple NIC and Niantic models.

##### Relationships and Interactions
- Data Flow:
- User Inputs/Configurations → Sample Programs (pcie_bw.py, nic_bw.py).
- The sample programs call into the corresponding models housed within the “model” directory.
- Within the models, components such as PCIe, Memory, and NIC interact – for example, the NIC models combine PCIe transactions and memory data transfers into an overall bandwidth calculation.
- After computing, the sample programs output data which is then plotted via the associated gnuplot files.

- From sample programs (top level) to core modeling components.
- Within the “model” folder, show the call hierarchy and data dependencies among “pcie.py”, “mem_bw.py”, “simple_nic.py”, “niantic.py”, and supporting utility functions in “util.py”.

##### Important Architectural Patterns
- Modular Design: The project separates concerns by having self-contained modeling modules and independent sample applications.
- Simulated Data Flow: The process starts with input from the user (or preset configuration parameters), flows through the simulation model, and then results in data that can be visualized. This sequence mimics pipelined calculations.
- Extensibility: The separation of different NIC models (simple, Niantic) shows that the framework is designed to easily add more models or modify existing ones.

##### Relevant Technologies and Domain Concepts
- Mention that the simulation is based on PCIe hardware specifications (e.g., lanes, generation, MPS, MRRS).
- That gnuplot is used for output visualization.
- Algorithmic or performance considerations detailed in the SIGCOMM 2018 paper referenced in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Overall PCIe Modeling Tool"
        %% Modeling Core Subgraph
        subgraph "Modeling Core"
            PCIeModel["PCIe Model"]:::model
            MemBW["Memory Bandwidth Model"]:::model
            SimpleNIC["Simple NIC Model"]:::model
            NianticNIC["Niantic NIC Model"]:::model
            Utils["Supporting Utilities"]:::model
        end
        
        %% Sample Application Layer Subgraph
        subgraph "Sample Application Layer"
            PCIeApp["PCIe Bandwidth Application"]:::sample
            NICApp["NIC Bandwidth Application"]:::sample
        end
        
        %% External Visualization Subgraph
        subgraph "External Visualization"
            GnuplotNIC["Gnuplot NIC Script"]:::viz
            GnuplotPCIe["Gnuplot PCIe Script"]:::viz
        end
    end

    %% Connections from Sample Applications to Modeling Core
    PCIeApp -->|"calculates"| PCIeModel
    PCIeApp -->|"uses"| MemBW
    NICApp -->|"triggers"| SimpleNIC
    NICApp -->|"triggers"| NianticNIC

    %% Modeling Core Interconnections
    SimpleNIC -->|"uses"| PCIeModel
    SimpleNIC -->|"uses"| MemBW
    NianticNIC -->|"uses"| PCIeModel
    NianticNIC -->|"uses"| MemBW

    %% Modeling Core to Supporting Utilities
    PCIeModel -->|"utilizes"| Utils
    MemBW -->|"utilizes"| Utils
    SimpleNIC -->|"utilizes"| Utils
    NianticNIC -->|"utilizes"| Utils

    %% Output to External Visualization
    PCIeApp -->|"outputs"| GnuplotPCIe
    NICApp -->|"outputs"| GnuplotNIC

    %% Styles
    classDef model fill:#BBDEFB,stroke:#1E88E5,stroke-width:2px;
    classDef sample fill:#C8E6C9,stroke:#43A047,stroke-width:2px;
    classDef viz fill:#FFECB3,stroke:#FBC02D,stroke-width:2px;

    %% Click Events
    click PCIeModel "https://github.com/pcie-bench/pcie-model/blob/master/model/pcie.py"
    click MemBW "https://github.com/pcie-bench/pcie-model/blob/master/model/mem_bw.py"
    click SimpleNIC "https://github.com/pcie-bench/pcie-model/blob/master/model/simple_nic.py"
    click NianticNIC "https://github.com/pcie-bench/pcie-model/blob/master/model/niantic.py"
    click Utils "https://github.com/pcie-bench/pcie-model/blob/master/model/util.py"
    click PCIeApp "https://github.com/pcie-bench/pcie-model/blob/master/pcie_bw.py"
    click NICApp "https://github.com/pcie-bench/pcie-model/blob/master/nic_bw.py"
    click GnuplotNIC "https://github.com/pcie-bench/pcie-model/blob/master/nic_bw.gpl"
    click GnuplotPCIe "https://github.com/pcie-bench/pcie-model/blob/master/pcie_bw.gpl"
```
