Skip to content

feat: add support for Android and iOS runtime #44

feat: add support for Android and iOS runtime

feat: add support for Android and iOS runtime #44

Workflow file for this run

name: Build TensorFlow Lite runtime
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
env:
PYTHON_VERSION: '3.10.11'
jobs:
build-android:
runs-on: ubuntu-22.04
env:
# TFLite bug https://github.com/tensorflow/tensorflow/issues/61311
ANDROID_PLATFORM: android-26
ANDROID_SDK_API_LEVEL: 30
ANDROID_NDK_API_LEVEL: 26
ANDROID_BUILD_TOOLS_VERSION: 30.0.3
steps:
- uses: actions/checkout@v3
with:
repository: tensorflow/tensorflow
ref: ${{ github.ref_name }}
submodules: recursive
github-server-url: https://github.com
- uses: bazelbuild/setup-bazelisk@v2
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
pip install numpy
SDKMANAGER=${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager
echo "y" | $SDKMANAGER "ndk;21.4.7075529"
- name: Build runtime
run: |
mkdir -p Android
export ANDROID_SDK_HOME=$ANDROID_HOME
export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/21.4.7075529
bazel build -c opt --fat_apk_cpu=arm64-v8a --cxxopt=--std=c++17 --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder //tensorflow/lite/java:tensorflow-lite
cp -f bazel-bin/tensorflow/lite/java/tensorflow-lite.aar Android
bazel build -c opt --fat_apk_cpu=arm64-v8a --cxxopt=--std=c++17 --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder //tensorflow/lite/java:tensorflow-lite-gpu
cp -f bazel-bin/tensorflow/lite/java/tensorflow-lite-gpu.aar Android
bazel build -c opt --config=android_arm64 --cxxopt=--std=c++17 --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always //tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_gl.so
mkdir -p Android/arm64-v8a; cp -f bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_gl.so Android/arm64-v8a
tar cvjf tflite-runtime-${{ github.ref_name }}-android.bz2 Android
- uses: actions/upload-artifact@v3
with:
name: bin-android
path: '*.bz2'
build-ios:
runs-on: macos-12
steps:
- uses: actions/checkout@v3
with:
repository: tensorflow/tensorflow
ref: ${{ github.ref_name }}
submodules: recursive
github-server-url: https://github.com
- uses: bazelbuild/setup-bazelisk@v2
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
pip install numpy
- name: Build runtime
run: |
mv tensorflow/lite/ios/BUILD.apple tensorflow/lite/ios/BUILD
mv tensorflow/lite/objc/BUILD.apple tensorflow/lite/objc/BUILD
mv tensorflow/lite/swift/BUILD.apple tensorflow/lite/swift/BUILD
mkdir -p iOS
bazel build -c opt --config=ios_arm64 --cxxopt=--std=c++17 //tensorflow/lite/ios:TensorFlowLiteC_framework
unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip -d iOS
bazel build -c opt --config=ios_arm64 --cxxopt=--std=c++17 //tensorflow/lite/ios:TensorFlowLiteCMetal_framework
unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteCMetal_framework.zip -d iOS
bazel build -c opt --config=ios_arm64 --cxxopt=--std=c++17 //tensorflow/lite/ios:TensorFlowLiteCCoreML_framework
unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteCCoreML_framework.zip -d iOS
tar cvjf tflite-runtime-${{ github.ref_name }}-ios.bz2 iOS
- uses: actions/upload-artifact@v3
with:
name: bin-ios
path: '*.bz2'
build-linux:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
repository: tensorflow/tensorflow
ref: ${{ github.ref_name }}
submodules: recursive
github-server-url: https://github.com
- uses: bazelbuild/setup-bazelisk@v2
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
pip install numpy
- name: Build runtime
run: |
mkdir -p Linux
bazel build -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
mkdir -p Linux/x86_64; cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so Linux/x86_64
bazel build --config=elinux_aarch64 -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
mkdir -p Linux/arm64; cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so Linux/arm64
tar cvjf tflite-runtime-${{ github.ref_name }}-linux.bz2 Linux
- uses: actions/upload-artifact@v3
with:
name: bin-linux
path: '*.bz2'
build-macos:
runs-on: macos-12
steps:
- uses: actions/checkout@v3
with:
repository: tensorflow/tensorflow
ref: ${{ github.ref_name }}
submodules: recursive
github-server-url: https://github.com
- uses: bazelbuild/setup-bazelisk@v2
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
pip install numpy
- name: Build runtime
run: |
mkdir -p macOS
bazel build --config=macos --cpu=darwin -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
mkdir -p x86_64; cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.dylib x86_64
bazel build --config=macos_arm64 --cpu=darwin_arm64 -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
mkdir -p arm64; cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.dylib arm64
lipo -create -output macOS/libtensorflowlite_c.dylib x86_64/libtensorflowlite_c.dylib arm64/libtensorflowlite_c.dylib
tar cvjf tflite-runtime-${{ github.ref_name }}-macos.bz2 macOS
- uses: actions/upload-artifact@v3
with:
name: bin-macos
path: '*.bz2'
build-windows:
# TODO(soon): Using windows-2019 as build is broken on windows-latest runner due to another
# bazel bug https://github.com/bazelbuild/bazel/issues/18592
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
with:
repository: tensorflow/tensorflow
ref: ${{ github.ref_name }}
submodules: recursive
github-server-url: https://github.com
- uses: bazelbuild/setup-bazelisk@v2
- name: Install dependencies
run: |
pip3 install numpy
- name: Build runtime
shell: bash
run: |
mkdir -p Windows
bazel build -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
cp -f bazel-bin/tensorflow/lite/c/tensorflowlite_c.dll Windows
tar cvjf tflite-runtime-${{ github.ref_name }}-windows.bz2 Windows
- uses: actions/upload-artifact@v3
with:
name: bin-windows
path: '*.bz2'
release:
needs: [build-android, build-ios, build-linux, build-macos, build-windows]
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/download-artifact@v3
- uses: softprops/action-gh-release@v1
with:
files: '**/*'