# gat45/htp-npu-runtime architecture

> Architecture diagram of the GitHub repository gat45/htp-npu-runtime, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gat45/htp-npu-runtime
- Repository: https://github.com/gat45/htp-npu-runtime

## Overview

This repository is a reproducible Android inference benchmarking and tuning workspace for Qualcomm HTP/NPU and Adreno GPU, with an APK profiler and a separate Python governor. The main user workflow is to configure benchmark campaigns, execute guarded device scripts, collect throughput and hardware/thermal evidence, then compare placements, MTP, and layer profiles. The governor adds a observe-to-execute tuning loop backed by cost, causal, and provenance memories. The graph reflects README capabilities and the supplied source index; unsampled device scripts and runtime wiring are not expanded into guessed call paths.

Main entry points: [`apk_profiler/ExperimentController.kt`](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/ExperimentController.kt) (Campaign controller), [`governor/engine.py`](https://github.com/gat45/htp-npu-runtime/blob/main/governor/engine.py) (Governor loop), [`apk_profiler/PerLayerProfiler.kt`](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/PerLayerProfiler.kt) (Layer campaigns), [`apk_profiler/HardwareProfiler.kt`](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/HardwareProfiler.kt) (Hardware profiling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_android["Android profiling"]
  node_campaign["Campaign controller"]
  node_layerprof["Layer campaigns"]
  node_providers["Execution providers"]
end

subgraph group_device["Device execution"]
  node_shell["Root command runner<br/>[RootShell.kt]"]
  node_guard["Script integrity<br/>[ScriptGuard.kt]"]
  node_thermal["Thermal and placement experiments"]
end

subgraph group_governor["Adaptive governor"]
  node_governor_engine["Governor loop<br/>[engine.py]"]
  node_adapter["Project adapter<br/>[adapter.py]"]
  node_op15["OnePlus adapter<br/>[op15.py]"]
  node_policy["Action policy<br/>[policy.py]"]
  node_cost["Performance cost model<br/>[cost_model.py]"]
  node_causal[("Causal memory<br/>[causal.py]")]
  node_provenance[("Provenance memory<br/>[provenance.py]")]
end

subgraph group_evidence["Measurement and memory"]
  node_collector["Common collector<br/>[CommonCollector.kt]"]
  node_hardware["Hardware profiling"]
  node_logs["Log parsing<br/>[LogParser.kt]"]
  node_gguf["GGUF inspection<br/>[GgufReader.kt]"]
  node_roofline["Roofline prediction"]
  node_profiler["Layer format profiler<br/>[profiler.py]"]
  node_facts["Benchmark fact indexing<br/>[index_facts.py]"]
end

node_engineer(("Engineer"))
node_phone["Android device"]

node_engineer -->|"configures"| node_campaign
node_campaign -->|"selects provider"| node_providers
node_campaign -->|"executes scripts"| node_shell
node_campaign -->|"collects metrics"| node_collector
node_campaign -->|"profiles device"| node_hardware
node_campaign -->|"parses output"| node_logs
node_campaign -->|"verifies scripts"| node_guard
node_layerprof -->|"delegates campaigns"| node_campaign
node_layerprof -->|"uses profiling"| node_hardware
node_layerprof -->|"guards scripts"| node_guard
node_layerprof -->|"parses results"| node_logs
node_shell -->|"runs root commands"| node_phone
node_guard -->|"checks hashes"| node_shell
node_collector -->|"reads device data"| node_shell
node_hardware -->|"reads profiling logs"| node_shell
node_hardware -->|"parses profiler output"| node_logs
node_hardware -->|"uses model metadata"| node_gguf
node_engineer -->|"starts tuning"| node_governor_engine
node_governor_engine -->|"requests actions"| node_adapter
node_governor_engine -->|"ranks actions"| node_policy
node_governor_engine -->|"updates estimates"| node_cost
node_governor_engine -->|"uses causal memory"| node_causal
node_governor_engine -->|"uses provenance"| node_provenance
node_adapter -.->|"specializes device"| node_op15
node_op15 -->|"profiles layers"| node_profiler
node_facts -->|"stores facts"| node_provenance
node_facts -->|"records relations"| node_causal
node_engineer -->|"runs experiments"| node_thermal
node_thermal -.->|"measures placement and heat"| node_phone
node_engineer -->|"requests layer analysis"| node_layerprof

click node_campaign "https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/ExperimentController.kt"
click node_layerprof "https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/PerLayerProfiler.kt"
click node_providers "https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/ExecutionProvider.kt"
click node_shell "https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/RootShell.kt"
click node_guard "https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/ScriptGuard.kt"
click node_collector "https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/CommonCollector.kt"
click node_hardware "https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/HardwareProfiler.kt"
click node_logs "https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/LogParser.kt"
click node_gguf "https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/GgufReader.kt"
click node_roofline "https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/RooflinePredictor.kt"
click node_governor_engine "https://github.com/gat45/htp-npu-runtime/blob/main/governor/engine.py"
click node_adapter "https://github.com/gat45/htp-npu-runtime/blob/main/governor/adapter.py"
click node_op15 "https://github.com/gat45/htp-npu-runtime/blob/main/governor/op15.py"
click node_policy "https://github.com/gat45/htp-npu-runtime/blob/main/governor/policy.py"
click node_cost "https://github.com/gat45/htp-npu-runtime/blob/main/governor/cost_model.py"
click node_causal "https://github.com/gat45/htp-npu-runtime/blob/main/governor/causal.py"
click node_provenance "https://github.com/gat45/htp-npu-runtime/blob/main/governor/provenance.py"
click node_profiler "https://github.com/gat45/htp-npu-runtime/blob/main/governor/profiler.py"
click node_facts "https://github.com/gat45/htp-npu-runtime/blob/main/governor/index_facts.py"
click node_thermal "https://github.com/gat45/htp-npu-runtime/tree/main/device"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_campaign,node_layerprof,node_providers toneBlue
class node_shell,node_guard,node_thermal toneAmber
class node_governor_engine,node_adapter,node_op15,node_policy,node_cost,node_causal,node_provenance toneMint
class node_collector,node_hardware,node_logs,node_gguf,node_roofline,node_profiler,node_facts toneRose
class node_engineer,node_phone toneIndigo
```

## Components

### Android profiling

- [Campaign controller](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/ExperimentController.kt): `apk_profiler/ExperimentController.kt`
- [Layer campaigns](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/PerLayerProfiler.kt): `apk_profiler/PerLayerProfiler.kt`
- [Execution providers](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/ExecutionProvider.kt): `apk_profiler/ExecutionProvider.kt`

### Device execution

- [Root command runner](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/RootShell.kt): `apk_profiler/RootShell.kt`
- [Script integrity](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/ScriptGuard.kt): `apk_profiler/ScriptGuard.kt`
- [Thermal and placement experiments](https://github.com/gat45/htp-npu-runtime/tree/main/device): `device`

### Adaptive governor

- [Governor loop](https://github.com/gat45/htp-npu-runtime/blob/main/governor/engine.py): `governor/engine.py`
- [Project adapter](https://github.com/gat45/htp-npu-runtime/blob/main/governor/adapter.py): `governor/adapter.py`
- [OnePlus adapter](https://github.com/gat45/htp-npu-runtime/blob/main/governor/op15.py): `governor/op15.py`
- [Action policy](https://github.com/gat45/htp-npu-runtime/blob/main/governor/policy.py): `governor/policy.py`
- [Performance cost model](https://github.com/gat45/htp-npu-runtime/blob/main/governor/cost_model.py): `governor/cost_model.py`
- [Causal memory](https://github.com/gat45/htp-npu-runtime/blob/main/governor/causal.py): `governor/causal.py`
- [Provenance memory](https://github.com/gat45/htp-npu-runtime/blob/main/governor/provenance.py): `governor/provenance.py`

### Measurement and memory

- [Common collector](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/CommonCollector.kt): `apk_profiler/CommonCollector.kt`
- [Hardware profiling](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/HardwareProfiler.kt): `apk_profiler/HardwareProfiler.kt`
- [Log parsing](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/LogParser.kt): `apk_profiler/LogParser.kt`
- [GGUF inspection](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/GgufReader.kt): `apk_profiler/GgufReader.kt`
- [Roofline prediction](https://github.com/gat45/htp-npu-runtime/blob/main/apk_profiler/RooflinePredictor.kt): `apk_profiler/RooflinePredictor.kt`
- [Layer format profiler](https://github.com/gat45/htp-npu-runtime/blob/main/governor/profiler.py): `governor/profiler.py`
- [Benchmark fact indexing](https://github.com/gat45/htp-npu-runtime/blob/main/governor/index_facts.py): `governor/index_facts.py`

### Other components

- **Engineer**
- **Android device**

## Connections

- Engineer → Campaign controller: configures (evidence: `README.md`)
- Campaign controller → Execution providers: selects provider (evidence: `apk_profiler/ExperimentController.kt`)
- Campaign controller → Root command runner: executes scripts (evidence: `apk_profiler/RootShell.kt`)
- Campaign controller → Common collector: collects metrics (evidence: `apk_profiler/ExperimentController.kt`)
- Campaign controller → Hardware profiling: profiles device (evidence: `apk_profiler/ExperimentController.kt`)
- Campaign controller → Log parsing: parses output (evidence: `apk_profiler/ExperimentController.kt`)
- Campaign controller → Script integrity: verifies scripts (evidence: `apk_profiler/ExperimentController.kt`)
- Layer campaigns → Campaign controller: delegates campaigns (evidence: `apk_profiler/PerLayerProfiler.kt`)
- Layer campaigns → Hardware profiling: uses profiling (evidence: `apk_profiler/PerLayerProfiler.kt`)
- Layer campaigns → Script integrity: guards scripts (evidence: `apk_profiler/PerLayerProfiler.kt`)
- Layer campaigns → Log parsing: parses results (evidence: `apk_profiler/PerLayerProfiler.kt`)
- Root command runner → Android device: runs root commands (evidence: `apk_profiler/RootShell.kt`)
- Script integrity → Root command runner: checks hashes (evidence: `apk_profiler/ScriptGuard.kt`)
- Common collector → Root command runner: reads device data (evidence: `apk_profiler/CommonCollector.kt`)
- Hardware profiling → Root command runner: reads profiling logs (evidence: `apk_profiler/HardwareProfiler.kt`)
- Hardware profiling → Log parsing: parses profiler output (evidence: `apk_profiler/HardwareProfiler.kt`)
- Hardware profiling → GGUF inspection: uses model metadata (evidence: `apk_profiler/HardwareProfiler.kt`)
- Engineer → Governor loop: starts tuning (evidence: `README.md`)
- Governor loop → Project adapter: requests actions (evidence: `governor/engine.py`)
- Governor loop → Action policy: ranks actions (evidence: `governor/engine.py`)
- Governor loop → Performance cost model: updates estimates (evidence: `governor/engine.py`)
- Governor loop → Causal memory: uses causal memory (evidence: `governor/engine.py`)
- Governor loop → Provenance memory: uses provenance (evidence: `governor/engine.py`)
- Project adapter → OnePlus adapter: specializes device (evidence: `governor/op15.py`)
- OnePlus adapter → Layer format profiler: profiles layers (evidence: `governor/op15.py`)
- Benchmark fact indexing → Provenance memory: stores facts (evidence: `governor/index_facts.py`)
- Benchmark fact indexing → Causal memory: records relations (evidence: `governor/index_facts.py`)
- Engineer → Thermal and placement experiments: runs experiments (evidence: `README.md`)
- Thermal and placement experiments → Android device: measures placement and heat (evidence: `README.md`)
- Engineer → Layer campaigns: requests layer analysis (evidence: `README.md`)
