1- name : Build TensorFlow Lite runtime
1+ name : Build TFLite runtime
22
33on :
44 release :
77 workflow_dispatch :
88 inputs :
99 version :
10- description : " Semantic version (e.g., 2.15.0)"
10+ description : " Semantic version (e.g., 2.19.0)"
11+ required : true
12+ release :
13+ description : " If true, release the artifact"
14+ type : boolean
1115 required : true
1216 repository :
1317 description : " Name of a target repository"
1418 default : ' tensorflow/tensorflow'
1519 required : false
20+ xnn_arm_options :
21+ description : " XNNPack ARM options"
22+ default : ' --define=xnn_enable_arm_i8mm=false --define=xnn_enable_arm_bf16=false'
23+ required : false
24+ xnn_avx_options :
25+ description : " XNNPack AVX options"
26+ default : ' --define=xnn_enable_avx512amx=false --define=xnn_enable_avxvnniint8=false --define=xnn_enable_avxvnni=false --define=xnn_enable_avx512fp16=false'
27+ required : false
1628
1729permissions :
1830 contents : write
1931
2032env :
21- TF_PYTHON_VERSION : ' 3.10'
2233 VERSION :
2334 |- # Enter release tag name or version in workflow_dispatch. Recent version if not specified
24- ${{ github.event.release.tag_name || github.event.inputs.version || '2.15 .0' }}
35+ ${{ github.event.release.tag_name || github.event.inputs.version || '2.19 .0' }}
2536 REPOSITORY :
2637 ${{ github.event.inputs.repository || 'tensorflow/tensorflow' }}
27-
38+
2839jobs :
2940 build-android :
3041 runs-on : ubuntu-22.04
@@ -44,20 +55,25 @@ jobs:
4455 ANDROID_SDK_API_LEVEL : 31
4556 ANDROID_NDK_API_LEVEL : 26
4657 ANDROID_BUILD_TOOLS_VERSION : ' 31.0.0'
58+ CC : clang-17
59+ CXX : clang++-17
60+ HERMETIC_PYTHON_VERSION : 3.12
4761 steps :
48- - uses : actions/checkout@v3
62+ - uses : actions/checkout@v4
4963 with :
5064 repository : ${{ env.REPOSITORY }}
5165 ref : v${{ env.VERSION }}
5266 submodules : recursive
5367 github-server-url : https://github.com
54- - uses : bazelbuild/setup-bazelisk@v2
55- - uses : actions/setup-python@v4
56- with :
57- python-version : ${{ env.TF_PYTHON_VERSION }}
68+ - uses : bazel-contrib/setup-bazel@0.15.0
5869 - name : Install dependencies
5970 run : |
60- pip install numpy
71+ sudo apt-get remove -y gcc g++
72+ wget https://apt.llvm.org/llvm.sh
73+ chmod u+x llvm.sh
74+ sudo ./llvm.sh 17
75+ sudo apt-get update
76+ sudo apt-get install -y mesa-common-dev libegl1-mesa-dev libgles2-mesa-dev clang-17 llvm-17
6177 - uses : nttld/setup-ndk@v1
6278 id : setup-ndk
6379 with :
@@ -72,19 +88,19 @@ jobs:
7288 export ANDROID_SDK_HOME=$ANDROID_HOME
7389
7490 # Main
75- bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 --define=xnn_enable_arm_fp16=false --define=xnn_enable_arm_i8mm=false tensorflow/lite/c:tensorflowlite_c
91+ bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 ${{ inputs.xnn_arm_options }} ${{ inputs.xnn_avx_options }} tensorflow/lite/c:tensorflowlite_c
7692 cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so artifact
7793
7894 # GPU Delegate
79- bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 --define=xnn_enable_arm_fp16=false --define=xnn_enable_arm_i8mm=false --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so
95+ bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 ${{ inputs.xnn_arm_options }} ${{ inputs.xnn_avx_options }} --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so
8096 cp -f bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_delegate.so artifact
8197
8298 # GL Delegate
83- bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 --define=xnn_enable_arm_fp16=false --define=xnn_enable_arm_i8mm=false --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_gl.so
99+ bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 ${{ inputs.xnn_arm_options }} ${{ inputs.xnn_avx_options }} --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_gl.so
84100 cp -f bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_gl.so artifact
85101
86102 # NNAPI Delegate
87- # bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 --define=xnn_enable_arm_fp16=false --define=xnn_enable_arm_i8mm=false tensorflow/lite/delegates/nnapi:nnapi_delegate
103+ # bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 ${{ inputs.xnn_arm_options }} ${{ inputs.xnn_avx_options }} tensorflow/lite/delegates/nnapi:nnapi_delegate
88104 # cp -f bazel-bin/tensorflow/lite/delegates/nnapi/libnnapi_delegate.so artifact
89105 - name : Build AAR
90106 if : ${{ matrix.config == 'android_fat_aar' }}
@@ -95,23 +111,24 @@ jobs:
95111 export ANDROID_SDK_HOME=$ANDROID_HOME
96112
97113 # Main
98- bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a,x86_64 --cxxopt=--std=c++17 --define=xnn_enable_arm_fp16=false --define=xnn_enable_arm_i8mm=false --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
114+ bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a,x86_64 --cxxopt=--std=c++17 ${{ inputs.xnn_arm_options }} ${{ inputs.xnn_avx_options }} --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
99115 cp -f bazel-bin/tensorflow/lite/java/tensorflow-lite.aar artifact
100116
101117 # GPU Delegate
102- bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a,x86_64 --cxxopt=--std=c++17 --define=xnn_enable_arm_fp16=false --define=xnn_enable_arm_i8mm=false --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
118+ bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a,x86_64 --cxxopt=--std=c++17 ${{ inputs.xnn_arm_options }} ${{ inputs.xnn_avx_options }} --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
103119 cp -f bazel-bin/tensorflow/lite/java/tensorflow-lite-gpu.aar artifact
104120 - name : Compress artifact
105121 run : |
106122 mv artifact/ "${{ matrix.artifact_name }}-${{ env.VERSION }}"
107123 tar czf "${{ matrix.artifact_name }}-${{ env.VERSION }}.tgz" "${{ matrix.artifact_name }}-${{ env.VERSION }}"
108- - uses : softprops/action-gh-release@v1
124+ - uses : softprops/action-gh-release@v2
125+ if : ${{ inputs.release }}
109126 with :
110127 files : " *.tgz"
111128 tag_name : ${{ env.VERSION }}
112129
113130 build-ios :
114- runs-on : macos-12
131+ runs-on : macos-15
115132 strategy :
116133 fail-fast : false
117134 matrix :
@@ -122,20 +139,16 @@ jobs:
122139 artifact_name : tflite-runtime-ios-sim-arm64
123140 - config : ios_x86_64
124141 artifact_name : tflite-runtime-ios-sim-x86_64
142+ env :
143+ HERMETIC_PYTHON_VERSION : 3.12
125144 steps :
126- - uses : actions/checkout@v3
145+ - uses : actions/checkout@v4
127146 with :
128147 repository : ${{ env.REPOSITORY }}
129148 ref : v${{ env.VERSION }}
130149 submodules : recursive
131150 github-server-url : https://github.com
132- - uses : bazelbuild/setup-bazelisk@v2
133- - uses : actions/setup-python@v4
134- with :
135- python-version : ${{ env.TF_PYTHON_VERSION }}
136- - name : Install dependencies
137- run : |
138- pip install numpy
151+ - uses : bazel-contrib/setup-bazel@0.15.0
139152 - name : Build runtime
140153 run : |
141154 mv tensorflow/lite/ios/BUILD.apple tensorflow/lite/ios/BUILD
@@ -145,20 +158,21 @@ jobs:
145158 mkdir -p artifact
146159
147160 # Main
148- bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 tensorflow/lite/ios:TensorFlowLiteC_framework
161+ bazel build -c opt --config=${{ matrix.config }} ${{ inputs.xnn_avx_options }} --cxxopt=--std=c++17 tensorflow/lite/ios:TensorFlowLiteC_framework
149162 unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip -d artifact
150163
151164 # Metal Delegate
152- bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 tensorflow/lite/ios:TensorFlowLiteCMetal_framework
165+ bazel build -c opt --config=${{ matrix.config }} ${{ inputs.xnn_avx_options }} --cxxopt=--std=c++17 tensorflow/lite/ios:TensorFlowLiteCMetal_framework
153166 unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteCMetal_framework.zip -d artifact
154167
155168 # CoreML Delegate
156- bazel build -c opt --config=${{ matrix.config }} --cxxopt=--std=c++17 tensorflow/lite/ios:TensorFlowLiteCCoreML_framework
169+ bazel build -c opt --config=${{ matrix.config }} ${{ inputs.xnn_avx_options }} --cxxopt=--std=c++17 tensorflow/lite/ios:TensorFlowLiteCCoreML_framework
157170 unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteCCoreML_framework.zip -d artifact
158171
159172 mv artifact/ "${{ matrix.artifact_name }}-${{ env.VERSION }}"
160173 7z a "${{ matrix.artifact_name }}-${{ env.VERSION }}.zip" "${{ matrix.artifact_name }}-${{ env.VERSION }}"
161- - uses : softprops/action-gh-release@v1
174+ - uses : softprops/action-gh-release@v2
175+ if : ${{ inputs.release }}
162176 with :
163177 files : " *.zip"
164178 tag_name : ${{ env.VERSION }}
@@ -173,71 +187,81 @@ jobs:
173187 artifact_name : tflite-runtime-linux-x86_64
174188 - config : elinux_aarch64
175189 artifact_name : tflite-runtime-linux-arm64
190+ env :
191+ CC : gcc-12
192+ CXX : g++-12
193+ HERMETIC_PYTHON_VERSION : 3.12
176194 steps :
177- - uses : actions/checkout@v3
195+ - uses : actions/checkout@v4
178196 with :
179197 repository : ${{ env.REPOSITORY }}
180198 ref : v${{ env.VERSION }}
181199 submodules : recursive
182200 github-server-url : https://github.com
183- - uses : bazelbuild/setup-bazelisk@v2
184- - uses : actions/setup-python@v4
185- with :
186- python-version : ${{ env.TF_PYTHON_VERSION }}
201+ - uses : bazel-contrib/setup-bazel@0.15.0
187202 - name : Install dependencies
188203 run : |
189- sudo apt-get update && sudo apt-get install libegl1-mesa-dev
190- pip install numpy
204+ sudo apt-get remove -y gcc g++
205+ sudo apt update
206+ sudo apt-get install -y mesa-common-dev libegl1-mesa-dev libgles2-mesa-dev gcc-12 g++-12
191207 - name : Build runtime
192208 run : |
193209 mkdir -p artifact
194210
195- bazel build --config=${{ matrix.config }} -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
211+ bazel build --config=${{ matrix.config }} -c opt --define tflite_with_xnnpack=true ${{ inputs.xnn_avx_options }} tensorflow/lite/c:tensorflowlite_c
196212 cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so artifact
197213
198214 mv artifact/ "${{ matrix.artifact_name }}-${{ env.VERSION }}"
199215 tar cfz "${{ matrix.artifact_name }}-${{ env.VERSION }}.tgz" "${{ matrix.artifact_name }}-${{ env.VERSION }}"
200- - uses : softprops/action-gh-release@v1
216+ - uses : softprops/action-gh-release@v2
217+ if : ${{ inputs.release }}
201218 with :
202219 files : " *.tgz"
203220 tag_name : ${{ env.VERSION }}
204221
205222 build-macos :
206- runs-on : macos-12
223+ runs-on : ${{ matrix.vm }}
207224 strategy :
208225 fail-fast : false
209226 matrix :
210227 include :
211228 - config : macos
212229 cpu : x86_64
213230 artifact_name : tflite-runtime-osx-x86_64
231+ vm : macos-13
214232 - config : macos_arm64
215233 cpu : arm64
216234 artifact_name : tflite-runtime-osx-arm64
235+ vm : macos-13
236+ env :
237+ HERMETIC_PYTHON_VERSION : 3.12
217238 steps :
218- - uses : actions/checkout@v3
239+ - uses : actions/checkout@v4
219240 with :
220241 repository : ${{ env.REPOSITORY }}
221242 ref : v${{ env.VERSION }}
222243 submodules : recursive
223244 github-server-url : https://github.com
224- - uses : bazelbuild/setup-bazelisk@v2
225- - uses : actions/setup-python@v4
226- with :
227- python-version : ${{ env.TF_PYTHON_VERSION }}
245+ - uses : bazel-contrib/setup-bazel@0.15.0
228246 - name : Install dependencies
247+ if : ${{ matrix.vm != 'macos-15' }}
248+ shell : bash
229249 run : |
230- pip install numpy
250+ brew install llvm@17 \
251+ && echo 'export PATH="/opt/homebrew/opt/llvm@17/bin:$PATH"' >> /Users/runner/.bash_profile \
252+ && source /Users/runner/.bash_profile \
253+ && which clang++
231254 - name : Build runtime
255+ shell : bash
232256 run : |
233257 mkdir -p artifact
234258
235259 # Main
236- bazel build --config=${{ matrix.config }} --macos_cpus=${{ matrix.cpu }} --cxxopt=--std=c++17 -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
260+ bazel build --config=${{ matrix.config }} --macos_cpus=${{ matrix.cpu }} --cxxopt=--std=c++17 ${{ inputs.xnn_avx_options }} -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
237261 cp -f bazel-bin/tensorflow/lite/c/libtensorflowlite_c.dylib artifact
238262
239263 # Metal Delegate
240- bazel build --config=${{ matrix.config }} --macos_cpus=${{ matrix.cpu }} --cxxopt=--std=c++17 -c opt --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=default --linkopt -s --strip always tensorflow/lite/delegates/gpu:tensorflow_lite_gpu_dylib
264+ bazel build --config=${{ matrix.config }} --macos_cpus=${{ matrix.cpu }} --cxxopt=--std=c++17 ${{ inputs.xnn_avx_options }} -c opt --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=default --linkopt -s --strip always tensorflow/lite/delegates/gpu:tensorflow_lite_gpu_dylib
241265 cp -f bazel-bin/tensorflow/lite/delegates/gpu/tensorflow_lite_gpu_dylib.dylib artifact/libtensorflowlite_metal_delegate.dylib
242266
243267 mv artifact/ "${{ matrix.artifact_name }}-${{ env.VERSION }}"
@@ -247,24 +271,26 @@ jobs:
247271 name : ${{ matrix.artifact_name }}
248272 path : ${{ matrix.artifact_name }}-${{ env.VERSION }}
249273 retention-days : 1
250- - uses : softprops/action-gh-release@v1
274+ - uses : softprops/action-gh-release@v2
275+ if : ${{ inputs.release }}
251276 with :
252277 files : " *.tgz"
253278 tag_name : ${{ env.VERSION }}
254279
255280 build-macos-universal :
256281 needs : [build-macos]
257- runs-on : macos-12
282+ runs-on : macos-15
258283 steps :
259284 - uses : actions/download-artifact@v4
260285 - name : Build universal binary
261286 run : |
262287 mkdir -p artifact
263- lipo -create -output artifact/libtensorflowlite_c.dylib "tflite-runtime-osx-x86_64-${{ env.VERSION }} /libtensorflowlite_c.dylib" "tflite-runtime-osx-arm64-${{ env.VERSION }} /libtensorflowlite_c.dylib"
264- lipo -create -output artifact/libtensorflowlite_metal_delegate.dylib "tflite-runtime-osx-x86_64-${{ env.VERSION }} /libtensorflowlite_metal_delegate.dylib" "tflite-runtime-osx-arm64-${{ env.VERSION }} /libtensorflowlite_metal_delegate.dylib"
288+ lipo -create -output artifact/libtensorflowlite_c.dylib "tflite-runtime-osx-x86_64/libtensorflowlite_c.dylib" "tflite-runtime-osx-arm64/libtensorflowlite_c.dylib"
289+ lipo -create -output artifact/libtensorflowlite_metal_delegate.dylib "tflite-runtime-osx-x86_64/libtensorflowlite_metal_delegate.dylib" "tflite-runtime-osx-arm64/libtensorflowlite_metal_delegate.dylib"
265290 mv artifact/ "tflite-runtime-osx-universal2-${{ env.VERSION }}"
266291 tar cfz "tflite-runtime-osx-universal2-${{ env.VERSION }}.tgz" "tflite-runtime-osx-universal2-${{ env.VERSION }}"
267- - uses : softprops/action-gh-release@v1
292+ - uses : softprops/action-gh-release@v2
293+ if : ${{ inputs.release }}
268294 with :
269295 files : " *.tgz"
270296 tag_name : ${{ env.VERSION }}
@@ -280,32 +306,29 @@ jobs:
280306 - config : windows_x86_64
281307 cpu : x86_64
282308 artifact_name : tflite-runtime-win-x86_64
309+ env :
310+ HERMETIC_PYTHON_VERSION : 3.12
283311 steps :
284- - uses : actions/checkout@v3
312+ - uses : actions/checkout@v4
285313 with :
286314 repository : ${{ env.REPOSITORY }}
287315 ref : v${{ env.VERSION }}
288316 submodules : recursive
289317 github-server-url : https://github.com
290- - uses : bazelbuild/setup-bazelisk@v2
291- - uses : actions/setup-python@v4
292- with :
293- python-version : ${{ env.TF_PYTHON_VERSION }}
294- - name : Install dependencies
295- run : |
296- pip install numpy
318+ - uses : bazel-contrib/setup-bazel@0.15.0
297319 - name : Build runtime
298320 shell : bash
299321 run : |
300322 mkdir -p artifact
301323
302324 # Main
303- bazel build -c opt --define tflite_with_xnnpack=true tensorflow/lite/c:tensorflowlite_c
325+ bazel build --cxxopt=/std:c++20 -c opt --define tflite_with_xnnpack=true ${{ inputs.xnn_avx_options }} tensorflow/lite/c:tensorflowlite_c
304326 cp -f bazel-bin/tensorflow/lite/c/tensorflowlite_c.dll artifact
305327
306328 mv artifact/ "${{ matrix.artifact_name }}-${{ env.VERSION }}"
307329 7z a "${{ matrix.artifact_name }}-${{ env.VERSION }}.zip" "${{ matrix.artifact_name }}-${{ env.VERSION }}"
308- - uses : softprops/action-gh-release@v1
330+ - uses : softprops/action-gh-release@v2
331+ if : ${{ inputs.release }}
309332 with :
310333 files : " *.zip"
311334 tag_name : ${{ env.VERSION }}
@@ -314,7 +337,8 @@ jobs:
314337 needs : [build-android, build-ios, build-linux, build-macos-universal, build-windows]
315338 runs-on : ubuntu-latest
316339 steps :
317- - uses : softprops/action-gh-release@v1
340+ - uses : softprops/action-gh-release@v2
341+ if : ${{ inputs.release }}
318342 with :
319343 name : TFLite Runtime v${{ env.VERSION }}
320344 tag_name : ${{ env.VERSION }}
0 commit comments