提交 576ca249 编写于 作者: L Liangliang He

Add support for CMake

Refactor cmake build flags
Add arm linux toolchains
Add macOS+iOS build support
Support windows
Add library install
Refactor gitlab CI
上级 2d650b67
BasedOnStyle: google
MaxEmptyLinesToKeep: 3
DerivePointerAlignment: false
PointerAlignment: Right
BinPackParameters: false
stages:
- cpplint
- pycodestyle
- docs
- platform_compatible_tests
- build_libraries
- ndk_versions_compatible_tests
- ops_test_disable_neon
- ops_test
- api_test
- model_tests
- quantization_tests
- build_android_demo
- ops_benchmark
- extra_tests
- so_size_check
- dynamic_link_test
- python3_test
- linting
- basic-build
- smoke-test
- build
- test
- extra
cpplint:
stage: cpplint
stage: linting
script:
- curl -o cpplint.py https://raw.githubusercontent.com/google/styleguide/gh-pages/cpplint/cpplint.py
- python cpplint.py --linelength=80 --counting=detailed $(find mace -name "*.h" -or -name "*.cc")
- sh tools/cpplint.sh
pycodestyle:
stage: pycodestyle
pylint:
stage: linting
script:
- pycodestyle $(find -name "*.py")
docs:
stage: docs
build_docs:
stage: basic-build
script:
- cd docs
- make html
......@@ -46,205 +34,108 @@ docs:
paths:
- docs/_build
platform_compatible_tests:
stage: platform_compatible_tests
script:
- bazel build mace/core:core --define openmp=false
- bazel build --config arm_linux_gnueabihf --define openmp=false --define opencl=true --define neon=true //mace/libmace:libmace.so
- bazel build --config aarch64_linux_gnu --define openmp=false --define opencl=true --define neon=true //mace/libmace:libmace.so
build_libraries:
stage: build_libraries
script:
- bash tools/build-standalone-lib.sh
ndk_versions_compatible_tests:
stage: ndk_versions_compatible_tests
script:
- DEFAULT_NDK_PATH=$ANDROID_NDK_HOME
- prefix_path=${DEFAULT_NDK_PATH%android-ndk-*}
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- >
if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git
DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi
- >
for ndk in android-ndk-r15c android-ndk-r16 android-ndk-r17b;
do
new_ndk_path=${prefix_path}${ndk};
if [ "$new_ndk_path" != "$DEFAULT_NDK_PATH" ]; then
export ANDROID_NDK_HOME=$new_ndk_path;
export PATH=$ANDROID_NDK_HOME:$PATH;
echo "ndk path: $ANDROID_NDK_HOME";
python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a --target_socs=$TARGET_SOCS --enable_neon=false --args="--gtest_filter=ActivationOpTest*" || exit 1;
python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a --target_socs=$TARGET_SOCS --args="--gtest_filter=ActivationOpTest*" || exit 1;
python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=arm64-v8a --target_socs=$TARGET_SOCS --args="--gtest_filter=ActivationOpTest*" || exit 1;
fi
done
- export ANDROID_NDK_HOME=$DEFAULT_NDK_PATH
- export PATH=$ANDROID_NDK_HOME:$PATH
ops_test_disable_neon:
stage: ops_test_disable_neon
script:
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- >
if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git
DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi
- python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a,arm64 --target_socs=$TARGET_SOCS --enable_neon=false || exit 1;
ops_test:
stage: ops_test
script:
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- >
if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git
DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi
- python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a,arm64 --target_socs=$TARGET_SOCS || exit 1;
api_test:
stage: api_test
script:
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- python tools/bazel_adb_run.py --target="//mace/test:mace_api_test" --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a --target_socs=$TARGET_SOCS || exit 1;
- python tools/bazel_adb_run.py --target="//mace/test:mace_api_mt_test" --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a --target_socs=$TARGET_SOCS || exit 1;
- python tools/bazel_adb_run.py --target="//mace/test:mace_api_exception_test" --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a --target_socs=$TARGET_SOCS || exit 1;
- >
if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git
DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi
- python tools/bazel_adb_run.py --target="//mace/test:mace_api_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=arm64 --target_socs=$TARGET_SOCS || exit 1;
- python tools/bazel_adb_run.py --target="//mace/test:mace_api_mt_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=arm64 --target_socs=$TARGET_SOCS || exit 1;
- python tools/bazel_adb_run.py --target="//mace/test:mace_api_exception_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=arm64 --target_socs=$TARGET_SOCS || exit 1;
model_tests:
stage: model_tests
script:
- pwd
- rm -rf mace-models
- rm -rf generic-mobile-devices
- GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@github.com:XiaoMi/mace-models.git
- CONF_FILE=mace-models/mobilenet-v1/mobilenet-v1.yml
- >
if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git
DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- >
python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file --cl_mem_type=buffer || exit 1;
python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --device_yml=${DEVICE_CONF_FILE} --round=1 --target_abis=armeabi-v7a,arm64 --validate --model_graph_format=file --model_data_format=file || exit 1;
python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --device_yml=${DEVICE_CONF_FILE} --example --target_abis=armeabi-v7a,arm64 --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1;
- CONF_FILE=mace-models/mobilenet-v2/mobilenet-v2-host.yml
- >
python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file || exit 1;
python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=1 --validate --model_graph_format=file --model_data_format=file --address_sanitizer || exit 1;
python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --example --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1;
python tools/converter.py benchmark --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=5 --model_graph_format=file --model_data_format=file || exit 1;
python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=code --model_data_format=file || exit 1;
python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=1 --validate --model_graph_format=code --model_data_format=file || exit 1;
python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --example --round=1 --validate --model_graph_format=code --model_data_format=file || exit 1;
python tools/converter.py benchmark --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=5 --model_graph_format=code --model_data_format=file || exit 1;
- rm -rf mace-models
quantization_tests:
stage: quantization_tests
script:
- pwd
- rm -rf mace-models
- GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@github.com:XiaoMi/mace-models.git
- >
if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git
DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- >
for CONF_FILE in mace-models/mobilenet-v1/mobilenet-v1-quantize-friendly.yml mace-models/mobilenet-v1/mobilenet-v1-quantize-retrain-for-check-only.yml mace-models/mobilenet-v1/mobilenet-v1-quantize-retrain-dsp.yml;
do
python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file || exit 1;
python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --device_yml=${DEVICE_CONF_FILE} --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1;
python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --device_yml=${DEVICE_CONF_FILE} --example --round=1 --validate --layers=0 --model_graph_format=file --model_data_format=file || exit 1;
done
- rm -rf mace-models
build_android-armeabi-v7a:
stage: basic-build
script:
- sh tools/build-android-armeabi-v7a-full.sh
build_android-arm64-v8:
stage: basic-build
script:
- sh tools/build-android-arm64-v8a-full.sh
code_footprint_check:
stage: basic-build
script:
- echo check shared library size
cc_test_smoketest:
stage: smoke-test
script:
- echo tests
cc_benchmark_smoketest:
stage: smoke-test
script:
- echo benchmark
build_arm-linux-gnueabihf:
stage: build
script:
- sh tools/build-arm-linux-gnueabihf-full.sh
only:
- triggers
build_aarch64-linux-gnu:
stage: build
script:
- sh tools/build-aarch64-linux-gnu-full.sh
only:
- triggers
build_host:
stage: build
script:
- sh tools/build-host.sh
only:
- triggers
build_android_demo:
stage: build_android_demo
stage: build
script:
- echo build android demo
only:
- triggers
cc_test:
stage: test
script:
- echo cc_test
only:
- triggers
cc_benchmark:
stage: test
script:
- echo cc_benchmark
only:
- triggers
quantization_test:
stage: test
script:
- echo quantization_test
only:
- triggers
model_test:
stage: test
script:
- echo model_test
only:
- triggers
ndk_compatibility_check:
stage: extra
script:
- pushd mace/examples/android/ && bash build.sh static && bash build.sh dynamic && popd
- echo ndk_compatibility_check
only:
- triggers
ops_benchmark:
stage: ops_benchmark
python_compatibility_check:
stage: extra
script:
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- python tools/bazel_adb_run.py --target="//mace/ops:ops_benchmark" --run_target=True --stdout_processor=ops_benchmark_stdout_processor --target_abis=armeabi-v7a,arm64-v8a --target_socs=$TARGET_SOCS --args="--filter=.*SIGMOID.*" || exit 1;
- echo python3 check
only:
- triggers
extra_tests:
stage: extra_tests
script:
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- >
if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git
DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi
- python tools/bazel_adb_run.py --target="//mace/utils:utils_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a,arm64 --target_socs=$TARGET_SOCS || exit 1;
- python tools/bazel_adb_run.py --target="//mace/port:port_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a,arm64 --target_socs=$TARGET_SOCS || exit 1;
so_size_check:
stage: so_size_check
script:
- DYNAMIC_LIB_PATH="bazel-bin/mace/libmace/libmace.so"
- bazel build -s --config android --config optimization mace/libmace:libmace_dynamic --define neon=true --define openmp=false --define opencl=false --define quantize=false --cpu=armeabi-v7a
- CURRENT_LIBMACE_SO_SIZE=`ls -l $DYNAMIC_LIB_PATH --block-size=K -s | cut -f 1 -d "K"`
- TARGET_MACE_WORK_DIR=`mktemp -d`
- pushd $TARGET_MACE_WORK_DIR
- GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@github.com:XiaoMi/mace.git
- pushd mace
- bazel build -s --config android --config optimization mace/libmace:libmace_dynamic --define neon=true --define openmp=false --define opencl=false --define quantize=false --cpu=armeabi-v7a
- TARGET_LIBMACE_SO_SIZE=`ls -l $DYNAMIC_LIB_PATH --block-size=K -s | cut -f 1 -d "K"`
- popd
- popd
- rm -rf $TARGET_MACE_WORK_DIR
- echo "The libmace.so size grows from $TARGET_LIBMACE_SO_SIZE(KB) to $CURRENT_LIBMACE_SO_SIZE(KB)"
- if [ $TARGET_LIBMACE_SO_SIZE -lt `expr \( $CURRENT_LIBMACE_SO_SIZE - $TARGET_LIBMACE_SO_SIZE \) \* 10` ]; then echo "The libmace.so size grows larger than 10%"; exit 1; fi
dynamic_link_test:
stage: dynamic_link_test
script:
- pwd
- rm -rf mace-models
- rm -rf generic-mobile-devices
- GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@github.com:XiaoMi/mace-models.git
- CONF_FILE=mace-models/mobilenet-v1/mobilenet-v1.yml
- >
if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git
DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- >
python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file --cl_mem_type=buffer || exit 1;
python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --device_yml=${DEVICE_CONF_FILE} --example --mace_lib_type=dynamic --target_abis=armeabi-v7a,arm64 --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1;
- rm -rf mace-models
python3_test:
stage: python3_test
script:
- pyenv local 3.6.3
- rm -rf mace-models
- GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@github.com:XiaoMi/mace-models.git
- CONF_FILE=mace-models/mobilenet-v1/mobilenet-v1.yml
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- >
python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file || exit 1;
python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1;
- python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --run_target=False --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a --target_socs=$TARGET_SOCS --validate || exit 1;
- pyenv local 2.7.14
stage: extra
script:
- ops_test_disable_neon
- ops_test
- api_test
- extra_tests
- dynamic_link_test
only:
- triggers
# new CUDA support requires 3.8 for Linux/Mac, and 3.9 for Windows
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
message("CMAKE_VERSION: ${CMAKE_VERSION}")
project(mace C CXX)
option(MACE_ENABLE_NEON "whether to enable NEON support" OFF)
option(MACE_ENABLE_QUANTIZE "whether to enable NEON int8 support" OFF)
option(MACE_ENABLE_OPENCL "whether to enable OpenCL support" OFF)
option(MACE_ENABLE_CUDA "whether to enable CUDA support" OFF)
option(MACE_ENABLE_HEXAGON_DSP "whether to enable Hexagon DSP support" OFF)
option(MACE_ENABLE_HEXAGON_HTA "whether to enable Hexagon HTA support" OFF)
option(MACE_ENABLE_TESTS "whether to build c++ unit tests" OFF)
option(MACE_ENABLE_BENCHMARK "whether to build c++ micro benchmarks" OFF)
option(MACE_ENABLE_EXAMPLES "whether to build examples" OFF)
option(MACE_ENABLE_OPT_SIZE "whether to build with optimized binary size" ON)
option(MACE_ENABLE_OBFUSCATE "whether to build with code obfuscation" ON)
message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
# TODO make these flags well defined and organized
# TODO enable sanitizer
set(MACE_CC_FLAGS "${MACE_CC_FLAGS} -fPIC")
if(MACE_ENABLE_OPT_SIZE)
if(NOT APPLE)
set(MACE_LINKER_FLAGS "${MACE_LINKER_FLAGS} -Wl,--strip-all -Wl,--gc-sections")
set(MACE_CC_FLAGS "${MACE_CC_FLAGS} -ffunction-sections -fdata-sections")
endif()
set(MACE_CC_FLAGS "${MACE_CC_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
set(MACE_CODE_CC_FLAGS "${MACE_CODE_CC_FLAGS} -fno-rtti -fno-exceptions -DGOOGLE_PROTOBUF_NO_RTTI -DPROTOBUF_USE_EXCEPTIONS=0")
endif()
# flags apply only to mace code (third_party excluded)
set(MACE_CODE_CC_FLAGS "${MACE_CODE_CC_FLAGS} -Wall -Werror")
set(MACE_CODE_CC_FLAGS "${MACE_CODE_CC_FLAGS} -std=c++11 -D_GLIBCXX_USE_C99_MATH_TR1")
if(IOS)
# TODO correct the code
set(MACE_CODE_CC_FLAGS "${MACE_CODE_CC_FLAGS} -Wno-error=shorten-64-to-32")
endif()
if(MACE_ENABLE_NEON)
add_definitions(-DMACE_ENABLE_NEON)
if(ANDROID_ABI STREQUAL "armeabi-v7a")
# Enable NEON fp16 support
string(REPLACE "-mfpu=neon " "-mfpu=neon-fp16 " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif(ANDROID_ABI STREQUAL "armeabi-v7a")
endif()
if(MACE_ENABLE_QUANTIZE)
add_definitions(-DMACE_ENABLE_QUANTIZE)
add_definitions(-DGEMMLOWP_USE_MACE_THREAD_POOL)
add_definitions(-DMACE_DEPTHWISE_U8_USE_MULTI_THREAD)
endif()
if(MACE_ENABLE_OPENCL)
if(IOS)
message(FATAL_ERROR "OpenCL is not supported for iOS")
endif()
add_definitions(-DMACE_ENABLE_OPENCL)
endif()
if(MACE_ENABLE_CUDA)
# new CUDA support requires 3.8 for Linux/Mac, and 3.9 for Windows
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
enable_language(CUDA)
endif()
if((MACE_ENABLE_HEXAGON_DSP OR MACE_ENABLE_HEXAGON_HTA))
if(ANDROID_ABI STREQUAL "arm64-v8a")
# Use gold linker to avoid linking check of libcdsprpc.so
set(MACE_LINKER_FLAGS "${MACE_LINKER_FLAGS} -fuse-ld=gold")
endif(ANDROID_ABI STREQUAL "arm64-v8a")
endif(MACE_ENABLE_HEXAGON_DSP OR MACE_ENABLE_HEXAGON_HTA)
if(MACE_ENABLE_HEXAGON_DSP)
if(NOT ANDROID)
message(FATAL_ERROR "Hexagon DSP is only supported on Android")
endif(NOT ANDROID)
# TODO => -DMACE_ENABLE_HEXAGON_DSP
add_definitions(-DMACE_ENABLE_HEXAGON)
endif()
if(MACE_ENABLE_HEXAGON_HTA)
if(NOT ANDROID)
message(FATAL_ERROR "Hexagon HTA is only supported on Android")
endif(NOT ANDROID)
add_definitions(-DMACE_ENABLE_HEXAGON_HTA)
endif()
if(MACE_ENABLE_OBFUSCATE)
add_definitions(-DMACE_OBFUSCATE_LITERALS)
endif()
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MACE_CODE_CC_FLAGS} ${MACE_CC_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${MACE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MACE_LINKER_FLAGS}")
endif()
include(${PROJECT_SOURCE_DIR}/third_party/third_party.cmake)
include_directories("${PROJECT_SOURCE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_BINARY_DIR}") # proto
add_subdirectory(include)
add_subdirectory(mace)
if(MACE_ENABLE_EXAMPLES)
add_subdirectory(examples)
endif()
if(MACE_ENABLE_TESTS OR MACE_ENABLE_BENCHMARK)
add_subdirectory(test)
endif()
......@@ -61,7 +61,6 @@ new_http_archive(
strip_prefix = "half-code-356-trunk",
urls = [
"https://cnbj1.fds.api.xiaomi.com/mace/third-party/half/half-code-356-trunk.zip",
"https://sourceforge.net/code-snapshots/svn/h/ha/half/code/half-code-356-trunk.zip",
],
)
......
# Tested with gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu
# https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER "${CROSSTOOL_ROOT}/bin/aarch64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "${CROSSTOOL_ROOT}/bin/aarch64-linux-gnu-g++")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_CXX_FLAGS "-march=armv8-a ${CMAKE_CXX_FLAGS}")
# Tested with gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabi
# https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabi-gcc")
set(CMAKE_CXX_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabi-g++")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}")
# Tested with gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf
# https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabihf-g++")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}")
# This file is part of the ios-cmake project. It was retrieved from
# https://github.com/cristeab/ios-cmake.git, which is a fork of
# https://code.google.com/p/ios-cmake/. Which in turn is based off of
# the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which
# are included with CMake 2.8.4
#
# The ios-cmake project is licensed under the new BSD license.
#
# Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software,
# Kitware, Inc., Insight Software Consortium. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# This file is based off of the Platform/Darwin.cmake and
# Platform/UnixPaths.cmake files which are included with CMake 2.8.4
# It has been altered for iOS development.
#
# Updated by Alex Stewart (alexs.mac@gmail.com)
#
# *****************************************************************************
# Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com)
# under the BSD-3-Clause license
# https://github.com/leetal/ios-cmake
# *****************************************************************************
#
# INFORMATION / HELP
#
# The following arguments control the behaviour of this toolchain:
#
# PLATFORM: (default "OS")
# OS = Build for iPhoneOS.
# OS64 = Build for arm64 iphoneOS.
# OS64COMBINED = Build for arm64 x86_64 iphoneOS. Combined into FAT STATIC lib (supported on 3.14+ of CMakewith "-G Xcode" argument ONLY)
# SIMULATOR = Build for x86 i386 iphoneOS Simulator.
# SIMULATOR64 = Build for x86_64 iphoneOS Simulator.
# TVOS = Build for arm64 tvOS.
# TVOSCOMBINED = Build for arm64 x86_64 tvOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY)
# SIMULATOR_TVOS = Build for x86_64 tvOS Simulator.
# WATCHOS = Build for armv7k arm64_32 for watchOS.
# WATCHOSCOMBINED = Build for armv7k arm64_32 x86_64 watchOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY)
# SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator.
#
# CMAKE_OSX_SYSROOT: Path to the SDK to use. By default this is
# automatically determined from PLATFORM and xcodebuild, but
# automatically determined from PLATFORM and xcodebuild, but
# can also be manually specified (although this should not be required).
#
# CMAKE_DEVELOPER_ROOT: Path to the Developer directory for the platform
# being compiled for. By default this is automatically determined from
# CMAKE_OSX_SYSROOT, but can also be manually specified (although this should
# not be required).
#
# DEPLOYMENT_TARGET: Minimum SDK version to target. Default 2.0 on watchOS and 9.0 on tvOS+iOS
#
# ENABLE_BITCODE: (1|0) Enables or disables bitcode support. Default 1 (true)
#
# ENABLE_ARC: (1|0) Enables or disables ARC support. Default 1 (true, ARC enabled by default)
#
# ENABLE_VISIBILITY: (1|0) Enables or disables symbol visibility support. Default 0 (false, visibility hidden by default)
#
# ARCHS: (armv7 armv7s armv7k arm64 arm64_32 i386 x86_64) If specified, will override the default architectures for the given PLATFORM
# OS = armv7 armv7s arm64 (if applicable)
# OS64 = arm64 (if applicable)
# SIMULATOR = i386
# SIMULATOR64 = x86_64
# TVOS = arm64
# SIMULATOR_TVOS = x86_64 (i386 has since long been deprecated)
# WATCHOS = armv7k arm64_32 (if applicable)
# SIMULATOR_WATCHOS = x86_64 (i386 has since long been deprecated)
#
# This toolchain defines the following variables for use externally:
#
# XCODE_VERSION: Version number (not including Build version) of Xcode detected.
# SDK_VERSION: Version of SDK being used.
# CMAKE_OSX_ARCHITECTURES: Architectures being compiled for (generated from PLATFORM).
#
# This toolchain defines the following macros for use externally:
#
# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT)
# A convenience macro for setting xcode specific properties on targets.
# Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel
# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1" "all").
#
# find_host_package (PROGRAM ARGS)
# A macro used to find executable programs on the host system, not within the
# environment. Thanks to the android-cmake project for providing the
# command.
#
# ******************************** DEPRECATIONS *******************************
#
# IOS_DEPLOYMENT_TARGET: (Deprecated) Alias to DEPLOYMENT_TARGET
# CMAKE_IOS_DEVELOPER_ROOT: (Deprecated) Alias to CMAKE_DEVELOPER_ROOT
# IOS_PLATFORM: (Deprecated) Alias to PLATFORM
# IOS_ARCH: (Deprecated) Alias to ARCHS
#
# *****************************************************************************
#
# Fix for PThread library not in path
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
# Cache what generator is used
set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14")
set(MODERN_CMAKE YES)
message(STATUS "Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!")
endif()
# Get the Xcode version being used.
execute_process(COMMAND xcodebuild -version
OUTPUT_VARIABLE XCODE_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}")
string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}")
message(STATUS "Building with Xcode version: ${XCODE_VERSION}")
######## ALIASES (DEPRECATION WARNINGS)
if(DEFINED IOS_PLATFORM)
set(PLATFORM ${IOS_PLATFORM})
message(DEPRECATION "IOS_PLATFORM argument is DEPRECATED. Consider using the new PLATFORM argument instead.")
endif()
if(DEFINED IOS_DEPLOYMENT_TARGET)
set(DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET})
message(DEPRECATION "CMAKE_IOS_DEVELOPER_ROOT argument is DEPRECATED. Consider using the new CMAKE_DEVELOPER_ROOT argument instead.")
endif()
if(DEFINED CMAKE_IOS_DEVELOPER_ROOT)
set(CMAKE_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT})
message(DEPRECATION "CMAKE_IOS_DEVELOPER_ROOT argument is DEPRECATED. Consider using the new CMAKE_DEVELOPER_ROOT argument instead.")
endif()
if(DEFINED IOS_ARCH)
set(ARCHS ${IOS_ARCH})
message(DEPRECATION "IOS_ARCH argument is DEPRECATED. Consider using the new ARCHS argument instead.")
endif()
######## END ALIASES
# Default to building for iPhoneOS if not specified otherwise, and we cannot
# determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use
# of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly
# determine the value of PLATFORM from the root project, as
# CMAKE_OSX_ARCHITECTURES is propagated to them by CMake.
if (NOT DEFINED PLATFORM)
if (CMAKE_OSX_ARCHITECTURES)
if(CMAKE_OSX_ARCHITECTURES MATCHES ".*arm.*" AND CMAKE_OSX_SYSROOT MATCHES ".*iphoneos.*")
set(PLATFORM "OS")
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*")
set(PLATFORM "SIMULATOR")
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*")
set(PLATFORM "SIMULATOR64")
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "arm64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvos.*")
set(PLATFORM "TVOS")
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvsimulator.*")
set(PLATFORM "SIMULATOR_TVOS")
elseif(CMAKE_OSX_ARCHITECTURES MATCHES ".*armv7k.*" AND CMAKE_OSX_SYSROOT MATCHES ".*watchos.*")
set(PLATFORM "WATCHOS")
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*watchsimulator.*")
set(PLATFORM "SIMULATOR_WATCHOS")
endif()
endif()
if (NOT PLATFORM)
set(PLATFORM "OS")
endif()
endif()
set(PLATFORM_INT "${PLATFORM}" CACHE STRING "Type of platform for which the build targets.")
# Handle the case where we are targeting iOS and a version above 10.0 (32-bit support dropped officially)
if(PLATFORM_INT STREQUAL "OS" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.0)
set(PLATFORM_INT "OS64")
message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.")
elseif(PLATFORM_INT STREQUAL "SIMULATOR" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.0)
set(PLATFORM_INT "SIMULATOR64")
message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.")
endif()
# Determine the platform name and architectures for use in xcodebuild commands
# from the specified PLATFORM name.
if(PLATFORM_INT STREQUAL "OS")
set(SDK_NAME iphoneos)
if(NOT ARCHS)
set(ARCHS armv7 armv7s arm64)
endif()
elseif(PLATFORM_INT STREQUAL "OS64")
set(SDK_NAME iphoneos)
if(NOT ARCHS)
if (XCODE_VERSION VERSION_GREATER 10.0)
set(ARCHS arm64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example
else()
set(ARCHS arm64)
endif()
endif()
elseif(PLATFORM_INT STREQUAL "OS64COMBINED")
set(SDK_NAME iphoneos)
if(MODERN_CMAKE)
if(NOT ARCHS)
if (XCODE_VERSION VERSION_GREATER 10.0)
set(ARCHS arm64 x86_64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example
else()
set(ARCHS arm64 x86_64)
endif()
endif()
else()
message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the OS64COMBINED setting work")
endif()
elseif(PLATFORM_INT STREQUAL "SIMULATOR")
set(SDK_NAME iphonesimulator)
if(NOT ARCHS)
set(ARCHS i386)
endif()
message(DEPRECATION "SIMULATOR IS DEPRECATED. Consider using SIMULATOR64 instead.")
elseif(PLATFORM_INT STREQUAL "SIMULATOR64")
set(SDK_NAME iphonesimulator)
if(NOT ARCHS)
set(ARCHS x86_64)
endif()
elseif(PLATFORM_INT STREQUAL "TVOS")
set(SDK_NAME appletvos)
if(NOT ARCHS)
set(ARCHS arm64)
endif()
elseif (PLATFORM_INT STREQUAL "TVOSCOMBINED")
set(SDK_NAME appletvos)
if(MODERN_CMAKE)
if(NOT ARCHS)
set(ARCHS arm64 x86_64)
endif()
else()
message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the TVOSCOMBINED setting work")
endif()
elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS")
set(SDK_NAME appletvsimulator)
if(NOT ARCHS)
set(ARCHS x86_64)
endif()
elseif(PLATFORM_INT STREQUAL "WATCHOS")
set(SDK_NAME watchos)
if(NOT ARCHS)
if (XCODE_VERSION VERSION_GREATER 10.0)
set(ARCHS armv7k arm64_32)
else()
set(ARCHS armv7k)
endif()
endif()
elseif(PLATFORM_INT STREQUAL "WATCHOSCOMBINED")
set(SDK_NAME watchos)
if(MODERN_CMAKE)
if(NOT ARCHS)
if (XCODE_VERSION VERSION_GREATER 10.0)
set(ARCHS armv7k arm64_32 i386)
else()
set(ARCHS armv7k i386)
endif()
endif()
else()
message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the WATCHOSCOMBINED setting work")
endif()
elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS")
set(SDK_NAME watchsimulator)
if(NOT ARCHS)
set(ARCHS i386)
endif()
else()
message(FATAL_ERROR "Invalid PLATFORM: ${PLATFORM_INT}")
endif()
message(STATUS "Configuring ${SDK_NAME} build for platform: ${PLATFORM_INT}, architecture(s): ${ARCHS}")
if(MODERN_CMAKE AND PLATFORM_INT MATCHES ".*COMBINED" AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode")
message(FATAL_ERROR "The COMBINED options only work with Xcode generator, -G Xcode")
endif()
# If user did not specify the SDK root to use, then query xcodebuild for it.
execute_process(COMMAND xcodebuild -version -sdk ${SDK_NAME} Path
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT DEFINED CMAKE_OSX_SYSROOT_INT AND NOT DEFINED CMAKE_OSX_SYSROOT)
message(SEND_ERROR "Please make sure that Xcode is installed and that the toolchain"
"is pointing to the correct path. Please run:"
"sudo xcode-select -s /Applications/Xcode.app/Contents/Developer"
"and see if that fixes the problem for you.")
message(FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} "
"does not exist.")
elseif(DEFINED CMAKE_OSX_SYSROOT)
message(STATUS "Using manually set SDK: ${CMAKE_OSX_SYSROOT} for platform: ${PLATFORM_INT}")
elseif(DEFINED CMAKE_OSX_SYSROOT_INT)
message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT_INT} for platform: ${PLATFORM_INT}")
set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "")
endif()
# Set Xcode property for SDKROOT as well if Xcode generator is used
if(USED_CMAKE_GENERATOR MATCHES "Xcode")
set(CMAKE_OSX_SYSROOT "${SDK_NAME}" CACHE INTERNAL "")
if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM)
set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM 123456789A CACHE INTERNAL "")
endif()
endif()
# Specify minimum version of deployment target.
if(NOT DEFINED DEPLOYMENT_TARGET)
if (PLATFORM_INT STREQUAL "WATCHOS" OR PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS")
# Unless specified, SDK version 2.0 is used by default as minimum target version (watchOS).
set(DEPLOYMENT_TARGET "2.0"
CACHE STRING "Minimum SDK version to build for." )
else()
# Unless specified, SDK version 9.0 is used by default as minimum target version (iOS, tvOS).
set(DEPLOYMENT_TARGET "9.0"
CACHE STRING "Minimum SDK version to build for." )
endif()
message(STATUS "Using the default min-version since DEPLOYMENT_TARGET not provided!")
endif()
# Use bitcode or not
if(NOT DEFINED ENABLE_BITCODE AND NOT ARCHS MATCHES "((^|, )(i386|x86_64))+")
# Unless specified, enable bitcode support by default
message(STATUS "Enabling bitcode support by default. ENABLE_BITCODE not provided!")
set(ENABLE_BITCODE TRUE)
elseif(NOT DEFINED ENABLE_BITCODE)
message(STATUS "Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!")
set(ENABLE_BITCODE FALSE)
endif()
set(ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL "Whether or not to enable bitcode" FORCE)
# Use ARC or not
if(NOT DEFINED ENABLE_ARC)
# Unless specified, enable ARC support by default
set(ENABLE_ARC TRUE)
message(STATUS "Enabling ARC support by default. ENABLE_ARC not provided!")
endif()
set(ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL "Whether or not to enable ARC" FORCE)
# Use hidden visibility or not
if(NOT DEFINED ENABLE_VISIBILITY)
# Unless specified, disable symbols visibility by default
set(ENABLE_VISIBILITY FALSE)
message(STATUS "Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!")
endif()
set(ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)" FORCE)
# Get the SDK version information.
execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion
OUTPUT_VARIABLE SDK_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Find the Developer root for the specific iOS platform being compiled for
# from CMAKE_OSX_SYSROOT. Should be ../../ from SDK specified in
# CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain
# this information from xcrun or xcodebuild.
if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode")
get_filename_component(IOS_PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH)
get_filename_component(CMAKE_DEVELOPER_ROOT ${IOS_PLATFORM_SDK_DIR} PATH)
if (NOT DEFINED CMAKE_DEVELOPER_ROOT)
message(FATAL_ERROR "Invalid CMAKE_DEVELOPER_ROOT: "
"${CMAKE_DEVELOPER_ROOT} does not exist.")
endif()
endif()
# Find the C & C++ compilers for the specified SDK.
if(NOT CMAKE_C_COMPILER)
execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang
OUTPUT_VARIABLE CMAKE_C_COMPILER
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}")
endif()
if(NOT CMAKE_CXX_COMPILER)
execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang++
OUTPUT_VARIABLE CMAKE_CXX_COMPILER
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}")
endif()
# Find (Apple's) libtool.
execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find libtool
OUTPUT_VARIABLE BUILD_LIBTOOL
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Using libtool: ${BUILD_LIBTOOL}")
# Configure libtool to be used instead of ar + ranlib to build static libraries.
# This is required on Xcode 7+, but should also work on previous versions of
# Xcode.
set(CMAKE_C_CREATE_STATIC_LIBRARY
"${BUILD_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
set(CMAKE_CXX_CREATE_STATIC_LIBRARY
"${BUILD_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
# Get the version of Darwin (OS X) of the host.
execute_process(COMMAND uname -r
OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
# CMake 3.14+ support building for iOS, watchOS and tvOS out of the box.
if(MODERN_CMAKE)
if(SDK_NAME MATCHES "iphone")
set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" FORCE)
elseif(SDK_NAME MATCHES "appletv")
set(CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" FORCE)
elseif(SDK_NAME MATCHES "watch")
set(CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" FORCE)
endif()
# Provide flags for a combined FAT library build on newer CMake versions
if(PLATFORM_INT MATCHES ".*COMBINED")
set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO CACHE INTERNAL "")
set(CMAKE_IOS_INSTALL_COMBINED YES CACHE INTERNAL "")
message(STATUS "Will combine built (static) artifacts into FAT lib...")
endif()
else()
# Legacy code path prior to CMake 3.14
set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "" FORCE)
endif()
# Standard settings.
set(CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL "")
set(UNIX TRUE CACHE BOOL "")
set(APPLE TRUE CACHE BOOL "")
set(IOS TRUE CACHE BOOL "")
set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE)
# Set the architectures for which to build.
set(CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE STRING "Build architecture for iOS")
# Change the type of target generated for try_compile() so it'll work when cross-compiling
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# All iOS/Darwin specific settings - some may be redundant.
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
set(CMAKE_SHARED_MODULE_PREFIX "lib")
set(CMAKE_SHARED_MODULE_SUFFIX ".so")
set(CMAKE_C_COMPILER_ABI ELF)
set(CMAKE_CXX_COMPILER_ABI ELF)
set(CMAKE_C_HAS_ISYSROOT 1)
set(CMAKE_CXX_HAS_ISYSROOT 1)
set(CMAKE_MODULE_EXISTS 1)
set(CMAKE_DL_LIBS "")
set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
set(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
if(ARCHS MATCHES "((^|, )(arm64|arm64e|x86_64))+")
set(CMAKE_C_SIZEOF_DATA_PTR 8)
set(CMAKE_CXX_SIZEOF_DATA_PTR 8)
message(STATUS "Using a data_ptr size of 8")
else()
set(CMAKE_C_SIZEOF_DATA_PTR 4)
set(CMAKE_CXX_SIZEOF_DATA_PTR 4)
message(STATUS "Using a data_ptr size of 4")
endif()
message(STATUS "Building for minimum ${SDK_NAME} version: ${DEPLOYMENT_TARGET}"
" (SDK version: ${SDK_VERSION})")
# Note that only Xcode 7+ supports the newer more specific:
# -m${SDK_NAME}-version-min flags, older versions of Xcode use:
# -m(ios/ios-simulator)-version-min instead.
if(PLATFORM_INT STREQUAL "OS" OR PLATFORM_INT STREQUAL "OS64")
if(XCODE_VERSION VERSION_LESS 7.0)
set(SDK_NAME_VERSION_FLAGS
"-mios-version-min=${DEPLOYMENT_TARGET}")
else()
# Xcode 7.0+ uses flags we can build directly from SDK_NAME.
set(SDK_NAME_VERSION_FLAGS
"-m${SDK_NAME}-version-min=${DEPLOYMENT_TARGET}")
endif()
elseif(PLATFORM_INT STREQUAL "TVOS")
set(SDK_NAME_VERSION_FLAGS
"-mtvos-version-min=${DEPLOYMENT_TARGET}")
elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS")
set(SDK_NAME_VERSION_FLAGS
"-mtvos-simulator-version-min=${DEPLOYMENT_TARGET}")
elseif(PLATFORM_INT STREQUAL "WATCHOS")
set(SDK_NAME_VERSION_FLAGS
"-mwatchos-version-min=${DEPLOYMENT_TARGET}")
elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS")
set(SDK_NAME_VERSION_FLAGS
"-mwatchos-simulator-version-min=${DEPLOYMENT_TARGET}")
else()
# SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min.
set(SDK_NAME_VERSION_FLAGS
"-mios-simulator-version-min=${DEPLOYMENT_TARGET}")
endif()
message(STATUS "Version flags set to: ${SDK_NAME_VERSION_FLAGS}")
set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} CACHE STRING
"Set CMake deployment target" FORCE)
if(ENABLE_BITCODE_INT)
set(BITCODE "-fembed-bitcode")
set(HEADER_PAD "")
set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode CACHE INTERNAL "")
message(STATUS "Enabling bitcode support.")
else()
set(BITCODE "")
set(HEADER_PAD "-headerpad_max_install_names")
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE NO CACHE INTERNAL "")
message(STATUS "Disabling bitcode support.")
endif()
if(ENABLE_ARC_INT)
set(FOBJC_ARC "-fobjc-arc")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES CACHE INTERNAL "")
message(STATUS "Enabling ARC support.")
else()
set(FOBJC_ARC "-fno-objc-arc")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC NO CACHE INTERNAL "")
message(STATUS "Disabling ARC support.")
endif()
if(NOT ENABLE_VISIBILITY_INT)
set(VISIBILITY "-fvisibility=hidden")
set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES CACHE INTERNAL "")
message(STATUS "Hiding symbols (-fvisibility=hidden).")
else()
set(VISIBILITY "")
set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN NO CACHE INTERNAL "")
endif()
#Check if Xcode generator is used, since that will handle these flags automagically
if(USED_CMAKE_GENERATOR MATCHES "Xcode")
message(STATUS "Not setting any manual command-line buildflags, since Xcode is selected as generator.")
else()
set(CMAKE_C_FLAGS
"${SDK_NAME_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}")
# Hidden visibilty is required for C++ on iOS.
set(CMAKE_CXX_FLAGS
"${SDK_NAME_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} -fvisibility-inlines-hidden -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g ${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG -Os -ffast-math ${CMAKE_CXX_FLAGS_MINSIZEREL}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -g -ffast-math ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -ffast-math ${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_C_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
set(CMAKE_CXX_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
# In order to ensure that the updated compiler flags are used in try_compile()
# tests, we have to forcibly set them in the CMake cache, not merely set them
# in the local scope.
list(APPEND VARS_TO_FORCE_IN_CACHE
CMAKE_C_FLAGS
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_LINK_FLAGS
CMAKE_CXX_LINK_FLAGS)
foreach(VAR_TO_FORCE ${VARS_TO_FORCE_IN_CACHE})
set(${VAR_TO_FORCE} "${${VAR_TO_FORCE}}" CACHE STRING "")
endforeach()
endif()
set(CMAKE_PLATFORM_HAS_INSTALLNAME 1)
set(CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks")
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib ${HEADER_PAD}")
set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle ${HEADER_PAD}")
set(CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
# Hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old
# build tree (where install_name_tool was hardcoded) and where
# CMAKE_INSTALL_NAME_TOOL isn't in the cache and still cmake didn't fail in
# CMakeFindBinUtils.cmake (because it isn't rerun) hardcode
# CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did
# before, Alex.
if(NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
# Set the find root to the iOS developer roots and to user defined paths.
set(CMAKE_FIND_ROOT_PATH ${CMAKE_DEVELOPER_ROOT} ${CMAKE_OSX_SYSROOT}
${CMAKE_PREFIX_PATH} CACHE STRING "SKD find search path root" FORCE)
# Default to searching for frameworks first.
set(CMAKE_FIND_FRAMEWORK FIRST)
# Set up the default search directories for frameworks.
set(CMAKE_SYSTEM_FRAMEWORK_PATH
${CMAKE_OSX_SYSROOT}/System/Library/Frameworks
${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks
${CMAKE_OSX_SYSROOT}/Developer/Library/Frameworks)
# Only search the specified iOS SDK, not the remainder of the host filesystem.
if( NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM )
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
endif()
if( NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY )
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
endif()
if( NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
endif()
#
# Some helper-macros below to simplify and beautify the CMakeFile
#
# This little macro lets you set any XCode specific property.
macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION)
set(XCODE_RELVERSION_I "${XCODE_RELVERSION}")
if(XCODE_RELVERSION_I STREQUAL "All")
set_property(TARGET ${TARGET} PROPERTY
XCODE_ATTRIBUTE_${XCODE_PROPERTY} "${XCODE_VALUE}")
else()
set_property(TARGET ${TARGET} PROPERTY
XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] "${XCODE_VALUE}")
endif()
endmacro(set_xcode_property)
# This macro lets you find executable programs on the host system.
macro(find_host_package)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
set(IOS FALSE)
find_package(${ARGN})
set(IOS TRUE)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endmacro(find_host_package)
......@@ -104,7 +104,7 @@ RUN cd /opt/ && \
unzip -q android-ndk-r15c-linux-x86_64.zip && \
rm -f android-ndk-r15c-linux-x86_64.zip
ENV ANDROID_NDK_VERSION r15c
ENV ANDROID_NDK_VERSION r19c
ENV ANDROID_NDK_HOME /opt/android-ndk-${ANDROID_NDK_VERSION}
# add to PATH
......
......@@ -73,14 +73,45 @@ RUN wget https://cmake.org/files/v3.11/cmake-3.11.3-Linux-x86_64.tar.gz -P /tmp/
update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force && \
rm -f /tmp/cmake-3.11.3-Linux-x86_64.tar.gz
# mace-dev-lite image already included NDK r15c
## Download other NDK r16
# mace-dev-lite image already included NDK r19c
## Download other NDK r15c
RUN cd /opt/ && \
wget -q https://dl.google.com/android/repository/android-ndk-r16-linux-x86_64.zip && \
unzip -q android-ndk-r16-linux-x86_64.zip && \
rm -f android-ndk-r16-linux-x86_64.zip
wget -q https://dl.google.com/android/repository/android-ndk-r15c-linux-x86_64.zip && \
unzip -q android-ndk-r15c-linux-x86_64.zip && \
rm -f android-ndk-r15c-linux-x86_64.zip
## Download other NDK r16b
RUN cd /opt/ && \
wget -q https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip && \
unzip -q android-ndk-r16b-linux-x86_64.zip && \
rm -f android-ndk-r16b-linux-x86_64.zip
## Download other NDK r17b
RUN cd /opt/ && \
wget -q https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip && \
unzip -q android-ndk-r17b-linux-x86_64.zip && \
rm -f android-ndk-r17b-linux-x86_64.zip
## Download other NDK r18b
RUN cd /opt/ && \
wget -q https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip && \
unzip -q android-ndk-r18b-linux-x86_64.zip && \
rm -f android-ndk-r18b-linux-x86_64.zip
# Mirror of https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/arm-linux-gnueabihf/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz
RUN cd /opt && \
wget -q https://cnbj1.fds.api.xiaomi.com/mace/third-party/gcc-linaro/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz && \
tar xf gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz && \
rm -rf gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz
# Mirror of https://cnbj1.fds.api.xiaomi.com/mace/third-party/gcc-linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
RUN cd /opt && \
wget -q https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
tar xf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz && \
rm -rf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
ENV CROSS_TOOLCHAIN_PARENT /opt
ENV ANDROID_NDK_VERSION r19c
ENV ANDROID_NDK_HOME /opt/android-ndk-${ANDROID_NDK_VERSION}
ENV LINARO_ARM_LINUX_GNUEABIHF /opt/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf
ENV LINARO_AARCH64_LINUX_GNU /opt/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu
file(GLOB MACE_EXAMPLE_SRCS
cli/example.cc
)
add_executable(mace_example ${MACE_EXAMPLE_SRCS})
target_link_libraries(mace_example PUBLIC
mace_static
gflags
)
install(TARGETS mace_example RUNTIME DESTINATION bin)
install(DIRECTORY mace DESTINATION include)
......@@ -16,11 +16,18 @@
#define MACE_PORT_ENV_H_
#include <cstdint>
#include <cstdlib>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#ifdef _WIN32
#include <malloc.h>
#endif
#include <sys/stat.h>
#include "mace/public/mace.h"
namespace mace {
......@@ -38,6 +45,7 @@ class LogWriter;
class Env {
public:
virtual int64_t NowMicros() = 0;
virtual MaceStatus AdviseFree(void *addr, size_t length);
virtual MaceStatus GetCPUMaxFreq(std::vector<float> *max_freqs);
virtual MaceStatus SchedSetAffinity(const std::vector<size_t> &cpu_ids);
virtual FileSystem *GetFileSystem() = 0;
......@@ -58,6 +66,10 @@ inline int64_t NowMicros() {
return port::Env::Default()->NowMicros();
}
inline MaceStatus AdviseFree(void *addr, size_t length) {
return port::Env::Default()->AdviseFree(addr, length);
}
inline MaceStatus GetCPUMaxFreq(std::vector<float> *max_freqs) {
return port::Env::Default()->GetCPUMaxFreq(max_freqs);
}
......@@ -70,6 +82,59 @@ inline port::FileSystem *GetFileSystem() {
return port::Env::Default()->GetFileSystem();
}
inline MaceStatus Memalign(void **memptr, size_t alignment, size_t size) {
#ifdef _WIN32
*memptr = _aligned_malloc(size, alignment);
if (*memptr == nullptr) {
return MaceStatus::MACE_OUT_OF_RESOURCES;
} else {
return MaceStatus::MACE_SUCCESS;
}
#else
#if defined(__ANDROID__) || defined(__hexagon__)
*memptr = memalign(alignment, size);
if (*memptr == nullptr) {
return MaceStatus::MACE_OUT_OF_RESOURCES;
} else {
return MaceStatus::MACE_SUCCESS;
}
#else
int error = posix_memalign(memptr, alignment, size);
if (error != 0) {
if (*memptr != nullptr) {
free(*memptr);
*memptr = nullptr;
}
return MaceStatus::MACE_OUT_OF_RESOURCES;
} else {
return MaceStatus::MACE_SUCCESS;
}
#endif
#endif
}
inline MaceStatus GetEnv(const char *name, std::string *value) {
#ifdef _WIN32
char *val;
size_t len;
errno_t error = _dupenv_s(&val, &len, name);
if (error != 0) {
return MaceStatus::MACE_RUNTIME_ERROR;
} else {
*value = std::string(val);
free(val);
return MaceStatus::MACE_SUCCESS;
}
#else
char *val = getenv(name);
*value = std::string(val);
return MaceStatus::MACE_SUCCESS;
#endif
}
#if defined(_WIN32) && !defined(S_ISREG)
#define S_ISREG(m) (((m) & 0170000) == (0100000))
#endif
} // namespace mace
#endif // MACE_PORT_ENV_H_
......@@ -19,6 +19,7 @@
#include <memory>
#include "mace/public/mace.h"
#include "mace/utils/macros.h"
namespace mace {
namespace port {
......@@ -29,6 +30,8 @@ class ReadOnlyMemoryRegion {
virtual ~ReadOnlyMemoryRegion() = default;
virtual const void *data() const = 0;
virtual uint64_t length() const = 0;
private:
MACE_DISABLE_COPY_AND_ASSIGN(ReadOnlyMemoryRegion);
};
class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion {
......@@ -44,12 +47,25 @@ class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion {
uint64_t length_;
};
class WritableFile {
public:
WritableFile() {}
virtual ~WritableFile();
virtual MaceStatus Append(const char *data, size_t length) = 0;
virtual MaceStatus Close() = 0;
virtual MaceStatus Flush() = 0;
private:
MACE_DISABLE_COPY_AND_ASSIGN(WritableFile);
};
class FileSystem {
public:
FileSystem() = default;
virtual ~FileSystem() = default;
virtual MaceStatus NewReadOnlyMemoryRegionFromFile(const char *fname,
std::unique_ptr<ReadOnlyMemoryRegion>* result) = 0;
virtual MaceStatus NewWritableFile(const char *fname,
std::unique_ptr<WritableFile>* result);
};
} // namespace port
......
......@@ -25,8 +25,20 @@
#include <vector>
#ifndef MACE_API
#ifdef _MSC_VER
#define MACE_API
#else
#define MACE_API __attribute__((visibility("default")))
#endif
#endif
#ifndef MACE_DEPRECATED
#ifdef _MSC_VER
#define MACE_DEPRECATED
#else
#define MACE_DEPRECATED __attribute__((deprecated))
#endif
#endif
namespace mace {
......@@ -435,7 +447,8 @@ MACE_API MaceStatus CreateMaceEngineFromProto(
const std::vector<std::string> &input_nodes,
const std::vector<std::string> &output_nodes,
const MaceEngineConfig &config,
std::shared_ptr<MaceEngine> *engine) __attribute__((deprecated));
std::shared_ptr<MaceEngine> *engine) MACE_DEPRECATED;
} // namespace mace
......
......@@ -75,6 +75,15 @@ T &&CheckNotNull(const char *file, int line, const char *exprtext, T &&t) {
#define MACE_NOT_IMPLEMENTED MACE_CHECK(false, "not implemented")
#define MACE_CHECK_SUCCESS(stmt) \
{ \
MaceStatus status = (stmt); \
if (status != MaceStatus::MACE_SUCCESS) { \
LOG(FATAL) << #stmt << " failed with error: " \
<< status.information(); \
} \
}
#define MACE_RETURN_IF_ERROR(stmt) \
{ \
MaceStatus status = (stmt); \
......
add_subdirectory(codegen)
add_subdirectory(core)
add_subdirectory(libmace)
add_subdirectory(ops)
add_subdirectory(port)
add_subdirectory(proto)
add_subdirectory(tools)
add_subdirectory(utils)
# Generate MACE version source
set(MACE_VERSION_GEN_TOOL "${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_version_source.sh")
set(MACE_VERSION_SRC "${CMAKE_CURRENT_BINARY_DIR}/version/version.cc")
add_custom_command(
OUTPUT ${MACE_VERSION_SRC}
COMMAND ${MACE_VERSION_GEN_TOOL} ${MACE_VERSION_SRC}
DEPENDS ${MACE_VERSION_GEN_TOOL}
COMMENT "Generating version source file" )
add_custom_target(version_src DEPENDS ${MACE_VERSION_SRC}
COMMENT "Checking if re-generation is required" )
add_library(generated_version ${MACE_VERSION_SRC})
add_dependencies(generated_version version_src)
# Generate OpenCL kernel source
set(MACE_OPENCL_KERNELS_GEN_TOOL "${PROJECT_SOURCE_DIR}/mace/python/tools/encrypt_opencl_codegen.py")
set(MACE_OPENCL_KERNELS_DIR "${PROJECT_SOURCE_DIR}/mace/ops/opencl/cl")
set(MACE_OPENCL_KERNELS_SRC "${CMAKE_CURRENT_BINARY_DIR}/opencl/encrypt_opencl_kernel.cc")
add_custom_command(
OUTPUT ${MACE_OPENCL_KERNELS_SRC}
COMMAND python ${MACE_OPENCL_KERNELS_GEN_TOOL} --output_path=${MACE_OPENCL_KERNELS_SRC} --cl_kernel_dir=${MACE_OPENCL_KERNELS_DIR}
DEPENDS ${MACE_OPENCL_KERNELS_GEN_TOOL}
COMMENT "Generating OpenCL kernel source file" )
add_custom_target(opencl_kernel_src DEPENDS ${MACE_OPENCL_KERNELS_SRC}
COMMENT "Checking if re-generation is required" )
add_library(generated_opencl_kernel ${MACE_OPENCL_KERNELS_SRC})
add_dependencies(generated_opencl_kernel opencl_kernel_src)
install(TARGETS generated_version ARCHIVE DESTINATION lib)
install(TARGETS generated_opencl_kernel ARCHIVE DESTINATION lib)
......@@ -13,29 +13,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
MACE_SOURCE_DIR=$(dirname $(dirname $(dirname $(dirname $0))))
OUTPUT_FILENAME=$1
if [[ -z "${OUTPUT_FILENAME}}" ]]; then
if [[ -z "${OUTPUT_FILENAME}" ]]; then
echo "Usage: $0 <filename>"
exit 1
fi
OUTPUT_DIR=$(dirname $OUTPUT_FILENAME)
if [ -d $OUTPUT_DIR ]; then
rm -rf $OUTPUT_DIR
fi
mkdir -p $OUTPUT_DIR
mkdir -p $(dirname $OUTPUT_FILENAME)
GIT_VERSION=$(git --git-dir=${MACE_SOURCE_DIR}/.git --work-tree=${MACE_SOURCE_DIR} describe --long --tags)
GIT_VERSION=$(git describe --tags --long)
if [[ $? != 0 ]]; then
GIT_VERSION=unknown
else
GIT_VERSION=${GIT_VERSION}
fi
echo $GIT_VERSION
echo write version $GIT_VERSION to ${OUTPUT_FILENAME}
cat <<EOF > ${OUTPUT_FILENAME}
// Copyright 2018 The MACE Authors. All Rights Reserved.
......@@ -55,7 +48,9 @@ cat <<EOF > ${OUTPUT_FILENAME}
// This is a generated file. DO NOT EDIT!
namespace mace {
#ifndef _MSC_VER
__attribute__((visibility("default")))
#endif
const char *MaceVersion() { return "MACEVER-${GIT_VERSION}" + 8; }
} // namespace mace
EOF
......
set(CORE_SRCS
allocator.cc
arg_helper.cc
device.cc
device_context.cc
kv_storage.cc
memory_optimizer.cc
net.cc
net_def_adapter.cc
net_optimizer.cc
op_context.cc
operator.cc
quantize.cc
runtime_failure_mock.cc
types.cc
workspace.cc
runtime/cpu/cpu_runtime.cc
)
if(MACE_ENABLE_OPENCL)
set(CORE_SRCS ${CORE_SRCS}
runtime/opencl/gpu_device.cc
runtime/opencl/gpu_runtime.cc
runtime/opencl/opencl_allocator.cc
runtime/opencl/opencl_runtime.cc
runtime/opencl/opencl_util.cc
runtime/opencl/opencl_wrapper.cc
runtime/opencl/scratch_image.cc
)
set(EXTRA_LINK_LIBS ${EXTRA_LINK_LIBS} generated_opencl_kernel dl)
endif(MACE_ENABLE_OPENCL)
if(MACE_ENABLE_HEXAGON_DSP)
set(CORE_SRCS ${CORE_SRCS} runtime/hexagon/hexagon_dsp_wrapper.cc)
set(EXTRA_LINK_LIBS ${EXTRA_LINK_LIBS} hexagon_controller)
endif(MACE_ENABLE_HEXAGON_DSP)
if(MACE_ENABLE_HEXAGON_HTA)
set(CORE_SRCS ${CORE_SRCS} runtime/hexagon/hexagon_hta_wrapper.cc)
set(EXTRA_LINK_LIBS ${EXTRA_LINK_LIBS} hta_controller hta_hexagon_runtime npu)
endif(MACE_ENABLE_HEXAGON_HTA)
add_library(core STATIC ${CORE_SRCS})
target_link_libraries(core PRIVATE
proto
utils
port
generated_version
${EXTRA_LINK_LIBS}
)
add_dependencies(core half)
if(MACE_ENABLE_OPENCL)
add_dependencies(core opencl_clhpp)
endif(MACE_ENABLE_OPENCL)
if(MACE_ENABLE_QUANTIZE)
add_dependencies(core gemmlowp)
endif(MACE_ENABLE_QUANTIZE)
install(TARGETS core ARCHIVE DESTINATION lib)
......@@ -14,10 +14,6 @@
#include "mace/core/allocator.h"
#include <unistd.h>
#include <sys/mman.h>
#include <memory>
namespace mace {
Allocator *GetCPUAllocator() {
......@@ -25,22 +21,4 @@ Allocator *GetCPUAllocator() {
return &allocator;
}
void AdviseFree(void *addr, size_t length) {
int page_size = sysconf(_SC_PAGESIZE);
void *addr_aligned =
reinterpret_cast<void *>(
(reinterpret_cast<uintptr_t>(addr) + page_size - 1)
& (~(page_size - 1)));
uintptr_t delta =
reinterpret_cast<uintptr_t>(addr_aligned)
- reinterpret_cast<uintptr_t>(addr);
if (length >= delta + page_size) {
size_t len_aligned = (length - delta) & (~(page_size - 1));
int ret = madvise(addr_aligned, len_aligned, MADV_DONTNEED);
if (ret != 0) {
LOG(ERROR) << "Advise free failed: " << strerror(errno);
}
}
}
} // namespace mace
......@@ -74,32 +74,9 @@ class CPUAllocator : public Allocator {
return MaceStatus::MACE_OUT_OF_RESOURCES;
}
void *data = nullptr;
#if defined(__ANDROID__) || defined(__hexagon__)
data = memalign(kMaceAlignment, nbytes);
if (data == NULL) {
LOG(WARNING) << "Allocate CPU Buffer with "
<< nbytes << " bytes failed because of"
<< strerror(errno);
*result = nullptr;
return MaceStatus::MACE_OUT_OF_RESOURCES;
}
#else
int ret = posix_memalign(&data, kMaceAlignment, nbytes);
if (ret != 0) {
LOG(WARNING) << "Allocate CPU Buffer with "
<< nbytes << " bytes failed because of"
<< strerror(errno);
if (data != NULL) {
free(data);
}
*result = nullptr;
return MaceStatus::MACE_OUT_OF_RESOURCES;
}
#endif
MACE_RETURN_IF_ERROR(Memalign(result, kMaceAlignment, nbytes));
// TODO(heliangliang) This should be avoided sometimes
memset(data, 0, nbytes);
*result = data;
memset(*result, 0, nbytes);
return MaceStatus::MACE_SUCCESS;
}
......@@ -143,8 +120,6 @@ class CPUAllocator : public Allocator {
// Global CPU allocator used for CPU/GPU/DSP
Allocator *GetCPUAllocator();
void AdviseFree(void *addr, size_t length);
} // namespace mace
#endif // MACE_CORE_ALLOCATOR_H_
......@@ -16,6 +16,8 @@
#include <sys/stat.h>
#include "mace/port/env.h"
namespace mace {
namespace {
......
......@@ -12,11 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <climits>
#include <algorithm>
#include <cstring>
......@@ -26,6 +21,8 @@
#include "mace/core/kv_storage.h"
#include "mace/utils/macros.h"
#include "mace/utils/logging.h"
#include "mace/port/env.h"
#include "mace/port/file_system.h"
namespace mace {
......@@ -98,69 +95,24 @@ FileStorage::FileStorage(const std::string &file_path):
loaded_(false), data_changed_(false), file_path_(file_path) {}
int FileStorage::Load() {
struct stat st;
if (stat(file_path_.c_str(), &st) == -1) {
if (errno == ENOENT) {
VLOG(1) << "File " << file_path_
<< " does not exist";
return 0;
} else {
LOG(WARNING) << "Stat file " << file_path_
<< " failed, error code: " << strerror(errno);
return -1;
}
}
utils::WriteLock lock(&data_mutex_);
if (loaded_) {
return 0;
}
int fd = open(file_path_.c_str(), O_RDONLY);
if (fd < 0) {
if (errno == ENOENT) {
LOG(INFO) << "File " << file_path_
<< " does not exist";
return 0;
} else {
LOG(WARNING) << "open file " << file_path_
<< " failed, error code: " << strerror(errno);
return -1;
}
}
size_t file_size = st.st_size;
unsigned char *file_data =
static_cast<unsigned char *>(mmap(nullptr, file_size, PROT_READ,
MAP_PRIVATE, fd, 0));
int res = 0;
if (file_data == MAP_FAILED) {
LOG(WARNING) << "mmap file " << file_path_
<< " failed, error code: " << strerror(errno);
res = close(fd);
if (res != 0) {
LOG(WARNING) << "close file " << file_path_
<< " failed, error code: " << strerror(errno);
}
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> kv_data =
make_unique<mace::port::ReadOnlyBufferMemoryRegion>();
auto fs = GetFileSystem();
auto status = fs->NewReadOnlyMemoryRegionFromFile(
file_path_.c_str(), &kv_data);
if (status != MaceStatus::MACE_SUCCESS) {
LOG(ERROR) << "Failed to read kv store file: " << file_path_;
return -1;
} else {
ParseKVData(static_cast<const unsigned char *>(kv_data->data()),
kv_data->length(), &data_);
}
ParseKVData(file_data, file_size, &data_);
res = munmap(file_data, file_size);
if (res != 0) {
LOG(WARNING) << "munmap file " << file_path_
<< " failed, error code: " << strerror(errno);
res = close(fd);
if (res != 0) {
LOG(WARNING) << "close file " << file_path_
<< " failed, error code: " << strerror(errno);
}
return -1;
}
res = close(fd);
if (res != 0) {
LOG(WARNING) << "close file " << file_path_
<< " failed, error code: " << strerror(errno);
return -1;
}
loaded_ = true;
return 0;
}
......@@ -196,8 +148,10 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) {
int FileStorage::Flush() {
utils::WriteLock lock(&data_mutex_);
if (!data_changed_) return 0;
int fd = open(file_path_.c_str(), O_WRONLY | O_CREAT, 0600);
if (fd < 0) {
auto fs = GetFileSystem();
std::unique_ptr<port::WritableFile> file;
MaceStatus s = fs->NewWritableFile(file_path_.c_str(), &file);
if (s != MaceStatus::MACE_SUCCESS) {
LOG(WARNING) << "open file " << file_path_
<< " failed, error code: " << strerror(errno);
return -1;
......@@ -209,8 +163,8 @@ int FileStorage::Flush() {
for (auto &kv : data_) {
data_size += 2 * int_size + kv.first.size() + kv.second.size();
}
std::unique_ptr<unsigned char[]> buffer(new unsigned char[data_size]);
unsigned char *buffer_ptr = &buffer[0];
std::unique_ptr<char[]> buffer = make_unique<char[]>(data_size);
char *buffer_ptr = buffer.get();
int64_t num_of_data = data_.size();
memcpy(buffer_ptr, &num_of_data, sizeof(int64_t));
......@@ -230,32 +184,16 @@ int FileStorage::Flush() {
memcpy(buffer_ptr, kv.second.data(), kv.second.size());
buffer_ptr += kv.second.size();
}
int res = 0;
buffer_ptr = &buffer[0];
int64_t remain_size = data_size;
while (remain_size > 0) {
size_t buffer_size = std::min<int64_t>(remain_size, SSIZE_MAX);
res = write(fd, buffer_ptr, buffer_size);
if (res == -1) {
LOG(WARNING) << "write file " << file_path_
<< " failed, error code: " << strerror(errno);
res = close(fd);
if (res != 0) {
LOG(WARNING) << "close file " << file_path_
<< " failed, error code: " << strerror(errno);
}
return -1;
}
remain_size -= buffer_size;
buffer_ptr += buffer_size;
s = file->Append(buffer.get(), data_size);
if (s != MaceStatus::MACE_SUCCESS) {
file->Close();
return -1;
}
res = close(fd);
if (res != 0) {
LOG(WARNING) << "close file " << file_path_
<< " failed, error code: " << strerror(errno);
s = file->Close();
if (s != MaceStatus::MACE_SUCCESS) {
return -1;
}
data_changed_ = false;
return 0;
}
......
......@@ -32,7 +32,7 @@
namespace mace {
HexagonHTAWrapper::HexagonHTAWrapper(Device *device)
: device_(device), quantize_util_(&device->cpu_runtime()->thread_pool()) {
: quantize_util_(&device->cpu_runtime()->thread_pool()) {
}
int HexagonHTAWrapper::GetVersion() {
......
......@@ -50,7 +50,6 @@ class HexagonHTAWrapper : public HexagonControlWrapper {
void SetDebugLevel(int level) override;
private:
Device *device_;
QuantizeUtil<uint8_t> quantize_util_;
MACE_DISABLE_COPY_AND_ASSIGN(HexagonHTAWrapper);
};
......
......@@ -37,7 +37,7 @@
#pragma GCC diagnostic ignored "-Wignored-attributes"
#endif // MACE_OS_MAC
#include "include/CL/cl2.hpp"
#include "CL/cl2.hpp"
#ifdef MACE_OS_MAC
#pragma GCC diagnostic pop
......
......@@ -147,8 +147,8 @@ void *OpenCLAllocator::MapImage(void *buffer,
VLOG(3) << "Map OpenCL Image";
MACE_CHECK(image_shape.size() == 2) << "Just support map 2d image";
auto cl_image = static_cast<cl::Image2D *>(buffer);
std::array<size_t, 3> origin = {0, 0, 0};
std::array<size_t, 3> region = {image_shape[0], image_shape[1], 1};
std::array<size_t, 3> origin = {{0, 0, 0}};
std::array<size_t, 3> region = {{image_shape[0], image_shape[1], 1}};
mapped_image_pitch->resize(2);
cl_int error;
......
......@@ -14,8 +14,6 @@
#include "mace/core/runtime/opencl/opencl_runtime.h"
#include <sys/stat.h>
#include <cstdlib>
#include <fstream>
#include <memory>
......
set(LIBMACE_SRCS capability.cc mace.cc)
add_library(mace SHARED ${LIBMACE_SRCS})
target_link_libraries(mace ops)
if(NOT APPLE)
set_target_properties(mace PROPERTIES LINK_FLAGS
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/mace_version_script.lds")
endif(NOT APPLE)
add_library(mace_static STATIC ${LIBMACE_SRCS})
target_link_libraries(mace_static ops)
install(TARGETS mace LIBRARY DESTINATION lib)
install(TARGETS mace_static ARCHIVE DESTINATION lib)
......@@ -19,7 +19,7 @@
#include "mace/core/device_context.h"
#include "mace/core/memory_optimizer.h"
#include "mace/core/net.h"
#include "mace/ops/ops_registry.h"
#include "mace/ops/registry/ops_registry.h"
#include "mace/ops/common/transpose.h"
#include "mace/utils/math.h"
#include "mace/utils/memory.h"
......
file(GLOB OPS_COMMON_SRCS common/*.cc)
file(GLOB OPS_REF_KERNELS_SRCS ref/*.cc)
file(GLOB OPS_ARM_NEON_FP32_KERNELS_SRCS
arm/fp32/*.cc
)
file(GLOB OPS_ARM_NEON_Q8_KERNELS_SRCS
arm/q8/*.cc
)
file(GLOB OPS_OPENCL_KERNELS_SRCS
opencl/*.cc
opencl/cl/*.cc
opencl/buffer/*.cc
opencl/image/*.cc
)
file(GLOB OPS_INTERNAL_OPS_SRCS *.cc)
set(OPS_SRCS registry/ops_registry.cc)
set(OPS_SRCS ${OPS_SRCS} ${OPS_COMMON_SRCS})
set(OPS_SRCS ${OPS_SRCS} ${OPS_INTERNAL_OPS_SRCS})
# TODO we need to remove this in production build
set(OPS_SRCS ${OPS_SRCS} ${OPS_REF_KERNELS_SRCS})
if(MACE_ENABLE_NEON)
set(OPS_SRCS ${OPS_SRCS} ${OPS_ARM_NEON_FP32_KERNELS_SRCS})
endif(MACE_ENABLE_NEON)
if(MACE_ENABLE_QUANTIZE)
set(OPS_SRCS ${OPS_SRCS} ${OPS_ARM_NEON_Q8_KERNELS_SRCS})
endif(MACE_ENABLE_QUANTIZE)
if(MACE_ENABLE_OPENCL)
set(OPS_SRCS ${OPS_SRCS} ${OPS_OPENCL_KERNELS_SRCS})
endif(MACE_ENABLE_OPENCL)
add_library(ops STATIC ${OPS_SRCS})
target_link_libraries(ops PRIVATE core proto utils port)
if(MACE_ENABLE_QUANTIZE)
add_dependencies(ops tflite)
endif(MACE_ENABLE_QUANTIZE)
install(TARGETS ops ARCHIVE DESTINATION lib)
......@@ -17,14 +17,12 @@
#if defined(MACE_ENABLE_NEON)
#include <arm_neon.h>
#endif
namespace mace {
namespace ops {
namespace arm {
namespace fp32 {
#ifdef MACE_ENABLE_NEON
inline float32x4_t neon_vfma_lane_0(float32x4_t a,
float32x4_t b,
float32x4_t c) {
......@@ -64,11 +62,11 @@ inline float32x4_t neon_vfma_lane_3(float32x4_t a,
return vmlaq_lane_f32(a, b, vget_high_f32(c), 1);
#endif
}
#endif
} // namespace fp32
} // namespace arm
} // namespace ops
} // namespace mace
#endif // MACE_ENABLE_NEON
#endif // MACE_OPS_ARM_FP32_COMMON_NEON_H_
......@@ -19,6 +19,8 @@
#include <algorithm>
#include <utility>
#include "mace/port/env.h"
namespace mace {
namespace ops {
namespace arm {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/ops/quantization_util.h"
#include "mace/ops/arm/q8/quantization_util.h"
namespace mace {
namespace ops {
......
......@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MACE_OPS_QUANTIZATION_UTIL_H_
#define MACE_OPS_QUANTIZATION_UTIL_H_
#ifndef MACE_OPS_ARM_Q8_QUANTIZATION_UTIL_H_
#define MACE_OPS_ARM_Q8_QUANTIZATION_UTIL_H_
#include <vector>
......@@ -30,4 +30,4 @@ const int32_t *GetBiasData(const Tensor *bias,
} // namespace ops
} // namespace mace
#endif // MACE_OPS_QUANTIZATION_UTIL_H_
#endif // MACE_OPS_ARM_Q8_QUANTIZATION_UTIL_H_
......@@ -52,7 +52,7 @@
#ifdef MACE_ENABLE_QUANTIZE
#include "mace/ops/common/gemmlowp_util.h"
#include "mace/ops/quantization_util.h"
#include "mace/ops/arm/q8/quantization_util.h"
#endif // MACE_ENABLE_QUANTIZE
#ifdef MACE_ENABLE_OPENCL
......
......@@ -29,7 +29,7 @@
#endif // MACE_ENABLE_NEON
#ifdef MACE_ENABLE_QUANTIZE
#include "mace/ops/quantization_util.h"
#include "mace/ops/arm/q8/quantization_util.h"
// We reuse TensorFlow Lite's optimized depthwiseconv_uint8 and parallelized it
// using OpenMP for MACE's quantized depthwise_conv2d.
#include "tensorflow/contrib/lite/kernels/internal/optimized/depthwiseconv_uint8.h"
......
......@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/ops/opencl/lstm_cell.h"
#include <algorithm>
#include <memory>
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/ops/ops_registry.h"
#include "mace/ops/registry/ops_registry.h"
namespace mace {
......
......@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MACE_OPS_OPS_REGISTRY_H_
#define MACE_OPS_OPS_REGISTRY_H_
#ifndef MACE_OPS_REGISTRY_OPS_REGISTRY_H_
#define MACE_OPS_REGISTRY_OPS_REGISTRY_H_
#include "mace/core/operator.h"
......@@ -27,4 +27,4 @@ class OpRegistry : public OpRegistryBase {
} // namespace mace
#endif // MACE_OPS_OPS_REGISTRY_H_
#endif // MACE_OPS_REGISTRY_OPS_REGISTRY_H_
add_library(port_base STATIC
env.cc
logger.cc
file_system.cc
)
target_link_libraries(port_base utils)
if(ANDROID)
add_subdirectory(posix)
add_subdirectory(linux_base)
add_subdirectory(android)
add_library(port ALIAS port_android)
elseif(APPLE)
add_subdirectory(posix)
add_subdirectory(darwin)
add_library(port ALIAS port_darwin)
elseif(WIN32)
add_subdirectory(windows)
add_library(port ALIAS port_windows)
else(WIN32)
add_subdirectory(posix)
add_subdirectory(linux_base)
add_subdirectory(linux)
add_library(port ALIAS port_linux)
endif(ANDROID)
install(TARGETS port_base ARCHIVE DESTINATION lib)
add_library(port_android STATIC
logger.cc
malloc_logger.cc
env.cc
)
target_link_libraries(port_android port_linux_base log)
install(TARGETS port_android ARCHIVE DESTINATION lib)
add_library(port_darwin STATIC
env.cc
)
target_link_libraries(port_darwin port_posix)
install(TARGETS port_darwin ARCHIVE DESTINATION lib)
......@@ -22,6 +22,10 @@
namespace mace {
namespace port {
MaceStatus Env::AdviseFree(void *addr, size_t length) {
return MaceStatus::MACE_UNSUPPORTED;
}
MaceStatus Env::GetCPUMaxFreq(std::vector<float> *max_freqs) {
return MaceStatus::MACE_UNSUPPORTED;
}
......
// Copyright 2019 The MACE 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
//
// http://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 "mace/port/file_system.h"
#include <cstdio>
#include <string>
#include "mace/utils/memory.h"
#include "mace/utils/logging.h"
namespace mace {
namespace port {
namespace {
class StdWritableFile : public WritableFile {
public:
StdWritableFile(const std::string& fname, FILE* f)
: fname_(fname), file_(f) {}
~StdWritableFile() override {
if (file_ != nullptr) {
// Ignoring any potential errors
fclose(file_);
}
}
MaceStatus Append(const char *data, size_t length) override {
size_t r = fwrite(data, 1, length, file_);
if (r != length) {
LOG(ERROR) << "Failed to append file: " << fname_
<< ", requested: " << length
<< ", written: " << r
<< ", error: " << errno;
return MaceStatus::MACE_RUNTIME_ERROR;
}
return MaceStatus::MACE_SUCCESS;
}
MaceStatus Close() override {
if (fclose(file_) != 0) {
LOG(ERROR) << "Failed to close file: " << fname_
<< ", error: " << errno;
return MaceStatus::MACE_RUNTIME_ERROR;
}
file_ = nullptr;
return MaceStatus::MACE_SUCCESS;
}
MaceStatus Flush() override {
if (fflush(file_) != 0) {
LOG(ERROR) << "Failed to flush file: " << fname_
<< ", error: " << errno;
return MaceStatus::MACE_RUNTIME_ERROR;
}
return MaceStatus::MACE_SUCCESS;
}
private:
std::string fname_;
FILE* file_;
};
} // namespace
WritableFile::~WritableFile() {}
MaceStatus FileSystem::NewWritableFile(const char *fname,
std::unique_ptr<WritableFile>* result) {
FILE* f = fopen(fname, "w");
if (f == nullptr) {
LOG(ERROR) << "Failed to open file to write: " << fname
<< ", error: " << errno;
return MaceStatus::MACE_RUNTIME_ERROR;
} else {
*result = make_unique<StdWritableFile>(fname, f);
}
return MaceStatus::MACE_SUCCESS;
}
} // namespace port
} // namespace mace
add_library(port_linux STATIC
env.cc
)
target_link_libraries(port_linux port_linux_base)
install(TARGETS port_linux ARCHIVE DESTINATION lib)
add_library(port_linux_base STATIC
env.cc
)
target_link_libraries(port_linux_base port_posix)
install(TARGETS port_linux_base ARCHIVE DESTINATION lib)
......@@ -17,6 +17,7 @@
#include <errno.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <unistd.h>
#include <cstddef>
......@@ -121,5 +122,26 @@ MaceStatus LinuxBaseEnv::SchedSetAffinity(const std::vector<size_t> &cpu_ids) {
return MaceStatus::MACE_SUCCESS;
}
MaceStatus LinuxBaseEnv::AdviseFree(void *addr, size_t length) {
int page_size = sysconf(_SC_PAGESIZE);
void *addr_aligned =
reinterpret_cast<void *>(
(reinterpret_cast<uintptr_t>(addr) + page_size - 1)
& (~(page_size - 1)));
uintptr_t delta =
reinterpret_cast<uintptr_t>(addr_aligned)
- reinterpret_cast<uintptr_t>(addr);
if (length >= delta + page_size) {
size_t len_aligned = (length - delta) & (~(page_size - 1));
int error = madvise(addr_aligned, len_aligned, MADV_DONTNEED);
if (error != 0) {
LOG(ERROR) << "Advise free failed: " << strerror(errno);
return MaceStatus::MACE_RUNTIME_ERROR;
}
}
return MaceStatus::MACE_SUCCESS;
}
} // namespace port
} // namespace mace
......@@ -26,6 +26,7 @@ namespace port {
class LinuxBaseEnv : public Env {
public:
int64_t NowMicros() override;
MaceStatus AdviseFree(void *addr, size_t length) override;
MaceStatus GetCPUMaxFreq(std::vector<float> *max_freqs) override;
FileSystem *GetFileSystem() override;
MaceStatus SchedSetAffinity(const std::vector<size_t> &cpu_ids) override;
......
add_library(port_posix STATIC
file_system.cc
)
target_link_libraries(port_posix port_base)
install(TARGETS port_posix ARCHIVE DESTINATION lib)
......@@ -37,9 +37,9 @@ class PosixReadOnlyMemoryRegion : public ReadOnlyMemoryRegion {
if (length_ > 0) {
munmap(const_cast<void *>(addr_), length_);
}
};
const void *data() const override { return addr_; };
uint64_t length() const override { return length_; };
}
const void *data() const override { return addr_; }
uint64_t length() const override { return length_; }
private:
const void *addr_;
......@@ -50,11 +50,11 @@ class PosixReadOnlyMemoryRegion : public ReadOnlyMemoryRegion {
MaceStatus PosixFileSystem::NewReadOnlyMemoryRegionFromFile(
const char *fname,
std::unique_ptr<ReadOnlyMemoryRegion>* result) {
MaceStatus s = MaceStatus(MaceStatus::MACE_SUCCESS);
MaceStatus s = MaceStatus::MACE_SUCCESS;
int fd = open(fname, O_RDONLY);
if (fd < 0) {
// TODO(heliangliang) check errno
s = MaceStatus(MaceStatus::MACE_RUNTIME_ERROR);
s = MaceStatus::MACE_RUNTIME_ERROR;
} else {
struct stat st;
fstat(fd, &st);
......@@ -63,7 +63,7 @@ MaceStatus PosixFileSystem::NewReadOnlyMemoryRegionFromFile(
mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (address == MAP_FAILED) {
// TODO(heliangliang) check errno
s = MaceStatus(MaceStatus::MACE_RUNTIME_ERROR);
s = MaceStatus::MACE_RUNTIME_ERROR;
} else {
*result = make_unique<PosixReadOnlyMemoryRegion>(address, st.st_size);
}
......
add_library(port_windows STATIC
env.cc
file_system.cc
)
target_link_libraries(port_windows port_base)
install(TARGETS port_windows ARCHIVE DESTINATION lib)
// Copyright 2019 The MACE 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
//
// http://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 "mace/port/windows/env.h"
#include <windows.h>
#include <ctime>
#include <string>
#include <vector>
namespace mace {
namespace port {
int64_t WindowsEnv::NowMicros() {
int64_t sec = time(nullptr);
SYSTEMTIME sys_time;
GetLocalTime(&sys_time);
int64_t msec = sys_time.wMilliseconds;
return sec * 1000000 + msec * 1000;
}
FileSystem *WindowsEnv::GetFileSystem() {
return &windows_file_system_;
}
LogWriter *WindowsEnv::GetLogWriter() {
return &log_writer_;
}
std::vector<std::string> WindowsEnv::GetBackTraceUnsafe(int max_steps) {
std::vector<std::string> empty;
return empty;
}
Env *Env::Default() {
static WindowsEnv windows_env;
return &windows_env;
}
} // namespace port
} // namespace mace
// Copyright 2019 The MACE 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
//
// http://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.
#ifndef MACE_PORT_WINDOWS_ENV_H_
#define MACE_PORT_WINDOWS_ENV_H_
#include <string>
#include <vector>
#include "mace/port/env.h"
#include "mace/port/logger.h"
#include "mace/port/port-arch.h"
#include "mace/port/windows/file_system.h"
namespace mace {
namespace port {
class WindowsEnv : public Env {
public:
int64_t NowMicros() override;
FileSystem *GetFileSystem() override;
LogWriter *GetLogWriter() override;
std::vector<std::string> GetBackTraceUnsafe(int max_steps) override;
private:
LogWriter log_writer_;
WindowsFileSystem windows_file_system_;
};
} // namespace port
} // namespace mace
#endif // MACE_PORT_WINDOWS_ENV_H_
// Copyright 2019 The MACE 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
//
// http://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 "mace/port/windows/file_system.h"
#include <fstream>
#include <string>
#include <vector>
#include <utility>
#include "mace/utils/memory.h"
namespace mace {
namespace port {
namespace {
class WindowsReadOnlyMemoryRegion : public ReadOnlyMemoryRegion {
public:
WindowsReadOnlyMemoryRegion() = delete;
explicit WindowsReadOnlyMemoryRegion(std::vector<char> &&buffer) {
buffer_.swap(buffer); // forward
}
~WindowsReadOnlyMemoryRegion() override {}
const void *data() const override { return buffer_.data(); }
uint64_t length() const override { return buffer_.size(); }
private:
std::vector<char> buffer_;
};
} // namespace
MaceStatus WindowsFileSystem::NewReadOnlyMemoryRegionFromFile(
const char *fname, std::unique_ptr<ReadOnlyMemoryRegion> *result) {
// TODO(heliangliang) change to CreateFileMapping
std::ifstream ifs(fname, std::ios::in | std::ios::binary);
if (!ifs.is_open()) {
return MaceStatus::MACE_RUNTIME_ERROR;
}
ifs.seekg(0, ifs.end);
size_t length = ifs.tellg();
ifs.seekg(0, ifs.beg);
std::vector<char> buffer(length);
ifs.read(reinterpret_cast<char *>(buffer.data()), length);
if (ifs.fail()) {
return MaceStatus::MACE_RUNTIME_ERROR;
}
ifs.close();
*result = make_unique<WindowsReadOnlyMemoryRegion>(std::move(buffer));
return MaceStatus::MACE_SUCCESS;
}
} // namespace port
} // namespace mace
// Copyright 2019 The MACE 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
//
// http://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.
#ifndef MACE_PORT_WINDOWS_FILE_SYSTEM_H_
#define MACE_PORT_WINDOWS_FILE_SYSTEM_H_
#include <string>
#include <memory>
#include "mace/port/file_system.h"
namespace mace {
namespace port {
class WindowsFileSystem : public FileSystem {
public:
WindowsFileSystem() = default;
~WindowsFileSystem() override = default;
MaceStatus NewReadOnlyMemoryRegionFromFile(const char *fname,
std::unique_ptr<ReadOnlyMemoryRegion>* result) override;
};
} // namespace port
} // namespace mace
#endif // MACE_PORT_WINDOWS_FILE_SYSTEM_H_
set(MACE_PROTO_PROTOS mace.proto)
set(MACE_PROTO_SRCS)
set(MACE_PROTO_HDRS)
foreach(proto_file ${MACE_PROTO_PROTOS})
get_filename_component(proto_file_abs ${proto_file} ABSOLUTE)
get_filename_component(basename ${proto_file} NAME_WE)
set(PROTO_GENERATED_FILES ${basename}.pb.cc ${basename}.pb.h)
list(APPEND MACE_PROTO_SRCS ${basename}.pb.cc)
list(APPEND MACE_PROTO_HDRS ${basename}.pb.h)
add_custom_command(
OUTPUT ${PROTO_GENERATED_FILES}
COMMAND ${PROTOC_BIN} --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} ${proto_file_abs}
COMMENT "Generating ${PROTO_GENERATED_FILES} from ${proto_file}"
DEPENDS protoc_bin
VERBATIM
)
endforeach()
add_custom_target(mace_proto_src DEPENDS ${MACE_PROTO_SRCS}
COMMENT "Checking if re-generation is required" )
add_library(proto ${MACE_PROTO_SRCS})
target_link_libraries(proto libprotobuf_lite)
install(TARGETS proto ARCHIVE DESTINATION lib)
file(GLOB MACE_RUN_SRCS
validation/mace_run.cc
)
add_executable(mace_run ${MACE_RUN_SRCS})
target_link_libraries(mace_run PUBLIC
mace_static
gflags
)
file(GLOB MACE_BENCHMARK_MODEL_SRCS
benchmark/benchmark_model.cc
)
add_executable(benchmark_model ${MACE_BENCHMARK_MODEL_SRCS})
target_link_libraries(benchmark_model PUBLIC
mace_static
gflags
)
file(GLOB MACE_BENCHMARK_MODEL_THROUGHPUT_SRCS
benchmark/benchmark_model_throughput.cc
)
add_executable(benchmark_model_throughput ${MACE_BENCHMARK_MODEL_THROUGHPUT_SRCS})
target_link_libraries(benchmark_model_throughput PUBLIC
mace_static
gflags
)
install(TARGETS mace_run RUNTIME DESTINATION bin)
install(TARGETS benchmark_model RUNTIME DESTINATION bin)
install(TARGETS benchmark_model_throughput RUNTIME DESTINATION bin)
......@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <sys/time.h>
#include <cstdlib>
#include <fstream>
#include <memory>
......@@ -27,7 +25,7 @@
#include "mace/utils/logging.h"
#include "mace/utils/memory.h"
#include "mace/utils/math.h"
#include "mace/benchmark/statistics.h"
#include "mace/utils/statistics.h"
#ifdef MODEL_GRAPH_FORMAT_CODE
#include "mace/codegen/engine/mace_engine_factory.h"
#endif
......@@ -57,12 +55,6 @@ std::string FormatName(const std::string input) {
return res;
}
inline int64_t NowMicros() {
struct timeval tv;
gettimeofday(&tv, nullptr);
return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
}
DeviceType ParseDeviceType(const std::string &device_str) {
if (device_str.compare("CPU") == 0) {
return DeviceType::CPU;
......
......@@ -249,7 +249,12 @@ int Main(int argc, char **argv) {
buffer_out);
}
#if defined(MACE_CPU_MODEL_TAG) || \
defined(MACE_GPU_MODEL_TAG) || \
defined(MACE_DSP_MODEL_TAG)
int64_t t0, t1, init_micros;
#endif
#ifdef MACE_CPU_MODEL_TAG
/* --------------------- CPU init ----------------------- */
LOG(INFO) << "Load & init cpu model and warm up";
......@@ -306,10 +311,14 @@ int Main(int argc, char **argv) {
LOG(INFO) << "DSP 1st warm up run latency: " << t1 - t0 << " us";
#endif
#if defined(MACE_CPU_MODEL_TAG) || \
defined(MACE_GPU_MODEL_TAG) || \
defined(MACE_DSP_MODEL_TAG)
double cpu_throughput = 0;
double gpu_throughput = 0;
double dsp_throughput = 0;
int64_t run_micros = FLAGS_run_seconds * 1000000;
#endif
#ifdef MACE_CPU_MODEL_TAG
std::thread cpu_thread([&]() {
......
add_library(utils STATIC
string_util.cc
thread_pool.cc
status.cc
statistics.cc
)
if(NOT ANDROID AND NOT WIN32)
target_link_libraries(utils PUBLIC pthread)
endif(NOT ANDROID AND NOT WIN32)
install(TARGETS utils ARCHIVE DESTINATION lib)
......@@ -17,7 +17,7 @@
#include <functional>
#include <set>
#include "mace/benchmark/statistics.h"
#include "mace/utils/statistics.h"
#include "mace/utils/logging.h"
#include "mace/utils/string_util.h"
......
......@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MACE_BENCHMARK_STATISTICS_H_
#define MACE_BENCHMARK_STATISTICS_H_
#ifndef MACE_UTILS_STATISTICS_H_
#define MACE_UTILS_STATISTICS_H_
#include <algorithm>
#include <cmath>
......@@ -182,4 +182,4 @@ class OpStat {
} // namespace benchmark
} // namespace mace
#endif // MACE_BENCHMARK_STATISTICS_H_
#endif // MACE_UTILS_STATISTICS_H_
......@@ -179,7 +179,7 @@ void ThreadPool::Init() {
if (threads_.size() <= 1) {
return;
}
count_down_latch_.Reset(threads_.size() - 1);
count_down_latch_.Reset(static_cast<int>(threads_.size() - 1));
event_ = kThreadPoolInit;
for (size_t i = 1; i < threads_.size(); ++i) {
threads_[i] = std::thread(&ThreadPool::ThreadLoop, this, i);
......@@ -206,7 +206,7 @@ void ThreadPool::Run(const std::function<void(const int64_t)> &func,
iters_offset = thread_infos_[i].range_end;
}
count_down_latch_.Reset(thread_count - 1);
count_down_latch_.Reset(static_cast<int>(thread_count - 1));
{
std::unique_lock<std::mutex> m(event_mutex_);
event_.store(kThreadPoolRun | ~(event_ | kThreadPoolEventMask),
......
......@@ -15,31 +15,30 @@
#ifndef MACE_UTILS_TUNER_H_
#define MACE_UTILS_TUNER_H_
// TODO(heliangliang) Fix portability
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <limits>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "mace/port/env.h"
#include "mace/port/file_system.h"
#include "mace/utils/logging.h"
#include "mace/utils/memory.h"
#include "mace/utils/string_util.h"
#include "mace/utils/timer.h"
namespace mace {
inline bool IsTuning() {
const char *tuning = getenv("MACE_TUNING");
return tuning != nullptr && strlen(tuning) == 1 && tuning[0] == '1';
std::string tuning;
GetEnv("MACE_TUNING", &tuning);
return tuning.size() == 1 && tuning[0] == '1';
}
template <typename param_type>
......@@ -49,7 +48,7 @@ class Tuner {
const unsigned char *param_byte_stream = nullptr,
const size_t param_byte_stream_size = 0):
tuned_param_file_path_(tuned_param_file_path) {
path_ = getenv("MACE_RUN_PARAMETER_PATH");
GetEnv("MACE_RUN_PARAMETER_PATH", &path_);
if (param_byte_stream != nullptr && param_byte_stream_size != 0) {
ParseData(param_byte_stream, param_byte_stream_size);
} else {
......@@ -94,10 +93,10 @@ class Tuner {
}
private:
inline void WriteRunParameters() {
if (path_ != nullptr) {
void WriteRunParameters() {
if (!path_.empty()) {
VLOG(3) << "Write tuning result to " << path_;
std::ofstream ofs(path_, std::ios::binary | std::ios::out);
std::ofstream ofs(path_.c_str(), std::ios::binary | std::ios::out);
if (ofs.is_open()) {
int64_t num_pramas = param_table_.size();
ofs.write(reinterpret_cast<char *>(&num_pramas), sizeof(num_pramas));
......@@ -124,7 +123,7 @@ class Tuner {
}
}
inline void ParseData(const unsigned char *data, size_t data_size) {
void ParseData(const unsigned char *data, size_t data_size) {
const size_t int_size = sizeof(int32_t);
const size_t param_type_size = sizeof(param_type);
......@@ -160,68 +159,20 @@ class Tuner {
}
}
inline void ReadRunParamters() {
void ReadRunParamters() {
if (!tuned_param_file_path_.empty()) {
struct stat st;
if (stat(tuned_param_file_path_.c_str(), &st) == -1) {
if (errno == ENOENT) {
VLOG(1) << "File " << tuned_param_file_path_
<< " does not exist";
} else {
LOG(WARNING) << "Stat file " << tuned_param_file_path_
<< " failed, error code: " << strerror(errno);
}
return;
} else if (!S_ISREG(st.st_mode)) {
VLOG(1) << "The path " << tuned_param_file_path_
<< " is not a file";
return;
}
int fd = open(tuned_param_file_path_.c_str(), O_RDONLY);
if (fd < 0) {
if (errno == ENOENT) {
LOG(INFO) << "File " << tuned_param_file_path_
<< " does not exist";
} else {
LOG(WARNING) << "open file " << tuned_param_file_path_
<< " failed, error code: " << strerror(errno);
}
return;
}
size_t file_size = st.st_size;
unsigned char *file_data =
static_cast<unsigned char *>(mmap(nullptr, file_size, PROT_READ,
MAP_PRIVATE, fd, 0));
int res = 0;
if (file_data == MAP_FAILED) {
LOG(WARNING) << "mmap file " << tuned_param_file_path_
<< " failed, error code: " << strerror(errno);
res = close(fd);
if (res != 0) {
LOG(WARNING) << "close file " << tuned_param_file_path_
<< " failed, error code: " << strerror(errno);
}
return;
}
ParseData(file_data, file_size);
res = munmap(file_data, file_size);
if (res != 0) {
LOG(WARNING) << "munmap file " << tuned_param_file_path_
<< " failed, error code: " << strerror(errno);
res = close(fd);
if (res != 0) {
LOG(WARNING) << "close file " << tuned_param_file_path_
<< " failed, error code: " << strerror(errno);
}
return;
}
res = close(fd);
if (res != 0) {
LOG(WARNING) << "close file " << tuned_param_file_path_
<< " failed, error code: " << strerror(errno);
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> param_data =
make_unique<mace::port::ReadOnlyBufferMemoryRegion>();
auto fs = GetFileSystem();
auto status = fs->NewReadOnlyMemoryRegionFromFile(
tuned_param_file_path_.c_str(), &param_data);
if (status != MaceStatus::MACE_SUCCESS) {
LOG(ERROR) << "Failed to read tuned param file: "
<< tuned_param_file_path_;
return;
} else {
ParseData(static_cast<const unsigned char *>(param_data->data()),
param_data->length());
}
} else {
VLOG(1) << "There is no tuned parameters.";
......@@ -229,15 +180,14 @@ class Tuner {
}
template <typename RetType>
inline RetType Run(
const std::function<RetType(const std::vector<param_type> &,
Timer *,
std::vector<param_type> *)> &func,
const std::vector<param_type> &params,
Timer *timer,
int num_runs,
double *time_us,
std::vector<param_type> *tuning_result) {
RetType Run(const std::function<RetType(const std::vector<param_type> &,
Timer *,
std::vector<param_type> *)> &func,
const std::vector<param_type> &params,
Timer *timer,
int num_runs,
double *time_us,
std::vector<param_type> *tuning_result) {
RetType res = 0;
int iter = 0;
int64_t total_time_us = 0;
......@@ -255,14 +205,13 @@ class Tuner {
}
template <typename RetType>
inline RetType Tune(
const std::function<std::vector<std::vector<param_type>>()>
&param_generator,
const std::function<RetType(const std::vector<param_type> &,
Timer *,
std::vector<param_type> *)> &func,
Timer *timer,
std::vector<param_type> *opt_params) {
RetType Tune(const std::function<std::vector<std::vector<param_type>>()>
&param_generator,
const std::function<RetType(const std::vector<param_type> &,
Timer *,
std::vector<param_type> *)> &func,
Timer *timer,
std::vector<param_type> *opt_params) {
RetType res = 0;
double opt_time = std::numeric_limits<double>::max();
auto params = param_generator();
......@@ -288,7 +237,7 @@ class Tuner {
private:
std::string tuned_param_file_path_;
const char *path_;
std::string path_;
std::unordered_map<std::string, std::vector<param_type>> param_table_;
};
......
......@@ -20,7 +20,7 @@ def _git_version_conf_impl(repository_ctx):
unused_var = repository_ctx.path(Label("//:.git/refs/heads/master"))
repository_ctx.execute([
'bash', '%s/mace/tools/git/gen_version_source.sh' % mace_root_path
'bash', '%s/mace/codegen/tools/gen_version_source.sh' % mace_root_path
, '%s/version' % generated_files_path
], quiet=False)
......
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/ccutils")
add_subdirectory(ccutils)
if(MACE_ENABLE_TESTS)
add_subdirectory(ccunit)
endif()
if(MACE_ENABLE_BENCHMARK)
add_subdirectory(ccbenchmark)
endif()
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
if(NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif()
file(GLOB MACE_BENCHMARK_TEST_SRCS
mace/benchmark_utils/*.cc
mace/ops/*.cc
)
add_executable(mace_cc_benchmark ${MACE_BENCHMARK_TEST_SRCS})
target_link_libraries(mace_cc_benchmark PUBLIC
mace_cc_test_utils
ops
gflags
)
add_dependencies(mace_cc_benchmark eigen3)
install(TARGETS mace_cc_benchmark RUNTIME DESTINATION bin)
......@@ -19,7 +19,7 @@
#include <regex> // NOLINT(build/c++11)
#include <vector>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/port/env.h"
#include "mace/utils/logging.h"
......
......@@ -13,15 +13,13 @@
// limitations under the License.
// Simple benchmarking facility.
#ifndef MACE_CORE_TESTING_TEST_BENCHMARK_H_
#define MACE_CORE_TESTING_TEST_BENCHMARK_H_
#ifndef MACE_BENCHMARK_UTILS_TEST_BENCHMARK_H_
#define MACE_BENCHMARK_UTILS_TEST_BENCHMARK_H_
#include <string>
#include <utility>
#include <vector>
#include "mace/core/types.h"
#define MACE_BENCHMARK(n) \
static ::mace::testing::Benchmark *__benchmark_##n = \
(new ::mace::testing::Benchmark(#n, (n)))
......@@ -52,4 +50,4 @@ void StopTiming();
} // namespace testing
} // namespace mace
#endif // MACE_CORE_TESTING_TEST_BENCHMARK_H_
#endif // MACE_BENCHMARK_UTILS_TEST_BENCHMARK_H_
......@@ -16,7 +16,7 @@
#include "gflags/gflags.h"
#include "mace/core/runtime/cpu/cpu_runtime.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
DEFINE_string(filter, "all", "op benchmark regex filter, eg:.*CONV.*");
......
......@@ -14,7 +14,7 @@
#include <string>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,7 +14,7 @@
#include <string>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -15,7 +15,7 @@
#ifdef MACE_ENABLE_OPENCL
#include "mace/core/runtime/opencl/opencl_runtime.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/opencl/buffer_transformer.h"
#include "mace/ops/ops_test_util.h"
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,8 +14,8 @@
#include <algorithm>
#include "mace/benchmark/statistics.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/utils/statistics.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/common/conv_pool_2d_util.h"
#include "mace/ops/ops_test_util.h"
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,8 +14,8 @@
#include <algorithm>
#include "mace/benchmark/statistics.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/utils/statistics.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/common/conv_pool_2d_util.h"
#include "mace/ops/ops_test_util.h"
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,8 +14,8 @@
#include <algorithm>
#include "mace/benchmark/statistics.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/utils/statistics.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/common/conv_pool_2d_util.h"
#include "mace/ops/ops_test_util.h"
......
......@@ -14,9 +14,9 @@
#include <algorithm>
#include "mace/benchmark/statistics.h"
#include "mace/utils/statistics.h"
#include "mace/core/operator.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/benchmark/statistics.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/utils/statistics.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/lstmcell_test_util.h"
#include "mace/ops/ops_test_util.h"
......
......@@ -14,7 +14,7 @@
#include <string>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/eltwise.h"
#include "mace/ops/ops_test_util.h"
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,8 +14,8 @@
#include <string>
#include "mace/benchmark/statistics.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/utils/statistics.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,7 +14,7 @@
#include <string>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/lstmcell_test_util.h"
#include "mace/ops/ops_test_util.h"
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/lstmcell_test_util.h"
#include "mace/ops/ops_test_util.h"
......
......@@ -19,8 +19,8 @@
#include <vector>
#include "public/gemmlowp.h"
#include "mace/benchmark/statistics.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/utils/statistics.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace gemmlowp {
......
......@@ -16,7 +16,7 @@
#include <string>
#include <vector>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
namespace mace {
namespace ops {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
#include "mace/ops/pad.h"
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,7 +14,7 @@
#include <string>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/common/conv_pool_2d_util.h"
#include "mace/ops/pooling.h"
#include "mace/ops/ops_test_util.h"
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -15,7 +15,7 @@
#ifdef MACE_ENABLE_QUANTIZE
#include "mace/core/operator.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,8 +14,8 @@
#include <string>
#include "mace/benchmark/statistics.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/utils/statistics.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,8 +14,8 @@
#include <string>
#include "mace/benchmark/statistics.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/utils/statistics.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,8 +14,8 @@
#include <string>
#include "mace/benchmark/statistics.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/utils/statistics.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,7 +14,7 @@
#include <string>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -13,7 +13,7 @@
// limitations under the License.
#include "mace/core/operator.h"
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,7 +14,7 @@
#include <string>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -14,7 +14,7 @@
#include <string>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
......@@ -18,7 +18,8 @@
#include <string>
#include <vector>
#include "mace/core/testing/test_benchmark.h"
#include "mace/core/types.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/utils/thread_pool.h"
#define MACE_EMPTY_STATEMENT asm volatile("":::"memory");
......
......@@ -15,7 +15,7 @@
#include <string>
#include <vector>
#include "mace/core/testing/test_benchmark.h"
#include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
namespace mace {
......
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB MACE_CC_TEST_SRCS
mace/utils/*.cc
mace/port/*.cc
mace/ops/*.cc
mace/libmace/*.cc
)
add_executable(mace_cc_test ${MACE_CC_TEST_SRCS})
target_link_libraries(mace_cc_test PUBLIC
mace_cc_test_utils
mace_static
gtest
gtest_main
)
install(TARGETS mace_cc_test RUNTIME DESTINATION bin)
......@@ -16,7 +16,7 @@
#include <thread> // NOLINT(build/c++11)
#include "mace/test/mace_api_test.h"
#include "mace/libmace/mace_api_test.h"
namespace mace {
namespace test {
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/test/mace_api_test.h"
#include "mace/libmace/mace_api_test.h"
namespace mace {
namespace test {
......
......@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MACE_TEST_MACE_API_TEST_H_
#define MACE_TEST_MACE_API_TEST_H_
#ifndef MACE_LIBMACE_MACE_API_TEST_H_
#define MACE_LIBMACE_MACE_API_TEST_H_
#include <functional>
#include <map>
......@@ -187,4 +187,4 @@ void CheckOutputs(const NetDef &net_def,
}
} // namespace test
} // namespace mace
#endif // MACE_TEST_MACE_API_TEST_H_
#endif // MACE_LIBMACE_MACE_API_TEST_H_
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB MACE_CC_TEST_UTILS_SRCS
mace/ops/*.cc
)
add_library(mace_cc_test_utils ${MACE_CC_TEST_UTILS_SRCS})
target_link_libraries(mace_cc_test_utils PUBLIC
ops
)
......@@ -31,7 +31,7 @@
#include "mace/core/device_context.h"
#include "mace/core/tensor.h"
#include "mace/core/workspace.h"
#include "mace/ops/ops_registry.h"
#include "mace/ops/registry/ops_registry.h"
#include "mace/public/mace.h"
#include "mace/utils/memory.h"
#include "mace/utils/math.h"
......
INCLUDE(ExternalProject)
set(EIGEN3_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/eigen3")
set(EIGEN3_INCLUDE_DIR "${EIGEN3_SRCS_DIR}/src/eigen3" CACHE PATH "eigen3 include directory." FORCE)
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})
# Mirror of https://bitbucket.org/eigen/eigen/get/f3a22f35b044.tar.gz
set(EIGEN3_URL "http://cnbj1.fds.api.xiaomi.com/mace/third-party/eigen/f3a22f35b044.tar.gz")
set(EIGEN3_HASH "SHA256=ca7beac153d4059c02c8fc59816c82d54ea47fe58365e8aded4082ded0b820c4")
ExternalProject_Add(
eigen3
URL_HASH "${EIGEN3_HASH}"
URL "${EIGEN3_URL}"
PREFIX "${EIGEN3_SRCS_DIR}"
BINARY_DIR ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
include(ExternalProject)
set(GEMMLOWP_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/gemmlowp")
set(GEMMLOWP_INCLUDE_DIR "${GEMMLOWP_SRCS_DIR}/src/gemmlowp" CACHE PATH "gemmlowp include directory." FORCE)
include_directories(SYSTEM ${GEMMLOWP_INCLUDE_DIR})
set(GEMMLOWP_URL "http://cnbj1.fds.api.xiaomi.com/mace/third-party/gemmlowp/gemmlowp-master-48c0547a046d49b466aa01e3a82a18028f288924.zip")
set(GEMMLOWP_HASH "SHA256=f340384e7728cea605e83597593699dfe8d13ff333b834d24c256935e3dc1758")
ExternalProject_Add(
gemmlowp
URL_HASH "${GEMMLOWP_HASH}"
URL "${GEMMLOWP_URL}"
PREFIX "${GEMMLOWP_SRCS_DIR}"
BINARY_DIR ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
INCLUDE(ExternalProject)
set(GFLAGS_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/gflags")
set(GFLAGS_INSTALL_DIR "${MACE_THIRD_PARTY_DIR}/install/gflags")
set(GFLAGS_INCLUDE_DIR "${GFLAGS_INSTALL_DIR}/include" CACHE PATH "gflags include directory." FORCE)
if(MSVC)
set(GFLAGS_LIBRARIES "${GFLAGS_INSTALL_DIR}/lib/gflags_static.lib" CACHE FILEPATH "GFLAGS_LIBRARIES" FORCE)
else(MSVC)
set(GFLAGS_LIBRARIES "${GFLAGS_INSTALL_DIR}/lib/libgflags.a" CACHE FILEPATH "GFLAGS_LIBRARIES" FORCE)
endif(MSVC)
include_directories(SYSTEM ${GFLAGS_INCLUDE_DIR})
# Mirror of https://github.com/gflags/gflags/archive/v2.2.2.zip
set(GFLAGS_URL "https://cnbj1.fds.api.xiaomi.com/mace/third-party/gflags/v2.2.2.zip")
set(GFLAGS_HASH "SHA256=19713a36c9f32b33df59d1c79b4958434cb005b5b47dc5400a7a4b078111d9b5")
ExternalProject_Add(
gflags_gflags
URL_HASH "${GFLAGS_HASH}"
URL "${GFLAGS_URL}"
PREFIX ${GFLAGS_SRCS_DIR}
UPDATE_COMMAND ""
BUILD_BYPRODUCTS ${GFLAGS_LIBRARIES}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GFLAGS_INSTALL_DIR}
-DBUILD_STATIC_LIBS=ON
-DBUILD_TESTING=OFF
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
${THIRD_PARTY_EXTRA_CMAKE_ARGS}
)
if(MSVC)
add_custom_command(TARGET gflags_gflags POST_BUILD
COMMAND if $<CONFIG:Debug>==1 (${CMAKE_COMMAND} -E copy ${GFLAGS_INSTALL_DIR}/lib/gflags_static_debug.lib ${GFLAGS_INSTALL_DIR}/lib/gflags_static.lib)
)
endif(MSVC)
add_library(gflags STATIC IMPORTED GLOBAL)
set_property(TARGET gflags PROPERTY IMPORTED_LOCATION ${GFLAGS_LIBRARIES})
add_dependencies(gflags gflags_gflags)
if(MSVC)
set_target_properties(gflags
PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES
Shlwapi.lib)
endif(MSVC)
if(MACE_ENABLE_TESTS)
enable_testing()
include(ExternalProject)
set(GTEST_SOURCES_DIR ${MACE_THIRD_PARTY_DIR}/gtest)
set(GTEST_INSTALL_DIR ${MACE_THIRD_PARTY_DIR}/install/gtest)
set(GTEST_INCLUDE_DIR "${GTEST_INSTALL_DIR}/include" CACHE PATH "gtest include directory." FORCE)
include_directories(SYSTEM ${GTEST_INCLUDE_DIR})
if(MSVC)
set(GTEST_LIBRARIES
"${GTEST_INSTALL_DIR}/lib/gtest.lib" CACHE FILEPATH "gtest libraries." FORCE)
set(GTEST_MAIN_LIBRARIES
"${GTEST_INSTALL_DIR}/lib/gtest_main.lib" CACHE FILEPATH "gtest main libraries." FORCE)
else(MSVC)
set(GTEST_LIBRARIES
"${GTEST_INSTALL_DIR}/lib/libgtest.a" CACHE FILEPATH "gtest libraries." FORCE)
set(GTEST_MAIN_LIBRARIES
"${GTEST_INSTALL_DIR}/lib/libgtest_main.a" CACHE FILEPATH "gtest main libraries." FORCE)
endif(MSVC)
# Mirror of "https://github.com/google/googletest/archive/release-1.8.0.zip"
set(GTEST_URL "https://cnbj1.fds.api.xiaomi.com/mace/third-party/googletest/googletest-release-1.8.0.zip")
set(GTEST_HASH "SHA256=f3ed3b58511efd272eb074a3a6d6fb79d7c2e6a0e374323d1e6bcbcc1ef141bf")
ExternalProject_Add(
extern_gtest
URL_HASH "${GTEST_HASH}"
URL "${GTEST_URL}"
PREFIX ${GTEST_SOURCES_DIR}
UPDATE_COMMAND ""
BUILD_BYPRODUCTS ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GTEST_INSTALL_DIR}
-DBUILD_GMOCK=ON
-Dgtest_disable_pthreads=ON
-Dgtest_force_shared_crt=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
${THIRD_PARTY_EXTRA_CMAKE_ARGS}
)
add_library(gtest STATIC IMPORTED GLOBAL)
set_property(TARGET gtest PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARIES})
add_dependencies(gtest extern_gtest)
add_library(gtest_main STATIC IMPORTED GLOBAL)
set_property(TARGET gtest_main PROPERTY IMPORTED_LOCATION ${GTEST_MAIN_LIBRARIES})
add_dependencies(gtest_main extern_gtest)
endif(MACE_ENABLE_TESTS)
include(ExternalProject)
set(HALF_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/half")
set(HALF_INCLUDE_DIR "${HALF_SRCS_DIR}/src/half" CACHE PATH "half include directory." FORCE)
include_directories(SYSTEM ${HALF_INCLUDE_DIR})
set(HALF_URL "https://cnbj1.fds.api.xiaomi.com/mace/third-party/half/half-code-356-trunk.zip")
set(HALF_HASH "SHA256=0f514a1e877932b21dc5edc26a148ddc700b6af2facfed4c030ca72f74d0219e")
ExternalProject_Add(
half
URL "${HALF_URL}"
URL_HASH "${HALF_HASH}"
PREFIX "${HALF_SRCS_DIR}"
BINARY_DIR ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
set(HTA_INSTALL_DIR "${PROJECT_SOURCE_DIR}/third_party/hta")
set(HTA_INCLUDE_DIR "${HTA_INSTALL_DIR}")
include_directories(SYSTEM "${HTA_INCLUDE_DIR}")
set(HTA_CONTROLLER
"${HTA_INSTALL_DIR}/${ANDROID_ABI}/libhta_controller.so"
)
set(HTA_RUNTIME
"${HTA_INSTALL_DIR}/${ANDROID_ABI}/libhta_hexagon_runtime.so"
)
set(HTA_NPU
"${HTA_INSTALL_DIR}/${ANDROID_ABI}/libnpu.so"
)
add_library(hta_controller SHARED IMPORTED GLOBAL)
add_library(hta_hexagon_runtime SHARED IMPORTED GLOBAL)
add_library(npu SHARED IMPORTED GLOBAL)
set_target_properties(hta_controller PROPERTIES IMPORTED_LOCATION ${HTA_CONTROLLER})
set_target_properties(hta_hexagon_runtime PROPERTIES IMPORTED_LOCATION ${HTA_RUNTIME})
set_target_properties(npu PROPERTIES IMPORTED_LOCATION ${HTA_NPU})
install(FILES ${HTA_CONTROLLER} DESTINATION lib)
install(FILES ${HTA_RUNTIME} DESTINATION lib)
install(FILES ${HTA_NPU} DESTINATION lib)
set(NNLIB_INSTALL_DIR "${PROJECT_SOURCE_DIR}/third_party/nnlib")
set(NNLIB_INCLUDE_DIR "${NNLIB_INSTALL_DIR}")
include_directories(SYSTEM "${NNLIB_INCLUDE_DIR}")
set(NNLIB_CONTROLLER "${NNLIB_INSTALL_DIR}/${ANDROID_ABI}/libhexagon_controller.so")
add_library(hexagon_controller SHARED IMPORTED GLOBAL)
set_target_properties(hexagon_controller PROPERTIES IMPORTED_LOCATION ${NNLIB_CONTROLLER})
install(FILES ${NNLIB_CONTROLLER} DESTINATION lib)
include(ExternalProject)
set(OPENCL_CLHPP_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/opencl-clhpp")
set(OPENCL_CLHPP_INSTALL_DIR "${MACE_THIRD_PARTY_DIR}/install/opencl-clhpp")
set(OPENCL_CLHPP_INCLUDE_DIR "${OPENCL_CLHPP_INSTALL_DIR}" CACHE PATH "opencl-clhpp include directory." FORCE)
include_directories(SYSTEM ${OPENCL_CLHPP_INCLUDE_DIR})
# Mirror of https://github.com/KhronosGroup/OpenCL-CLHPP/archive/4c6f7d56271727e37fb19a9b47649dd175df2b12.zip
set(OPENCL_CLHPP_URL "https://cnbj1.fds.api.xiaomi.com/mace/third-party/OpenCL-CLHPP/OpenCL-CLHPP-4c6f7d56271727e37fb19a9b47649dd175df2b12.zip")
set(OPENCL_CLHPP_HASH "SHA256=dab6f1834ec6e3843438cc0f97d63817902aadd04566418c1fcc7fb78987d4e7")
ExternalProject_Add(
opencl_clhpp
URL_HASH "${OPENCL_CLHPP_HASH}"
URL "${OPENCL_CLHPP_URL}"
PREFIX "${OPENCL_CLHPP_SRCS_DIR}"
CMAKE_ARGS -DBUILD_DOCS=OFF
-DBUILD_EXAMPLES=OFF
-DBUILD_TESTS=OFF
-DCMAKE_INSTALL_PREFIX=${OPENCL_CLHPP_INSTALL_DIR}
${THIRD_PARTY_EXTRA_CMAKE_ARGS}
)
add_dependencies(opencl_clhpp opencl_headers)
include(ExternalProject)
set(OPENCL_HEADERS_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/opencl-headers")
set(OPENCL_HEADERS_INCLUDE_DIR "${OPENCL_HEADERS_SRCS_DIR}/src/opencl_headers/opencl20" CACHE PATH "opencl-headers include directory." FORCE)
include_directories(SYSTEM ${OPENCL_HEADERS_INCLUDE_DIR})
# Mirror of https://github.com/KhronosGroup/OpenCL-Headers/archive/f039db6764d52388658ef15c30b2237bbda49803.zip
set(OPENCL_HEADERS_URL "https://cnbj1.fds.api.xiaomi.com/mace/third-party/OpenCL-Headers/f039db6764d52388658ef15c30b2237bbda49803.zip")
set(OPENCL_HEADERS_HASH "SHA256=b2b813dd88a7c39eb396afc153070f8f262504a7f956505b2049e223cfc2229b")
ExternalProject_Add(
opencl_headers
URL_HASH "${OPENCL_HEADERS_HASH}"
URL "${OPENCL_HEADERS_URL}"
PREFIX "${OPENCL_HEADERS_SRCS_DIR}"
BINARY_DIR ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
Copyright 2008 Google Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Code generated by the Protocol Buffer compiler is owned by the owner
of the input file used when generating it. This code is not
standalone and requires a support library to be linked with it. This
support library is itself covered by the above license.
include (ExternalProject)
set(PROTOBUF_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/protobuf")
set(PROTOBUF_INSTALL_DIR "${MACE_THIRD_PARTY_DIR}/install/protobuf")
set(PROTOBUF_INCLUDE_DIR "${PROTOBUF_INSTALL_DIR}/include")
set(PROTOC_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/protoc")
set(PROTOC_INSTALL_DIR "${MACE_THIRD_PARTY_DIR}/install/protoc")
include_directories(SYSTEM ${PROTOBUF_INCLUDE_DIR})
if(MSVC)
set(PROTOBUF_LITE_LIBRARIES
"${PROTOBUF_INSTALL_DIR}/lib/libprotobuf-lite.lib" CACHE FILEPATH "libprotobuf lite libraries." FORCE)
set(PROTOC_BIN
"${PROTOC_INSTALL_DIR}/bin/protoc.exe" CACHE FILEPATH "protoc compiler." FORCE)
else(MSVC)
set(PROTOBUF_LITE_LIBRARIES
"${PROTOBUF_INSTALL_DIR}/lib/libprotobuf-lite.a" CACHE FILEPATH "libprotobuf lite libraries." FORCE)
set(PROTOC_BIN
"${PROTOC_INSTALL_DIR}/bin/protoc" CACHE FILEPATH "protoc compiler." FORCE)
endif(MSVC)
# Mirror of https://github.com/google/protobuf/archive/v3.6.1.zip
set(PROTOBUF_URL "https://cnbj1.fds.api.xiaomi.com/mace/third-party/protobuf/protobuf-3.6.1.zip")
set(PROTOBUF_HASH "SHA256=d7a221b3d4fb4f05b7473795ccea9e05dab3b8721f6286a95fffbffc2d926f8b")
ExternalProject_Add(
protobuf
URL_HASH "${PROTOBUF_HASH}"
URL "${PROTOBUF_URL}"
PREFIX "${PROTOBUF_SRCS_DIR}"
BUILD_BYPRODUCTS ${PROTOBUF_LITE_LIBRARIES}
SOURCE_DIR "${PROTOBUF_SRCS_DIR}/src/protobuf"
CONFIGURE_COMMAND ${CMAKE_COMMAND} ../protobuf/cmake/
#-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR}
-DCMAKE_VERBOSE_MAKEFILE=OFF
-Dprotobuf_BUILD_TESTS=OFF
-Dprotobuf_WITH_ZLIB=OFF
-Dprotobuf_BUILD_PROTOC_BINARIES=OFF
-Dprotobuf_MSVC_STATIC_RUNTIME=OFF
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
${THIRD_PARTY_EXTRA_CMAKE_ARGS}
)
if(MSVC)
add_custom_command(TARGET protobuf POST_BUILD
COMMAND if $<CONFIG:Debug>==1 (cmake -E copy ${PROTOBUF_INSTALL_DIR}/lib/libprotobuf-lited.lib ${PROTOBUF_INSTALL_DIR}/lib/libprotobuf-lite.lib)
)
endif(MSVC)
add_library(libprotobuf_lite STATIC IMPORTED GLOBAL)
set_property(TARGET libprotobuf_lite PROPERTY IMPORTED_LOCATION ${PROTOBUF_LITE_LIBRARIES})
add_dependencies(libprotobuf_lite protobuf)
install(FILES ${PROTOBUF_LITE_LIBRARIES} DESTINATION lib)
if(NOT APPLE)
# Actually this works for iOS build on macOS, but the compatibility is not
# thoroughly tested, so we use the downloaded version instead.
set(PROTOC_CMAKE_GENERATOR ${CMAKE_GENERATOR})
if(APPLE AND ${CMAKE_GENERATOR} STREQUAL "Xcode")
# Force Xcode to build protoc on host
set(PROTOC_CMAKE_GENERATOR "Unix Makefiles")
execute_process(COMMAND sw_vers -productVersion OUTPUT_VARIABLE MACOS_PRODVER)
set(EXTRA_MACOS_CMAKE_ARGS
-DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOS_PRODVER}
)
endif(APPLE AND ${CMAKE_GENERATOR} STREQUAL "Xcode")
ExternalProject_Add(
protoc_bin
URL_HASH "${PROTOBUF_HASH}"
URL "${PROTOBUF_URL}"
PREFIX "${PROTOC_SRCS_DIR}"
BUILD_BYPRODUCTS "${PROTOC_BIN}"
SOURCE_DIR "${PROTOC_SRCS_DIR}/src/protoc"
CONFIGURE_COMMAND ${CMAKE_COMMAND} ../protoc/cmake/
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=${PROTOC_INSTALL_DIR}
-DCMAKE_VERBOSE_MAKEFILE=OFF
-Dprotobuf_BUILD_TESTS=OFF
-Dprotobuf_WITH_ZLIB=OFF
-Dprotobuf_BUILD_PROTOC_BINARIES=ON
-DCMAKE_GENERATOR=${PROTOC_CMAKE_GENERATOR}
${EXTRA_MACOS_CMAKE_ARGS}
)
else(APPLE)
# This is backup protoc when build doesn't work for macOS+iOS
# Mirror of "https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-osx-x86_64.zip"
set(PROTOC_URL "https://cnbj1.fds.api.xiaomi.com/mace/third-party/protobuf/protoc-3.6.1-osx-x86_64.zip")
set(PROTOC_HASH "SHA256=0decc6ce5beed07f8c20361ddeb5ac7666f09cf34572cca530e16814093f9c0c")
ExternalProject_Add(
protoc_bin
URL_HASH "${PROTOC_HASH}"
URL "${PROTOC_URL}"
PREFIX "${PROTOC_SRCS_DIR}"
BINARY_DIR ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
set(PROTOC_BIN
"${PROTOC_SRCS_DIR}/src/protoc_bin/bin/protoc" CACHE FILEPATH "protoc compiler." FORCE)
endif(NOT APPLE)
include(ExternalProject)
set(TFLITE_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/tflite")
set(TFLITE_INCLUDE_DIR "${TFLITE_SRCS_DIR}/src/tflite" CACHE PATH "tflite include directory." FORCE)
include_directories(SYSTEM ${TFLITE_INCLUDE_DIR})
set(TFLITE_URL "http://cnbj1.fds.api.xiaomi.com/mace/third-party/tflite/tensorflow-mace-d73e88fc830320d3818ac24e57cd441820a85cc9.zip")
set(TFLITE_HASH "SHA256=6f2671a02fe635a82c289c8c40a6e5bc24670ff1d4c3c2ab4a7aa9b825256a18")
ExternalProject_Add(
tflite
URL_HASH "${TFLITE_HASH}"
URL "${TFLITE_URL}"
PREFIX "${TFLITE_SRCS_DIR}"
BINARY_DIR ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
set(MACE_THIRD_PARTY_DIR "${PROJECT_BINARY_DIR}/third_party" CACHE STRING "Third party libraries download & build directories.")
# Forwarding the cross compile flags
set(THIRD_PARTY_EXTRA_CMAKE_ARGS
-DCMAKE_C_FLAGS=${MACE_CC_FLAGS}
-DCMAKE_CXX_FLAGS=${MACE_CC_FLAGS}
)
if(CMAKE_TOOLCHAIN_FILE)
set(THIRD_PARTY_EXTRA_CMAKE_ARGS
${THIRD_PARTY_EXTRA_CMAKE_ARGS}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)
endif(CMAKE_TOOLCHAIN_FILE)
if(CROSSTOOL_ROOT)
set(THIRD_PARTY_EXTRA_CMAKE_ARGS
${THIRD_PARTY_EXTRA_CMAKE_ARGS}
-DCROSSTOOL_ROOT=${CROSSTOOL_ROOT}
)
endif(CROSSTOOL_ROOT)
if(ANDROID_ABI)
set(THIRD_PARTY_EXTRA_CMAKE_ARGS
${THIRD_PARTY_EXTRA_CMAKE_ARGS}
-DANDROID_ABI=${ANDROID_ABI}
)
endif(ANDROID_ABI)
if(ANDROID_NATIVE_API_LEVEL)
set(THIRD_PARTY_EXTRA_CMAKE_ARGS
${THIRD_PARTY_EXTRA_CMAKE_ARGS}
-DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL}
)
endif(ANDROID_NATIVE_API_LEVEL)
if(PLATFORM)
set(THIRD_PARTY_EXTRA_CMAKE_ARGS
${THIRD_PARTY_EXTRA_CMAKE_ARGS}
-DPLATFORM=${PLATFORM}
)
endif(PLATFORM)
include(${PROJECT_SOURCE_DIR}/third_party/eigen3/eigen3.cmake)
include(${PROJECT_SOURCE_DIR}/third_party/gemmlowp/gemmlowp.cmake)
include(${PROJECT_SOURCE_DIR}/third_party/gflags/gflags.cmake)
include(${PROJECT_SOURCE_DIR}/third_party/googletest/googletest.cmake)
include(${PROJECT_SOURCE_DIR}/third_party/half/half.cmake)
include(${PROJECT_SOURCE_DIR}/third_party/opencl-clhpp/opencl-clhpp.cmake)
include(${PROJECT_SOURCE_DIR}/third_party/opencl-headers/opencl-headers.cmake)
include(${PROJECT_SOURCE_DIR}/third_party/protobuf/protobuf.cmake)
include(${PROJECT_SOURCE_DIR}/third_party/tflite/tflite.cmake)
if(MACE_ENABLE_HEXAGON_DSP)
include(${PROJECT_SOURCE_DIR}/third_party/nnlib/nnlib.cmake)
endif(MACE_ENABLE_HEXAGON_DSP)
if(MACE_ENABLE_HEXAGON_HTA)
include(${PROJECT_SOURCE_DIR}/third_party/hta/hta.cmake)
endif(MACE_ENABLE_HEXAGON_HTA)
#!/usr/bin/env sh
set -e
# build for arm linux aarch64
BUILD_DIR=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 -j8 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android arm64-v8a
BUILD_DIR=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_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j8 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android arm64-v8a
BUILD_DIR=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=ON \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j8 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android armeabi-v7a
BUILD_DIR=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_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j8 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android armeabi-v7a
BUILD_DIR=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=ON \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j8 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for arm linux gnueabihf
BUILD_DIR=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 -j8 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for host
BUILD_DIR=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 -j8 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
curl -o cpplint.py https://raw.githubusercontent.com/google/styleguide/gh-pages/cpplint/cpplint.py
python cpplint.py --linelength=80 --counting=detailed $(find mace -name "*.h" -or -name "*.cc")
python cpplint.py --linelength=80 --counting=detailed --root=include $(find include -name "*.h" -or -name "*.cc")
python cpplint.py --linelength=80 --counting=detailed --root=test/ccutils $(find test/ccutils -name "*.h" -or -name "*.cc")
python cpplint.py --linelength=80 --counting=detailed --root=test/ccunit $(find test/ccunit -name "*.h" -or -name "*.cc")
python cpplint.py --linelength=80 --counting=detailed --root=test/ccbenchmark $(find test/ccbenchmark -name "*.h" -or -name "*.cc")
rm cpplint.py
# Copyright 2018 The MACE 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
#
# http://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.
import json
import socket
import itertools
import sys
import six
class FalconCli(object):
def __init__(self, addr, debug=True, buf_size=1000):
self.socket_ = socket.create_connection(addr)
self.stream = self.socket_.makefile()
self.id_counter = itertools.count()
self.debug = debug
self.buf_size = buf_size
def __del__(self):
self.socket_.close()
self.stream.close()
@classmethod
def connect(cls,
server,
port=8433,
debug=True,
buf_size=1000):
try:
return FalconCli((server, port), debug, buf_size)
except socket.error as exc:
six.print_("error: connect to %s:%s error: %s"
% (server, port, exc), file=sys.stderr)
def call(self, name, *params):
request = dict(
id=next(self.id_counter), params=list(params), method=name)
payload = json.dumps(request).encode()
if self.debug:
six.print_("--> req:", payload)
self.socket_.sendall(payload)
response = self.stream.readline()
if not response:
raise Exception('empty response')
if self.debug:
six.print_("<-- resp:", response)
response = json.loads(response.decode("utf8"))
if response.get('error') is not None:
raise Exception(response.get('error'))
return response.get('result')
def update(self, lines):
s = 0
resp = []
while True:
buf = lines[s:s + self.buf_size]
s = s + self.buf_size
if len(buf) == 0:
break
r = self.call("Transfer.Update", buf)
resp.append(r)
return resp
#!/bin/bash
clang-format \
-style="{BasedOnStyle: google, \
DerivePointerAlignment: false, \
PointerAlignment: Right, \
BinPackParameters: false}" -i $1
......@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import falcon_cli
import glob
import logging
import numpy as np
......@@ -972,31 +971,3 @@ def build_run_throughput_test(abi,
_fg=True)
six.print_("throughput_test done!\n")
################################
# falcon
################################
def falcon_tags(tags_dict):
tags = ""
for k, v in tags_dict.iteritems():
if tags == "":
tags = "%s=%s" % (k, v)
else:
tags = tags + ",%s=%s" % (k, v)
return tags
def falcon_push_metrics(server, metrics, endpoint="mace_dev", tags={}):
cli = falcon_cli.FalconCli.connect(server=server, port=8433, debug=False)
ts = int(time.time())
falcon_metrics = [{
"endpoint": endpoint,
"metric": key,
"tags": falcon_tags(tags),
"timestamp": ts,
"value": value,
"step": 600,
"counterType": "GAUGE"
} for key, value in metrics.iteritems()]
cli.update(falcon_metrics)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册