[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix locating flatc in CMake build.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 646844670
  • Loading branch information
qukhan authored and tensorflower-gardener committed Jun 26, 2024
1 parent 22804b0 commit 02bca39
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
42 changes: 27 additions & 15 deletions tensorflow/lite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,29 @@ option(TFLITE_ENABLE_XNNPACK "Enable XNNPACK backend" ON)
option(TFLITE_ENABLE_EXTERNAL_DELEGATE "Enable External Delegate backend" ON)

option(TFLITE_KERNEL_TEST "Enable tflite kernel unit test" OFF)
if(TFLITE_KERNEL_TEST AND ${CMAKE_CROSSCOMPILING})

if(${CMAKE_CROSSCOMPILING})
set(TFLITE_HOST_TOOLS_DIR "" CACHE PATH "Host tools directory")
if(TFLITE_HOST_TOOLS_DIR STREQUAL "")
message(FATAL_ERROR "Path to the natively compiled 'flatc' compiler binary has not been provided!\
Please specify it using -DTFLITE_HOST_TOOLS_DIR=<flatc_dir_path> launch argument.")
message(FATAL_ERROR "When cross-compiling, some tools need to be available to run on the host (current required tools: flatc). Please specify where those binaries can be found by using -DTFLITE_HOST_TOOLS_DIR=<flatc_dir_path>.")
endif()

# Setup the host FlatBuffers compiler.
set(FLATC_PATHS
${TFLITE_HOST_TOOLS_DIR}
${TFLITE_HOST_TOOLS_DIR}/bin
${TFLITE_HOST_TOOLS_DIR}/flatbuffers-flatc/bin
)
find_program(FLATC_BIN flatc PATHS ${FLATC_PATHS})
if(${FLATC_BIN} STREQUAL "FLATC_BIN-NOTFOUND")
message(FATAL_ERROR "Host 'flatc' compiler has not been found in the following locations: ${FLATC_PATHS}")
else()
message(STATUS "Pre-built 'flatc' compiler for cross-compilation purposes found: ${FLATC_BIN}")
set(FLATBUFFERS_FLATC_EXECUTABLE "${FLATC_BIN}")
endif()
else()
set(FLATBUFFERS_FLATC_EXECUTABLE "${CMAKE_BINARY_DIR}/flatbuffers-flatc/bin/flatc")
set(FLATC_TARGET "flatbuffers-flatc")
endif()

set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -495,19 +512,14 @@ if(TFLITE_ENABLE_XNNPACK)
TFLITE_DELEGATES_XNNPACK_SRCS
FILTER ".*(_test|_tester)\\.(cc|h)"
)
if(FLATBUFFERS_FLATC_EXECUTABLE)
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
else()
set(FLATC flatc)
endif()
add_custom_command(
OUTPUT "${PROJECT_BINARY_DIR}/tensorflow/lite/delegates/xnnpack/weight_cache_schema_generated.h"
COMMAND "${FLATC}" -c
-o "${PROJECT_BINARY_DIR}/tensorflow/lite/delegates/xnnpack/"
--gen-mutable --gen-object-api
"${TFLITE_SOURCE_DIR}/delegates/xnnpack/weight_cache_schema.fbs"
DEPENDS "${TFLITE_SOURCE_DIR}/delegates/xnnpack/weight_cache_schema.fbs"
)
OUTPUT "${PROJECT_BINARY_DIR}/tensorflow/lite/delegates/xnnpack/weight_cache_schema_generated.h"
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" -c
-o "${PROJECT_BINARY_DIR}/tensorflow/lite/delegates/xnnpack/"
--gen-mutable --gen-object-api
"${TFLITE_SOURCE_DIR}/delegates/xnnpack/weight_cache_schema.fbs"
DEPENDS "${FLATC_TARGET}" "${TFLITE_SOURCE_DIR}/delegates/xnnpack/weight_cache_schema.fbs"
)

add_library(xnnpack-delegate STATIC
"${TFLITE_DELEGATES_XNNPACK_SRCS}"
Expand Down
14 changes: 14 additions & 0 deletions tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ cp "${TENSORFLOW_LITE_DIR}/python/interpreter.py" \
echo "__version__ = '${PACKAGE_VERSION}'" >> "${BUILD_DIR}/tflite_runtime/__init__.py"
echo "__git_version__ = '$(git -C "${TENSORFLOW_DIR}" describe)'" >> "${BUILD_DIR}/tflite_runtime/__init__.py"

# Build host tools
if [[ "${TENSORFLOW_TARGET}" != "native" ]]; then
echo "Building for host tools."
HOST_BUILD_DIR="${BUILD_DIR}/cmake_build_host"
mkdir -p "${HOST_BUILD_DIR}"
pushd "${HOST_BUILD_DIR}"
cmake "${TENSORFLOW_LITE_DIR}"
cmake --build . --verbose -j ${BUILD_NUM_JOBS} -t flatbuffers-flatc
popd
fi

# Build python interpreter_wrapper.
mkdir -p "${BUILD_DIR}/cmake_build"
cd "${BUILD_DIR}/cmake_build"
Expand All @@ -80,6 +91,7 @@ case "${TENSORFLOW_TARGET}" in
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=armv7 \
-DTFLITE_ENABLE_XNNPACK=OFF \
-DTFLITE_HOST_TOOLS_DIR="${HOST_BUILD_DIR}" \
"${TENSORFLOW_LITE_DIR}"
;;
rpi0)
Expand All @@ -93,6 +105,7 @@ case "${TENSORFLOW_TARGET}" in
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=armv6 \
-DTFLITE_ENABLE_XNNPACK=OFF \
-DTFLITE_HOST_TOOLS_DIR="${HOST_BUILD_DIR}" \
"${TENSORFLOW_LITE_DIR}"
;;
aarch64)
Expand All @@ -106,6 +119,7 @@ case "${TENSORFLOW_TARGET}" in
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
-DXNNPACK_ENABLE_ARM_I8MM=OFF \
-DTFLITE_HOST_TOOLS_DIR="${HOST_BUILD_DIR}" \
"${TENSORFLOW_LITE_DIR}"
;;
native)
Expand Down

0 comments on commit 02bca39

Please sign in to comment.