How pulp-platform/dory works
Project type and purpose
• DORY is a command-line, full-pipeline code-generation tool written in Python. It ingests quantized ONNX graphs (from Nemo/Quantlab), formulates a memory-tiling CP problem, and emits ANSI C code for multiple embedded hardware targets (GAP8, Diana, Occamy, PULP variants).
• It is neither a web app nor a microservice: it’s a modular, plugin-based compiler/code-generator.
File structure
• Top-level CLI scripts and Docker helper (network_generate.py, layer_generate.py, docker_utils/).
• Core Python package dory/ with subpackages:
• Frontend_frameworks: NEMO & Quantlab ONNX pattern matchers.
• Hardware_targets: one plugin per SoC family (Diana, Occamy, PULP/(GAP8, GAP9, etc.)).
• Parsers: graph converters (ONNX→DORY IR→HW IR→C).
• Utils/Templates_writer: Mako-based C code templates for layers, networks, Makefiles.
• Configuration files (*.json rules, HW_description.json, .yml CI).
• Tests and examples in conftest.py, test_PULP.py, dory_examples/.
Extract README insights
• Highlights a multi-stage flow: ONNX import → CP tiling (OR-Tools) → codegen
• External dependencies: mako, numpy, onnx, ortools, pulp-sdk / gap-sdk
• Docker image for environment reproducibility
Main components & interactions
a. Frontend Plugins
• NEMO Parser
• Quantlab Parser
→ transform ONNX into DORY graphnodes.
b. Core Engine
• DORY IR (DORY_node, Layer_node, HW_node)
• Constraint Programming Solver (OR-Tools) → computes L3/L2/L1 tiling parameters.
c. Parsers/Translators
• Parser_DORY_to_HW: adapts DORY IR to hardware-specific IR.
• Parser_HW_to_C: prepares for codegen.
d. Templates & Code Generation
• Templates_writer: layer, network, Makefile templates (Mako)
→ Merges IR + tiling results into C, header, Makefiles.
e. Hardware Backends (plugin-based)
• Diana_SoC & Diana_TVM
• Occamy
• PULP family (GAP8, GAP9, NE16, gvsoc, etc.)
→ each provides Parsers, Pattern_rewriter, Templates, Utils_files
f. Output
• Generated C project tree (+ pulp-nn submodule) ready to compile/deploy.
g. Docker Environment
• docker_utils scripts → Dockerfile → reproducible Python + SDK setup
ONNX Input → (1) Frontend → DORY IR → (2) CP Solver → DORY IR + tiling params → (3) Parser_DORY_to_HW → HW IR → (4) Parser_HW_to_C → Template Writers → C/Makefiles → Output directory
Architectural patterns & principles
• Plugin architecture: separate Frontend_frameworks and Hardware_targets directories—each can be extended independently.
• Pipeline (compiler-style) pattern: successive transforms from ONNX → IR → optimized IR → code.
• Template-based codegen (Mako) for flexibility and hardware-specific customization.
• Separation of concerns: parsing, optimization (tiling), codegen, and platform integration are decoupled.
Essential elements to capture
• All plugin directories under dory/Frontend_frameworks and dory/Hardware_targets.
• Parsers in dory/Parsers.
• Utils/Templates_writer module.
• Docker scripts and CI workflows.
• External dependencies block.