# johnponggit/easydk architecture

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

- Interactive diagram: https://gitdiagram.com/johnponggit/easydk
- Repository: https://github.com/johnponggit/easydk

## Overview

##### Main components
- Core EasyDK Modules:
- Platform: Initialization routines, hardware information retrieval (see “include/cnedk_platform.h” and “src/cnedk_platform.cpp”).
- Buffer Management (BufSurface): Buffer description and management functions (found in “include/cnedk_buf_surface.h” and related source files in “src/”).
- Decode/Encode: Modules dedicated to hardware-accelerated video & image decode (e.g., “src/cnedk_decode.cpp”, “src/ce3226/cnedk_decode_impl_ce3226.cpp”, etc.) and encode operations.
- Transform & OSD: Image transformation utilities and on-screen display drawing (modules in “include/cnedk_transform.h”, “src/cnedk_transform.cpp”, “include/cnedk_osd.h”, “src/cnedk_osd.cpp”).
- VIN/VOUT: Components for capturing camera input and rendering output (refer to “include/cnedk_vin_capture.h”, “include/cnedk_vout_display.h”, and corresponding source files).

- InferServer:
- Model Management: Modules for model loading and management (located in “src/infer_server/model”).
- Processing Pipeline: The processor component, which handles backend pre- and post-processing (in “src/infer_server/processor”).
- Core Inference Engine: Components to handle task scheduling, session management, and inference execution (found in “src/infer_server/core”).

- Hardware Specific Implementations:
- Implementation variations are organized per hardware series (subdirectories “ce3226”, “mlu370”, “mlu590” in “src/”). These show how the same API may be supported with different hardware-specific optimizations or adaptations.

- Python Wrappers:
- The “python” directory contains C++ source files for wrapping core APIs (using pybind11), making the library accessible in a Python environment.

- Supporting Build and Test Infrastructure:
- 3rd party libraries: GoogleTest for testing (“3rdparty/googletest” and “unitest” folders), libyuv for image manipulation, and pybind11 for Python interfacing.
- Extensive sample directories (e.g., “samples” and “python/samples”) that demonstrate usage of the toolkit, including an “easy_pipeline” which likely shows a complete pipeline integration (from decode/encode to inference).

##### Relationships and interactions
- Inside the InferServer container, further split the responsibilities into Model Management, Processor (handling pre/post processing), and the core InferServer functionality (session, engine, scheduling).
- For video/image processing: Data flows from VIN (capture) → Buffer Management → Decode → Transform → OSD/VOUT, or through encode after processing.
- For inference: Input (decoded/processed frames) flows into the InferServer engine, which utilizes the Model and Processor modules, and then feeds results back into the pipeline.
- Also, indicate that the Python wrappers interact with these native modules, providing a separate layer that calls into the core functions.

##### Architectural patterns and design principles
- Modularity: Each feature (e.g., decode, encode, transform) is encapsulated into separate modules, which helps in maintaining clear interfaces.
- Hardware Abstraction: The use of different subdirectories (ce3226, mlu370, mlu590) shows a plug-in like strategy to support multiple Cambricon hardware platforms.
- Testability: The presence of unit tests (using GoogleTest) and integration tests emphasizes a robust, test-driven approach.
- Extensibility: The InferServer API design, with separate modules for model, processor, and inference, supports customization of the AI pipeline.

##### Relevant technologies and frameworks
- C/C++ as the primary language for high-performance modules.
- GoogleTest for unit testing.
- CMake for building the system (evident from multiple CMakeLists.txt files).
- pybind11 for building the Python wrappers.
- 3rd party libraries like libyuv for image and video processing tasks.

