# arm-software/cmsis-nn architecture

> Architecture diagram of the GitHub repository arm-software/cmsis-nn, 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/arm-software/cmsis-nn
- Repository: https://github.com/arm-software/cmsis-nn

## Overview

##### Main Components
- Library Core: Represent the core neural network kernel implementations. Highlight the “Source” folder, which is further subdivided into directories for each operator category (e.g., ActivationFunctions, BasicMathFunctions, ConvolutionFunctions, Depthwise, FullyConnectedFunctions, LSTMFunctions, NNSupportFunctions, etc.). These are where the actual optimized implementations reside.
- Public Interface: Show the “Include” directory that contains the public API headers (for example, arm_nnfunctions.h and arm_nn_types.h) that expose the kernel functionality to client projects.
- Internal Interfaces: Optionally, include the “Include/Internal” subfolder that contains helper header files (such as the arm_nn_compiler.h) used privately by the library.
- Build and Configuration: Illustrate the presence of build configuration using CMake (CMakeLists.txt at top-level and in subdirectories) as well as the toolchain/integration with Arm Ethos-U Core Platform toolchain files. This part can include compiler flags and customization options (for example, CMSIS_OPTIMIZATION_LEVEL and OPTIONAL_RESTRICT_KEYWORD).
- Testing Infrastructure: Represent the “Tests/UnitTest” directory where unit tests are organized per operator or group (e.g., RefactoredTestGen, TestCases). This verifies that each algorithm’s performance and accuracy are validated against reference data.
- Documentation: Include the “Documentation” folder showing Doxygen configurations and scripts to auto-generate the library’s documentation.
- CI/External Integration: Optionally, you may also show integration with GitHub workflows, dependency configuration (e.g., .github/workflows and .clang-format), and version check scripts (such as check_pdsc.sh, check_version_and_date.sh).

##### Out the Operator Variants
- Which quantitative precision is supported – int8, int16, and in some cases int4 – as specified in the README’s feature table.

##### Detail the Separation of Interface and Implementation
- Optionally, include how “Internal” headers support the implementation and act as glue between various modules.

##### Build and Testing Flow
- A module/block for the build system where the top-level CMakeLists.txt aggregates submodule builds. Note that toolchain configuration (e.g. TARGET_CPU and optimization flags) is provided during the build process.
- A component for Unit Testing (from “Tests/UnitTest”) which feeds test data and validates each operator function. Indicate that integration and regression tests run via scripts like “build_and_run_tests.sh.”

##### Final Remarks
- Strive for detail – separate CMSIS-NN into as many distinct architectural components as possible using the file tree. This design helps contributors quickly locate and understand each module’s role in the overall system.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% API & Interfaces
    subgraph "API & Interfaces"
        API["Public API Headers (Include)"]:::api
        Internal["Internal Helper Headers (Include/Internal)"]:::api
    end

    %% Library Core
    subgraph "Library Core"
        Core["Library Core (Source)"]:::core
        A["Activation Functions"]:::core
        B["Basic Math Functions"]:::core
        C["Convolution Functions"]:::core
        FC["Fully Connected Functions"]:::core
        LSTM["LSTM Functions"]:::core
        NN["NNSupport Functions"]:::core

        %% Operator Variants for Convolution
        subgraph "Convolution Variants"
            C_C["Pure C"]:::variant
            C_D["DSP Optimized"]:::variant
            C_M["MVE Optimized"]:::variant
        end
        C --> C_C
        C --> C_D
        C --> C_M
    end

    %% Build & Configuration
    subgraph "Build & Configuration"
        CMake["Top-level CMake (CMakeLists.txt)"]:::build
        SourceCMake["Source CMake (Source/CMakeLists.txt)"]:::build
        Scripts["Build Scripts (check_pdsc.sh, check_version_and_date.sh, gen_pack.sh)"]:::build
    end

    %% Testing Infrastructure
    subgraph "Testing & Validation"
        UnitTest["Unit Tests (Tests/UnitTest)"]:::test
    end

    %% Documentation and CI/External Integration
    subgraph "Documentation & CI"
        Doc["Documentation Generator"]:::doc
        CI["CI/External Integration"]:::ci
    end

    %% Relationships
    API -->|"exposes"| Core
    Internal -->|"supports"| Core
    Core -->|"compiled via"| CMake
    Core -->|"compiled via"| SourceCMake
    Scripts -->|"triggers build of"| Core
    Core -->|"validated by"| UnitTest
    Doc -->|"documents"| Core
    CI -->|"automates build via"| CMake

    %% Click Events
    click Core "https://github.com/arm-software/cmsis-nn/tree/main/Source/"
    click A "https://github.com/arm-software/cmsis-nn/tree/main/Source/ActivationFunctions"
    click B "https://github.com/arm-software/cmsis-nn/tree/main/Source/BasicMathFunctions"
    click C "https://github.com/arm-software/cmsis-nn/tree/main/Source/ConvolutionFunctions"
    click FC "https://github.com/arm-software/cmsis-nn/tree/main/Source/FullyConnectedFunctions"
    click LSTM "https://github.com/arm-software/cmsis-nn/tree/main/Source/LSTMFunctions"
    click NN "https://github.com/arm-software/cmsis-nn/tree/main/Source/NNSupportFunctions"
    click API "https://github.com/arm-software/cmsis-nn/tree/main/Include/"
    click Internal "https://github.com/arm-software/cmsis-nn/tree/main/Include/Internal/"
    click CMake "https://github.com/arm-software/cmsis-nn/blob/main/CMakeLists.txt"
    click SourceCMake "https://github.com/arm-software/cmsis-nn/blob/main/Source/CMakeLists.txt"
    click UnitTest "https://github.com/arm-software/cmsis-nn/tree/main/Tests/UnitTest/"
    click Doc "https://github.com/arm-software/cmsis-nn/blob/main/Documentation/Doxygen/gen_doc.sh"
    click CI "https://github.com/arm-software/cmsis-nn/tree/main/.github/workflows"

    %% Styles
    classDef api fill:#CCF,stroke:#333,stroke-width:2px;
    classDef core fill:#FCE,stroke:#333,stroke-width:2px;
    classDef variant fill:#EFE,stroke:#333,stroke-width:2px;
    classDef build fill:#CFC,stroke:#333,stroke-width:2px;
    classDef test fill:#FCC,stroke:#333,stroke-width:2px;
    classDef doc fill:#FCF,stroke:#333,stroke-width:2px;
    classDef ci fill:#FFC,stroke:#333,stroke-width:2px;
```
