diff --git a/third_party/gflags/gflags.cmake b/third_party/gflags/gflags.cmake index 1134718ca28ef9fd09d62f0aba37120e0f60831d..2a4f0343d901f70406c97dfae2c63917381890b3 100644 --- a/third_party/gflags/gflags.cmake +++ b/third_party/gflags/gflags.cmake @@ -24,12 +24,11 @@ ExternalProject_Add( UPDATE_COMMAND "" BUILD_BYPRODUCTS ${GFLAGS_LIBRARIES} CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GFLAGS_INSTALL_DIR} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -DBUILD_STATIC_LIBS=ON -DBUILD_TESTING=OFF - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR=${CMAKE_GENERATOR} ${THIRD_PARTY_EXTRA_CMAKE_ARGS} ) diff --git a/third_party/protobuf/protobuf.cmake b/third_party/protobuf/protobuf.cmake index d38635136387c5f82b04b0a3b0a43b18fcd908dd..d6111008f19126960ff1bd5261188853de9ff75b 100644 --- a/third_party/protobuf/protobuf.cmake +++ b/third_party/protobuf/protobuf.cmake @@ -33,7 +33,7 @@ ExternalProject_Add( BUILD_BYPRODUCTS ${PROTOBUF_LITE_LIBRARIES} SOURCE_DIR "${PROTOBUF_SRCS_DIR}/src/protobuf" CONFIGURE_COMMAND ${CMAKE_COMMAND} ../protobuf/cmake/ - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR} diff --git a/tools/clear_workspace.sh b/tools/clear_workspace.sh index 338a5410983bd93611b38a9f077a19ed4d372d53..9635964b374e045fc4ca1d44abc3c2dd816e20c7 100755 --- a/tools/clear_workspace.sh +++ b/tools/clear_workspace.sh @@ -5,7 +5,8 @@ rm -rf mace/codegen/engine rm -rf mace/codegen/opencl for d in build/*; do - if [[ "$d" != "build/cmake-build*" ]]; then + if [[ "$d" != "build/cmake-build" ]]; then + echo "remove $d" rm -rf "$d" fi done diff --git a/tools/cmake-build-aarch64-linux-gnu-full.sh b/tools/cmake-build-aarch64-linux-gnu-full.sh deleted file mode 100755 index 603d44ee5f456cf4bebe15c0043dcee5034581e4..0000000000000000000000000000000000000000 --- a/tools/cmake-build-aarch64-linux-gnu-full.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env sh - -set -e - -# build for arm linux aarch64 -BUILD_DIR=cmake-build/aarch64-linux-gnu-full -rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} -cmake -DCROSSTOOL_ROOT=${LINARO_AARCH64_LINUX_GNU} \ - -DCMAKE_TOOLCHAIN_FILE=../../cmake/toolchains/aarch64-linux-gnu.cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DMACE_ENABLE_NEON=ON \ - -DMACE_ENABLE_QUANTIZE=ON \ - -DMACE_ENABLE_OPENCL=ON \ - -DMACE_ENABLE_OPT_SIZE=ON \ - -DMACE_ENABLE_OBFUSCATE=ON \ - -DCMAKE_INSTALL_PREFIX=install \ - ../.. -make -j6 VERBOSE=1 && make install -cd ../.. diff --git a/tools/cmake-build-android-arm64-v8a-cpu.sh b/tools/cmake-build-android-arm64-v8a-cpu.sh deleted file mode 100755 index 57d2a3607c402dc8c6dbde6bb1d79124fe5cc5ae..0000000000000000000000000000000000000000 --- a/tools/cmake-build-android-arm64-v8a-cpu.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env sh - -set -e - -# build for android arm64-v8a -BUILD_DIR=cmake-build/android-arm64-v8a-cpu -rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} -cmake -DANDROID_ABI="arm64-v8a" \ - -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ - -DANDROID_NATIVE_API_LEVEL=14 \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_ANDROID_STL_TYPE=c++_shared \ - -DMACE_ENABLE_NEON=ON \ - -DMACE_ENABLE_QUANTIZE=OFF \ - -DMACE_ENABLE_OPENCL=OFF \ - -DMACE_ENABLE_HEXAGON_DSP=OFF \ - -DMACE_ENABLE_HEXAGON_HTA=OFF \ - -DMACE_ENABLE_MTK_APU=OFF \ - -DMACE_ENABLE_OPT_SIZE=ON \ - -DMACE_ENABLE_OBFUSCATE=ON \ - -DCMAKE_INSTALL_PREFIX=install \ - ../.. -make -j6 VERBOSE=1 && make install -cd ../.. diff --git a/tools/cmake-build-android-arm64-v8a-full.sh b/tools/cmake-build-android-arm64-v8a-full.sh deleted file mode 100755 index 9e9355bf769b5f12c11bed630979200006099bcd..0000000000000000000000000000000000000000 --- a/tools/cmake-build-android-arm64-v8a-full.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env sh - -set -e - -# build for android arm64-v8a -BUILD_DIR=cmake-build/android-arm64-v8a-full -rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} -cmake -DANDROID_ABI="arm64-v8a" \ - -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ - -DANDROID_NATIVE_API_LEVEL=28 \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_ANDROID_STL_TYPE=c++_shared \ - -DMACE_ENABLE_NEON=ON \ - -DMACE_ENABLE_QUANTIZE=ON \ - -DMACE_ENABLE_OPENCL=ON \ - -DMACE_ENABLE_HEXAGON_DSP=ON \ - -DMACE_ENABLE_HEXAGON_HTA=OFF \ - -DMACE_ENABLE_MTK_APU=ON \ - -DMACE_ENABLE_OPT_SIZE=ON \ - -DMACE_ENABLE_OBFUSCATE=ON \ - -DCMAKE_INSTALL_PREFIX=install \ - ../.. -make -j6 VERBOSE=1 && make install -cd ../.. diff --git a/tools/cmake-build-android-armeabi-v7a-cpu.sh b/tools/cmake-build-android-armeabi-v7a-cpu.sh deleted file mode 100755 index 4018b8d5ba9b00405e79864be4f1822b4e64dd36..0000000000000000000000000000000000000000 --- a/tools/cmake-build-android-armeabi-v7a-cpu.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env sh - -set -e - -# build for android armeabi-v7a -BUILD_DIR=cmake-build/android-armeabi-v7a-cpu -rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} -cmake -DANDROID_ABI="armeabi-v7a" \ - -DANDROID_ARM_NEON=ON \ - -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ - -DANDROID_NATIVE_API_LEVEL=14 \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_ANDROID_STL_TYPE=c++_shared \ - -DMACE_ENABLE_NEON=ON \ - -DMACE_ENABLE_QUANTIZE=OFF \ - -DMACE_ENABLE_OPENCL=OFF \ - -DMACE_ENABLE_HEXAGON_DSP=OFF \ - -DMACE_ENABLE_HEXAGON_HTA=OFF \ - -DMACE_ENABLE_MTK_APU=OFF \ - -DMACE_ENABLE_OPT_SIZE=ON \ - -DMACE_ENABLE_OBFUSCATE=ON \ - -DCMAKE_INSTALL_PREFIX=install \ - ../.. -make -j6 VERBOSE=1 && make install -cd ../.. diff --git a/tools/cmake-build-android-armeabi-v7a-full.sh b/tools/cmake-build-android-armeabi-v7a-full.sh deleted file mode 100755 index 1eaf6077917068372d67b859bad8b1bae09d2953..0000000000000000000000000000000000000000 --- a/tools/cmake-build-android-armeabi-v7a-full.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env sh - -set -e - -# build for android armeabi-v7a -BUILD_DIR=cmake-build/android-armeabi-v7a-full -rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} -cmake -DANDROID_ABI="armeabi-v7a" \ - -DANDROID_ARM_NEON=ON \ - -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ - -DANDROID_NATIVE_API_LEVEL=28 \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_ANDROID_STL_TYPE=c++_shared \ - -DMACE_ENABLE_NEON=ON \ - -DMACE_ENABLE_QUANTIZE=ON \ - -DMACE_ENABLE_OPENCL=ON \ - -DMACE_ENABLE_HEXAGON_DSP=ON \ - -DMACE_ENABLE_HEXAGON_HTA=OFF \ - -DMACE_ENABLE_MTK_APU=OFF \ - -DMACE_ENABLE_OPT_SIZE=ON \ - -DMACE_ENABLE_OBFUSCATE=ON \ - -DCMAKE_INSTALL_PREFIX=install \ - ../.. -make -j6 VERBOSE=1 && make install -cd ../.. diff --git a/tools/cmake-build-arm-linux-gnueabihf-full.sh b/tools/cmake-build-arm-linux-gnueabihf-full.sh deleted file mode 100755 index 91fd18f7174b89cb66ff137014fcab39a6c08d31..0000000000000000000000000000000000000000 --- a/tools/cmake-build-arm-linux-gnueabihf-full.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env sh - -set -e - -# build for arm linux gnueabihf -BUILD_DIR=cmake-build/arm-linux-gnueabihf-full -rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} -cmake -DCROSSTOOL_ROOT=${LINARO_ARM_LINUX_GNUEABIHF} \ - -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/arm-linux-gnueabihf.cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DMACE_ENABLE_NEON=ON \ - -DMACE_ENABLE_QUANTIZE=ON \ - -DMACE_ENABLE_OPENCL=ON \ - -DMACE_ENABLE_OPT_SIZE=ON \ - -DMACE_ENABLE_OBFUSCATE=ON \ - -DCMAKE_INSTALL_PREFIX=install \ - ../.. -make -j6 VERBOSE=1 && make install -cd ../.. diff --git a/tools/cmake-build-host.sh b/tools/cmake-build-host.sh deleted file mode 100755 index 4119bc2f9665e847f88358206492ff9a9b9af3d8..0000000000000000000000000000000000000000 --- a/tools/cmake-build-host.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env sh - -set -e - -# build for host -BUILD_DIR=cmake-build/host -rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} -cmake -DMACE_ENABLE_NEON=OFF \ - -DMACE_ENABLE_QUANTIZE=OFF \ - -DMACE_ENABLE_OPENCL=ON \ - -DCMAKE_INSTALL_PREFIX=install \ - ../.. -make -j6 VERBOSE=1 && make install -cd ../.. diff --git a/tools/cmake-build-standalone-lib.sh b/tools/cmake-build-standalone-lib.sh deleted file mode 100755 index ecdf77bdbfd61dff1c8c9f62cc9b121b6671758c..0000000000000000000000000000000000000000 --- a/tools/cmake-build-standalone-lib.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env sh - -set -e - -# build for local host -sh tools/cmake-build-host.sh - -# Nuild for Android arm64-v8a with NEON -sh tools/cmake-build-android-arm64-v8a-cpu.sh - -# Build for Android arm64-v8a with NEON, Quantize, OpenCL, Hexagon HTA, Hexagon DSP -sh tools/cmake-build-android-arm64-v8a-full.sh - -# Nuild for Android armeabi-v7a with NEON -sh tools/cmake-build-android-armeabi-v7a-cpu.sh - -# Build for Android armeabi-v7a with NEON, Quantize, OpenCL, Hexagon HTA, Hexagon DSP -sh tools/cmake-build-android-armeabi-v7a-full.sh - -# Build for arm-linux-gnueabihf with NEON, Quantize, OpenCL -sh tools/cmake-build-arm-linux-gnueabihf-full.sh - -# Build for aarch64-linux-gnu with NEON, Quantize, OpenCL -sh tools/cmake-build-aarch64-linux-gnu-full.sh diff --git a/tools/cmake/cmake-build-arm64-v8a.sh b/tools/cmake/cmake-build-arm64-v8a.sh index c6b603e3554d1d5b179ce55037e2022fc62a146b..7212ba9c55c0089b31e0537761ec6296ce9a4995 100755 --- a/tools/cmake/cmake-build-arm64-v8a.sh +++ b/tools/cmake/cmake-build-arm64-v8a.sh @@ -31,7 +31,7 @@ cmake -DANDROID_ABI="arm64-v8a" \ -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ -DANDROID_NATIVE_API_LEVEL=28 \ -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_ANDROID_STL_TYPE=c++_shared \ + -DANDROID_STL=c++_shared \ -DMACE_ENABLE_NEON=ON \ -DMACE_ENABLE_QUANTIZE=ON \ -DMACE_ENABLE_OPENCL=${MACE_ENABLE_OPENCL} \ diff --git a/tools/cmake/cmake-build-armeabi-v7a.sh b/tools/cmake/cmake-build-armeabi-v7a.sh index e38afa837b653f0e33e4d092458393326ba7157f..c953807f927811b5bf1a2516e6a80219a16ebfe5 100755 --- a/tools/cmake/cmake-build-armeabi-v7a.sh +++ b/tools/cmake/cmake-build-armeabi-v7a.sh @@ -33,7 +33,7 @@ cmake -DANDROID_ABI="armeabi-v7a" \ -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ -DANDROID_NATIVE_API_LEVEL=28 \ -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_ANDROID_STL_TYPE=c++_shared \ + -DANDROID_STL=c++_shared \ -DMACE_ENABLE_NEON=ON \ -DMACE_ENABLE_QUANTIZE=ON \ -DMACE_ENABLE_OPENCL=${MACE_ENABLE_OPENCL} \ diff --git a/tools/python/run_target.py b/tools/python/run_target.py index 41d89c6793303e9f9082915fd93bb9ca8f2983a2..0c7f0e52bd1b4df3b857a74445a30a980fa59f9f 100644 --- a/tools/python/run_target.py +++ b/tools/python/run_target.py @@ -48,7 +48,7 @@ def run_target(target_abi, install_dir, target_obj, device_ids="all"): # reinstall target print("Install target from %s to %s" % (target_obj.path, install_dir)) - device_target = dev.install(target_obj, install_dir) + device_target = dev.install(target_obj, install_dir, install_deps=True) print(device_target) # run on device diff --git a/tools/python/utils/device.py b/tools/python/utils/device.py index f15be425600f0a3822f8877d65d3f306bbbc81a7..579d70ff284e28cb9ba689cceb399504c07973e1 100644 --- a/tools/python/utils/device.py +++ b/tools/python/utils/device.py @@ -16,6 +16,7 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function +import copy import os import re import subprocess @@ -60,10 +61,11 @@ def execute(cmd, verbose=True): class Device(object): - def __init__(self, device_id): + def __init__(self, device_id, target_abi): self._device_id = device_id + self._target_abi = target_abi - def install(self, target, install_dir): + def install(self, target, install_dir, install_deps=False): pass def run(self, target): @@ -80,14 +82,14 @@ class Device(object): class HostDevice(Device): - def __init__(self, device_id): - super(HostDevice, self).__init__(device_id) + def __init__(self, device_id, target_abi): + super(HostDevice, self).__init__(device_id, target_abi) @staticmethod def list_devices(): return ["host"] - def install(self, target, install_dir): + def install(self, target, install_dir, install_deps=False): install_dir = os.path.abspath(install_dir) if install_dir.strip() and install_dir != os.path.dirname(target.path): @@ -119,8 +121,8 @@ class HostDevice(Device): class AndroidDevice(Device): - def __init__(self, device_id): - super(AndroidDevice, self).__init__(device_id) + def __init__(self, device_id, target_abi): + super(AndroidDevice, self).__init__(device_id, target_abi) @staticmethod def list_devices(): @@ -134,7 +136,7 @@ class AndroidDevice(Device): return devices - def install(self, target, install_dir): + def install(self, target, install_dir, install_deps=False): install_dir = os.path.abspath(install_dir) sn = self._device_id @@ -149,12 +151,36 @@ class AndroidDevice(Device): for lib in target.libs: execute("adb -s %s push %s %s" % (sn, lib, install_dir), False) - target.path = "%s/%s" % (install_dir, os.path.basename(target.path)) - target.libs = ["%s/%s" % (install_dir, os.path.basename(lib)) - for lib in target.libs] - target.envs.append("LD_LIBRARY_PATH=%s" % install_dir) + device_target = copy.deepcopy(target) + device_target.path = "%s/%s" % (install_dir, + os.path.basename(target.path)) + device_target.libs = ["%s/%s" % (install_dir, os.path.basename(lib)) + for lib in target.libs] + device_target.envs.append("LD_LIBRARY_PATH=%s" % install_dir) - return target + if install_deps: + self.install_common_libs_for_target(target, install_dir) + + return device_target + + def install_common_libs_for_target(self, target, install_dir): + sn = self._device_id + dep_so_libs = execute(os.environ["ANDROID_NDK_HOME"] + "/ndk-depends " + + target.path) + lib_file = "" + for dep in dep_so_libs.split("\n"): + if dep == "libgnustl_shared.so": + lib_file = "%s/sources/cxx-stl/gnu-libstdc++/4.9/libs/" \ + "%s/libgnustl_shared.so" \ + % (os.environ["ANDROID_NDK_HOME"], self._target_abi) + elif dep == "libc++_shared.so": + lib_file = "%s/sources/cxx-stl/llvm-libc++/libs/" \ + "%s/libc++_shared.so" \ + % (os.environ["ANDROID_NDK_HOME"], self._target_abi) + + if lib_file: + execute("adb -s %s push %s %s" % (sn, lib_file, install_dir), + False) def run(self, target): tmpdirname = tempfile.mkdtemp() @@ -198,8 +224,8 @@ class AndroidDevice(Device): class ArmLinuxDevice(Device): devices = {} - def __init__(self, device_id): - super(ArmLinuxDevice, self).__init__(device_id) + def __init__(self, device_id, target_abi): + super(ArmLinuxDevice, self).__init__(device_id, target_abi) @staticmethod def list_devices(): @@ -215,7 +241,7 @@ class ArmLinuxDevice(Device): def set_devices(devices): ArmLinuxDevice.devices = devices - def install(self, target, install_dir): + def install(self, target, install_dir, install_deps=False): install_dir = os.path.abspath(install_dir) ip = self._device_id @@ -260,7 +286,7 @@ def device_class(target_abi): def crete_device(target_abi, device_id=None): - return device_class(target_abi)(device_id) + return device_class(target_abi)(device_id, target_abi) def choose_devices(target_abi, target_ids):