# allenzyj/edge-computing-engine architecture

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

- Interactive diagram: https://gitdiagram.com/allenzyj/edge-computing-engine
- Repository: https://github.com/allenzyj/edge-computing-engine

## Overview

##### Main Components
- Computational Graph Core: This includes the key classes like ComputeGraph and ComputeNode, which manage the creation of nodes and orchestrate forward and backward propagation.
- Matrix Computation Modules: Include both the CPU-based matrix operations (such as reading CSV files, performing basic arithmetic, transposition, slicing, etc.) and CUDA-accelerated operations (e.g. Matrix_CU in the cuda_mat directory).
- CUDA Kernel Layer: Represent the CUDA kernels responsible for operations such as ReLU, Sigmoid, matrix multiplication (both forward and backward kernels), element-wise operations, and any helper kernels like negGradKernel.
- Automatic Differentiation (Autodiff): Modules in the autodiff directory provide support for differentiating matrix operations, fixed-point arithmetic (or the like), and likely involve classes and headers for computing gradients.
- CPU Miscellaneous Utilities: This includes helper files for CSV reading, broadcasting, and high-level APIs for operations like fully connected layers, activation functions, and loss computations.
- Build and Installation Tools: The install_diff directory (with its examples, Makefiles, and installation scripts) demonstrates how the engine is built, installed, and how sample applications are structured.

##### Relationships and Interactions
- Input Data Workflow: Start with the data input (whether via CSV file reading or through CUDA matrix initialization), as well as parameter initialization.
- Forward Propagation: Show how input flows into the ComputeGraph to generate intermediate outputs – e.g., passing through functionalities like matrix multiplication and activation functions (ReLU, Sigmoid).
- Testing & Examples: Include a node or a module representing the example executables (e.g., those in install_diff/bin, conv_test.cpp, etc.) which serve as validation for the engine’s core functionalities.

##### Architectural Patterns and Design Principles
- Modular Separation: Clearly distinguish between the GPU/CUDA modules and the CPU/autodiff modules. This separation helps in understanding dependencies and allows extensibility in GPU acceleration.
- Computational Graph Pattern: Emphasize that the core engine is built around creating and manipulating a computational graph where nodes represent operations (OP_INPUT, OP_ADD, OP_MATMUL, etc.) with explicit data flows.
- Build and Deployment Automation: The Makefiles and installation directories (install_diff, root/Makefile) illustrate a well-defined build process, which could be depicted as part of the “Deployment” or “Build” modules.

##### Relevant Technologies and Frameworks
- C++ (with C++11 or above) as the primary programming language.
- CUDA Toolkit and nvcc for GPU-accelerated operations.
- Standard build tools (Makefiles) and version control (Git, GitHub workflows).
- The integration of libraries for matrix operations and automatic differentiation.