##### Elements
- A distinct container for the InferServer showing Model, Processor, and Core Inference Engine.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "EasyDK Core (Media Processing Pipeline)"
        Platform["Platform"]:::core
        BufSurface["BufSurface"]:::core
        DecodeEncode["Decode/Encode"]:::core
        Transform["Transform"]:::core
        Osd["OSD"]:::core
        Vin["VIN Capture"]:::core
        Vout["VOUT Display"]:::core
    end

    subgraph "InferServer Pipeline"
        InferModel["Model Management"]:::infer
        InferProcessor["Processor"]:::infer
        InferCore["Core Inference Engine"]:::infer
    end

    subgraph "Hardware Abstraction"
        CE3226["CE3226"]:::hardware
        MLU370["MLU370"]:::hardware
        MLU590["MLU590"]:::hardware
    end

    PythonWrappers["Python Wrappers"]:::python
    BuildTest["Build & Test Infrastructure"]:::test

    %% Media processing flow
    Vin -->|"flow"| BufSurface
    BufSurface -->|"flow"| DecodeEncode
    DecodeEncode -->|"flow"| Transform
    Transform -->|"flow"| Osd
    Transform -->|"flow"| Vout

    %% Inference integration
    Transform -->|"inference"| InferCore
    InferCore -->|"results"| Osd
    InferModel -->|"supplies_model"| InferCore
    InferProcessor -->|"prepost"| InferCore

    %% Hardware-specific integrations
    Platform -->|"hw_info"| CE3226
    Platform -->|"hw_info"| MLU370
    Platform -->|"hw_info"| MLU590
    DecodeEncode -->|"hw_opt"| CE3226
    DecodeEncode -->|"hw_opt"| MLU370
    DecodeEncode -->|"hw_opt"| MLU590
    Transform -->|"hw_opt"| CE3226
    Transform -->|"hw_opt"| MLU370
    Transform -->|"hw_opt"| MLU590

    %% Python wrappers calling into core modules
    PythonWrappers -->|"calls"| Platform
    PythonWrappers -->|"calls"| BufSurface
    PythonWrappers -->|"calls"| DecodeEncode
    PythonWrappers -->|"calls"| Transform
    PythonWrappers -->|"calls"| Osd
    PythonWrappers -->|"calls"| InferCore

    %% Build and Test infrastructure
    BuildTest -->|"tests"| Platform
    BuildTest -->|"tests"| BufSurface
    BuildTest -->|"tests"| DecodeEncode
    BuildTest -->|"tests"| Transform
    BuildTest -->|"tests"| Osd
    BuildTest -->|"tests"| Vin
    BuildTest -->|"tests"| Vout
    BuildTest -->|"tests"| PythonWrappers
    BuildTest -->|"tests"| InferCore

    %% Class Definitions for coloring
    classDef core fill:#a8d08d,stroke:#333,stroke-width:2px;
    classDef infer fill:#f4b183,stroke:#333,stroke-width:2px;
    classDef hardware fill:#9fc5e8,stroke:#333,stroke-width:2px;
    classDef python fill:#d9d2e9,stroke:#333,stroke-width:2px;
    classDef test fill:#ffe599,stroke:#333,stroke-width:2px;

    %% Click Events
    click Platform "https://github.com/johnponggit/easydk/blob/master/include/cnedk_platform.h"
    click BufSurface "https://github.com/johnponggit/easydk/blob/master/include/cnedk_buf_surface.h"
    click DecodeEncode "https://github.com/johnponggit/easydk/blob/master/include/cnedk_decode.h"
    click Transform "https://github.com/johnponggit/easydk/blob/master/include/cnedk_transform.h"
    click Osd "https://github.com/johnponggit/easydk/blob/master/include/cnedk_osd.h"
    click Vin "https://github.com/johnponggit/easydk/blob/master/include/cnedk_vin_capture.h"
    click Vout "https://github.com/johnponggit/easydk/blob/master/include/cnedk_vout_display.h"
    click InferModel "https://github.com/johnponggit/easydk/tree/master/src/infer_server/model"
    click InferProcessor "https://github.com/johnponggit/easydk/tree/master/src/infer_server/processor"
    click InferCore "https://github.com/johnponggit/easydk/tree/master/src/infer_server/core"
    click CE3226 "https://github.com/johnponggit/easydk/tree/master/src/ce3226"
    click MLU370 "https://github.com/johnponggit/easydk/tree/master/src/mlu370"
    click MLU590 "https://github.com/johnponggit/easydk/tree/master/src/mlu590"
    click PythonWrappers "https://github.com/johnponggit/easydk/tree/master/python"
    click BuildTest "https://github.com/johnponggit/easydk/tree/master/unitest"
```
