How hqu-little-boy/ncnn-compiler works
ncnn-compiler turns an ncnn .param network and .bin weights into a Linux shared library and model-specific C ABI header. The main user workflow runs through ncnn-compile, which orchestrates import and staged MLIR lowering before code generation, linking, and execution checks. The graph also preserves the documented debug-driver path and the execution-plan and profiling capabilities. Stage ordering is based on the README and pipeline excerpts; unsampled implementation details are not expanded into additional call relationships.
Main entry points: CompileSession.cpp Compile session · CompileSession.hpp Header and shared library · ncnn-mlir-driver.cpp MLIR debug driver · NCNNPipelines.cpp NCNN to TOSA
Components 20
Model frontend
- ncnn-compile
tools/ncnn-compile.cpp - Compile session
tools/CompileSession.cpp - Graph parser
lib/Graph/parser.cpp - Parsed graph
lib/Graph/graph.cpp - NCNN importer
lib/Importer/NCNNImporter.cpp - MLIR debug driver
tools/ncnn-mlir-driver.cpp
IR lowering
- NCNN dialect
lib/Dialect/NCNN/IR/NCNNDialect.cpp - NCNN to TOSA
lib/Pipelines/NCNNPipelines.cpp - TOSA conversion
lib/Conversion/NCNNToTosa/NCNNToTosa.cpp - Linalg optimization
lib/Transforms/StrategyNCNN/StrategyNCNN.cpp - Bufferization
lib/Transforms/BufferizeNCNN/BufferizeNCNN.cpp
Code generation
- LLVM lowering
lib/Pipelines/NCNNPipelines.cpp - C ABI generation
lib/Transforms/GenerateCAPI/GenerateCAPIEmitWrapper.cpp - Header and shared library
tools/CompileSession.hpp
Plans and profiling
- Execution plan
lib/Transforms/EmitModelPlan/EmitModelPlan.cpp - Profile instrumentation
lib/Transforms/InstrumentNCNNProfile/InstrumentNCNNProfile.cpp - Profile runtime
lib/ProfileRuntime/profile_runtime.c - Attribution reports
tools/attr/attr_report.py
Other components
- ncnn model files
- C/C++ consumer
Connections 24
- ncnn model files → ncnn-compile: provides inputs
- ncnn-compile → Compile session: starts session
- ncnn model files → MLIR debug driver: provides inputs
- MLIR debug driver → Graph parser: parses parameters
- Compile session → Graph parser: imports model
- Graph parser → Parsed graph: builds graph
- Parsed graph → NCNN importer: supplies layers
- MLIR debug driver → NCNN importer: runs frontend
- NCNN importer → NCNN dialect: builds IR
- Compile session → NCNN to TOSA: runs pipeline
- NCNN to TOSA → TOSA conversion: lowers NCNN
- TOSA conversion → Linalg optimization: produces Linalg
- Linalg optimization → Bufferization: lowers to buffers
- Bufferization → LLVM lowering: lowers to LLVM
- Compile session → C ABI generation: emits ABI
- Compile session → Execution plan: requests plan
- Compile session → Header and shared library: publishes outputs
- C ABI generation → Header and shared library: emits header
- LLVM lowering → Header and shared library: feeds native link
- C/C++ consumer → Header and shared library: calls model API
- NCNN to TOSA → Profile instrumentation: adds instrumentation
- Profile instrumentation → Profile runtime: emits callbacks
- Profile runtime → Attribution reports: provides measurements
- Execution plan → Attribution reports: provides plan data