##### Instructing the Principal Software Engineer
- Data Input & Preprocessing
- Computational Graph Core (includes ComputeGraph and ComputeNode)
- Matrix Computation Modules (CPU-based and CUDA-accelerated)
- CUDA Kernel Execution Layer
- Automatic Differentiation & Gradient Flow
- Testing, Examples, and Deployment Build Infrastructure
- Component with key technologies (e.g., “CUDA: matmulForwardKernel, reluForwardKernel,” “Autodiff Module: autodiff/graphs, nodes, etc.”) to provide context.
- Finally, provide detailed notes on how testing and build scripts integrate with the runtime architecture to ensure correctness and performance (link the CI/CD in the .github/workflows directory and build instructions in Makefiles).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    DataInput["Data Input & Preprocessing"]:::input

    %% Computational Graph Core Subgraph
    subgraph "Computational Graph Core"
        ComputeGraphCPU["Compute Graph (Core CPU)"]:::core
        ComputeNodeCPU["Compute Node (Core CPU)"]:::core
    end

    %% Matrix Computation Modules Subgraph
    subgraph "Matrix Computation Modules"
        %% CPU-based Matrix Modules
        subgraph "CPU Modules"
            MatrixCPUD["Matrix CPU: Def"]:::cpu
            MatrixCPUPro["Matrix CPU: Pro"]:::cpu
        end
        %% CUDA-based Matrix Modules and Kernel Layer
        subgraph "CUDA Modules"
            CUDAMatCuDef["CUDA Matrix: CuDef"]:::gpu
            CUDAMatAdd["CUDA Matrix: Add"]:::gpu
            CUDAMatGrad["CUDA Matrix: Grad"]:::gpu
        end
    end

    %% Automatic Differentiation Subgraph
    subgraph "Automatic Differentiation"
        AutodiffGraph["Autodiff Graph"]:::autodiff
        AutodiffNode["Autodiff Node"]:::autodiff
    end

    %% Build and Installation Tools
    BuildInstall["Build & Installation Tools"]:::build

    %% Connections
    DataInput -->|"inputPropagation"| ComputeGraphCPU
    ComputeGraphCPU -->|"nodeCreation"| ComputeNodeCPU

    %% Matrix Modules interactions
    ComputeGraphCPU -->|"CPU_MatrixOps"| MatrixCPUD
    ComputeGraphCPU -->|"CPU_MatrixOps"| MatrixCPUPro
    ComputeGraphCPU -->|"CUDA_Offload"| CUDAMatCuDef
    CUDAMatCuDef -->|"KernelExec"| CUDAMatAdd
    CUDAMatAdd -->|"KernelExec"| CUDAMatGrad
    CUDAMatGrad -->|"GPUResults"| ComputeGraphCPU

    %% Autodiff interactions for backward propagation
    ComputeGraphCPU -->|"BackwardProp"| AutodiffGraph
    AutodiffGraph -->|"ComputeGrad"| AutodiffNode
    AutodiffNode -->|"GradUpdate"| ComputeGraphCPU

    %% Build and Deployment flow
    ComputeGraphCPU -->|"BuildTest"| BuildInstall

    %% Click Events for Computational Graph Core
    click ComputeGraphCPU "https://github.com/allenzyj/edge-computing-engine/blob/master/root/include/graph.h"
    click ComputeNodeCPU "https://github.com/allenzyj/edge-computing-engine/blob/master/root/include/node.h"

    %% Click Events for Matrix Computation Modules (CPU-based)
    click MatrixCPUD "https://github.com/allenzyj/edge-computing-engine/blob/master/matrix/matrix_def.h"
    click MatrixCPUPro "https://github.com/allenzyj/edge-computing-engine/blob/master/matrix/matrix_pro.h"

    %% Click Events for Matrix Computation Modules (CUDA-accelerated)
    click CUDAMatAdd "https://github.com/allenzyj/edge-computing-engine/blob/master/cuda_mat/add.cu"
    click CUDAMatGrad "https://github.com/allenzyj/edge-computing-engine/blob/master/cuda_mat/mat_grad.cu"
    click CUDAMatCuDef "https://github.com/allenzyj/edge-computing-engine/blob/master/cuda_mat/matrix_cudadef.cu"

    %% Click Events for Automatic Differentiation
    click AutodiffGraph "https://github.com/allenzyj/edge-computing-engine/blob/master/autodiff/graph.h"
    click AutodiffNode "https://github.com/allenzyj/edge-computing-engine/blob/master/autodiff/node.h"

    %% Click Event for Build & Installation Tools
    click BuildInstall "https://github.com/allenzyj/edge-computing-engine/tree/master/install_diff/"

    %% Styles
    classDef input fill:#FFCCCC,stroke:#333,stroke-width:2px;
    classDef core fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef cpu fill:#BBF,stroke:#333,stroke-width:2px;
    classDef gpu fill:#FFDAB9,stroke:#333,stroke-width:2px;
    classDef autodiff fill:#D9B3FF,stroke:#333,stroke-width:2px;
    classDef build fill:#CFC,stroke:#333,stroke-width:2px;
```
