Skip to content

Commit

Permalink
(conan-io#12390) [tensorflow-lite] Update to 2.10.0, prepare for Cona…
Browse files Browse the repository at this point in the history
…n v2, use the new CMake build helpers

* [tensorflow-lite] Prepare for Conan v2, use the new CMake build helpers

* [tensorflow-lite] Reorder and simplify patches

* [tensorflow-lite] Remove 2.6.x series and update compiler requirements

* [tensorflow-lite] Don't use collect_libs

* [tensorflow-lite] Update tests

Imported from
conan-io#12686

* [tensorflow-lite] Don't remove pdb files (no need)

* [tensorflow-lite] Use export_conandata_patches()

* [tensorflow-lite] self.copy() -> tools.files.copy()

* [tensorflow-lite] abseil: 20211102.0 -> 20220623.0

* [tensorflow-lite] Minor test_package fixes

* [tensorflow-lite] Add layout()

* [tensorflow-lite] Remove unnecessary destination arg to get()

* [tensorflow-lite] Update missed reference to C++14

* [tensorflow-lite] Don't use export_conandata_patches

* [tensorflow-lite] 2.9.1 -> 2.10.0

* Revert "[tensorflow-lite] Add layout()"

This reverts commit 4740f6b.

layout() breaks windows build.

* [tensorflow-lite] Add missing dependency patch

* [tensorflow-lite] Move methods

* [tensorflow-lite] Re-add layout() with windows build workaround

* [tensorflow-lite] Change back to using source_folder in test_v1

* [tensorflow-lite] Put the dll in the bin output folder...

...and be a bit stricter about which file patterns to copy.

* Revert "[tensorflow-lite] Don't use export_conandata_patches"

This reverts commit 1d946d8.

* [tensorflow-lite] Don't use self in static method

* [tensorflow-lite] Refactor layout()

* [tensorflow-lite] self.settings -> self.info.settings in validate()

* [tensorflow-lite] Explicitly specify source destination folder
  • Loading branch information
talyz authored and marc-mw committed Oct 7, 2022
1 parent 4c6d265 commit cd233fc
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 374 deletions.
7 changes: 0 additions & 7 deletions recipes/tensorflow-lite/all/CMakeLists.txt

This file was deleted.

34 changes: 7 additions & 27 deletions recipes/tensorflow-lite/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
sources:
"2.6.0":
url: "https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.6.0.tar.gz"
sha256: "41b32eeaddcbc02b0583660bcf508469550e4cd0f86b22d2abe72dfebeacde0f"
"2.6.2":
url: "https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.6.2.tar.gz"
sha256: "e68c1d346fc3d529653530ca346b2c62f5b31bd4fcca7ffc9c65bb39ab2f6ed3"
"2.9.1":
url: "https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.9.1.tar.gz"
sha256: "6eaf86ead73e23988fe192da1db68f4d3828bcdd0f3a9dc195935e339c95dbdc"
"2.10.0":
url: "https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.10.0.tar.gz"
sha256: "b5a1bb04c84b6fe1538377e5a1f649bb5d5f0b2e3625a3c526ff3a8af88633e8"
patches:
"2.9.1":
- patch_file: "patches/msvc_fixes.patch"
patch_description: "Fix Windows build: Apply fixes for compatibility with MSVC from master"
patch_source: "https://github.com/tensorflow/tensorflow/pull/56408"
patch_type: "backport"
base_path: "src"
- patch_file: "patches/dependencies_2_9.patch"
patch_description: "Dependency compatibility: Patch CMakeLists.txt, updating package names, target names, etc"
patch_type: "conan"
base_path: "src"
"2.10.0":
- patch_file: "patches/remove_simple_memory_arena_debug_dump.patch"
patch_description: "Shared build fails on Windows with error LNK2005. Resolve the conflict by removing the conflicting implementation for now."
base_path: "src"
"2.6.0":
- patch_file: "patches/dependencies_2_6.patch"
patch_description: "Dependency compatibility: Patch CMakeLists.txt, updating package names, target names, etc"
- patch_file: "patches/disable_fetch_content.patch"
patch_description: "Fail if the CMake build script tries to fetch external dependencies"
patch_type: "conan"
base_path: "src"
"2.6.2":
- patch_file: "patches/dependencies_2_6.patch"
- patch_file: "patches/dependencies_2_10.patch"
patch_description: "Dependency compatibility: Patch CMakeLists.txt, updating package names, target names, etc"
patch_type: "conan"
base_path: "src"
116 changes: 55 additions & 61 deletions recipes/tensorflow-lite/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from conan import ConanFile
from conan.tools import files
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.build import check_min_cppstd
from conan.tools.files import get, save, copy, export_conandata_patches, apply_conandata_patches
from conan.errors import ConanInvalidConfiguration
from conans import CMake, tools
import functools
import os
from os.path import join
import textwrap

required_conan_version = ">=1.50.0"
required_conan_version = ">=1.52.0"


class TensorflowLiteConan(ConanFile):
Expand Down Expand Up @@ -37,31 +37,19 @@ class TensorflowLiteConan(ConanFile):
"with_xnnpack": True
}


short_paths = True
generators = "cmake", "cmake_find_package", "cmake_find_package_multi"

@property
def _source_subfolder(self):
return "src"

@property
def _build_subfolder(self):
return "build"

@property
def _compilers_minimum_version(self):
return {
"gcc": "5",
"Visual Studio": "14",
"clang": "3.4",
"gcc": "8",
"Visual Studio": "15.8",
"clang": "5",
"apple-clang": "5.1",
}

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -76,60 +64,66 @@ def configure(self):
del self.options.fPIC

def requirements(self):
self.requires("abseil/20211102.0")
self.requires("abseil/20220623.0")
self.requires("eigen/3.4.0")
self.requires("farmhash/cci.20190513")
self.requires("fft/cci.20061228")
self.requires("flatbuffers/2.0.5")
self.requires("flatbuffers/2.0.6")
self.requires("gemmlowp/cci.20210928")
if self.settings.arch in ("x86", "x86_64"):
self.requires("intel-neon2sse/cci.20210225")
self.requires("ruy/cci.20220628")
if self.options.with_xnnpack:
self.requires("xnnpack/cci.20220621")
self.requires("xnnpack/cci.20220801")
if self.options.with_xnnpack or self.options.get_safe("with_nnapi", False):
self.requires("fp16/cci.20210320")

def build_requirements(self):
self.tool_requires("cmake/3.24.0")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 17 if Version(self.version) >= "2.9.1" else 14)

minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if not minimum_version:
self.output.warn(f"{self.name} requires C++14. Your compiler is unknown. Assuming it supports C++14.")
elif Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(f"{self.name} requires C++14, which your compiler does not support.")

def source(self):
files.get(self, **self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)

def build(self):
files.apply_conandata_patches(self)
cmake = self._configure_cmake()
cmake.build()
def layout(self):
cmake_layout(self, build_folder=f"build_folder/{self.settings.build_type}")

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions.update({
def generate(self):
tc = CMakeToolchain(self)
tc.variables.update({
"CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS": True,
"TFLITE_ENABLE_RUY": self.options.with_ruy,
"TFLITE_ENABLE_NNAPI": self.options.get_safe("with_nnapi", False),
"TFLITE_ENABLE_GPU": False,
"TFLITE_ENABLE_XNNPACK": self.options.with_xnnpack,
"TFLITE_ENABLE_MMAP": self.options.get_safe("with_mmap", False)
"TFLITE_ENABLE_MMAP": self.options.get_safe("with_mmap", False),
"FETCHCONTENT_FULLY_DISCONNECTED": True,
"clog_POPULATED": True,
})
if self.settings.arch == "armv8":
# Not defined by Conan for Apple Silicon. See https://github.com/conan-io/conan/pull/8026
cmake.definitions["CMAKE_SYSTEM_PROCESSOR"] = "arm64"
cmake.configure(build_folder=self._build_subfolder)
return cmake
tc.variables["CMAKE_SYSTEM_PROCESSOR"] = "arm64"
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def validate(self):
if self.info.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, 17)

minimum_version = self._compilers_minimum_version.get(str(self.info.settings.compiler), False)
if not minimum_version:
self.output.warn(f"{self.name} requires C++17. Your compiler is unknown. Assuming it supports C++17.")
elif Version(self.info.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(f"{self.name} requires C++17, which your compiler does not support.")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True, destination=self.source_folder)

def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure(build_script_folder=join("tensorflow", "lite"))
cmake.build()

@staticmethod
def _create_cmake_module_alias_target(module_file):
def _create_cmake_module_alias_target(conanfile, module_file):
aliased = "tensorflowlite::tensorflowlite"
alias = "tensorflow::tensorflowlite"
content = textwrap.dedent(f"""\
Expand All @@ -138,21 +132,21 @@ def _create_cmake_module_alias_target(module_file):
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""")
tools.save(module_file, content)
save(conanfile, module_file, content)

@property
def _module_file(self):
return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake")
return join("lib", "cmake", f"conan-official-{self.name}-targets.cmake")

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
self.copy("*.h", dst=os.path.join("include", "tensorflow", "lite"), src=os.path.join(self._source_subfolder, "tensorflow", "lite"))
self.copy("*", dst="lib", src=os.path.join(self._build_subfolder, "lib"))
if self.options.shared:
self.copy("*", dst="bin", src=os.path.join(self._build_subfolder, "bin"))
if self.settings.build_type == "Debug":
tools.remove_files_by_mask(self.package_folder, "*.pdb")
self._create_cmake_module_alias_target(os.path.join(self.package_folder, self._module_file))
copy(self, "LICENSE", self.source_folder, join(self.package_folder, "licenses"))
copy(self, "*.h", join(self.source_folder, "tensorflow", "lite"), join(self.package_folder, "include", "tensorflow", "lite"))
copy(self, "*.a", self.build_folder, join(self.package_folder, "lib"))
copy(self, "*.so", self.build_folder, join(self.package_folder, "lib"))
copy(self, "*.dylib", self.build_folder, join(self.package_folder, "lib"))
copy(self, "*.lib", self.build_folder, join(self.package_folder, "lib"), keep_path=False)
copy(self, "*.dll", self.build_folder, join(self.package_folder, "bin"), keep_path=False)
self._create_cmake_module_alias_target(self, join(self.package_folder, self._module_file))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "tensorflowlite")
Expand All @@ -170,6 +164,6 @@ def package_info(self):
defines.append("TFLITE_WITH_RUY")

self.cpp_info.defines = defines
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.libs = ["tensorflow-lite"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("dl")
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
commit fcb02f001504c4060f83233cedc9b8f197fcc607
Author: talyz <kim.lindberger@gmail.com>
Date: Wed Aug 24 19:09:53 2022 +0200

Conan deps

diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
index 40f9485b5d6..f184ac5d30d 100644
index 663f07ab31c..9f05de4ebec 100644
--- a/tensorflow/lite/CMakeLists.txt
+++ b/tensorflow/lite/CMakeLists.txt
@@ -50,14 +50,8 @@ if(NOT TENSORFLOW_SOURCE_DIR)
endif()
set(TF_SOURCE_DIR "${TENSORFLOW_SOURCE_DIR}/tensorflow")
set(TFLITE_SOURCE_DIR "${CMAKE_CURRENT_LIST_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}
-)
+list(APPEND CMAKE_MODULE_PATH "${TFLITE_SOURCE_DIR}/tools/cmake/modules")
+list(APPEND CMAKE_PREFIX_PATH "${TFLITE_SOURCE_DIR}/tools/cmake/modules")
include(CMakeDependentOption)
option(TFLITE_ENABLE_RUY "Enable experimental RUY integration" OFF)
option(TFLITE_ENABLE_RESOURCE "Enable experimental support for resources" ON)
@@ -138,12 +132,11 @@ macro(populate_tf_source_vars RELATIVE_DIR SOURCES_VAR)
@@ -138,12 +138,11 @@ macro(populate_tf_source_vars RELATIVE_DIR SOURCES_VAR)
endmacro()
# Find TensorFlow Lite dependencies.
find_package(absl REQUIRED)
Expand All @@ -35,18 +24,18 @@ index 40f9485b5d6..f184ac5d30d 100644
find_package(clog REQUIRED)
find_package(cpuinfo REQUIRED) #CPUINFO is used by XNNPACK and RUY library
find_package(ruy REQUIRED)
@@ -162,6 +155,10 @@ set(TFLITE_TARGET_PUBLIC_OPTIONS "")
@@ -162,6 +161,10 @@ set(TFLITE_TARGET_PUBLIC_OPTIONS "")
set(TFLITE_TARGET_PRIVATE_OPTIONS "")
# Additional library dependencies based upon enabled features.
set(TFLITE_TARGET_DEPENDENCIES "")
+if (NOT CMAKE_SYSTEM_PROCESSOR OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86")
+ find_package(NEON_2_SSE REQUIRED)
+ list(APPEND TFLITE_TARGET_DEPENDENCIES NEON_2_SSE::NEON_2_SSE)
+ find_package(intel-neon2sse REQUIRED)
+ list(APPEND TFLITE_TARGET_DEPENDENCIES intel-neon2sse::intel-neon2sse)
+endif()
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.
@@ -395,7 +392,7 @@ if(TFLITE_ENABLE_XNNPACK)
@@ -411,7 +414,7 @@ if(TFLITE_ENABLE_XNNPACK)
FILTER ".*(_test|_tester)\\.(cc|h)"
)
list(APPEND TFLITE_TARGET_DEPENDENCIES
Expand All @@ -55,7 +44,7 @@ index 40f9485b5d6..f184ac5d30d 100644
)
list(APPEND TFLITE_TARGET_PUBLIC_OPTIONS "-DTFLITE_BUILD_WITH_XNNPACK_DELEGATE")
endif()
@@ -499,18 +496,17 @@ target_include_directories(tensorflow-lite
@@ -519,17 +522,16 @@ target_include_directories(tensorflow-lite
target_link_libraries(tensorflow-lite
PUBLIC
Eigen3::Eigen
Expand All @@ -70,12 +59,10 @@ index 40f9485b5d6..f184ac5d30d 100644
- fft2d_fftsg2d
- flatbuffers
- gemmlowp
- ruy
+ farmhash::farmhash
+ fft::fft
+ flatbuffers::flatbuffers
+ gemmlowp::eight_bit_int_gemm
+ ruy::ruy
ruy::ruy
${CMAKE_DL_LIBS}
${TFLITE_TARGET_DEPENDENCIES}
)
Loading

0 comments on commit cd233fc

Please sign in to comment.