# peterlee0127/tensorflow-nvjetson architecture

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

- Interactive diagram: https://gitdiagram.com/peterlee0127/tensorflow-nvjetson
- Repository: https://github.com/peterlee0127/tensorflow-nvjetson

## Overview

##### Project type and purpose
- This is an open-source build-and-packaging tool for producing TensorFlow wheel files optimized for Nvidia Jetson TX1/TX2.
- It automates fetching TensorFlow sources, applying Jetson-specific patches, compiling with Bazel against CUDA/CuDNN/TensorRT, and bundling the resulting binary into pip-installable wheels.

##### File structure
- Top‐level scripts:
- installBazel.sh, installTF.sh, buildTensorflow.sh – orchestration of dependencies and build steps
- patch/ – a catalog of .patch files for various TensorFlow versions
- tf-test/ – test harnesses split by TensorFlow major version (1.0, 2.0), with GPU validation and TensorRT conversion tests
- Configuration:
- .github/ – CI/deployment boilerplate (e.g., FUNDING.yml)
- .gitignore, .gitattributes, README.md, _config.yml – repository metadata and site build settings
- Version artifacts: wheel file parts and merge instructions are generated during the build.

##### README for additional insights
- Describes hardware prerequisites (JetPack, CUDA, cuDNN, TensorRT), environment setup, and Python dependencies (numpy, keras, hdf5).
- Outlines usage: download prebuilt wheel or run installTF.sh to fetch & install latest build.
- Demonstrates test outputs for GPU availability and TensorRT integration.

a. Source Repository
- Hosts scripts, patches, tests on GitHub
- CI/CD triggers (e.g., GitHub Actions) can invoke build scripts
b. Builder Environment
- Linux host emulating Jetson or actual Jetson TX1/TX2 hardware
- Dependencies: Bazel, CUDA toolkit, CuDNN, CUPTI libraries, Python3 & dev headers, hdf5 libraries
- Build Orchestrator (buildTensorflow.sh) applies patches from patch/ then invokes Bazel to compile TensorFlow core with GPU and TensorRT support
c. Artifact Packaging
- The Bazel output is staged into a Python wheel (.whl) file
- Scripts split/merge large wheels for distribution
- installTF.sh downloads/releases the wheel and runs pip3 install
d. Runtime Environment & Tests
- Python environment on Jetson with installed wheel
- tf-test modules (gpu.py, mnist.py, test_tftrt.py) validate functionality: GPU detection, inference accuracy, TensorRT optimization
e. External Services
- GitHub Releases or custom CDN for wheel hosting
- NVIDIA package repos for CUDA/CuDNN/TensorRT
- PyPI (pip index) for fallback installs

##### Architectural patterns and design principles
- Modular build pipeline: clearly separated fetch-patch-build-package steps
- Layered dependencies: system libs (CUDA/CuDNN/CUPTI) → build tool (Bazel) → TensorFlow source → Python environment
- Test harness decoupled by TensorFlow major version for clarity and maintenance

