# pulp-platform/deeploy architecture

> Architecture diagram of the GitHub repository pulp-platform/deeploy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pulp-platform/deeploy
- Repository: https://github.com/pulp-platform/deeploy

## Overview

##### Project Type and Purpose
- Deeploy is a domain‐specific compiler: it takes an ONNX neural network graph as input and emits highly optimized, low-level C code for various target SoCs (Generic CPU, Cortex-M, MemPool, Siracusa, Snitch, Neureka, PULPOpen).
- It is organized as a bottom-up, modular compilation framework where each stage of compilation and each hardware backend is factored into separate “extensions” or “targets.”

##### High-Level File Structure Analysis
Top-level directories:
- Container, Dockerfile, .github/workflows – CI/CD and containerized environment
- Deeploy/ – core compiler engine, IR definitions, pass managers, and plugin extensions
- Deeploy/Targets/… – one subdirectory per hardware backend (CortexM, Generic, MemPool, etc.), each containing parsers, platform modelling, deployers, code generation templates, tile constraints, type-checkers
- Deeploy/CommonExtensions, EngineExtension, MemoryLevelExtension, FutureExtension, TilingExtension – compiler passes grouped by functional phase (IR transforms, memory/scheduling passes, future‐proofing, tiling)
- TargetLibraries/… – low-level C runtime libraries per backend (e.g., CMSIS-NN for CortexM, PULP SDK for PULPOpen)
- DeeployTest/ – test harnesses and ONNX test models, with per-platform test runners
- cmake/, setup.py, pyproject.toml – build system configuration (Python packaging, CMake modules for cross-compilation)
- docs/ – Sphinx documentation and tutorials

##### Key Architectural Patterns and Components
- Layered, plugin-based compiler pipeline (frontend → IR → passes → backend codegen)
- Separation of concerns: “Core engine” (graph and data types, pass manager, common utilities) vs. “Extensions” (specialized passes) vs. “Targets” (hardware backends) vs. “Libraries” (runtime support) vs. “Tests & CI”
- Pipeline pattern: each pass consumes and produces an intermediate representation (IR) stored as Python data structures; final codegen backends traverse the IR to produce C templates.
- Backends follow the same structure: Parser (ONNX→IR), Platform (target capabilities), Deployer (maps IR onto platform model), Templates (C code snippets), TileConstraints & Tiler (for data partitioning).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Stage 1: Input Layer
    subgraph "Input Layer"
        ONNX["ONNX Model File"]:::external
        CLI["CLI/API (Test Runner Scripts)"]:::python
        CLI -->|"loads model"| ONNX
    end

    %% Stage 2: Compiler Frontend
    subgraph "Compiler Frontend"
        Parser["ONNX Parser"]:::python
        IR["Core IR & DataTypes"]:::python
        ONNX -->|"parsed by"| Parser
        Parser -->|"produces IR"| IR
    end

    %% Stage 3: Pass Manager & Extensions
    subgraph "Pass Manager & Extensions"
        PM["Pass Manager"]:::python
        CE["CommonExtensions"]:::python
        TE["TilingExtension"]:::python
        ME["MemoryLevelExtension"]:::python
        FE["FutureExtension"]:::python
        EE["EngineExtension"]:::python

        IR -->|"feeds into"| PM
        PM --> CE
        CE --> TE
        TE --> ME
        ME --> FE
        FE --> EE
        EE -->|"transforms IR"| TransIR["Transformed IR"]:::python
    end

    %% Stage 4: Backend Code Generation
    subgraph "Backend Code Generation"
        TransIR -->|"to CortexM"| CM_Parser
        TransIR -->|"to Generic"| G_Parser
        TransIR -->|"to MemPool"| MP_Parser
        TransIR -->|"to Neureka"| N_Parser
        TransIR -->|"to PULPOpen"| PP_Parser
        TransIR -->|"to Snitch"| S_Parser

        subgraph CortexM
            CM_Parser["Parser & Platform"]:::python
            CM_Deployer["Deployer"]:::python
            CM_Templates["Templates"]:::c
            CM_Tiler["TileConstraints & Tiler"]:::python
            CM_Parser --> CM_Deployer
            CM_Deployer --> CM_Templates
            CM_Deployer --> CM_Tiler
        end

        subgraph Generic
            G_Parser["Parser & Platform"]:::python
            G_Deployer["Deployer"]:::python
            G_Templates["Templates"]:::c
            G_Tiler["TileConstraints & Tiler"]:::python
            G_Parser --> G_Deployer
            G_Deployer --> G_Templates
            G_Deployer --> G_Tiler
        end

        subgraph MemPool
            MP_Parser["Parser & Platform"]:::python
            MP_Deployer["Deployer"]:::python
            MP_Templates["Templates"]:::c
            MP_Parser --> MP_Deployer
            MP_Deployer --> MP_Templates
        end

        subgraph Neureka
            N_Parser["Parser & Platform"]:::python
            N_Deployer["Deployer"]:::python
            N_Templates["Templates"]:::c
            N_Tiler["TileConstraints & Tiler"]:::python
            N_Parser --> N_Deployer
            N_Deployer --> N_Templates
            N_Deployer --> N_Tiler
        end

        subgraph PULPOpen
            PP_Parser["Parser & Platform"]:::python
            PP_Deployer["Deployer"]:::python
            PP_Templates["Templates"]:::c
            PP_Tiler["TileConstraints & Tiler"]:::python
            PP_Parser --> PP_Deployer
            PP_Deployer --> PP_Templates
            PP_Deployer --> PP_Tiler
        end

        subgraph Snitch
            S_Parser["Parser & Platform"]:::python
            S_Deployer["Deployer"]:::python
            S_Templates["Templates"]:::c
            S_Tiler["TileConstraints & Tiler"]:::python
            S_Parser --> S_Deployer
            S_Deployer --> S_Templates
            S_Deployer --> S_Tiler
        end
    end

    %% Stage 5: Runtime Libraries & Build System
    subgraph "Runtime & Build"
        CCode["C Source + Headers"]:::c
        Libs["Runtime Libraries"]:::c
        Build["CMake Build System"]:::infra
        CM_Templates --> CCode
        G_Templates --> CCode
        MP_Templates --> CCode
        N_Templates --> CCode
        PP_Templates --> CCode
        S_Templates --> CCode
        Libs --> Build
        CCode --> Build
        Build --> Executable["Executable/Simulator Image"]:::infra
    end

    %% Stage 6: Testing & CI/CD
    subgraph "Testing & CI/CD"
        ExecRunner["TestRunner Scripts"]:::python
        Docker["Dockerfile"]:::infra
        CI["GitHub Actions Workflows"]:::infra
        Executable --> ExecRunner
        ExecRunner -->|"runs tests"| CI
        CI -->|"reports results"| CLI
    end

    %% Click Events
    click CLI "https://github.com/pulp-platform/deeploy/blob/devel/DeeployTest/testRunner_generic.py"
    click Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Generic/Parsers.py"
    click IR "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/AbstractDataTypes.py"
    click IR "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/DeeployTypes.py"
    click CE "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/CommonExtensions/"
    click TE "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/TilingExtension/"
    click ME "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/MemoryLevelExtension/"
    click FE "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/FutureExtension/"
    click EE "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/EngineExtension/"
    click CM_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/CortexM/Parsers.py"
    click CM_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/CortexM/Platform.py"
    click CM_Deployer "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/CortexM/Deployer.py"
    click CM_Templates "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/Targets/CortexM/Templates/"
    click G_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Generic/Parsers.py"
    click G_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Generic/Platform.py"
    click G_Deployer "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Generic/Deployer.py"
    click G_Templates "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/Targets/Generic/Templates/"
    click G_Tiler "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Generic/Tiler.py"
    click MP_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/MemPool/Parsers.py"
    click MP_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/MemPool/Platform.py"
    click MP_Deployer "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/MemPool/Deployer.py"
    click MP_Templates "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/Targets/MemPool/Templates/"
    click N_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Neureka/Parsers.py"
    click N_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Neureka/Platform.py"
    click N_Deployer "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Neureka/Deployer.py"
    click N_Templates "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/Targets/Neureka/Templates/"
    click N_Tiler "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Neureka/Tiler.py"
    click PP_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/PULPOpen/Parsers.py"
    click PP_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/PULPOpen/Platform.py"
    click PP_Deployer "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/PULPOpen/Deployer.py"
    click PP_Templates "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/Targets/PULPOpen/Templates/"
    click PP_Tiler "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/PULPOpen/Tiler.py"
    click S_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Snitch/Parsers.py"
    click S_Parser "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Snitch/Platform.py"
    click S_Deployer "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Snitch/Deployer.py"
    click S_Templates "https://github.com/pulp-platform/deeploy/tree/devel/Deeploy/Targets/Snitch/Templates/"
    click S_Tiler "https://github.com/pulp-platform/deeploy/blob/devel/Deeploy/Targets/Snitch/Tiler.py"
    click Libs "https://github.com/pulp-platform/deeploy/tree/devel/TargetLibraries/"
    click Build "https://github.com/pulp-platform/deeploy/tree/devel/cmake/"
    click ExecRunner "https://github.com/pulp-platform/deeploy/tree/devel/DeeployTest/"
    click Docker "https://github.com/pulp-platform/deeploy/tree/devel/Container/Dockerfile"
    click CI "https://github.com/pulp-platform/deeploy/tree/devel/.github/workflows/"

    %% Styles
    classDef python fill:#D0E8FF,stroke:#000
    classDef c fill:#E0FFE0,stroke:#000
    classDef infra fill:#F0F0F0,stroke:#000
    classDef external fill:#FFD0D0,stroke:#000
```
