diff options
author | 2016-06-15 08:07:50 -0700 | |
---|---|---|
committer | 2016-06-15 08:07:50 -0700 | |
commit | ea00daa3945d10bbce59e65164acc9d40f17f9a5 (patch) | |
tree | 71af117abb9011313bb112c5053942c63ab4087d | |
parent | 115f5185e56c3fc4c8ada87c56651434f6be585c (diff) |
Merge iOS and Pi changes into 0.9 branch (#2857)
* Updated iOS settings (#2694)
* Added linker options to armv7 in iOS makefile
* Updated Eigen version in Xcode iOS examples
* Updated iOS link flags
* Fixes for Raspberry Pi compilation (#2701)
* Added linker options to armv7 in iOS makefile
* Updated Eigen version in Xcode iOS examples
* Updated iOS link flags
* Added support for Raspberry Pi
* Updated Pi documentation and Eigen version in makefile (#2743)
* Updated Pi compilation documentation
* Updated Eigen version in makefile
* Updated documentation link
* Updated Pi documentation
* Updated Pi build settings
* Fix for build issue #2742; (#2749)
(1) Additionally added linking against pthread for linux machines
* Missing space; (#2762)
(1) bash file check will fail without the space;
* Updated Eigen include paths for iOS examples (#2841)
* Updated Eigen hashes
* Updated Eigen paths to a permanent link
* Merged Eigen header changes
* Merged Eigen header changes
6 files changed, 83 insertions, 33 deletions
diff --git a/tensorflow/contrib/ios_examples/camera/camera_example.xcodeproj/project.pbxproj b/tensorflow/contrib/ios_examples/camera/camera_example.xcodeproj/project.pbxproj index 0156188577..14785cc708 100644 --- a/tensorflow/contrib/ios_examples/camera/camera_example.xcodeproj/project.pbxproj +++ b/tensorflow/contrib/ios_examples/camera/camera_example.xcodeproj/project.pbxproj @@ -285,7 +285,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( "$(SRCROOT)/../../makefile/gen/proto", - "$(SRCROOT)/../../makefile/downloads/eigen-eigen-f3a13643ac1f", + "$(SRCROOT)/../../makefile/downloads/eigen-latest", "$(SRCROOT)/../../makefile/downloads", "$(SRCROOT)/../../makefile/downloads/protobuf/src/", "$(SRCROOT)/../../../..", @@ -300,6 +300,12 @@ OTHER_LDFLAGS = ( "-force_load", "$(SRCROOT)/../../makefile/gen/lib/libtensorflow-core.a", + "-Xlinker", + "-S", + "-Xlinker", + "-x", + "-Xlinker", + "-dead_strip", ); PRODUCT_BUNDLE_IDENTIFIER = com.google.CameraExample; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -344,7 +350,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( "$(SRCROOT)/../../makefile/gen/proto", - "$(SRCROOT)/../../makefile/downloads/eigen-eigen-f3a13643ac1f", + "$(SRCROOT)/../../makefile/downloads/eigen-latest", "$(SRCROOT)/../../makefile/downloads", "$(SRCROOT)/../../makefile/downloads/protobuf/src/", "$(SRCROOT)/../../../..", @@ -359,6 +365,12 @@ OTHER_LDFLAGS = ( "-force_load", "$(SRCROOT)/../../makefile/gen/lib/libtensorflow-core.a", + "-Xlinker", + "-S", + "-Xlinker", + "-x", + "-Xlinker", + "-dead_strip", ); PRODUCT_BUNDLE_IDENTIFIER = com.google.CameraExample; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/tensorflow/contrib/ios_examples/simple/tf_ios_makefile_example.xcodeproj/project.pbxproj b/tensorflow/contrib/ios_examples/simple/tf_ios_makefile_example.xcodeproj/project.pbxproj index 91866cecac..a81286a5b1 100644 --- a/tensorflow/contrib/ios_examples/simple/tf_ios_makefile_example.xcodeproj/project.pbxproj +++ b/tensorflow/contrib/ios_examples/simple/tf_ios_makefile_example.xcodeproj/project.pbxproj @@ -276,8 +276,8 @@ "$(SRCROOT)/../../../..", "$(SRCROOT)/../../makefile/downloads/protobuf/src/", "$(SRCROOT)/../../makefile/downloads", - "$(SRCROOT)/../../makefile/downloads/eigen-eigen-f3a13643ac1f", "$(SRCROOT)/../../makefile/gen/proto", + "$(SRCROOT)/../../makefile/downloads/eigen-latest", ); INFOPLIST_FILE = "$(SRCROOT)/RunModel-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.2; @@ -289,6 +289,12 @@ OTHER_LDFLAGS = ( "-force_load", "$(SRCROOT)/../../makefile/gen/lib/libtensorflow-core.a", + "-Xlinker", + "-S", + "-Xlinker", + "-x", + "-Xlinker", + "-dead_strip", ); PRODUCT_BUNDLE_IDENTIFIER = "com.google.TF-Test"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -304,8 +310,8 @@ "$(SRCROOT)/../../../..", "$(SRCROOT)/../../makefile/downloads/protobuf/src/", "$(SRCROOT)/../../makefile/downloads", - "$(SRCROOT)/../../makefile/downloads/eigen-eigen-f3a13643ac1f", "$(SRCROOT)/../../makefile/gen/proto", + "$(SRCROOT)/../../makefile/downloads/eigen-latest", ); INFOPLIST_FILE = "$(SRCROOT)/RunModel-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.2; @@ -314,10 +320,16 @@ "$(SRCROOT)/../../makefile/gen/protobuf_ios/lib", "$(SRCROOT)/../../makefile/gen/lib", ); - ONLY_ACTIVE_ARCH = NO; + ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = ( "-force_load", "$(SRCROOT)/../../makefile/gen/lib/libtensorflow-core.a", + "-Xlinker", + "-S", + "-Xlinker", + "-x", + "-Xlinker", + "-dead_strip", ); PRODUCT_BUNDLE_IDENTIFIER = "com.google.TF-Test"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/tensorflow/contrib/makefile/Makefile b/tensorflow/contrib/makefile/Makefile index 984250ce83..86ad8f41c1 100644 --- a/tensorflow/contrib/makefile/Makefile +++ b/tensorflow/contrib/makefile/Makefile @@ -35,8 +35,8 @@ HOST_OBJDIR := $(MAKEFILE_DIR)/gen/host_obj/ HOST_BINDIR := $(MAKEFILE_DIR)/gen/host_bin/ HOST_GENDIR := $(MAKEFILE_DIR)/gen/host_obj/ -# Which Eigen version we're using. -EIGEN_HASH := d02e6a705c30 +# Find the current Eigen version name from the Bazel build file +EIGEN_HASH := $(shell cat eigen.BUILD | grep archive_dir | head -1 | cut -f3 -d- | cut -f1 -d\") # Settings for the host compiler. HOST_CXX := gcc @@ -56,9 +56,15 @@ HOST_LIBS := \ # If we're on Linux, also link in the dl library. ifeq ($(HOST_OS),LINUX) - HOST_LIBS += -ldl + HOST_LIBS += -ldl -lpthread endif +# If we're on a Pi, link in pthreads and dl +ifeq ($(HOST_OS),PI) + HOST_LIBS += -ldl -lpthread +endif + + # proto_text is a tool that converts protobufs into a form we can use more # compactly within TensorFlow. It's a bit like protoc, but is designed to # produce a much more minimal result so we can save binary space. @@ -125,13 +131,13 @@ ifeq ($(TARGET),LINUX) endif # If we're on Linux, also link in the dl library. ifeq ($(TARGET),LINUX) - LIBS += -ldl + LIBS += -ldl -lpthread endif # If we're cross-compiling for the Raspberry Pi, use the right gcc. ifeq ($(TARGET),PI) - CXX := arm-linux-gnueabihf-g++ - LDFLAGS := -L$(GENDIR)protobuf_pi/lib/ -Wl,--no-whole-archive - LIBS += -ldl + CXXFLAGS += -D__ANDROID_TYPES_SLIM__ + LDFLAGS := -Wl,--no-whole-archive + LIBS += -ldl -lpthread LIBFLAGS += -Wl,--allow-multiple-definition -Wl,--whole-archive endif @@ -169,12 +175,16 @@ ifeq ($(TARGET),IOS) -Wno-c++11-narrowing \ -mno-thumb \ -DTF_LEAN_BINARY \ + -D__ANDROID_TYPES_SLIM__ \ -DMIN_LOG_LEVEL=0 \ -fno-exceptions \ -isysroot \ ${IPHONEOS_SYSROOT} LDFLAGS := -arch armv7 \ -miphoneos-version-min=${MIN_SDK_VERSION} \ + -Xlinker -S \ + -Xlinker -x \ + -Xlinker -dead_strip \ -all_load \ -L$(GENDIR)protobuf_ios/lib \ -lz @@ -186,6 +196,7 @@ ifeq ($(TARGET),IOS) -Wno-c++11-narrowing \ -mno-thumb \ -DTF_LEAN_BINARY \ + -D__ANDROID_TYPES_SLIM__ \ -DMIN_LOG_LEVEL=0 \ -fno-exceptions \ -isysroot \ @@ -205,6 +216,7 @@ ifeq ($(TARGET),IOS) -D__thread= \ -Wno-c++11-narrowing \ -DTF_LEAN_BINARY \ + -D__ANDROID_TYPES_SLIM__ \ -DMIN_LOG_LEVEL=0 \ -fno-exceptions \ -isysroot \ @@ -224,6 +236,7 @@ ifeq ($(TARGET),IOS) -D__thread= \ -Wno-c++11-narrowing \ -DTF_LEAN_BINARY \ + -D__ANDROID_TYPES_SLIM__ \ -DMIN_LOG_LEVEL=0 \ -fno-exceptions \ -isysroot \ @@ -243,6 +256,7 @@ ifeq ($(TARGET),IOS) -D__thread= \ -Wno-c++11-narrowing \ -DTF_LEAN_BINARY \ + -D__ANDROID_TYPES_SLIM__ \ -DMIN_LOG_LEVEL=0 \ -fno-exceptions \ -isysroot \ diff --git a/tensorflow/contrib/makefile/README.md b/tensorflow/contrib/makefile/README.md index f82b70187c..f7f46fca5c 100644 --- a/tensorflow/contrib/makefile/README.md +++ b/tensorflow/contrib/makefile/README.md @@ -42,7 +42,7 @@ at `tensorflow/contrib/makefile/gen/bin/benchmark`. To run the executable, use: tensorflow/contrib/makefile/gen/bin/benchmark --graph=tensorflow_inception_graph.pb ``` -You should download the example graph from [http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz](http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz). +You should download the example graph from [https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip](https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip). ## Supported Systems @@ -132,24 +132,31 @@ static library in a simple app. ## Raspberry Pi -The easiest way to build for the Raspberry Pi is to cross-compile from Linux. -To use this makefile to do that, you first need to install the right version of -the compiler to target the Pi, using a command like this on your Linux machine: +Building on the Raspberry Pi is similar to a normal Linux system, though we +recommend starting by compiling and installing protobuf: ```bash -sudo apt-get install g++-arm-linux-gnueabihf +cd tensorflow/contrib/makefile/downloads/protobuf/ +./autogen.sh +./configure +make +sudo make install +cd ../../../../.. ``` -After that, run `tensorflow/contrib/makefile/compile_pi_protobuf.sh` to build a -version of the protobuf library aimed at the Pi. Then you should be able to run: +Once that's done, you can use make to build the library and example: ```bash -make -f tensorflow/contrib/makefile/Makefile TARGET=PI +make -f tensorflow/contrib/makefile/Makefile HOST_OS=PI TARGET=PI OPTFLAGS="-Os" ``` -This will build the static library, and the example benchmark executable. You -can then copy the `tensorflow/contrib/makefile/gen/bin/benchmark` program over -to your Raspberry Pi, and run it there. +If you're only interested in building for Raspberry Pi's 2 and 3, you can supply +some extra optimization flags to give you code that will run faster: + +```bash +make -f tensorflow/contrib/makefile/Makefile HOST_OS=PI TARGET=PI \ +OPTFLAGS="-Os -mfpu=neon-vfpv4 -funsafe-math-optimizations -ftree-vectorize" +``` ## Dependencies diff --git a/tensorflow/contrib/makefile/download_dependencies.sh b/tensorflow/contrib/makefile/download_dependencies.sh index 2ff9013804..0596b7ddf4 100755 --- a/tensorflow/contrib/makefile/download_dependencies.sh +++ b/tensorflow/contrib/makefile/download_dependencies.sh @@ -18,7 +18,9 @@ DOWNLOADS_DIR=tensorflow/contrib/makefile/downloads mkdir ${DOWNLOADS_DIR} -EIGEN_HASH=d02e6a705c30 +# Grab the current Eigen version name from the Bazel build file +EIGEN_HASH=$(cat eigen.BUILD | grep archive_dir | head -1 | cut -f3 -d- | cut -f1 -d\") + curl "https://bitbucket.org/eigen/eigen/get/${EIGEN_HASH}.tar.gz" \ -o /tmp/eigen-${EIGEN_HASH}.tar.gz tar xzf /tmp/eigen-${EIGEN_HASH}.tar.gz -C ${DOWNLOADS_DIR} @@ -27,12 +29,8 @@ git clone https://github.com/google/re2.git ${DOWNLOADS_DIR}/re2 git clone https://github.com/google/gemmlowp.git ${DOWNLOADS_DIR}/gemmlowp git clone https://github.com/google/protobuf.git ${DOWNLOADS_DIR}/protobuf -# JPEG_VERSION=v9a -# curl "http://www.ijg.org/files/jpegsrc.${JPEG_VERSION}.tar.gz" \ -# -o /tmp/jpegsrc.${JPEG_VERSION}.tar.gz -# tar xzf /tmp/jpegsrc.${JPEG_VERSION}.tar.gz -C ${DOWNLOADS_DIR} - -# PNG_VERSION=v1.2.53 -# curl -L "https://github.com/glennrp/libpng/archive/${PNG_VERSION}.zip" \ -# -o /tmp/pngsrc.${PNG_VERSION}.zip -# unzip /tmp/pngsrc.${PNG_VERSION}.zip -d ${DOWNLOADS_DIR} +# Link to the downloaded Eigen library from a permanent directory name, since +# the downloaded name changes with every version. +cd ${DOWNLOADS_DIR} +rm -rf eigen-latest +ln -s eigen-eigen-${EIGEN_HASH} eigen-latest diff --git a/tensorflow/core/platform/platform.h b/tensorflow/core/platform/platform.h index 8f71a617b6..02731d9275 100644 --- a/tensorflow/core/platform/platform.h +++ b/tensorflow/core/platform/platform.h @@ -37,6 +37,13 @@ limitations under the License. #define IS_MOBILE_PLATFORM #endif +#elif defined(__arm__) +#define PLATFORM_POSIX + +// Since there's no macro for the Raspberry Pi, assume we're on a mobile +// platform if we're compiling for the ARM CPU. +#define IS_MOBILE_PLATFORM + #else // If no platform specified, use: #define PLATFORM_POSIX |