提交 ec59a624 编写于 作者: T Terry Heo 提交者: TensorFlower Gardener

Initial support of CMake for TensorFlow Lite

README.md is also added.

These commands show a way to use it.
$ git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
$ mkdir tflite_build && cd tflite_build
$ cmake ../tensorflow_src/tensorflow/lite
$ cmake --build . -j

PiperOrigin-RevId: 327736060
Change-Id: I35acf01b0b33156db5537c146c35de7dc534bb7e
上级 d523827b
#
# Copyright 2020 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
#
# https://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.
# Builds the Tensorflow Lite runtime.
#
# WARNING: This is an experimental that is subject to change.
# This has only been tested on Windows, Linux and macOS.
#
# The following are not currently supported:
# - GPU acceleration
# - Android
# - iOS
# - Micro backend
# - Tests
# - Many features in experimental
# - Host Tools (i.e conversion / analysis tools etc.)
cmake_minimum_required(VERSION 3.16)
# Double colon in target name means ALIAS or IMPORTED target.
cmake_policy(SET CMP0028 NEW)
# Enable MACOSX_RPATH (@rpath) for built dynamic libraries.
cmake_policy(SET CMP0042 NEW)
project(tensorflow-lite C CXX)
set(TENSORFLOW_SOURCE_DIR "" CACHE PATH
"Directory that contains the TensorFlow project"
)
if(NOT TENSORFLOW_SOURCE_DIR)
set(TENSORFLOW_SOURCE_DIR "${CMAKE_SOURCE_DIR}/../../")
endif()
set(TF_SOURCE_DIR "${TENSORFLOW_SOURCE_DIR}/tensorflow")
set(TFLITE_SOURCE_DIR "${CMAKE_SOURCE_DIR}")
set(CMAKE_MODULE_PATH "${TFLITE_SOURCE_DIR}/tools/cmake/modules" ${CMAKE_MODULE_PATH})
set(CMAKE_PREFIX_PATH "${TFLITE_SOURCE_DIR}/tools/cmake/modules" ${CMAKE_PREFIX_PATH})
option(TFLITE_ENABLE_RUY "Enable experimental RUY integration" OFF)
option(TFLITE_ENABLE_RESOURCE "Enable experimental support for resources" ON)
option(TFLITE_ENABLE_NNAPI "Enable NNAPI (Android only)." ON)
option(TFLITE_ENABLE_MMAP "Enable MMAP (unsupported on Windows)" ON)
option(TFLITE_ENABLE_GPU "Enable GPU (not supported)" OFF)
# This must be enabled when converting from TF models with SELECT_TF_OPS
# enabled.
# https://www.tensorflow.org/lite/guide/ops_select#converting_the_model
# This is currently not supported.
option(TFLITE_ENABLE_FLEX "Enable SELECT_TF_OPS" OFF) # TODO: Add support
option(TFLITE_ENABLE_XNNPACK "Enable XNNPACK backend" OFF) # TODO: Add XNNPACK
option(TFLITE_ENABLE_PROFILING "Enable profiling" OFF)
set(CMAKE_CXX_STANDARD 14) # Some components require C++14.
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(_TFLITE_ENABLE_NNAPI "${TFLITE_ENABLE_NNAPI}")
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
set(_TFLITE_ENABLE_NNAPI OFF)
endif()
set(_TFLITE_ENABLE_MMAP "${TFLITE_ENABLE_MMAP}")
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# See https://github.com/tensorflow/tensorflow/blob/\
# 2b96f3662bd776e277f86997659e61046b56c315/tensorflow/lite/tools/make/\
# Makefile#L157
set(_TFLITE_ENABLE_MMAP OFF)
endif()
# Simplifies inclusion of non-test sources and headers from a directory.
# SOURCE_DIR: Directory to search for files.
# SOURCES_VAR: Variable to append with all matching *.cc and *.h files.
# [FILTER expression0 .. expressionN]:
# Additional regular expressions to filter the set of matching
# files. By default, all files ending in "(_test|test_util)\\.(cc|h)" are
# removed.
# [RECURSE]: Whether to recursively search SOURCE_DIR.
macro(populate_source_vars SOURCE_DIR SOURCES_VAR)
cmake_parse_arguments(ARGS "RECURSE" "" "FILTER" ${ARGN})
if(ARGS_RECURSE)
set(GLOB_OP GLOB_RECURSE)
else()
set(GLOB_OP GLOB)
endif()
set(DEFAULT_FILE_FILTER ".*(_test|test_util)\\.(c|cc|h)$")
file(${GLOB_OP} FOUND_SOURCES "${SOURCE_DIR}/*.*")
list(FILTER FOUND_SOURCES INCLUDE REGEX ".*\\.(c|cc|h)$")
list(FILTER FOUND_SOURCES EXCLUDE REGEX "${DEFAULT_FILE_FILTER}")
foreach(FILE_FILTER ${ARGS_FILTER})
list(FILTER FOUND_SOURCES EXCLUDE REGEX "${FILE_FILTER}")
endforeach()
list(APPEND ${SOURCES_VAR} ${FOUND_SOURCES})
endmacro()
# Simplifies inclusion of non-test sources and headers from a directory
# relative to TFLITE_SOURCE_DIR. See populate_source_vars() for the
# description of arguments including and following SOURCES_VAR.
macro(populate_tflite_source_vars RELATIVE_DIR SOURCES_VAR)
populate_source_vars(
"${TFLITE_SOURCE_DIR}/${RELATIVE_DIR}" ${SOURCES_VAR} ${ARGN}
)
endmacro()
# Simplifies inclusion of non-test sources and headers from a directory
# relative to TF_SOURCE_DIR. See populate_source_vars() for the description of
# arguments including and following SOURCES_VAR.
macro(populate_tf_source_vars RELATIVE_DIR SOURCES_VAR)
populate_source_vars(
"${TF_SOURCE_DIR}/${RELATIVE_DIR}" ${SOURCES_VAR} ${ARGN}
)
endmacro()
# Find TensorFlow Lite dependencies.
find_package(absl REQUIRED CONFIG)
find_package(eigen REQUIRED)
find_package(farmhash REQUIRED)
find_package(fft2d REQUIRED)
find_package(flatbuffers REQUIRED)
find_package(gemmlowp REQUIRED)
find_package(neon2sse REQUIRED)
find_package(ruy REQUIRED)
# Generate TensorFlow Lite FlatBuffer code.
# This is not currently neccessary since the generated code is checked into
# the repository but it would likely be preferable to do this in future.
# NOTE: This will not work for cross compilation (e.g for iOS, Android etc.)
# as flatc needs to be compiled with the host toolchain and this currently
# builds with the target toolchain. Instead this should recursively call
# cmake with the default host toolchain to build flatc.
set(TFLITE_FLATBUFFERS_SCHEMAS "${TFLITE_SOURCE_DIR}/schema/schema.fbs")
set(TFLITE_FLATBUFFERS_GEN_DIR
"${CMAKE_BINARY_DIR}/flatbuffers_generated/"
)
set(TFLITE_FLATBUFFERS_HDRS "")
foreach(INPUT_SCHEMA ${TFLITE_FLATBUFFERS_SCHEMAS})
file(RELATIVE_PATH FILENAME "${TENSORFLOW_SOURCE_DIR}" "${INPUT_SCHEMA}")
get_filename_component(OUTPUT_DIR
"${TFLITE_FLATBUFFERS_GEN_DIR}/${FILENAME}" DIRECTORY
)
get_filename_component(OUTPUT_BASENAME
"${FILENAME}" NAME_WE
)
set(OUTPUT_FILENAME "${OUTPUT_DIR}/${OUTPUT_BASENAME}_generated.h")
list(APPEND TFLITE_FLATBUFFERS_HDRS "${OUTPUT_FILENAME}")
add_custom_command(
OUTPUT "${OUTPUT_FILENAME}"
COMMAND flatc
--cpp
--gen-mutable
--gen-object-api
--reflect-names
-I "${TENSORFLOW_SOURCE_DIR}"
-o "${OUTPUT_DIR}"
"${INPUT_SCHEMA}"
DEPENDS
"${INPUT_SCHEMA}")
endforeach()
set(TF_TARGET_PRIVATE_OPTIONS "")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
# TensorFlow uses a heap of deprecated proto fields so surpress these
# warnings until they're fixed.
list(APPEND TF_TARGET_PRIVATE_OPTIONS "-Wno-deprecated-declarations")
endif()
# Additional compiler flags used when compiling TF Lite.
set(TFLITE_TARGET_PUBLIC_OPTIONS "")
set(TFLITE_TARGET_PRIVATE_OPTIONS "")
# Additional library dependencies based upon enabled features.
set(TFLITE_TARGET_DEPENDENCIES "")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
# TFLite uses deprecated methods in neon2sse which generates a huge number of
# warnings so surpress these until they're fixed.
list(APPEND TFLITE_TARGET_PRIVATE_OPTIONS "-Wno-deprecated-declarations")
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
# Use NOMINMAX to disable the min / max macros in windows.h as they break
# use of std::min std::max.
# Use NOGDI to ERROR macro which breaks TensorFlow logging.
list(APPEND TFLITE_TARGET_PRIVATE_OPTIONS "-DNOMINMAX" "-DNOGDI")
endif()
# Build a list of source files to compile into the TF Lite library.
populate_tflite_source_vars("." TFLITE_SRCS)
if(_TFLITE_ENABLE_MMAP)
list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*mmap_allocation_disabled\\.cc$")
else()
list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*mmap_allocation\\.cc$")
endif()
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*minimal_logging_android\\.cc$")
endif()
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*minimal_logging_ios\\.cc$")
endif()
populate_tflite_source_vars("core" TFLITE_CORE_SRCS)
populate_tflite_source_vars("core/api" TFLITE_CORE_API_SRCS)
populate_tflite_source_vars("c" TFLITE_C_SRCS)
populate_tflite_source_vars("delegates" TFLITE_DELEGATES_SRCS)
if(TFLITE_ENABLE_FLEX)
message(FATAL_ERROR "TF Lite Flex delegate is currently not supported.")
populate_tflite_source_vars("delegates/flex" TFLITE_DELEGATES_FLEX_SRCS)
list(APPEND TFLITE_TARGET_DEPENDENCIES
absl::inlined_vector
absl::optional
absl::type_traits
)
endif()
if(TFLITE_ENABLE_GPU)
# Implementation is under delegates/gpu.
message(FATAL_ERROR
"GPU acceleration is not currently supported in CMake builds"
)
endif()
if(_TFLITE_ENABLE_NNAPI)
populate_tflite_source_vars("delegates/nnapi"
TFLITE_DELEGATES_NNAPI_SRCS
FILTER "(_test_list|_disabled)\\.(cc|h)$"
)
populate_tflite_source_vars(
"nnapi" TFLITE_NNAPI_SRCS FILTER "(_disabled)\\.(cc|h)$"
)
else()
set(TFLITE_DELEGATES_NNAPI_SRCS
"${TFLITE_SOURCE_DIR}/delegates/nnapi/nnapi_delegate_disabled.cc"
)
set(TFLITE_NNAPI_SRCS
"${TFLITE_SOURCE_DIR}/nnapi/nnapi_implementation_disabled.cc"
)
endif()
if(TFLITE_ENABLE_XNNPACK)
populate_tflite_source_vars("delegates/xnnpack"
TFLITE_DELEGATES_XNNPACK_SRCS
)
endif()
if (TFLITE_ENABLE_RESOURCE)
populate_tflite_source_vars("experimental/resource"
TFLITE_EXPERIMENTAL_RESOURCE_SRCS
)
endif()
populate_tflite_source_vars("experimental/ruy"
TFLITE_EXPERIMENTAL_RUY_SRCS
FILTER
".*(test(_fast|_slow|_special_specs))\\.(cc|h)$"
".*(benchmark|tune_tool|example)\\.(cc|h)$"
)
populate_tflite_source_vars("experimental/ruy/profiler"
TFLITE_EXPERIMENTAL_RUY_PROFILER_SRCS
FILTER ".*(test|test_instrumented_library)\\.(cc|h)$"
)
if(TFLITE_ENABLE_RUY)
list(APPEND TFLITE_TARGET_PUBLIC_OPTIONS "-DTFLITE_WITH_RUY")
endif()
populate_tflite_source_vars("kernels"
TFLITE_KERNEL_SRCS
FILTER ".*(_test_util_internal|test_main)\\.(cc|h)"
)
populate_tflite_source_vars("kernels/internal" TFLITE_KERNEL_INTERNAL_SRCS)
populate_tflite_source_vars("kernels/internal/optimized"
TFLITE_KERNEL_INTERNAL_OPT_SRCS
)
populate_tflite_source_vars("kernels/internal/optimized/integer_ops"
TFLITE_KERNEL_INTERNAL_OPT_INTEGER_OPS_SRCS
)
populate_tflite_source_vars("kernels/internal/optimized/sparse_ops"
TFLITE_KERNEL_INTERNAL_OPT_SPARSE_OPS_SRCS
)
populate_tflite_source_vars("kernels/internal/reference"
TFLITE_KERNEL_INTERNAL_REF_SRCS
)
populate_tflite_source_vars("kernels/internal/reference/integer_ops"
TFLITE_KERNEL_INTERNAL_REF_INTEGER_OPS_SRCS
)
populate_tflite_source_vars("kernels/internal/reference/sparse_ops"
TFLITE_KERNEL_INTERNAL_REF_SPARSE_OPS_SRCS
)
if(TFLITE_ENABLE_PROFILING)
populate_tflite_source_vars("profiling" TFLITE_KERNEL_PROFILING_SRCS)
endif()
populate_tflite_source_vars("tools/optimize" TFLITE_TOOLS_OPTIMIZE_SRCS)
populate_tflite_source_vars("tools/optimize/calibration"
TFLITE_TOOLS_OPTIMIZE_CALIBRATION_SRCS
)
populate_tflite_source_vars("tools/optimize/calibration/builtin_logging_ops"
TFLITE_TOOLS_OPTIMIZE_CALIBRATION_OPS_SRCS
)
populate_tflite_source_vars("tools/optimize/sparsity"
TFLITE_TOOLS_OPTIMIZE_SPARSITY_SRCS
)
add_library(tensorflowlite
${TFLITE_CORE_API_SRCS}
${TFLITE_CORE_SRCS}
${TFLITE_C_SRCS}
${TFLITE_DELEGATES_FLEX_SRCS}
${TFLITE_DELEGATES_NNAPI_SRCS}
${TFLITE_DELEGATES_SRCS}
${TFLITE_DELEGATES_XNNPACK_SRCS}
${TFLITE_EXPERIMENTAL_RESOURCE_SRCS}
${TFLITE_EXPERIMENTAL_RUY_PROFILER_SRCS}
${TFLITE_EXPERIMENTAL_RUY_SRCS}
${TFLITE_FLATBUFFERS_HDRS}
${TFLITE_KERNEL_INTERNAL_OPT_INTEGER_OPS_SRCS}
${TFLITE_KERNEL_INTERNAL_OPT_SPARSE_OPS_SRCS}
${TFLITE_KERNEL_INTERNAL_OPT_SRCS}
${TFLITE_KERNEL_INTERNAL_REF_INTEGER_OPS_SRCS}
${TFLITE_KERNEL_INTERNAL_REF_SPARSE_OPS_SRCS}
${TFLITE_KERNEL_INTERNAL_REF_SRCS}
${TFLITE_KERNEL_INTERNAL_SRCS}
${TFLITE_KERNEL_PROFILING_SRCS}
${TFLITE_KERNEL_SRCS}
${TFLITE_NNAPI_SRCS}
${TFLITE_SRCS}
${TFLITE_TOOLS_OPTIMIZE_CALIBRATION_OPS_SRCS}
${TFLITE_TOOLS_OPTIMIZE_CALIBRATION_SRCS}
${TFLITE_TOOLS_OPTIMIZE_SPARSITY_SRCS}
${TFLITE_TOOLS_OPTIMIZE_SRCS}
)
target_link_libraries(tensorflowlite
PUBLIC
Eigen3::Eigen
NEON_2_SSE
absl::flags
absl::hash
absl::status
absl::strings
absl::synchronization
absl::variant
farmhash
fft2d_fftsg2d
flatbuffers
gemmlowp
ruy
${TFLITE_TARGET_DEPENDENCIES}
)
target_include_directories(tensorflowlite
PUBLIC
"${TENSORFLOW_SOURCE_DIR}"
PRIVATE
"${TFLITE_FLATBUFFERS_GEN_DIR}"
)
target_compile_options(tensorflowlite
PUBLIC ${TFLITE_TARGET_PUBLIC_OPTIONS}
PRIVATE ${TFLITE_TARGET_PRIVATE_OPTIONS}
)
add_library(tensorflow::tensorflowlite ALIAS tensorflowlite)
# Build TensorFlow Lite with CMake
This page describes how to build the TensorFlow Lite static library with CMake
tool.
The following instructions have been tested on Ubuntu 16.04.3 64-bit PC (AMD64)
and TensorFlow devel docker image
[tensorflow/tensorflow:devel](https://hub.docker.com/r/tensorflow/tensorflow/tags/).
**Note:** This is an experimental that is subject to change.
**Note:** The following are not currently supported: Android, iOS, Tests and
Host Tools (i.e benchmark / analysis tools etc.)
#### Step 1. Install CMake tool
It requires CMake 3.16 or higher. On Ubunutu, you can simply run the following
command.
```sh
sudo apt-get install cmake
```
Or you can follow [the offcial cmake installation guide](https://cmake.org/install/)
#### Step 2. Clone TensorFlow repository
```sh
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
```
**Note:** If you're using the TensorFlow Docker image, the repo is already
provided in `/tensorflow_src/`.
#### Step 3. Create CMake build directory and run CMake tool
```sh
mkdir tflite_build
cd tflite_build
cmake ../tensorflow_src/tensorflow/lite
```
#### Step 4. Build TensorFlow Lite
```sh
cmake --build . -j
```
**Note:** This should compile a static library `libtensorflow-lite.a` in the
current directory.
#
# Copyright 2020 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(eigen)
if(eigen_POPULATED)
set(EIGEN_FOUND TRUE)
get_target_property(EIGEN_INCLUDE_DIRS eigen INTERFACE_DIRECTORIES)
set(EIGEN_LIBRARIES Eigen3::Eigen)
endif()
#
# Copyright 2020 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(farmhash)
if(farmhash_POPULATED)
set(FARMHASH_FOUND TRUE)
get_target_property(FARMHASH_INCLUDE_DIRS farmhash INTERFACE_DIRECTORIES)
add_library(farmhash::farmhash ALIAS farmhash)
set(FARMHASH_LIBRARIES farmhash::farmhash)
endif()
#
# Copyright 2020 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(fft2d)
if(fft2d_POPULATED)
set(FFT2D_FOUND TRUE CACHE BOOL "Found FF2D")
get_target_property(FFT2D_INCLUDE_DIRS fft2d INCLUDE_DIRECTORIES)
set(FFT2D_INCLUDE_DIRS ${FFT2D_INCLUDE_DIRS} CACHE STRING
"FFT2D include dirs"
)
set(FFT2D_LIBRARIES
fft2d_alloc
fft2d_fft4f2d
fft2d_fftsg
fft2d_fftsg2d
fft2d_fftsg3d
fft2d_shrtdct
CACHE
STRING
"FFT2D libraries"
)
endif()
#
# Copyright 2020 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(flatbuffers)
if(flatbuffers_POPULATED)
set(FLATBUFFERS_FOUND TRUE)
get_target_property(FLATBUFFERS_INCLUDE_DIRS flatbuffers INCLUDE_DIRECTORIES)
set(FLATBUFFERS_LIBRARIES flatbuffers)
set(FLATBUFFERS_PROJECT_DIR "${flatbuffers_SOURCE_DIR}" CACHE STRING
"Flatbuffers project dir"
)
endif()
#
# Copyright 2020 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(gemmlowp)
if(gemmlowp_POPULATED)
set(GEMMLOWP_FOUND TRUE)
get_target_property(GEMMLOWP_INCLUDE_DIRS gemmlowp INTERFACE_DIRECTORIES)
set(GEMMLOWP_LIBRARIES
gemmlowp
gemmlowp_fixedpoint
gemmlowp_profiler
gemmlowp_eight_bit_int_gemm
)
endif()
#
# Copyright 2020 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
#
# https://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.
# tensorflow-lite uses find_package for this package, so override the system
# installation and build from source instead.
include(neon2sse)
if(neon2sse_POPULATED)
set(NEON2SSE_FOUND TRUE)
get_target_property(NEON2SSE_INCLUDE_DIRS NEON_2_SSE INTERFACE_DIRECTORIES)
set(NEON2SSE_LIBRARIES NEON_2_SSE)
endif()
#
# Copyright 2020 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
#
# https://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.
include(ruy)
#
# Copyright 2020 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
#
# https://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.
# Use absl_base as a proxy for the project being included.
if(TARGET absl_base OR abseil-cpp_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
abseil-cpp
GIT_REPOSITORY https://github.com/abseil/abseil-cpp
GIT_TAG 20200225.2 # TODO: What version does GRPC and TFLite need?
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/abseil-cpp"
)
OverridableFetchContent_GetProperties(abseil-cpp)
if(NOT abseil-cpp_POPULATED)
OverridableFetchContent_Populate(abseil-cpp)
endif()
set(ABSL_USE_GOOGLETEST_HEAD OFF CACHE BOOL "Disable googletest")
set(ABSL_RUN_TESTS OFF CACHE BOOL "Disable build of ABSL tests")
add_subdirectory(
"${abseil-cpp_SOURCE_DIR}"
"${abseil-cpp_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
#
# Copyright 2020 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
#
# https://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.
# grpc uses find_package in CONFIG mode for this package, so override the
# system installation and build from source instead.
include(abseil-cpp)
if(abseil-cpp_POPULATED)
set(_ABSL_LIBRARY_NAMES
algorithm
algorithm_container
any
atomic_hook
atomic_hook_test_helper
awesome
bad_any_cast
bad_any_cast_impl
bad_optional_access
bad_variant_access
base
base_internal
bind_front
bits
btree
btree_test_common
city
civil_time
compare
compressed_tuple
config
conformance_testing
container
container_common
container_memory
cord
cord_test_helpers
core_headers
counting_allocator
debugging
debugging_internal
demangle_internal
dynamic_annotations
endian
errno_saver
examine_stack
exception_safety_testing
exception_testing
exponential_biased
failure_signal_handler
fantastic_lib
fast_type_id
fixed_array
flags
flags_commandlineflag
flags_commandlineflag_internal
flags_config
flags_internal
flags_marshalling
flags_parse
flags_path_util
flags_private_handle_accessor
flags_program_name
flags_reflection
flags_usage
flags_usage_internal
flat_hash_map
flat_hash_set
function_ref
graphcycles_internal
hash
hash_function_defaults
hash_generator_testing
hash_policy_testing
hash_policy_traits
hash_testing
hashtable_debug
hashtable_debug_hooks
hashtablez_sampler
have_sse
hdrs
inlined_vector
inlined_vector_internal
int128
kernel_timeout_internal
layout
leak_check
leak_check_api_disabled_for_testing
leak_check_api_enabled_for_testing
leak_check_disable
log_severity
main_lib
malloc_internal
memory
meta
node_hash_map
node_hash_policy
node_hash_set
numeric
optional
per_thread_sem_test_common
periodic_sampler
pow10_helper
pretty_function
random_bit_gen_ref
random_distributions
random_internal_distribution_caller
random_internal_distribution_test_util
random_internal_explicit_seed_seq
random_internal_fast_uniform_bits
random_internal_fastmath
random_internal_generate_real
random_internal_iostream_state_saver
random_internal_mock_helpers
random_internal_mock_overload_set
random_internal_nonsecure_base
random_internal_pcg_engine
random_internal_platform
random_internal_pool_urbg
random_internal_randen
random_internal_randen_engine
random_internal_randen_hwaes
random_internal_randen_hwaes_impl
random_internal_randen_slow
random_internal_salted_seed_seq
random_internal_seed_material
random_internal_sequence_urbg
random_internal_traits
random_internal_uniform_helper
random_internal_wide_multiply
random_mocking_bit_gen
random_random
random_seed_gen_exception
random_seed_sequences
raw_hash_map
raw_hash_set
raw_logging_internal
scoped_set_env
span
spinlock_test_common
spinlock_wait
spy_hash_state
stack_consumption
stacktrace
status
str_format
str_format_internal
strerror
strings
strings_internal
symbolize
synchronization
test_instance_tracker
thread_pool
throw_delegate
time
time_internal_test_util
time_zone
tracked
type_traits
unordered_map_constructor_test
unordered_map_lookup_test
unordered_map_members_test
unordered_map_modifiers_test
unordered_set_constructor_test
unordered_set_lookup_test
unordered_set_members_test
unordered_set_modifiers_test
utility
variant
)
set(_ABSL_LIBRARIES ${_ABSL_LIBRARY_NAMES})
foreach(_LIBRARY ${_ABSL_LIBRARY_NAMES})
list(APPEND _ABSL_LIBRARIES "absl::${LIBRARY}")
endforeach()
set(ABSL_LIBRARIES ${ABSL_LIBRARIES} CACHE STRING "absl libs")
endif()
#
# Copyright 2020 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
#
# https://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.
if(TARGET eigen OR eigen_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen
# TODO: Verify this is the version required by TFLite
GIT_TAG b9362fb8f76fbba805b56afbc0f5de0a279631b5
# It's not currently (cmake 3.17) possible to shallow clone with a GIT TAG
# as cmake attempts to git checkout the commit hash after the clone
# which doesn't work as it's a shallow clone hence a different commit hash.
# https://gitlab.kitware.com/cmake/cmake/-/issues/17770
# GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
PREFIX "${CMAKE_BINARY_DIR}"
SOURCE_DIR "${CMAKE_BINARY_DIR}/eigen"
LICENSE_FILE "COPYING.MPL2"
)
OverridableFetchContent_GetProperties(eigen)
if(NOT eigen_POPULATED)
OverridableFetchContent_Populate(eigen)
endif()
# Patch Eigen to disable Fortran compiler check for BLAS and LAPACK tests.
if(NOT EIGEN_DISABLED_FORTRAN_COMPILER_CHECK)
file(WRITE "${eigen_SOURCE_DIR}/cmake/language_support.cmake" "
function(workaround_9220 language language_works)
set(\${language_works} OFF PARENT_SCOPE)
endfunction()"
)
endif()
# Patch Eigen to disable benchmark suite.
if(NOT EIGEN_BUILD_BTL)
file(WRITE "${eigen_SOURCE_DIR}/bench/spbench/CMakeLists.txt" "")
endif()
set(EIGEN_DISABLED_FORTRAN_COMPILER_CHECK ON CACHE BOOL "Disabled Fortran")
set(EIGEN_LEAVE_TEST_IN_ALL_TARGET OFF CACHE BOOL
"Remove tests from all target."
)
set(BUILD_TESTING OFF CACHE BOOL "Disable tests.")
set(EIGEN_TEST_CXX11 OFF CACHE BOOL "Disable tests of C++11 features.")
set(EIGEN_BUILD_BTL OFF CACHE BOOL "Disable benchmark suite.")
set(EIGEN_BUILD_PKGCONFIG OFF CACHE BOOL "Disable pkg-config.")
set(EIGEN_SPLIT_LARGE_TESTS OFF CACHE BOOL "Disable test splitting.")
set(EIGEN_DEFAULT_TO_ROW_MAJOR OFF CACHE BOOL
"Disable row-major matrix storage"
)
set(EIGEN_TEST_NOQT ON CACHE BOOL "Disable Qt support in tests.")
set(EIGEN_TEST_SSE2 OFF CACHE BOOL "Disable SSE2 test.")
set(EIGEN_TEST_SSE3 OFF CACHE BOOL "Disable SSE3 test.")
set(EIGEN_TEST_SSSE3 OFF CACHE BOOL "Disable SSSE3 test.")
set(EIGEN_TEST_SSE4_1 OFF CACHE BOOL "Disable SSE4.1 test.")
set(EIGEN_TEST_SSE4_2 OFF CACHE BOOL "Disable SSE4.2 test.")
set(EIGEN_TEST_AVX OFF CACHE BOOL "Disable AVX test.")
set(EIGEN_TEST_FMA OFF CACHE BOOL "Disable FMA test.")
set(EIGEN_TEST_AVX512 OFF CACHE BOOL "Disable AVX512 test.")
set(EIGEN_TEST_F16C OFF CACHE BOOL "Disable F16C test.")
set(EIGEN_TEST_ALTIVEC OFF CACHE BOOL "Disable AltiVec test.")
set(EIGEN_TEST_VSX OFF CACHE BOOL "Disable VSX test.")
set(EIGEN_TEST_MSA OFF CACHE BOOL "Disable MSA test.")
set(EIGEN_TEST_NEON OFF CACHE BOOL "Disable NEON test.")
set(EIGEN_TEST_NEON64 OFF CACHE BOOL "Disable NEON64 test.")
set(EIGEN_TEST_Z13 OFF CACHE BOOL "Disable Z13 test.")
set(EIGEN_TEST_Z14 OFF CACHE BOOL "Disable Z14 test.")
set(EIGEN_TEST_OPENMP OFF CACHE BOOL "Disable OpenMP test.")
set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION OFF CACHE BOOL "Disable vectorization")
set(EIGEN_TEST_X87 OFF CACHE BOOL "Disable X87 instructions test")
set(EIGEN_TEST_32BIT OFF CACHE BOOL "Disable 32-bit instructions test")
set(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT OFF CACHE BOOL "Disable alignment test")
set(EIGEN_TEST_NO_EXCEPTIONS OFF CACHE BOOL "Disable alignment test")
set(EIGEN_TEST_SYCL OFF CACHE BOOL "Disable Sycl test")
set(EIGEN_SYCL_TRISYCL OFF CACHE BOOL "Disable triSYCL test")
# Make sure only MPL2.0 or more permissively licensed code is included.
add_compile_definitions(EIGEN_MPL2_ONLY)
add_subdirectory("${eigen_SOURCE_DIR}" "${eigen_BINARY_DIR}" EXCLUDE_FROM_ALL)
#
# Copyright 2020 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
#
# https://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.
if(TARGET farmhash OR farmhash_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
farmhash
GIT_REPOSITORY https://github.com/google/farmhash
# TODO: Reference the source of this.
GIT_TAG 816a4ae622e964763ca0862d9dbd19324a1eaf45
# It's not currently possible to shallow clone with a GIT TAG
# as cmake attempts to git checkout the commit hash after the clone
# which doesn't work as it's a shallow clone hence a different commit hash.
# https://gitlab.kitware.com/cmake/cmake/-/issues/17770
# GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/farmhash"
)
OverridableFetchContent_GetProperties(farmhash)
if(NOT farmhash_POPULATED)
OverridableFetchContent_Populate(farmhash)
endif()
set(FARMHASH_SOURCE_DIR "${farmhash_SOURCE_DIR}" CACHE PATH
"Source directory for the CMake project."
)
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/farmhash"
"${farmhash_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
#
# Copyright 2020 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
#
# https://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.
project(farmhash CXX)
set(FARMHASH_SOURCE_DIR "" CACHE PATH
"Directory that contains the farmhash project"
)
if(NOT FARMHASH_SOURCE_DIR)
message(FATAL_ERROR "Must specify source directory")
endif()
# Transcribed from farmhash/src/Makefile.am
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"int main(int argc, char* argv[]) { return (int)__builtin_expect(0, 0); }"
FARMHASH_HAS_BUILTIN_EXPECT
)
add_library(farmhash
"${FARMHASH_SOURCE_DIR}/src/farmhash.cc"
"${FARMHASH_SOURCE_DIR}/src/farmhash.h"
)
target_include_directories(farmhash PUBLIC "${FARMHASH_SOURCE_DIR}/src")
if(NOT FARMHASH_HAS_BUILTIN_EXPECT)
target_compile_definitions(farmhash PUBLIC -DFARMHASH_NO_BUILTIN_EXPECT)
endif()
#
# Copyright 2020 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
#
# https://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.
if(TARGET fft2d OR fft2d_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
fft2d
URL https://storage.googleapis.com/mirror.tensorflow.org/www.kurims.kyoto-u.ac.jp/~ooura/fft2d.tgz
# TODO: Reference where this comes from.
URL_HASH SHA256=ada7e99087c4ed477bfdf11413f2ba8db8a840ba9bbf8ac94f4f3972e2a7cec9
SOURCE_DIR "${CMAKE_BINARY_DIR}/fft2d"
LICENSE_FILE "readme2d.txt"
LICENSE_URL "http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html"
)
OverridableFetchContent_GetProperties(fft2d)
if(NOT fft2d_POPULATED)
OverridableFetchContent_Populate(fft2d)
endif()
set(FFT2D_SOURCE_DIR "${fft2d_SOURCE_DIR}" CACHE PATH "fft2d source")
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/fft2d"
"${fft2d_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
#
# Copyright 2020 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
#
# https://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.
project(fft2d C)
set(FFT2D_SOURCE_DIR "" CACHE PATH
"Directory that contains the fft2d project"
)
if(NOT FFT2D_SOURCE_DIR)
message(FATAL_ERROR "Must specify source directory")
endif()
# fft2d doesn't have a CMake project so define it here transcribed from
# sample2d/Makefile.
# A developer should link this library if they haven't provided their own
# implementation of these allocation methods.
add_library(fft2d_alloc
"${FFT2D_SOURCE_DIR}/alloc.c"
"${FFT2D_SOURCE_DIR}/alloc.h"
)
target_include_directories(fft2d_alloc PUBLIC "${FFT2D_SOURCE_DIR}")
# Requires implementation of fft2d_alloc.
add_library(fft2d_fft4f2d "${FFT2D_SOURCE_DIR}/fft4f2d.c")
target_include_directories(fft2d_fft4f2d PRIVATE "${FFT2D_SOURCE_DIR}")
add_library(fft2d_fftsg "${FFT2D_SOURCE_DIR}/fftsg.c")
# Requires implementation of fft2d_alloc.
add_library(fft2d_fftsg2d "${FFT2D_SOURCE_DIR}/fftsg2d.c")
target_link_libraries(fft2d_fftsg2d fft2d_fftsg)
target_include_directories(fft2d_fftsg2d PRIVATE "${FFT2D_SOURCE_DIR}")
# Requires implementation of fft2d_alloc.
add_library(fft2d_fftsg3d "${FFT2D_SOURCE_DIR}/fftsg3d.c")
target_link_libraries(fft2d_fftsg3d fft2d_fftsg)
target_include_directories(fft2d_fftsg3d PRIVATE "${FFT2D_SOURCE_DIR}")
add_library(fft2d_shrtdct "${FFT2D_SOURCE_DIR}/shrtdct.c")
add_library(fft2d ALIAS fft2d_fftsg2d)
#
# Copyright 2020 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
#
# https://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.
if(TARGET flatbuffers OR flatbuffers_POPULATED)
return()
endif()
include(FetchContent)
OverridableFetchContent_Declare(
flatbuffers
GIT_REPOSITORY https://github.com/google/flatbuffers
GIT_TAG v1.12.0 # TODO: What version does TFLite need?
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/flatbuffers"
)
OverridableFetchContent_GetProperties(flatbuffers)
if(NOT flatbuffers_POPULATED)
OverridableFetchContent_Populate(flatbuffers)
endif()
# Required for Windows, since it has macros called min & max which
# clashes with std::min
add_definitions(-DNOMINMAX=1)
add_subdirectory(
"${flatbuffers_SOURCE_DIR}"
"${flatbuffers_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
remove_definitions(-DNOMINMAX)
#
# Copyright 2020 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
#
# https://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.
if(TARGET gemmlowp OR gemmlowp_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
gemmlowp
GIT_REPOSITORY https://github.com/google/gemmlowp
GIT_TAG fda83bdc38b118cc6b56753bd540caa49e570745
# It's not currently (cmake 3.17) possible to shallow clone with a GIT TAG
# as cmake attempts to git checkout the commit hash after the clone
# which doesn't work as it's a shallow clone hence a different commit hash.
# https://gitlab.kitware.com/cmake/cmake/-/issues/17770
# GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/gemmlowp"
)
OverridableFetchContent_GetProperties(gemmlowp)
if(NOT gemmlowp_POPULATED)
OverridableFetchContent_Populate(gemmlowp)
endif()
set(GEMMLOWP_SOURCE_DIR "${gemmlowp_SOURCE_DIR}" CACHE PATH "Source directory")
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/gemmlowp"
"${gemmlowp_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
#
# Copyright 2020 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
#
# https://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.
project(gemmlowp CXX)
option(GEMMLOWP_ADD_HEADERS_TO_TARGETS OFF
"Whether to add sources to gemmlowp's interface library targets.
This will cause all users of these libraries to also include these headers"
)
set(GEMMLOWP_SOURCE_DIR "" CACHE PATH
"Directory that contains the gemmlowp project"
)
if(NOT GEMMLOWP_SOURCE_DIR)
message(FATAL_ERROR "Must specify source directory")
endif()
# gemmlowp doesn't have a CMake project so this is transcribed from
# gemmlowp/BUILD.
file(GLOB GEMMLOWP_EIGHTBITINT_HEADERS
"${GEMMLOWP_SOURCE_DIR}/eight_bit_int_gemm/*.h"
)
file(GLOB GEMMLOWP_EIGHTBITINT_SOURCES
"${GEMMLOWP_SOURCE_DIR}/eight_bit_int_gemm/*.cc"
)
file(GLOB GEMMLOWP_FIXEDPOINT_HEADERS "${GEMMLOWP_SOURCE_DIR}/fixedpoint/*.h")
file(GLOB GEMMLOWP_INTERNAL_HEADERS "${GEMMLOWP_SOURCE_DIR}/internal/*.h")
file(GLOB GEMMLOWP_META_HEADERS "${GEMMLOWP_SOURCE_DIR}/meta/*.h")
file(GLOB GEMMLOWP_PROFILING_HEADERS "${GEMMLOWP_SOURCE_DIR}/profiling/*.h")
file(GLOB GEMMLOWP_PUBLIC_HEADERS "${GEMMLOWP_SOURCE_DIR}/public/*.h")
set(GEMMLOWP_PRIVATE_HEADERS "")
list(APPEND GEMMLOWP_PRIVATE_HEADERS ${GEMMLOWP_FIXEDPOINT_HEADERS})
list(APPEND GEMMLOWP_PRIVATE_HEADERS ${GEMMLOWP_INTERNAL_HEADERS})
add_library(gemmlowp_private INTERFACE)
if(GEMMLOWP_ADD_HEADERS_TO_TARGETS)
target_sources(gemmlowp_private INTERFACE ${GEMMLOWP_PRIVATE_HEADERS})
endif()
target_include_directories(gemmlowp_private INTERFACE "${GEMMLOWP_SOURCE_DIR}")
add_library(gemmlowp INTERFACE)
if(GEMMLOWP_ADD_HEADERS_TO_TARGETS)
target_sources(gemmlowp INTERFACE ${GEMMLOWP_PUBLIC_HEADERS})
endif()
target_include_directories(gemmlowp INTERFACE "${GEMMLOWP_SOURCE_DIR}/public")
target_link_libraries(gemmlowp INTERFACE gemmlowp_private)
add_library(gemmlowp_eight_bit_int_gemm
${GEMMLOWP_EIGHTBITINT_SOURCES}
${GEMMLOWP_EIGHTBITINT_HEADERS}
)
target_include_directories(gemmlowp_eight_bit_int_gemm
PUBLIC "${GEMMLOWP_SOURCE_DIR}/eight_bit_int_gemm"
)
add_library(gemmlowp_fixedpoint INTERFACE)
if(GEMMLOWP_ADD_HEADERS_TO_TARGETS)
target_sources(gemmlowp_fixedpoint INTERFACE ${GEMMLOWP_FIXEDPOINT_HEADERS})
endif()
target_include_directories(gemmlowp_fixedpoint
INTERFACE "${GEMMLOWP_SOURCE_DIR}/fixedpoint"
)
target_link_libraries(gemmlowp_fixedpoint INTERFACE gemmlowp_private)
add_library(gemmlowp_profiler INTERFACE)
if(GEMMLOWP_ADD_HEADERS_TO_TARGETS)
target_sources(gemmlowp_profiler INTERFACE ${GEMMLOWP_PROFILING_HEADERS})
endif()
target_include_directories(gemmlowp_profiler
INTERFACE "${GEMMLOWP_SOURCE_DIR}/profiling"
)
#
# Copyright 2020 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
#
# https://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.
include(ExternalProject)
if(TARGET neon2sse OR neon2sse_POPULATED)
return()
endif()
OverridableFetchContent_Declare(
neon2sse
GIT_REPOSITORY https://github.com/intel/ARM_NEON_2_x86_SSE
GIT_TAG master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/neon2sse"
)
OverridableFetchContent_GetProperties(neon2sse)
if(NOT neon2sse_POPULATED)
OverridableFetchContent_Populate(neon2sse)
endif()
add_subdirectory(
"${neon2sse_SOURCE_DIR}"
"${neon2sse_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
#
# Copyright 2020 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
#
# https://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.
if(TARGET ruy OR ruy_POPULATED)
return()
endif()
include(OverridableFetchContent)
OverridableFetchContent_Declare(
ruy
GIT_REPOSITORY https://github.com/google/ruy
GIT_TAG master # TODO
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR "${CMAKE_BINARY_DIR}/ruy"
)
OverridableFetchContent_GetProperties(ruy)
if(NOT ruy_POPULATED)
OverridableFetchContent_Populate(ruy)
endif()
set(RUY_SOURCE_DIR "${ruy_SOURCE_DIR}" CACHE PATH "RUY source directory")
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/ruy"
"${ruy_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
#
# Copyright 2020 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
#
# https://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.
cmake_minimum_required(VERSION 3.16)
project(ruy CXX)
set(CMAKE_CXX_STANDARD 14) # Some components require C++14.
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(RUY_SOURCE_DIR "" CACHE PATH
"Directory that contains the RUY project"
)
if(NOT RUY_SOURCE_DIR)
message(FATAL_ERROR "Must specify source directory")
endif()
file(GLOB RUY_SOURCES "${RUY_SOURCE_DIR}/ruy/*.*")
list(FILTER RUY_SOURCES INCLUDE REGEX ".*\\.(c|cc|h)$")
list(FILTER RUY_SOURCES EXCLUDE REGEX ".*(_test)\\.(c|cc|h)$")
list(FILTER RUY_SOURCES EXCLUDE REGEX ".*/(benchmark|example|test_.*)\.cc$")
list(FILTER RUY_SOURCES EXCLUDE REGEX ".*/gtest_wrapper\\.h$")
add_library(ruy ${RUY_SOURCES})
target_include_directories(ruy PUBLIC "${RUY_SOURCE_DIR}")
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册