# ntnu-hpc-lab/bat architecture

> Architecture diagram of the GitHub repository ntnu-hpc-lab/bat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ntnu-hpc-lab/bat
- Repository: https://github.com/ntnu-hpc-lab/bat

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Core Framework Layer:
- Manager Component (batbench/manager/)
- Configuration Space Component (batbench/config_space/)
- Results Handler (batbench/result/)

b) Tuner Layer:
- Multiple Autotuner Implementations:
- Mintuner
- Optuna
- OpenTuner
- Kernel Tuner
- SMAC3
- KTT

c) Backend Layer:
- CUDA Kernel Runner
- Kernel Backend

d) Benchmark Layer:
- Various GPU Benchmarks (GEMM, Nbody, etc.)

**┌─────────────────────────────────────────┐**
- Client Layer               │
- ┘
- ↓
**┌─────────────────────────────────────────┐**
- Manager Component            │
- ┘
- ↓
**┌───────────────┬─────────────┬──────────┐**
- Config Space │   Tuners    │  Results │
- ┴─────────────┴──────────┘
- ↓
**┌─────────────────────────────────────────┐**
- Backend Layer              │
- ┘
- ↓
**┌─────────────────────────────────────────┐**
- Benchmark Layer              │
- ┘

##### Component Interaction Details

a) Control Flow:
- Client → Manager (initialization and control)
- Manager → Tuners (tuning requests)
- Tuners → Backend (kernel execution)
- Backend → Benchmarks (benchmark execution)

b) Data Flow:
- Benchmarks → Results (performance metrics)
- Config Space → Tuners (parameter spaces)
- Results → Manager (optimization feedback)

##### Implementation Details to Highlight

- Plugin architecture for tuners
- Standardized benchmark interface
- Result storage mechanism
- Configuration space definition system

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef tuner fill:#2ecc71,stroke:#27ae60,color:white
    classDef backend fill:#e67e22,stroke:#d35400,color:white
    classDef benchmark fill:#9b59b6,stroke:#8e44ad,color:white
    classDef support fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Client Layer
    Client[Client Application]:::support

    %% Core Framework Layer
    subgraph CoreFramework
        Manager["Manager Component"]:::core
        ExpManager["Experiment Manager"]:::core
        ConfigSpace["Configuration Space"]:::core
        ConfigArgs["Configuration Arguments"]:::core
        Results["Results Handler"]:::core
        Dataset["Results Dataset"]:::core
    end

    %% Tuner Layer
    subgraph Tuners
        Mintuner["Mintuner"]:::tuner
        Optuna["Optuna"]:::tuner
        OpenTuner["OpenTuner"]:::tuner
        KernelTuner["Kernel Tuner"]:::tuner
        SMAC3["SMAC3"]:::tuner
        KTT["KTT"]:::tuner
    end

    %% Backend Layer
    subgraph Backends
        CUDARunner["CUDA Kernel Runner"]:::backend
        KernelBackend["Kernel Backend"]:::backend
    end

    %% Benchmark Layer
    subgraph Benchmarks
        GEMM["GEMM"]:::benchmark
        NBody["NBody"]:::benchmark
        Conv["Convolution"]:::benchmark
        Hotspot["Hotspot"]:::benchmark
        TRIAD["TRIAD"]:::benchmark
    end

    %% Connections
    Client --> Manager
    Manager --> ExpManager
    Manager --> ConfigSpace
    ConfigSpace --> ConfigArgs
    Manager --> Results
    Results --> Dataset

    Manager --> Tuners
    Tuners --> Backends
    Backends --> Benchmarks
    Benchmarks --> Results

    %% Click Events
    click Manager "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/manager/manager.py"
    click ExpManager "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/manager/experiment_manager.py"
    click ConfigSpace "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/config_space/config_space.py"
    click ConfigArgs "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/config_space/arguments.py"
    click Results "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/result/result.py"
    click Dataset "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/result/dataset.py"
    click Mintuner "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/tuners/mintuner_runner/mintuner_runner.py"
    click Optuna "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/tuners/optuna_runner/optuna_runner.py"
    click OpenTuner "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/tuners/opentuner_runner/opentuner_runner.py"
    click KernelTuner "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/tuners/kerneltuner_runner/kerneltuner_runner.py"
    click SMAC3 "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/tuners/smac3_runner/smac3_runner.py"
    click KTT "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/tuners/KTT_runner/KTT_runner.py"
    click CUDARunner "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/backends/cuda_kernel_runner/cuda_kernel_runner.py"
    click KernelBackend "https://github.com/NTNU-HPC-Lab/BAT/blob/master/batbench/backends/kernelbackend/kerneltuner_runner.py"
    click GEMM "https://github.com/NTNU-HPC-Lab/BAT/tree/master/batbench/benchmarks/GEMM"
    click NBody "https://github.com/NTNU-HPC-Lab/BAT/tree/master/batbench/benchmarks/nbody"
    click Conv "https://github.com/NTNU-HPC-Lab/BAT/tree/master/batbench/benchmarks/convolution"
    click Hotspot "https://github.com/NTNU-HPC-Lab/BAT/tree/master/batbench/benchmarks/hotspot"
    click TRIAD "https://github.com/NTNU-HPC-Lab/BAT/tree/master/batbench/benchmarks/TRIAD"

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Tuner Components]:::tuner
        L3[Backend Components]:::backend
        L4[Benchmark Components]:::benchmark
        L5[Support Components]:::support
    end
```
