From a0b343c390028b511bdfe003d87d215a8f12322b Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 20 Jun 2024 11:41:50 +0200 Subject: [PATCH] Add tools and workflows. --- .github/workflows/commit.yml | 35 +++++++++ .github/workflows/tflm.yml | 145 +++++++++++++++++++++++++++++++++++ tools/ci.sh | 53 +++++++++++++ 3 files changed, 233 insertions(+) create mode 100644 .github/workflows/commit.yml create mode 100644 .github/workflows/tflm.yml create mode 100644 tools/ci.sh diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml new file mode 100644 index 0000000..e6a87f0 --- /dev/null +++ b/.github/workflows/commit.yml @@ -0,0 +1,35 @@ +name: '๐Ÿ“œ Check Commit Messages' + +on: + pull_request: + types: + - opened + - edited + - reopened + - synchronize + branches: + - 'master' + +jobs: + check-commit-messages: + runs-on: ubuntu-latest + steps: + - name: '๐Ÿ“œ Check commit messages format' + uses: gsactions/commit-message-checker@v2 + with: + pattern: '^[A-Za-z]+.+ .+\.$' + flags: 'gm' + error: 'Commit subject line must match the following pattern: ' + excludeTitle: 'false' + excludeDescription: 'true' + checkAllCommitMessages: 'true' + accessToken: ${{ secrets.GITHUB_TOKEN }} + - name: '๐Ÿ“œ Check commit messages length' + uses: gsactions/commit-message-checker@v2 + with: + pattern: '^[^#].{10,78}$' + error: 'Commit subject line maximum line length of 78 characters is exceeded.' + excludeTitle: 'false' + excludeDescription: 'true' + checkAllCommitMessages: 'true' + accessToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tflm.yml b/.github/workflows/tflm.yml new file mode 100644 index 0000000..9cab0ba --- /dev/null +++ b/.github/workflows/tflm.yml @@ -0,0 +1,145 @@ +name: '๐Ÿ”ฅ Build TFLM' + +on: + push: + tags: + - 'v*.*.*' + branches: + - 'main' + paths: + - 'src/**' + - '.github/workflows/*.yml' + - '.github/workflows/*.json' + - '!**/README.md' + - '!**.rst' + + pull_request: + branches: + - 'main' + paths: + - 'src/**' + - '.github/workflows/*.yml' + - '.github/workflows/*.json' + - '!**/README.md' + - '!**.rst' + +jobs: + build-tflm: + runs-on: ubuntu-20.04 + + strategy: + matrix: + target: [cortex-m0plus, cortex-m4+fp, cortex-m7+fp, cortex-m55] + fail-fast: false + + steps: + - name: 'โณ Checkout main' + uses: actions/checkout@v4 + with: + submodules: false + + - name: 'โณ Checkout TFLM' + uses: actions/checkout@v4 + with: + submodules: false + path: tflite-micro + repository: tensorflow/tflite-micro + ref: 8c458fc48ee972ea4fc56ddc08849823b9af7ea8 + + - name: 'โ™ป Caching dependencies' + uses: actions/cache@v4.0.2 + id: cache + with: + path: ~/cache/gcc + key: 'arm-gnu-toolchain-13.2.rel1' + + - name: '๐Ÿ›  Install toolchain ' + if: steps.cache.outputs.cache-hit != 'true' + run: source tools/ci.sh && ci_install_arm_gcc + + - name: '๐Ÿ›  Install dependencies' + run: | + python -m pip install --upgrade pip numpy==1.24 Pillow==10.3 + + - name: '๐Ÿ— Build TFLM' + run: source tools/ci.sh && ci_build_target ${{ matrix.target }} + + - name: 'โฌ† Upload libraries' + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.target }} + path: ${{ matrix.target }} + if-no-files-found: error + + build-tflm-headers: + runs-on: ubuntu-20.04 + needs: [build-tflm] + + steps: + - name: 'โณ Checkout main' + uses: actions/checkout@v4 + with: + submodules: false + + - name: 'โณ Checkout TFLM' + uses: actions/checkout@v4 + with: + submodules: false + path: tflite-micro + repository: tensorflow/tflite-micro + ref: 8c458fc48ee972ea4fc56ddc08849823b9af7ea8 + + - name: 'โ™ป Caching dependencies' + uses: actions/cache@v4.0.2 + id: cache + with: + path: ~/cache/gcc + key: 'arm-gnu-toolchain-13.2.rel1' + + - name: '๐Ÿ›  Install toolchain ' + if: steps.cache.outputs.cache-hit != 'true' + run: source tools/ci.sh && ci_install_arm_gcc + + - name: '๐Ÿ›  Install dependencies' + run: | + python -m pip install --upgrade pip numpy==1.24 Pillow==10.3 + + - name: '๐Ÿ— Build headers' + run: source tools/ci.sh && ci_build_headers + + - name: 'โฌ† Upload headers' + uses: actions/upload-artifact@v4 + with: + name: include + path: include + if-no-files-found: error + + push-artifacts: + runs-on: ubuntu-20.04 + needs: [build-tflm, build-tflm-headers] +# if: github.event_name == 'push' + permissions: + contents: write + pull-requests: write + + steps: + - name: 'โณ Checkout repository' + uses: actions/checkout@v4 + with: + submodules: false + + - name: '๐Ÿงน Remove old headers ' + run: rm -fr include + + - name: 'โฌ‡ Download artifacts' + uses: actions/download-artifact@v4 + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + base: main + branch: update_tflm + title: Update tflm libraries and headers. + commit-message: Update tflm libraries and headers. + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/tools/ci.sh b/tools/ci.sh new file mode 100644 index 0000000..4cf78d1 --- /dev/null +++ b/tools/ci.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# This file is part of the OpenMV project. +# +# Copyright (c) 2024 Ibrahim Abdelkader +# Copyright (c) 2024 Kwabena W. Agyeman +# +# This work is licensed under the MIT license, see the file LICENSE for details. + +# Install ARM GCC. +######################################################################################## +TFLM_REPO_PATH=tflite-micro +TOOLCHAIN_PATH=${HOME}/cache/gcc +export PATH=${TOOLCHAIN_PATH}/bin:${PATH} +TOOLCHAIN_URL="https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz" + +ci_install_arm_gcc() { + mkdir -p ${TOOLCHAIN_PATH} + wget --no-check-certificate -O - ${TOOLCHAIN_URL} | tar --strip-components=1 -Jx -C ${TOOLCHAIN_PATH} + export PATH=${TOOLCHAIN_PATH}/bin:${PATH} + arm-none-eabi-gcc --version +} + +# Update Submodules. +######################################################################################## +ci_update_submodules() { + git submodule update --init --depth=1 --no-single-branch +} + +# Build Targets. +######################################################################################## +ci_build_target() { + TARGET_PATH=${1} + mkdir -p ${TARGET_PATH} + pushd ${TFLM_REPO_PATH} + make -j$(nproc) -f tensorflow/lite/micro/tools/make/Makefile \ + TARGET=cortex_m_generic TARGET_ARCH=${TARGET_PATH} OPTIMIZED_KERNEL_DIR=cmsis_nn \ + TARGET_TOOLCHAIN_ROOT=${TOOLCHAIN_PATH}/bin/ TARGET_TOOLCHAIN_PREFIX=arm-none-eabi- \ + BUILD_TYPE=release CORE_OPTIMIZATION_LEVEL=-O2 MICROLITE_LIB_NAME=libtflm.a microlite + popd + mv ${TFLM_REPO_PATH}/gen/*/lib/libtflm.a ${TARGET_PATH} +} + +# Build Headers. +######################################################################################## +ci_build_headers() { + HEADERS_PATH="include" + mkdir -p ${HEADERS_PATH} + pushd ${TFLM_REPO_PATH} + python3 tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py --makefile_options="TARGET=cortex_m_generic TARGET_ARCH=cortex-m7+fp OPTIMIZED_KERNEL_DIR=cmsis_nn TARGET_TOOLCHAIN_ROOT=/opt/arm-none-eabi/bin/ TARGET_TOOLCHAIN_PREFIX=arm-none-eabi- BUILD_TYPE=release" headers + cd headers && find . -name "*.c" -type f -delete + popd + cp -r ${TFLM_REPO_PATH}/headers/* ${HEADERS_PATH} +}