From b3f1888650362005bdd8ac195c77a4620fea3ba2 Mon Sep 17 00:00:00 2001 From: kecsap Date: Sat, 14 Apr 2018 13:38:45 +0300 Subject: [PATCH] Cleanup for Raspberry Pi --- ...d_tensorflow_cpp_arm_crosscompiling_rpi.sh | 92 ------------------- 3_build_tensorflow_cpp_arm_rpi.sh | 2 +- tf_arm_crosscompiling.patch | 40 -------- 3 files changed, 1 insertion(+), 133 deletions(-) delete mode 100755 3_build_tensorflow_cpp_arm_crosscompiling_rpi.sh delete mode 100644 tf_arm_crosscompiling.patch diff --git a/3_build_tensorflow_cpp_arm_crosscompiling_rpi.sh b/3_build_tensorflow_cpp_arm_crosscompiling_rpi.sh deleted file mode 100755 index 8da66bd..0000000 --- a/3_build_tensorflow_cpp_arm_crosscompiling_rpi.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/bash - -# Get the directory where the script is stored -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -if [ ! -d $DIR/tensorflow ]; then - echo Clone the appropriate tensorflow branch or tag with 1_clone_tensorflow.sh script - exit 1 -fi - -# -# Generate the binaries -# -# Clean old packaging files if they exist -mkdir -p $DIR/packaging/libs -rm -rf $DIR/packaging/libs/* - -cd $DIR/tensorflow -# Clean up -git clean -fdx -git reset --hard -cat $DIR/tf_tensor_fix.txt >> tensorflow/contrib/makefile/tf_op_files.txt -git apply < $DIR/tf_arm_crosscompiling.patch || exit 1 - -# Download the dependencies -tensorflow/contrib/makefile/download_dependencies.sh || exit 1 - -# Build and extract native protoc for the host machine -cd $DIR/tensorflow/tensorflow/contrib/makefile/downloads/protobuf/ -./autogen.sh || exit 1 -./configure || exit 1 -make clean || exit 1 -make -j8 || exit 1 -cd src || exit 1 -cp -r google $DIR/tensorflow/ || exit 1 -cd .libs/ || exit 1 -cp protoc $DIR/tensorflow/ || exit 1 -cp libprotobuf.so* $DIR/tensorflow/ || exit 1 -cp libprotoc.so* $DIR/tensorflow/ || exit 1 - -# Build the protobuf library -export CXX=arm-linux-gnueabihf-g++-5 -export CC=arm-linux-gnueabihf-gcc-5 -export HOST_OS=PI -export TARGET=PI -export PROTOC=$DIR/tensorflow/protoc -export PATH=$DIR/tensorflow/:$PATH -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DIR/tensorflow/ -export CUSTOM_HOST_LIBS="-L$DIR/tensorflow/ -Wl,-rpath,$DIR/tensorflow/" - -cd $DIR/tensorflow/tensorflow/contrib/makefile/downloads/protobuf/ -./autogen.sh || exit 1 -CFLAGS="$CFLAGS -fPIC" CXXFLAGS="$CXXFLAGS -fPIC" ./configure --host=arm-linux --with-protoc=$PROTOC || exit 1 -make clean || exit 1 -make -j8 || exit 1 -mkdir -p $DIR/tensorflow/tensorflow/contrib/makefile/gen/protobuf/lib/ || exit 1 -cp src/.libs/libprotobuf.a $DIR/tensorflow/tensorflow/contrib/makefile/gen/protobuf/lib/ || exit 1 - -# Compile nsync for Raspberry Pi -cd $DIR/tensorflow -export HOST_NSYNC_LIB=`$DIR/tensorflow/tensorflow/contrib/makefile/compile_nsync.sh` -export TARGET_NSYNC_LIB="$DIR/tensorflow/tensorflow/contrib/makefile/downloads/nsync/builds/arm.linux.gcc.lrt/libnsync.a" - -cp $DIR/rpi_crosscompiling_fixes/Makefile $DIR/tensorflow/tensorflow/contrib/makefile/downloads/nsync/builds/arm.linux.gcc.lrt/ || exit 1 -make -C $DIR/tensorflow/tensorflow/contrib/makefile/downloads/nsync/builds/arm.linux.gcc.lrt/ || exit 1 - -# Build Tensorflow (this trial will fail because of a problem of the linking flags -export CUSTOM_HOST_LIBS="-L$DIR/tensorflow/ -Wl,-rpath,$DIR/tensorflow/" - -make -j8 -f tensorflow/contrib/makefile/Makefile \ - OPTFLAGS="-Os -mfpu=neon-vfpv4 -funsafe-math-optimizations -ftree-vectorize" \ - HOST_CXXFLAGS="--std=c++11" \ - MAKEFILE_DIR=$DIR/tensorflow/tensorflow/contrib/makefile/ - -# Build Tensorflow #2 -export CUSTOM_HOST_LIBS="$DIR/rpi_crosscompiling_fixes/libz.a -L$DIR/tensorflow/tensorflow/contrib/makefile/downloads/protobuf/src/.libs/" -export CUSTOM_TARGET_LIBS="-L$DIR/tensorflow/ -Wl,-rpath,$DIR/tensorflow/" - -make -j8 -f tensorflow/contrib/makefile/Makefile \ - OPTFLAGS="-Os -mfpu=neon-vfpv4 -funsafe-math-optimizations -ftree-vectorize" \ - HOST_CXXFLAGS="--std=c++11" \ - MAKEFILE_DIR=$DIR/tensorflow/tensorflow/contrib/makefile/ - - -# Copy/prepare the final binaries -cp tensorflow/contrib/makefile/gen/protobuf/lib/libprotobuf.a $DIR/packaging/libs/libprotobuf-tf-static.a || exit 1 -arm-linux-gnueabihf-g++-5 -shared -o $DIR/packaging/libs/libprotobuf-tf.so -Wl,--whole-archive -l:libprotobuf-tf-static.a -L$DIR/packaging/libs/ -Wl,--no-whole-archive || exit 1 -cp tensorflow/contrib/makefile/downloads/nsync/builds/arm.linux.gcc.lrt/nsync.a $DIR/packaging/libs/libnsync-tf.a || exit 1 -cp tensorflow/contrib/makefile/gen/lib/libtensorflow-core.a $DIR/packaging/libs/libtensorflow-core-static.a || exit 1 -arm-linux-gnueabihf-g++-5 -shared -o $DIR/packaging/libs/libtensorflow-core.so -Wl,--whole-archive -l:libtensorflow-core-static.a -L$DIR/packaging/libs/ -Wl,--no-whole-archive || exit 1 - -echo READY! Libraries are extracted to $DIR/packaging/libs/ diff --git a/3_build_tensorflow_cpp_arm_rpi.sh b/3_build_tensorflow_cpp_arm_rpi.sh index c9143be..e30c806 100755 --- a/3_build_tensorflow_cpp_arm_rpi.sh +++ b/3_build_tensorflow_cpp_arm_rpi.sh @@ -30,7 +30,7 @@ export CXX=g++-6 export CC=gcc-6 export HOST_OS=PI export TARGET=PI -export JOB_COUNT=2 +export JOB_COUNT=1 tensorflow/contrib/makefile/build_all_linux.sh || exit 1 # Copy/prepare the final binaries diff --git a/tf_arm_crosscompiling.patch b/tf_arm_crosscompiling.patch deleted file mode 100644 index 49a1acc..0000000 --- a/tf_arm_crosscompiling.patch +++ /dev/null @@ -1,40 +0,0 @@ -diff --git a/tensorflow/contrib/makefile/Makefile b/tensorflow/contrib/makefile/Makefile -index ee84b5b..e57118f 100644 ---- a/tensorflow/contrib/makefile/Makefile -+++ b/tensorflow/contrib/makefile/Makefile -@@ -97,7 +97,7 @@ endif - # override local versions in the source tree. - HOST_INCLUDES += -I/usr/local/include - --HOST_LIBS := \ -+HOST_LIBS := $(CUSTOM_HOST_LIBS) \ - $(HOST_NSYNC_LIB) \ - -lstdc++ \ - -lprotobuf \ -@@ -152,7 +152,7 @@ DEPDIR := $(GENDIR)dep/ - $(shell mkdir -p $(DEPDIR) >/dev/null) - - # Settings for the target compiler. --CXX := $(CC_PREFIX) gcc -+CXX := $(CC) - OPTFLAGS := -O2 - - ifneq ($(TARGET),ANDROID) -@@ -180,7 +180,7 @@ endif - # override local versions in the source tree. - INCLUDES += -I/usr/local/include - --LIBS := \ -+LIBS := $(CUSTOM_TARGET_LIBS) \ - $(TARGET_NSYNC_LIB) \ - -lstdc++ \ - -lprotobuf \ -@@ -623,7 +623,7 @@ BENCHMARK_OBJS := $(addprefix $(OBJDIR), $(BENCHMARK_SRCS:.cc=.o)) - .PHONY: clean cleantarget - - # The target that's compiled if there's no command-line arguments. --all: $(LIB_PATH) $(BENCHMARK_NAME) -+all: $(LIB_PATH) - - # Rules for target compilation. -