# ztachip/ztachip architecture

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

- Interactive diagram: https://gitdiagram.com/ztachip/ztachip
- Repository: https://github.com/ztachip/ztachip

## Overview

##### Main Components
- Hardware Block:
- RISC-V Core: Typically implemented by the VexRiscv CPU that coordinates system control.
- Mcore (Scheduling Processor): Manages scheduling on the accelerator.
- Dataplane: Feeds data and instructions to the tensor engine.
- Tensor Engine: Contains 28 (configurable) Pcores configured as a systolic array for in-memory computation, with individual ALUs and multi-threaded execution.
- Scratch-Pad Memory: For temporary data storage.
- Stream Processor: Handles I/O operations across the bus.
- Peripherals: Such as DRAM, camera interfaces, VGA output, and additional I/O.
- AXI Bus: The central communication fabric that wires together the main hardware components and peripherals.
- FPGA/ASIC Wrapper: Under “HW/platform”, show different implementation branches (Xilinx, Altera, simulation).

- Software Block:
- Ztachip DSL Compiler (in SW/compiler): Translates the C-like DSL into accelerator instructions.
- AI Vision Libraries and Application Examples (in SW/apps): Implements vision kernels (e.g., canny edge, Harris corner, neural nets, optical flow, etc.) demonstrating the acceleration.
- Runtime Libraries and Base Drivers (in SW/base & SW/src): Provide runtime support and SoC integration, including C/C++ or Micropython interfaces.
- Micropython Port: A separate branch (micropython folder) which offers a Python programming interface to run on the accelerator.
- File System/Inference Data (in SW/fs): Holds AI models and other binary data transferred to the system.

- Tools & Documentation:
- FPGA build and simulation scripts (under tools) for firmware programming and hardware simulation.
- Documentation directories that offer detailed technical overviews and hardware/software design guides.

##### Relationships and Interactions
- A separation between the hardware (physical RTL components and interconnects) and the software (compiler, runtime, and applications).
- For the Hardware:
– Indicate “Platform” wrappers that allow for different FPGA/ASIC implementations.
- For the Software:
– Map out the flow from high-level application code (e.g., vision tasks) written in either C/C++ or Micropython down through the runtime libraries and the DSL compiler to the generated instructions that drive the hardware accelerator.
– Show the DSP compiler output connecting to the hardware accelerator.
- Build and simulation process to both hardware (verified via simulation RTL files) and software images (standalone image vs. micropython image).

##### Architectural Patterns and Design Principles
- Hardware/Software Co-design: The system is clearly divided into an accelerator hardware block and its corresponding software stack.
- Modular and Layered Approach: For the hardware, modules such as the dataplane, tensor engine, and peripherals are isolated; for the software, separate modules exist for the DSL compiler, application libraries, and runtime environment.
- Dual-Boot Options: Clearly indicate the two build images – one standalone (native C/C++ interface) and one micropython-based, emphasizing how applications interface with the system.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Hardware Subsystem
    subgraph "Hardware Subsystem"
        CPU["VexRiscv CPU"]:::hardware
        MCore["Mcore Scheduler"]:::hardware
        DP["Dataplane"]:::hardware
        TE["Tensor Engine (28 Pcores)"]:::hardware
        SPM["Scratch-Pad Memory"]:::hardware
        SP["Stream Processor"]:::hardware
        PER["Peripherals"]:::hardware
        AXI["AXI Bus"]:::hardware
        WRAP["FPGA/ASIC Wrapper"]:::hardware
    end

    %% Software Subsystem
    subgraph "Software Subsystem"
        APPS["AI Vision Applications"]:::software
        COMP["Ztachip DSL Compiler"]:::software
        RUNTIME["Runtime Libraries & Base Drivers"]:::software
        MICRO["Micropython Port"]:::software
        FS["File System/Inference Data"]:::software
    end

    %% Tools & Documentation
    subgraph "Tools & Documentation"
        BUILDTOOLS["FPGA Build and Simulation Tools"]:::tools
        DOCS["Documentation"]:::tools
    end

    %% Hardware Connections
    CPU --> AXI
    MCore --> AXI
    DP --> AXI
    TE --> AXI
    SPM --> AXI
    SP --> AXI
    PER --> AXI
    AXI --> WRAP

    %% Software Flow
    FS --> APPS
    APPS --> COMP
    APPS --> MICRO
    COMP --> RUNTIME
    MICRO --> RUNTIME
    RUNTIME --> AXI

    %% Tools Connections
    BUILDTOOLS --> COMP
    BUILDTOOLS --> WRAP
    DOCS --> BUILDTOOLS

    %% Class Definitions for coloring
    classDef hardware fill:#ffcccc,stroke:#aa2222,stroke-width:2px;
    classDef software fill:#ccffcc,stroke:#22aa22,stroke-width:2px;
    classDef tools fill:#ccccff,stroke:#2222aa,stroke-width:2px;

    %% Click Events
    click CPU "https://github.com/ztachip/ztachip/tree/master/HW/riscv"
    click MCore "https://github.com/ztachip/ztachip/blob/master/SW/compiler/mcore.cpp"
    click DP "https://github.com/ztachip/ztachip/tree/master/HW/src/dp"
    click TE "https://github.com/ztachip/ztachip/tree/master/HW/src/pcore"
    click SPM "https://github.com/ztachip/ztachip/tree/master/HW/src/soc/tcm"
    click SP "https://github.com/ztachip/ztachip/blob/master/HW/src/top/sram.vhd"
    click PER "https://github.com/ztachip/ztachip/tree/master/HW/src/soc/peripherals"
    click AXI "https://github.com/ztachip/ztachip/tree/master/HW/src/soc/axi"
    click WRAP "https://github.com/ztachip/ztachip/tree/master/HW/platform"
    click COMP "https://github.com/ztachip/ztachip/tree/master/SW/compiler"
    click APPS "https://github.com/ztachip/ztachip/tree/master/SW/apps"
    click RUNTIME "https://github.com/ztachip/ztachip/tree/master/SW/base"
    click MICRO "https://github.com/ztachip/ztachip/tree/master/micropython/ztachip_port"
    click FS "https://github.com/ztachip/ztachip/tree/master/SW/fs"
    click BUILDTOOLS "https://github.com/ztachip/ztachip/tree/master/tools"
    click DOCS "https://github.com/ztachip/ztachip/tree/master/Documentation"
```