##### Detail
- Script and directory as a distinct node or subcomponent, especially patch/ and tf-test/
- Version branching (TensorFlow 1.x vs. 2.x) in the test harness

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Source Repository Layer
    subgraph "Source Repository"
        direction TB
        GitaAttr[".gitattributes"]:::config
        Gitignore[".gitignore"]:::config
        Readme["README.md"]:::config
        ConfigYml["_config.yml"]:::config
        FundingYml[".github/FUNDING.yml"]:::config
    end

    %% Scripts Layer
    subgraph "Build Scripts" 
        direction TB
        BazelScript["installBazel.sh"]:::build
        TFInstallScript["installTF.sh"]:::build
        BuildOrch["buildTensorflow.sh"]:::build
    end

    %% Patch Catalog
    subgraph "Patch Catalog" 
        direction TB
        PatchDir["patch/"]:::build
        P1["tensorflow1.7.patch"]:::build
        P2["tensorflow1.8.patch"]:::build
        P3["tensorflow1.9.patch"]:::build
        P4["tensorflow1.10rc1.patch"]:::build
        P5["tensorflow1.12.patch"]:::build
        PatchDir --> P1
        PatchDir --> P2
        PatchDir --> P3
        PatchDir --> P4
        PatchDir --> P5
    end

    %% Test Harness
    subgraph "Test Harness"
        direction TB
        subgraph "TensorFlow 1.x Tests"
            direction TB
            TFTest10_gpu["gpu.py"]:::test
            TFTest10_trt["test_tftrt.py"]:::test
        end
        subgraph "TensorFlow 2.x Tests"
            direction TB
            TFTest20_gpu["gpu.py"]:::test
            TFTest20_mnist["mnist.py"]:::test
        end
    end

    %% Builder Environment
    subgraph "Builder Environment"
        direction TB
        Dependencies["Bazel, CUDA, cuDNN, CUPTI, Python3, hdf5"]:::build
        BuildOrch -->|apply patches| PatchDir
        PatchDir -->|feeds| BuildOrch
        BuildOrch -->|invoke Bazel compile| Dependencies
        Dependencies -->|produces| WheelStage["Staged Wheel Artifact"]:::artifact
    end

    %% Packaging
    subgraph "Artifact Packaging"
        direction TB
        SplitMerge["split/merge scripts"]:::build
        WheelStage -->|split large wheel| SplitMerge
        SplitMerge -->|final wheel| WheelArtifact[".whl"]:::artifact
        TFInstallScript -->|downloads/releases| WheelArtifact
        TFInstallScript -->|pip3 install| RuntimeEnv["Runtime Python Env"]:::runtime
    end

    %% Runtime & Testing
    subgraph "Runtime & Validation"
        direction TB
        RuntimeEnv -->|"executes tests"| TFTest10_gpu
        RuntimeEnv -->|"executes tests"| TFTest10_trt
        RuntimeEnv -->|"executes tests"| TFTest20_gpu
        RuntimeEnv -->|"executes tests"| TFTest20_mnist
    end

    %% External Services
    GitHubActions["GitHub Actions (CI)"]:::external
    GitHubActions -->|trigger build| BuildOrch
    GitHubReleases["GitHub Releases"]:::external
    WheelArtifact -->|upload| GitHubReleases
    NVIDIARepos["NVIDIA Package Repos"]:::external
    Dependencies -->|"fetch CUDA/CuDNN/TensorRT"| NVIDIARepos
    PyPI["PyPI (pip index)"]:::external
    RuntimeEnv -->|fallback install| PyPI

    %% Click Events
    click GitaAttr "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/.gitattributes"
    click Gitignore "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/.gitignore"
    click Readme "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/README.md"
    click ConfigYml "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/_config.yml"
    click FundingYml "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/.github/FUNDING.yml"
    click BazelScript "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/installBazel.sh"
    click TFInstallScript "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/installTF.sh"
    click BuildOrch "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/buildTensorflow.sh"
    click PatchDir "https://github.com/peterlee0127/tensorflow-nvjetson/tree/master/patch/"
    click P1 "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/patch/tensorflow1.7.patch"
    click P2 "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/patch/tensorflow1.8.patch"
    click P3 "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/patch/tensorflow1.9.patch"
    click P4 "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/patch/tensorflow1.10rc1.patch"
    click P5 "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/patch/tensorflow1.12.patch"
    click TFTest10_gpu "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/tf-test/1.0/gpu.py"
    click TFTest10_trt "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/tf-test/1.0/test_tftrt.py"
    click TFTest20_gpu "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/tf-test/2.0/gpu.py"
    click TFTest20_mnist "https://github.com/peterlee0127/tensorflow-nvjetson/blob/master/tf-test/2.0/mnist.py"

    %% Styles
    classDef build fill:#ffe4b5,stroke:#cc8400
    classDef config fill:#e0ffff,stroke:#007d7d
    classDef test fill:#dfffdf,stroke:#2d7d2d
    classDef runtime fill:#f0e68c,stroke:#8d7d00
    classDef external fill:#cce0ff,stroke:#4d4dff
    classDef artifact fill:#ffd1dc,stroke:#ff4d6d
```
