-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script to build tflite for Mac Catalyst
- Loading branch information
Showing
2 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash -v | ||
|
||
if [ \( -n "$1" \) ]; then | ||
echo "Building with config $1" | ||
else | ||
echo "Please specify the ios config and architecture to build. e.g. $0 ios_fat; $0 ios_x86_64; $0 ios_sim_arm64; $0 ios_arm64; $0 ios_armv7" | ||
exit 1 | ||
fi | ||
|
||
cd "$(dirname "$0")" | ||
cd ../../ | ||
mkdir -p lib/ios | ||
cd tensorflow | ||
|
||
#check for x86_64 version of python3 from homebew | ||
if test -f "/usr/local/bin/python3"; then | ||
if test -d "/usr/local/lib/python3.9/site-packages"; then | ||
export PYTHON_BIN_PATH="/usr/local/bin/python3" | ||
export PYTHON_LIB_PATH="/usr/local/lib/python3.9/site-packages" | ||
fi | ||
fi | ||
|
||
#check for arm64 version of python3, if it is available, use this instead. | ||
if test -f "/opt/homebrew/bin/python3"; then | ||
if test -d "/opt/homebrew/lib/python3.9/site-packages"; then | ||
export PYTHON_BIN_PATH="/opt/homebrew/bin/python3" | ||
export PYTHON_LIB_PATH="/opt/homebrew/lib/python3.9/site-packages" | ||
fi | ||
fi | ||
|
||
#The python3 comes with Xcode seems to have issues when compiling for tflite using bazel, will disable it now. | ||
|
||
#if test -f "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/bin/python3"; then | ||
# if test -d "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/lib/python3.8/site-packages"; then | ||
# export PYTHON_BIN_PATH="/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/bin/python3" | ||
# export PYTHON_LIB_PATH="/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/lib/python3.8/site-packages" | ||
# fi | ||
#fi | ||
|
||
echo PYTHON_BIN_PATH=$PYTHON_BIN_PATH | ||
echo PYTHON_LIB_PATH=$PYTHON_LIB_PATH | ||
|
||
export TF_CONFIGURE_IOS='1' | ||
export TF_ENABLE_XLA=1 | ||
export TF_NEED_CUDA=0 | ||
export TF_NEED_ROCM=0 | ||
export TF_NEED_OPENCL_SYCL=0 | ||
export TF_DOWNLOAD_CLANG=0 | ||
export CC_OPT_FLAGS="-match=native -Wno-sign-compare" | ||
export TF_SET_ANDROID_WORKSPACE=0 | ||
|
||
BAZEL_OUTPUT_USER_ROOT="$(pwd)/../bazel_output_$1" | ||
|
||
cp -f tensorflow/lite/ios/BUILD.apple tensorflow/lite/ios/BUILD | ||
|
||
rm -rf bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip | ||
|
||
./configure | ||
#alias python="/usr/local/bin/python3" | ||
#bazel --output_user_root=$BAZEL_OUTPUT_USER_ROOT build --verbose_failures --config=ios_fat --copt="-DCL_DELEGATE_NO_GL" --copt="-D__IOS__" -c opt --action_env PATH="$PATH" //tensorflow/lite/ios:TensorFlowLiteC_framework | ||
bazel --output_user_root=$BAZEL_OUTPUT_USER_ROOT build --verbose_failures --incompatible_run_shell_command_string=false --apple_platform_type=macos --cpu==$1 --copt="-DCL_DELEGATE_NO_GL" --copt="-D__IOS__" -c opt ${@:2} //tensorflow/lite/ios:TensorFlowLiteC_framework | ||
unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip TensorFlowLiteC.framework/TensorFlowLiteC -d ../lib/ios | ||
mv ../lib/ios/TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern_$1.a | ||
#cp -r TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern.a | ||
cd .. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters