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..602f6fc --- /dev/null +++ b/.github/workflows/tflm.yml @@ -0,0 +1,116 @@ +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-m4+fp] + 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-repo + 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: '🏗 Build headers' + run: source tools/ci.sh && ci_build_headers + + - name: '⬆ Upload libraries' +# if: github.event_name != 'pull_request' + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.target }} + path: ${{ matrix.target }} + if-no-files-found: error + + - name: '⬆ Upload headers' + uses: actions/upload-artifact@v4 + with: + path: tflite-micro + if-no-files-found: error + + commit-artifacts: + needs: build-tflm + runs-on: ubuntu-20.04 +# if: github.event_name == 'push' + permissions: + contents: write + pull-requests: write + + steps: + - name: '⏳ Checkout repository' + uses: actions/checkout@v4 + with: + submodules: false + + - name: '⬇ Download artifacts' + uses: actions/download-artifact@v4 + +# - name: '🤌 Commit artifacts' +# run: | +# git config --local user.name "github-actions[bot]" +# git config --local user.email "github-actions[bot]@users.noreply.github.com" +# git add . +# git commit -m "Add build artifacts" + + - 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..94c7432 --- /dev/null +++ b/tools/ci.sh @@ -0,0 +1,72 @@ +#!/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-repo +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=${1} + mkdir -p ${TARGET} + pushd ${TFLM_REPO_PATH} +# make -j$(nproc) -f tensorflow/lite/micro/tools/make/Makefile \ +# TARGET=cortex_m_generic TARGET_ARCH=${TARGET} 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 + make -j$(nproc) -f tensorflow/lite/micro/tools/make/Makefile \ + TARGET=cortex_m_generic TARGET_ARCH=${TARGET} 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 clean + popd + touch ${TARGET}/libtflm.a +# mv ${TFLM_REPO_PATH}/gen/*/lib/libtflm.a ${TARGET} + +} + +# Build Headers. +######################################################################################## +ci_build_headers() { + HEADERS_PATH="tflite-micro" + rm -fr ${HEADERS_PATH} + mkdir -p ${HEADERS_PATH} + + pushd ${TFLM_REPO_PATH} + headers=$(make -j$(nproc) -f tensorflow/lite/micro/tools/make/Makefile \ + TARGET=cortex_m_generic TARGET_ARCH=cortex-m7+fp OPTIMIZED_KERNEL_DIR=cmsis_nn \ + TARGET_TOOLCHAIN_ROOT=${TOOLCHAIN_PATH}/bin/ TARGET_TOOLCHAIN_PREFIX=arm-none-eabi- \ + BUILD_TYPE=release list_library_headers list_third_party_headers) + + popd + + readarray -d ' ' -t files <<< $headers + for file in ${files[@]}; do + if test -f ${TFLM_REPO_PATH}/${file}; then + echo ${TFLM_REPO_PATH}/${file} + mkdir -p ${HEADERS_PATH}/$(dirname ${file}) + cp ${TFLM_REPO_PATH}/${file} ${HEADERS_PATH}/${file} + fi + done +}