# tencent/wechat-tfcc architecture

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

- Interactive diagram: https://gitdiagram.com/tencent/wechat-tfcc
- Repository: https://github.com/tencent/wechat-tfcc

## Overview

##### Main Components
- TFCC Core Library (located in the “tfcc” directory):
– Implements the core deep learning functionalities.
– Contains submodules for allocators, dataloaders, exception handling, the framework (sessions, device management, tensor/variable handling, etc.), various operations (arithmetic, neural network, RNN, etc.), layers, and interfaces for abstracting different operations.
– Has separate implementations or interfaces to support both MKL (for CPU) and CUDA (for GPU) environments.
- TFCC Code Generator (in “tfcc_code_generator”):
– A toolchain that optimizes and converts high-level models from formats such as ONNX or TensorFlow into the TFCC model format.
– The backend part involves generating C++ code, using node generators, IR representations (using modules like ir, ir/optimizer, etc.), and runtime helpers.
- TFCC Runtime (in “tfcc_runtime”):
– Provides the infrastructure for loading and inferring a TFCC model.
– Contains components for model loading, operation execution, graph management, and communication/utilities.

##### Key Relationships and Interactions
- The Runtime component loads a TFCC model (as a string or binary blob) and interacts with the Core Library components to execute operations. Show a directional flow from “TFCC Runtime” to “TFCC Core Library.”
- The Core Library itself is internally modularized, interacting with low-level subcomponents in distinct layers:
– An “Interfaces/Operations Layer” supports both CPU (MKL) and GPU (CUDA) by abstracting backend-specific operations.
– “Exception Management,” “Dataloaders,” and “Allocators” provide foundational support.
- Third-party libraries (like xbyak in “3rd”) support dynamic code generation and may have utility roles especially in performance-critical parts. Represent these as auxiliary dependencies linked to the Core Library.

##### Architectural Patterns and Design Principles
- Modular design separating concerns: The core inference logic, code generation, and runtime loading are all independent modules that communicate in a pipeline.
- Abstraction for cross-platform execution: Multiple subdirectories under “tfcc” (and its “cuda” and “mkl” subdirectories) clearly show the use of the Strategy or Bridge pattern by abstracting operations through interfaces, enabling multiple backend implementations.

##### Technologies, Frameworks, and Tools
- C++ as the primary language, with CMake build scripts evident in many directories (e.g., tfcc/CMakeLists.txt, tfcc_code_generator).
- CUDA and MKL libraries to support GPU and high-performance CPU operations.
- Dynamic code generation utilities (e.g., xbyak) integrated into the system.
- Testing frameworks and sample code provided in “samples” and “tfcc/test”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Components
    CG_Main["TFCC Code Generator"]:::codegen
    RT_Main["TFCC Runtime"]:::runtime
    CORE_Main["TFCC Core Library"]:::core
    TP["xbyak (3rd Party)"]:::thirdparty

    %% Internal details for TFCC Code Generator
    CG_Main --> CG1["Frontend Converters (ONNX,TensorFlow)"]:::codegen
    CG1 --> CG2["IR Generation"]:::codegen
    CG2 --> CG3["Backend Code Generation"]:::codegen
    CG3 --> CG4["Node Generators"]:::codegen

    %% Internal details for TFCC Runtime
    RT_Main --> RT1["Model Loading"]:::runtime
    RT1 --> RT2["Graph Execution"]:::runtime
    RT2 --> RT3["Operation Dispatch"]:::runtime

    %% Internal details for TFCC Core Library
    CORE_Main --> CORE1["Allocators"]:::core
    CORE1 --> CORE2["Dataloaders"]:::core
    CORE2 --> CORE3["Exceptions"]:::core
    CORE3 --> CORE4["Framework (Sessions,Devices,Tensors)"]:::core
    CORE4 --> CORE5["Interfaces/Operations (CUDA/MKL)"]:::core
    CORE5 --> CORE6["Layers & RNN"]:::core
    CORE6 --> CORE7["Utilities"]:::core

    %% Connections between main components
    CG_Main -->|"ModelConversion"| RT_Main
    RT_Main -->|"InferenceFlow"| CORE_Main
    TP --- CORE_Main

    %% Classes for styling
    classDef core fill:#e3ffe3,stroke:#009933,stroke-width:2px;
    classDef codegen fill:#e6f7ff,stroke:#007acc,stroke-width:2px;
    classDef runtime fill:#fff0e6,stroke:#cc6600,stroke-width:2px;
    classDef thirdparty fill:#f0f0f0,stroke:#666666,stroke-width:2px,stroke-dasharray: 5 5;

    class CG_Main,CG1,CG2,CG3,CG4 codegen;
    class RT_Main,RT1,RT2,RT3 runtime;
    class CORE_Main,CORE1,CORE2,CORE3,CORE4,CORE5,CORE6,CORE7 core;
    class TP thirdparty;

    %% Click Events for component mapping
    click CG_Main "https://github.com/tencent/wechat-tfcc/tree/master/tfcc_code_generator"
    click RT_Main "https://github.com/tencent/wechat-tfcc/tree/master/tfcc_runtime"
    click CORE_Main "https://github.com/tencent/wechat-tfcc/tree/master/tfcc"
```
