# yonseicasl/neurospector architecture

> Architecture diagram of the GitHub repository yonseicasl/neurospector, 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/yonseicasl/neurospector
- Repository: https://github.com/yonseicasl/neurospector

## Overview

##### Main Components
- Command-Line Interface & Main Entry: Represent the main executable (src/main.cc) that interprets runtime options.
- Mode Switch: A branch that directs execution into either the “optimizer” module or the “analyzer” module.
- Optimizer Module: Consisting of multiple strategies (see src/optimizer with bottom-up and brute-force implementations plus mapping space definitions). This module takes accelerator and network configurations to compute optimal dataflows and mappings.
- Analyzer Module: Represented by src/analyzer along with common modules to compute cost metrics based on a provided scheduling table.
- Common Libraries/Utilities: Components such as the “common” folder (handling accelerator, network, layer, and scheduling table objects) and “utility” (including the parser, version info, and other helper functions).
- Configuration Files: The different configuration directories under “configs” for accelerators, networks, and scheduling tables, which serve as the primary input for system parameters.

##### Relationships & Data Flow
- Both branches should feed into “Common” components – that is, shared data structures and utility functions responsible for parsing, encapsulating design parameters, and error-checking.

##### Architectural Patterns and Design Principles
- Separation of concerns by clearly segmenting modules: the configuration/parsing layer, the mode-specific algorithms, and the shared utility components.
- That the design is modular, allowing the framework to support various configurations of accelerators and networks and plug in alternative mapping strategies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Input & Initialization
    CLI("CLI Input"):::input
    Parser("CLI/Parser"):::processor
    Main("Main Execution"):::processor

    CLI -->|"command-line_flags"| Parser
    Parser -->|"parse_flags"| Main
    Main -->|"determine_run_type"| Mode[/"Mode Switch (run_type)"/]:::decision

    %% Configuration Files
    subgraph "Configuration Files"
        Accel("Accelerator Configs"):::config
        Network("Network Configs"):::config
        Schedule("Scheduling Table Configs"):::config
    end

    %% Optimizer Path
    subgraph "Optimizer Path"
        direction TB
        OptConfig("Accelerator & Network Configs"):::config
        Optimizer("Optimizer Module"):::processor
        OptCore("Optimizer Core"):::processor
        BottomUp("Bottom-Up Strategy"):::processor
        BruteForce("Brute Force Strategy"):::processor
        MappingSpace("Mapping Space"):::processor

        %% Ingest configuration from global configs
        Accel --> OptConfig
        Network --> OptConfig
        OptConfig --> Optimizer
        Optimizer --> OptCore
        OptCore --> BottomUp
        OptCore --> BruteForce
        OptCore --> MappingSpace
        Mode -->|"optimizer"| Optimizer
    end

    %% Analyzer Path
    subgraph "Analyzer Path"
        direction TB
        AnaConfig("Accelerator & Network Configs"):::config
        SchedulingConfig("Scheduling Table Config"):::config
        Analyzer("Analyzer Module"):::processor
        AnalyzerCore("Analyzer Core"):::processor
        AnalyzerHeader("Analyzer Header"):::processor

        Accel --> AnaConfig
        Network --> AnaConfig
        Schedule --> SchedulingConfig
        AnaConfig --> Analyzer
        SchedulingConfig --> Analyzer
        Analyzer --> AnalyzerCore
        Analyzer --> AnalyzerHeader
        Mode -->|"analyzer"| Analyzer
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        CommonDM("Common Domain Models"):::utility
        Util("Utility Functions & Parser"):::utility
        CommonDM --> Util
    end

    %% Data Flow from Processing Modules to Shared Libraries
    BottomUp --> CommonDM
    BruteForce --> CommonDM
    MappingSpace --> CommonDM
    AnalyzerCore --> CommonDM
    AnalyzerHeader --> CommonDM

    %% Final Output
    Output("Output Metrics"):::output
    Util --> Output

    %% Classes
    classDef input fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef config fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef processor fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef decision fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef utility fill:#FFDEAD,stroke:#333,stroke-width:2px;
    classDef output fill:#87CEEB,stroke:#333,stroke-width:2px;

    %% Click Events
    click Main "https://github.com/yonseicasl/neurospector/blob/main/src/main.cc"
    click Optimizer "https://github.com/yonseicasl/neurospector/tree/main/src/optimizer"
    click OptCore "https://github.com/yonseicasl/neurospector/blob/main/src/optimizer/optimizer.cc"
    click BottomUp "https://github.com/yonseicasl/neurospector/blob/main/src/optimizer/bottom_up.cc"
    click BruteForce "https://github.com/yonseicasl/neurospector/blob/main/src/optimizer/brute_force.cc"
    click MappingSpace "https://github.com/yonseicasl/neurospector/blob/main/src/optimizer/mapping_space.cc"
    click Analyzer "https://github.com/yonseicasl/neurospector/tree/main/src/analyzer"
    click AnalyzerCore "https://github.com/yonseicasl/neurospector/blob/main/src/analyzer/analyzer.cc"
    click AnalyzerHeader "https://github.com/yonseicasl/neurospector/blob/main/src/analyzer/analyzer.h"
    click CommonDM "https://github.com/yonseicasl/neurospector/tree/main/src/common"
    click Util "https://github.com/yonseicasl/neurospector/tree/main/src/utility"
    click Accel "https://github.com/yonseicasl/neurospector/tree/main/configs/accelerators"
    click Network "https://github.com/yonseicasl/neurospector/tree/main/configs/networks"
    click Schedule "https://github.com/yonseicasl/neurospector/tree/main/configs/scheduling_tables"
```
