Build TensorFlow Lite Flex iOS with TF Makefile
PiperOrigin-RevId: 218237600
This commit is contained in:
parent
d341198905
commit
93851963bd
@ -208,6 +208,16 @@ endif
|
|||||||
# override local versions in the source tree.
|
# override local versions in the source tree.
|
||||||
INCLUDES += -I/usr/local/include
|
INCLUDES += -I/usr/local/include
|
||||||
|
|
||||||
|
# If `$(WITH_TFLITE_FLEX)` is `true`, this Makefile will build a library
|
||||||
|
# for TensorFlow Lite Flex runtime.
|
||||||
|
# Farmhash and Flatbuffer is required for TensorFlow Lite Flex runtime.
|
||||||
|
ifeq ($(WITH_TFLITE_FLEX), true)
|
||||||
|
HOST_INCLUDES += -I$(MAKEFILE_DIR)/downloads/farmhash/src
|
||||||
|
HOST_INCLUDES += -I$(MAKEFILE_DIR)/downloads/flatbuffers/include
|
||||||
|
INCLUDES += -I$(MAKEFILE_DIR)/downloads/farmhash/src
|
||||||
|
INCLUDES += -I$(MAKEFILE_DIR)/downloads/flatbuffers/include
|
||||||
|
endif
|
||||||
|
|
||||||
LIBS := \
|
LIBS := \
|
||||||
$(TARGET_NSYNC_LIB) \
|
$(TARGET_NSYNC_LIB) \
|
||||||
-lstdc++ \
|
-lstdc++ \
|
||||||
@ -283,7 +293,7 @@ ifeq ($(TARGET),ANDROID)
|
|||||||
else
|
else
|
||||||
ANDROID_HOST_OS_ARCH := $(ANDROID_HOST_OS_ARCH)-$(HOST_ARCH)
|
ANDROID_HOST_OS_ARCH := $(ANDROID_HOST_OS_ARCH)-$(HOST_ARCH)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifndef ANDROID_ARCH
|
ifndef ANDROID_ARCH
|
||||||
ANDROID_ARCH := armeabi-v7a
|
ANDROID_ARCH := armeabi-v7a
|
||||||
endif
|
endif
|
||||||
@ -330,7 +340,7 @@ ifeq ($(TARGET),ANDROID)
|
|||||||
BIN_PREFIX := x86_64-linux-android
|
BIN_PREFIX := x86_64-linux-android
|
||||||
MARCH_OPTION :=
|
MARCH_OPTION :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifndef NDK_ROOT
|
ifndef NDK_ROOT
|
||||||
$(error "NDK_ROOT is not defined.")
|
$(error "NDK_ROOT is not defined.")
|
||||||
endif
|
endif
|
||||||
@ -717,6 +727,53 @@ tensorflow/core/util/reporter.cc \
|
|||||||
tensorflow/tools/benchmark/benchmark_model.cc \
|
tensorflow/tools/benchmark/benchmark_model.cc \
|
||||||
tensorflow/tools/benchmark/benchmark_model_main.cc
|
tensorflow/tools/benchmark/benchmark_model_main.cc
|
||||||
|
|
||||||
|
# If `$(WITH_TFLITE_FLEX)` is `true`, this Makefile will build a library
|
||||||
|
# for TensorFlow Lite Flex runtime.
|
||||||
|
# Adding the following dependencies>
|
||||||
|
# * TensorFlow Eager Runtime.
|
||||||
|
# * TensorFlow Lite Runtime.
|
||||||
|
# * TensorFlow Lite Flex Delegate.
|
||||||
|
ifeq ($(WITH_TFLITE_FLEX), true)
|
||||||
|
CORE_CC_SRCS += $(wildcard tensorflow/core/common_runtime/eager/*.cc)
|
||||||
|
TF_LITE_CORE_CC_ALL_SRCS := \
|
||||||
|
$(wildcard tensorflow/contrib/lite/*.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/*.c) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/c/*.c) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/core/api/*.cc)
|
||||||
|
|
||||||
|
TF_LITE_CORE_CC_ALL_SRCS += \
|
||||||
|
$(wildcard tensorflow/contrib/lite/kernels/*.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/kernels/internal/*.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/kernels/internal/optimized/*.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/kernels/internal/reference/*.cc) \
|
||||||
|
$(PROFILER_SRCS) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/kernels/*.c) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/kernels/internal/*.c) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/kernels/internal/optimized/*.c) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/kernels/internal/reference/*.c) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/delegates/flex/*.cc)
|
||||||
|
|
||||||
|
# Hack. This shouldn't be here?
|
||||||
|
TF_LITE_CORE_CC_ALL_SRCS += \
|
||||||
|
$(wildcard tensorflow/contrib/makefile/downloads/farmhash/src/farmhash.cc) \
|
||||||
|
|
||||||
|
# Remove any duplicates.
|
||||||
|
TF_LITE_CORE_CC_ALL_SRCS := $(sort $(TF_LITE_CORE_CC_ALL_SRCS))
|
||||||
|
TF_LITE_CORE_CC_EXCLUDE_SRCS := \
|
||||||
|
$(wildcard tensorflow/contrib/lite/*test.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/*/*test.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/*/*/*test.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/*/*/*/*test.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/kernels/test_util.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/delegates/flex/test_util.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/nnapi_delegate.cc) \
|
||||||
|
$(wildcard tensorflow/contrib/lite/mmap_allocation_disabled.cc)
|
||||||
|
|
||||||
|
# Filter out all the excluded files.
|
||||||
|
TF_LITE_CC_SRCS := $(filter-out $(TF_LITE_CORE_CC_EXCLUDE_SRCS), $(TF_LITE_CORE_CC_ALL_SRCS))
|
||||||
|
TF_CC_SRCS += $(TF_LITE_CC_SRCS)
|
||||||
|
endif
|
||||||
|
|
||||||
ifdef HEXAGON_LIBS
|
ifdef HEXAGON_LIBS
|
||||||
TF_CC_SRCS += \
|
TF_CC_SRCS += \
|
||||||
tensorflow/cc/framework/scope.cc \
|
tensorflow/cc/framework/scope.cc \
|
||||||
|
@ -138,7 +138,7 @@ if [[ ! -z "${BUILD_ARCH}" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# build the ios tensorflow libraries.
|
# build the ios tensorflow libraries.
|
||||||
echo "Building TensorFlow with flags: ${TF_SCRIPT_FLAGS} -f ${TF_CC_FLAGS}"
|
echo "Building TensorFlow with command: ${TF_SCRIPT_FLAGS} -f ${TF_CC_FLAGS}"
|
||||||
tensorflow/contrib/makefile/compile_ios_tensorflow.sh ${TF_SCRIPT_FLAGS} -f "${TF_CC_FLAGS}"
|
tensorflow/contrib/makefile/compile_ios_tensorflow.sh ${TF_SCRIPT_FLAGS} -f "${TF_CC_FLAGS}"
|
||||||
|
|
||||||
# Creates a static universal library in
|
# Creates a static universal library in
|
||||||
|
40
tensorflow/contrib/makefile/build_all_ios_with_tflite_flex.sh
Executable file
40
tensorflow/contrib/makefile/build_all_ios_with_tflite_flex.sh
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
# This shell script is used to build TensorFlow Lite Flex runtime for iOS.
|
||||||
|
# It compiles TensorFlow Lite and TensorFlow codebases together, and enable a
|
||||||
|
# route to use TensorFlow kernels in TensorFlow Lite.
|
||||||
|
#
|
||||||
|
# After the script is executed, the multi-architecture static libraries will be
|
||||||
|
# created under: `tensorflow/contrib/makefile/gen/lib/`.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
TOP_SRCDIR="${SCRIPT_DIR}/../../../"
|
||||||
|
cd ${TOP_SRCDIR}
|
||||||
|
|
||||||
|
# Exporting `WITH_TFLITE_FLEX`. The flag will be propagated all the way
|
||||||
|
# down to Makefile.
|
||||||
|
export WITH_TFLITE_FLEX="true"
|
||||||
|
# Execute `build_all_ios.sh` and propagate all parameters.
|
||||||
|
tensorflow/contrib/makefile/build_all_ios.sh $*
|
||||||
|
|
||||||
|
# Copy all the libraries required for TFLite Flex runtime together.
|
||||||
|
cd "${TOP_SRCDIR}/tensorflow/contrib/makefile"
|
||||||
|
cp 'downloads/nsync/builds/lipo.ios.c++11/nsync.a' 'gen/lib/'
|
||||||
|
cp 'gen/protobuf_ios/lib/libprotobuf.a' 'gen/lib/'
|
||||||
|
cp 'gen/lib/libtensorflow-core.a' 'gen/lib/libtensorflow-lite.a'
|
@ -43,6 +43,10 @@ DOUBLE_CONVERSION_URL="$(grep -o "https.*google/double-conversion.*\.zip" "${BZL
|
|||||||
ABSL_URL="$(grep -o 'https://github.com/abseil/abseil-cpp/.*tar.gz' "${BZL_FILE_PATH}" | head -n1)"
|
ABSL_URL="$(grep -o 'https://github.com/abseil/abseil-cpp/.*tar.gz' "${BZL_FILE_PATH}" | head -n1)"
|
||||||
CUB_URL="$(grep -o 'https.*cub/archive.*zip' "${BZL_FILE_PATH}" | grep -v mirror.bazel | head -n1)"
|
CUB_URL="$(grep -o 'https.*cub/archive.*zip' "${BZL_FILE_PATH}" | grep -v mirror.bazel | head -n1)"
|
||||||
|
|
||||||
|
# Required for TensorFlow Lite Flex runtime.
|
||||||
|
FARMHASH_URL="https://mirror.bazel.build/github.com/google/farmhash/archive/816a4ae622e964763ca0862d9dbd19324a1eaf45.tar.gz"
|
||||||
|
FLATBUFFERS_URL="https://github.com/google/flatbuffers/archive/1f5eae5d6a135ff6811724f6c57f911d1f46bb15.tar.gz"
|
||||||
|
|
||||||
# TODO(petewarden): Some new code in Eigen triggers a clang bug with iOS arm64,
|
# TODO(petewarden): Some new code in Eigen triggers a clang bug with iOS arm64,
|
||||||
# so work around it by patching the source.
|
# so work around it by patching the source.
|
||||||
replace_by_sed() {
|
replace_by_sed() {
|
||||||
@ -98,6 +102,10 @@ download_and_extract "${DOUBLE_CONVERSION_URL}" "${DOWNLOADS_DIR}/double_convers
|
|||||||
download_and_extract "${ABSL_URL}" "${DOWNLOADS_DIR}/absl"
|
download_and_extract "${ABSL_URL}" "${DOWNLOADS_DIR}/absl"
|
||||||
download_and_extract "${CUB_URL}" "${DOWNLOADS_DIR}/cub/external/cub_archive"
|
download_and_extract "${CUB_URL}" "${DOWNLOADS_DIR}/cub/external/cub_archive"
|
||||||
|
|
||||||
|
# Required for TensorFlow Lite Flex runtime.
|
||||||
|
download_and_extract "${FARMHASH_URL}" "${DOWNLOADS_DIR}/farmhash"
|
||||||
|
download_and_extract "${FLATBUFFERS_URL}" "${DOWNLOADS_DIR}/flatbuffers"
|
||||||
|
|
||||||
replace_by_sed 's#static uint32x4_t p4ui_CONJ_XOR = vld1q_u32( conj_XOR_DATA );#static uint32x4_t p4ui_CONJ_XOR; // = vld1q_u32( conj_XOR_DATA ); - Removed by script#' \
|
replace_by_sed 's#static uint32x4_t p4ui_CONJ_XOR = vld1q_u32( conj_XOR_DATA );#static uint32x4_t p4ui_CONJ_XOR; // = vld1q_u32( conj_XOR_DATA ); - Removed by script#' \
|
||||||
"${DOWNLOADS_DIR}/eigen/Eigen/src/Core/arch/NEON/Complex.h"
|
"${DOWNLOADS_DIR}/eigen/Eigen/src/Core/arch/NEON/Complex.h"
|
||||||
replace_by_sed 's#static uint32x2_t p2ui_CONJ_XOR = vld1_u32( conj_XOR_DATA );#static uint32x2_t p2ui_CONJ_XOR;// = vld1_u32( conj_XOR_DATA ); - Removed by scripts#' \
|
replace_by_sed 's#static uint32x2_t p2ui_CONJ_XOR = vld1_u32( conj_XOR_DATA );#static uint32x2_t p2ui_CONJ_XOR;// = vld1_u32( conj_XOR_DATA ); - Removed by scripts#' \
|
||||||
|
@ -27,6 +27,7 @@ tensorflow/core/grappler/costs/op_performance_data.pb.cc
|
|||||||
tensorflow/core/lib/core/error_codes.pb.cc
|
tensorflow/core/lib/core/error_codes.pb.cc
|
||||||
tensorflow/core/protobuf/cluster.pb.cc
|
tensorflow/core/protobuf/cluster.pb.cc
|
||||||
tensorflow/core/protobuf/config.pb.cc
|
tensorflow/core/protobuf/config.pb.cc
|
||||||
|
tensorflow/core/protobuf/eager_service.pb.cc
|
||||||
tensorflow/core/protobuf/debug.pb.cc
|
tensorflow/core/protobuf/debug.pb.cc
|
||||||
tensorflow/core/protobuf/device_properties.pb.cc
|
tensorflow/core/protobuf/device_properties.pb.cc
|
||||||
tensorflow/core/protobuf/meta_graph.pb.cc
|
tensorflow/core/protobuf/meta_graph.pb.cc
|
||||||
|
@ -29,6 +29,7 @@ tensorflow/core/protobuf/cluster.pb.h
|
|||||||
tensorflow/core/protobuf/config.pb.h
|
tensorflow/core/protobuf/config.pb.h
|
||||||
tensorflow/core/protobuf/debug.pb.h
|
tensorflow/core/protobuf/debug.pb.h
|
||||||
tensorflow/core/protobuf/device_properties.pb.h
|
tensorflow/core/protobuf/device_properties.pb.h
|
||||||
|
tensorflow/core/protobuf/eager_service.pb.h
|
||||||
tensorflow/core/protobuf/meta_graph.pb.h
|
tensorflow/core/protobuf/meta_graph.pb.h
|
||||||
tensorflow/core/protobuf/named_tensor.pb.h
|
tensorflow/core/protobuf/named_tensor.pb.h
|
||||||
tensorflow/core/protobuf/queue_runner.pb.h
|
tensorflow/core/protobuf/queue_runner.pb.h
|
||||||
|
@ -34,6 +34,7 @@ tensorflow/core/lib/core/error_codes.proto
|
|||||||
tensorflow/core/protobuf/cluster.proto
|
tensorflow/core/protobuf/cluster.proto
|
||||||
tensorflow/core/protobuf/config.proto
|
tensorflow/core/protobuf/config.proto
|
||||||
tensorflow/core/protobuf/debug.proto
|
tensorflow/core/protobuf/debug.proto
|
||||||
|
tensorflow/core/protobuf/eager_service.proto
|
||||||
tensorflow/core/protobuf/device_properties.proto
|
tensorflow/core/protobuf/device_properties.proto
|
||||||
tensorflow/core/protobuf/meta_graph.proto
|
tensorflow/core/protobuf/meta_graph.proto
|
||||||
tensorflow/core/protobuf/named_tensor.proto
|
tensorflow/core/protobuf/named_tensor.proto
|
||||||
|
Loading…
Reference in New Issue
Block a user