GPHO (Gating-Pass for Heterogeneous Offload) is an integrated LLVM 18 compiler pass paired with an asymmetric machine learning gating engine (XGBoost) and a first-principles hardware cost model. GPHO predicts whether candidate parallel loops are GPU-profitable (
"Not an unconstrained ML speedup oracle — a risk-managed, explainable compiler gating pass."
flowchart TD
A[Source Code: C / C++] -->|clang -O3 -emit-llvm| B[LLVM 18 SSA Intermediate Representation]
B --> C[GPHO LLVM 18 Analysis Pass]
subgraph LLVM Core Analyses
C --> D[ScalarEvolution - SCEV Trip Counts & Affine Strides]
C --> E[TargetTransformInfo - Instruction Throughput Costs]
C --> F[DependenceAnalysis - Loop-Carried Memory Safety]
end
C -->|Emits 12 Static IR Metrics JSON| G[Hybrid Graph Topology Encoder]
G -->|Extracts 4D CFG/DFG Topology Embedding| H[16D Enriched Feature Vector]
subgraph Asymmetric Decision Engine
H --> I[Asymmetric XGBoost Classifier: alpha = 3.5]
H --> J[Tree SHAP Local Feature Attribution]
H --> K[Analytical First-Principles Cost Baseline]
end
I & J & K --> L{GPHO Gate Decision}
L -->|Speedup >= 1.20x| M["[✓] GPU ACCEPTED: #pragma omp target teams distribute parallel for if(target: ...)"]
L -->|Speedup < 1.20x| N["[✗] GPU REJECTED: #pragma omp parallel for (Execute on Multicore CPU)"]
| Component | Path | Description |
|---|---|---|
| LLVM 18 C++ Pass | pass/GPHOAnalysisPass.cpp |
Extracts 12 IR structural metrics via SCEV, TTI, DA, BFI into JSON. |
| Pass Header | pass/GPHOAnalysisPass.h |
Declares pass classes, GPHOLoopMetrics struct, and analysis helpers. |
| Graph Encoder | ml/graph_encoder.py |
Generates 4D topological embeddings ( |
| Asymmetric Trainer | ml/gpho_trainer.py |
XGBoost trainer with asymmetric loss ( |
| Hardware Heuristic | ml/heuristic_baseline.py |
Deterministic SIMD vs GPU/PCIe first-principles cost model. |
| Diagnostic Driver | driver/gpho_gate.py |
End-to-end CLI tool evaluating C / .ll files with colorized SHAP reports. |
| GEMM Benchmark | benchmarks/kernel_gemm.c |
Compute-bound dense GEMM ( |
| Strided Benchmark | benchmarks/kernel_strided.c |
Memory-bound strided traversal (bandwidth bottleneck) |
- LLVM 18:
llvm-18,llvm-18-dev,opt-18,clang-18 - C++ Compiler:
g++(C++17 support) - Build System:
cmake(3.20+) - Python: Python 3.10+ (with
xgboost,shap,scikit-learn,joblib,pandas,numpy)
uv venv .venv
uv pip install 'numpy<2' xgboost scikit-learn shap pandas matplotlib joblib cmake# Configure and compile GPHOPass.so
uv run cmake -B build -S .
uv run cmake --build build.venv/bin/python ml/gpho_trainer.py --alpha 3.5# Evaluate dense GEMM kernel (Accepted for GPU offloading)
.venv/bin/python driver/gpho_gate.py benchmarks/kernel_gemm.c
# Evaluate strided memory traversal (Rejected to avoid regression)
.venv/bin/python driver/gpho_gate.py benchmarks/kernel_strided.c========================================================================
GPHO COMPILER OPTIMIZATION REPORT: HETEROGENEOUS OFFLOAD GATING
========================================================================
Target Loop: main:loop0 (Source / Benchmark: kernel_gemm.c)
Trip Count: 1048576 (Nest Depth: 1)
Compute Profile: 2 FP Ops, 3 INT Ops (AI: 0.62 Ops/Byte)
Memory Profile: 2 Stride-1, 0 Strided (Transfer: 8388608 Bytes)
------------------------------------------------------------------------
GPHO Decision: [✓] GPU OFF-LOADING ACCEPTED (Confidence: 98.4%)
Predicted Speedup: 4.86x over Multithreaded CPU Baseline
Decision Reason: High arithmetic intensity & coalesced stride (Clear ML margin)
Heuristic Model: GPU (Estimated: T_CPU=2.95ms, T_GPU=0.61ms)
------------------------------------------------------------------------
Primary Factor Drivers (Tree SHAP Explainability):
[+] strided_accesses = 0.0 (SHAP impact: +4.990) -> Un-coalesced Memory Stride Bottleneck
[-] graph_mem_clustering = 0.0256 (SHAP impact: -0.357) -> Spatial Memory Clustering Index
[+] arithmetic_intensity = 0.625 (SHAP impact: +0.063) -> High Compute Density (FLOPs/Byte)
------------------------------------------------------------------------
Recommended OpenMP Directive:
#pragma omp target teams distribute parallel for if(target: N >= 1048576)
========================================================================
clang-18 -O3 -fno-vectorize -S -emit-llvm benchmarks/kernel_gemm.c -o gemm.ll
opt -load-pass-plugin=build/pass/GPHOPass.so \
-passes=gpho-analysis \
-gpho-benchmark-id=kernel_gemm \
-gpho-suite=polybench \
-gpho-json-out=features.json \
-disable-output gemm.llApache License 2.0. Built for LLVM 18 research and production compiler infrastructure.