提交 52a379a2 编写于 作者: 卢旭辉

Merge branch 'cmake' into 'master'

Add support for CMake

See merge request !1086
BasedOnStyle: google
MaxEmptyLinesToKeep: 3
DerivePointerAlignment: false
PointerAlignment: Right
BinPackParameters: false
bazel-* bazel-*
tags
.idea/
cmake-build-debug/
*.pyc
mace/codegen/models/
mace/codegen/opencl/
mace/codegen/opencl_bin/
mace/codegen/tuning/
mace/codegen/version/
mace/codegen/engine/
mace/codegen/lib/
build/ build/
cmake-build/
cmake-build-debug/
docs/_build/ docs/_build/
*.a *.a
.idea/
.vscode/ .vscode/
builds/ tags
mace/examples/android/macelibrary/src/main/cpp/mace/
\.project/ \.project/
*swp *swp
*~ *~
*.pyc
.python-version .python-version
mace/examples/android/macelibrary/src/main/cpp/include/mace/public/ mace/codegen/models/
mace/codegen/opencl/
mace/examples/android/macelibrary/src/main/cpp/lib/arm64-v8a/ mace/codegen/opencl_bin/
mace/codegen/tuning/
mace/codegen/version/
mace/codegen/engine/
mace/codegen/lib/
mace/examples/android/macelibrary/src/main/jniLibs/arm64-v8a/ examples/android/macelibrary/src/main/cpp/mace/
examples/android/macelibrary/src/main/cpp/include/
examples/android/macelibrary/src/main/cpp/lib/arm64-v8a/
examples/android/macelibrary/src/main/jniLibs/arm64-v8a/
stages: stages:
- cpplint - linting
- pycodestyle - build
- docs - test
- platform_compatible_tests - extra
- 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
cpplint: cpplint:
stage: cpplint stage: linting
script: script:
- curl -o cpplint.py https://raw.githubusercontent.com/google/styleguide/gh-pages/cpplint/cpplint.py - sh tools/cpplint.sh
- python cpplint.py --linelength=80 --counting=detailed $(find mace -name "*.h" -or -name "*.cc")
pycodestyle: pylint:
stage: pycodestyle stage: linting
script: script:
- pycodestyle $(find -name "*.py") - pycodestyle $(find -name "*.py")
docs: build_docs:
stage: docs stage: build
script: script:
- cd docs - cd docs
- make html - make html
...@@ -46,58 +32,46 @@ docs: ...@@ -46,58 +32,46 @@ docs:
paths: paths:
- docs/_build - docs/_build
platform_compatible_tests: cmake_build_android-armeabi-v7a:
stage: platform_compatible_tests stage: build
script: script:
- bazel build mace/core:core --define openmp=false - sh tools/cmake-build-android-armeabi-v7a-full.sh
- bazel build --config arm_linux_gnueabihf --define openmp=false --define opencl=true --define neon=true //mace/libmace:libmace.so - LIBMACE32_FULL_SIZE=`stat -c%s cmake-build/android-armeabi-v7a-full/install/lib/libmace.so`
- bazel build --config aarch64_linux_gnu --define openmp=false --define opencl=true --define neon=true //mace/libmace:libmace.so - if (( LIBMACE32_FULL_SIZE > 2200000 )) ; then echo "The libmace.so size too large"; exit 1; fi
build_libraries: cmake_build_android-arm64-v8:
stage: build_libraries stage: build
script: script:
- bash tools/build-standalone-lib.sh - sh tools/cmake-build-android-arm64-v8a-full.sh
- LIBMACE64_FULL_SIZE=`stat -c%s cmake-build/android-arm64-v8a-full/install/lib/libmace.so`
- if (( LIBMACE64_FULL_SIZE > 3100000 )) ; then echo "The libmace.so size too large"; exit 1; fi
ndk_versions_compatible_tests: bazel_build:
stage: ndk_versions_compatible_tests stage: build
script: script:
- DEFAULT_NDK_PATH=$ANDROID_NDK_HOME - sh tools/bazel-build-standalone-lib.sh
- prefix_path=${DEFAULT_NDK_PATH%android-ndk-*} only:
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - triggers
- >
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: cmake_build:
stage: ops_test_disable_neon stage: build
script: script:
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - sh tools/cmake-build-standalone-lib.sh
- > only:
if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then - triggers
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: build_android_demo:
stage: ops_test stage: build
script:
- ANDROID_NDK_HOME_SAVED=${ANDROID_NDK_HOME}
- export ANDROID_NDK_HOME=/opt/android-ndk-r17b
- pushd examples/android/ && bash build.sh static && bash build.sh dynamic && popd
- export ANDROID_NDK_HOME=${ANDROID_NDK_HOME_SAVED}
only:
- triggers
mace_cc_test:
stage: test
script: script:
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi
- > - >
...@@ -105,26 +79,18 @@ ops_test: ...@@ -105,26 +79,18 @@ ops_test:
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 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 DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi 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; - python tools/bazel_adb_run.py --target="//test/ccunit:mace_cc_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
api_test: mace_cc_benchmark:
stage: api_test stage: test
script: script:
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - 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="//test/ccbenchmark:mace_cc_benchmark" --run_target=True --stdout_processor=ops_benchmark_stdout_processor --target_abis=armeabi-v7a,arm64-v8a --target_socs=$TARGET_SOCS --args="--filter=.*SIGMOID.*"
- 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; only:
- 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; - triggers
- >
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: model_tests:
stage: model_tests stage: test
script: script:
- pwd - pwd
- rm -rf mace-models - rm -rf mace-models
...@@ -137,25 +103,22 @@ model_tests: ...@@ -137,25 +103,22 @@ model_tests:
DEVICE_CONF_FILE=generic-mobile-devices/devices.yml DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi fi
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; 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
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
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
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 - 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
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
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
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
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
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
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
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
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 - rm -rf mace-models
quantization_tests: quantization_tests:
stage: quantization_tests stage: test
script: script:
- pwd - pwd
- rm -rf mace-models - rm -rf mace-models
...@@ -174,50 +137,11 @@ quantization_tests: ...@@ -174,50 +137,11 @@ quantization_tests:
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; 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 done
- rm -rf mace-models - rm -rf mace-models
only:
- triggers
build_android_demo: dynamic_linking_test:
stage: build_android_demo stage: extra
script:
- pushd mace/examples/android/ && bash build.sh static && bash build.sh dynamic && popd
ops_benchmark:
stage: ops_benchmark
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;
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: script:
- pwd - pwd
- rm -rf mace-models - rm -rf mace-models
...@@ -230,21 +154,8 @@ dynamic_link_test: ...@@ -230,21 +154,8 @@ dynamic_link_test:
DEVICE_CONF_FILE=generic-mobile-devices/devices.yml DEVICE_CONF_FILE=generic-mobile-devices/devices.yml
fi fi
- if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; 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
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
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 - rm -rf mace-models
only:
python3_test: - triggers
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
# 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_BENCHMARKS "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(APPLE)
set(MACE_LINKER_FLAGS "${MACE_LINKER_FLAGS} -Wl,-dead_strip -Wl,-dead_strip_dylibs")
else(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(APPLE)
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(MACE_ENABLE_OPT_SIZE)
# 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(IOS)
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(MACE_ENABLE_NEON)
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(MACE_ENABLE_QUANTIZE)
if(MACE_ENABLE_OPENCL)
if(IOS)
message(FATAL_ERROR "OpenCL is not supported for iOS")
endif(IOS)
add_definitions(-DMACE_ENABLE_OPENCL)
endif(MACE_ENABLE_OPENCL)
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(MACE_ENABLE_CUDA)
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(MACE_ENABLE_HEXAGON_DSP)
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(MACE_ENABLE_HEXAGON_HTA)
if(MACE_ENABLE_OBFUSCATE)
add_definitions(-DMACE_OBFUSCATE_LITERALS)
endif(MACE_ENABLE_OBFUSCATE)
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(NOT MSVC)
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(MACE_ENABLE_EXAMPLES)
if(MACE_ENABLE_TESTS OR MACE_ENABLE_BENCHMARKS)
add_subdirectory(test)
endif(MACE_ENABLE_TESTS OR MACE_ENABLE_BENCHMARKS)
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
[中文](README_zh.md) [中文](README_zh.md)
**Mobile AI Compute Engine** (or **MACE** for short) is a deep learning inference framework optimized for **Mobile AI Compute Engine** (or **MACE** for short) is a deep learning inference framework optimized for
mobile heterogeneous computing on Android, iOS and Linux devices. The design focuses on the following mobile heterogeneous computing on Android, iOS, Linux and Windows devices. The design focuses on the following
targets: targets:
* Performance * Performance
* Runtime is optimized with NEON, OpenCL and Hexagon, and * Runtime is optimized with NEON, OpenCL and Hexagon, and
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
[加入我们](JOBS.md) | [加入我们](JOBS.md) |
[English](README.md) [English](README.md)
**Mobile AI Compute Engine (MACE)** 是一个专为移动端异构计算平台(支持Android, iOS, Linux)优化的神经网络计算框架。 **Mobile AI Compute Engine (MACE)** 是一个专为移动端异构计算平台(支持Android, iOS, Linux, Windows)优化的神经网络计算框架。
主要从以下的角度做了专门的优化: 主要从以下的角度做了专门的优化:
* 性能 * 性能
* 代码经过NEON指令,OpenCL以及Hexagon HVX专门优化,并且采用 * 代码经过NEON指令,OpenCL以及Hexagon HVX专门优化,并且采用
......
...@@ -61,7 +61,6 @@ new_http_archive( ...@@ -61,7 +61,6 @@ new_http_archive(
strip_prefix = "half-code-356-trunk", strip_prefix = "half-code-356-trunk",
urls = [ urls = [
"https://cnbj1.fds.api.xiaomi.com/mace/third-party/half/half-code-356-trunk.zip", "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)
...@@ -50,8 +50,8 @@ RUN curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/py ...@@ -50,8 +50,8 @@ RUN curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/py
ENV PATH /root/.pyenv/bin:/root/.pyenv/shims/:${PATH} ENV PATH /root/.pyenv/bin:/root/.pyenv/shims/:${PATH}
RUN eval "$(pyenv init -)" RUN eval "$(pyenv init -)"
RUN eval "$(pyenv virtualenv-init -)" RUN eval "$(pyenv virtualenv-init -)"
RUN pyenv install 2.7.14 && pyenv install 3.6.3 RUN pyenv install 3.6.3
RUN pyenv global 2.7.14 RUN pyenv global 3.6.3
# Setup vim # Setup vim
RUN apt-get install -y --no-install-recommends \ RUN apt-get install -y --no-install-recommends \
...@@ -98,45 +98,46 @@ RUN mkdir -p /opt/sdk && \ ...@@ -98,45 +98,46 @@ RUN mkdir -p /opt/sdk && \
yes | android update sdk --no-ui -a --filter tools,platform-tools,${ANDROID_API_LEVELS},build-tools-${ANDROID_BUILD_TOOLS_VERSION} yes | android update sdk --no-ui -a --filter tools,platform-tools,${ANDROID_API_LEVELS},build-tools-${ANDROID_BUILD_TOOLS_VERSION}
RUN ${ANDROID_HOME}/tools/bin/sdkmanager "cmake;3.6.4111459" RUN ${ANDROID_HOME}/tools/bin/sdkmanager "cmake;3.6.4111459"
# Download NDK # Download NDK 19c
RUN cd /opt/ && \ RUN cd /opt/ && \
wget -q https://dl.google.com/android/repository/android-ndk-r15c-linux-x86_64.zip && \ wget -q https://dl.google.com/android/repository/android-ndk-r19c-linux-x86_64.zip && \
unzip -q android-ndk-r15c-linux-x86_64.zip && \ unzip -q android-ndk-r19c-linux-x86_64.zip && \
rm -f android-ndk-r15c-linux-x86_64.zip rm -f android-ndk-r19c-linux-x86_64.zip
ENV ANDROID_NDK_VERSION r15c ENV ANDROID_NDK_VERSION r19c
ENV ANDROID_NDK_HOME /opt/android-ndk-${ANDROID_NDK_VERSION} ENV ANDROID_NDK_HOME /opt/android-ndk-${ANDROID_NDK_VERSION}
# add to PATH
ENV PATH ${PATH}:${ANDROID_NDK_HOME}
# Install tools # Install tools
RUN apt-get install -y --no-install-recommends \ RUN apt-get install -y --no-install-recommends \
android-tools-adb android-tools-adb
RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com setuptools # fix docker in docker error: `error while loading shared libraries: libltdl.so.7`
RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \ # refer to: https://github.com/jenkinsci/docker/issues/506
"numpy>=1.14.0" \ RUN apt-get install -y libltdl7
scipy \
jinja2 \ RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com --upgrade pip setuptools
pyyaml \ RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \
numpy==1.15.4 \
scipy==1.2.0 \
Jinja2==2.10 \
PyYAML==3.13 \
sh==1.12.14 \ sh==1.12.14 \
pycodestyle==2.4.0 \ pycodestyle==2.4.0 \
filelock \ filelock==3.0.10 \
PTable PTable==0.9.2
# Install Tensorflow RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \
RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
tensorflow==1.8.0 tensorflow==1.8.0
# Install pytorch (refer to: https://pytorch.org/get-started/locally/) # Install pytorch (refer to: https://pytorch.org/get-started/locally/)
RUN pip install future==0.17.1 torchvision_nightly RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \
RUN pip install torch_nightly -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html future==0.17.1 \
Pillow==5.4.1 \
torch==1.1.0 \
torchvision==0.2.2.post3
# Install ONNX RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \
RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
onnx==1.3.0 \ onnx==1.3.0 \
onnx-tf==1.2.0 onnx-tf==1.2.0
# fix docker in docker error: `error while loading shared libraries: libltdl.so.7` RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \
# refer to: https://github.com/jenkinsci/docker/issues/506 cpplint==1.4.4
RUN apt-get install -y libltdl7
...@@ -9,78 +9,75 @@ RUN apt-get install -y --no-install-recommends \ ...@@ -9,78 +9,75 @@ RUN apt-get install -y --no-install-recommends \
screen \ screen \
htop htop
RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
sphinx \
sphinx-autobuild \
sphinx_rtd_theme \
recommonmark
# ============ Install same deps for python3 ============
RUN pyenv global 3.6.3 RUN pyenv global 3.6.3
# Install tools RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \
RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com setuptools
RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
"numpy>=1.14.0" \
scipy \
jinja2 \
pyyaml \
sh==1.12.14 \
pycodestyle==2.4.0 \
filelock \
PTable
# Install Tensorflow
RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
tensorflow==1.8.0
# Install pytorch (refer to: https://pytorch.org/get-started/locally/)
RUN pip install future==0.17.1 torchvision_nightly
RUN pip install torch_nightly -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
# Install ONNX
RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
onnx==1.3.0 \
onnx-tf==1.2.0
RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
sphinx \ sphinx \
sphinx-autobuild \ sphinx-autobuild \
sphinx_rtd_theme \ sphinx_rtd_theme \
recommonmark recommonmark
RUN pyenv global 2.7.14
# ============ End installing same deps for python3 ============
# Customize vim # Customize vim
RUN mkdir -p ~/.vim/autoload ~/.vim/bundle && \ RUN git clone --recursive https://github.com/llhe/vimrc.git && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim cd vimrc && \
RUN mkdir -p ~/.vim/bundle rm -rf ~/.vim && \
RUN cd ~/.vim/bundle && \ rm -rf ~/.vimrc && \
git clone https://github.com/scrooloose/nerdtree.git && \ ln -s `pwd`/vim ~/.vim && \
git clone https://github.com/vim-syntastic/syntastic.git && \ ln -s `pwd`/vimrc ~/.vimrc
git clone https://github.com/vim-airline/vim-airline.git && \
git clone https://github.com/altercation/vim-colors-solarized.git && \
git clone https://github.com/bazelbuild/vim-ft-bzl.git && \
git clone https://github.com/google/vim-maktaba.git && \
git clone https://github.com/google/vim-codefmt.git
RUN curl -LSso ~/.vimrc https://gist.githubusercontent.com/llhe/71c5802919debd5825c100c0135478a7/raw/16a35020cc65f9c25d0cf8f11a3ba7b345a1271d/.vimrc
# Upgrade CMake # Upgrade CMake
RUN wget https://cmake.org/files/v3.11/cmake-3.11.3-Linux-x86_64.tar.gz -P /tmp/ && \ RUN wget -q https://cmake.org/files/v3.11/cmake-3.11.3-Linux-x86_64.tar.gz -P /tmp/ && \
tar zxf /tmp/cmake-3.11.3-Linux-x86_64.tar.gz --strip-components=1 -C /usr/local/ && \ tar zxf /tmp/cmake-3.11.3-Linux-x86_64.tar.gz --strip-components=1 -C /usr/local/ && \
update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force && \ 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 rm -f /tmp/cmake-3.11.3-Linux-x86_64.tar.gz
# mace-dev-lite image already included NDK r15c # mace-dev-lite image already included NDK r19c
## Download other NDK r16 ## Download other NDK r15c
RUN cd /opt/ && \
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/ && \ RUN cd /opt/ && \
wget -q https://dl.google.com/android/repository/android-ndk-r16-linux-x86_64.zip && \ wget -q https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip && \
unzip -q android-ndk-r16-linux-x86_64.zip && \ unzip -q android-ndk-r16b-linux-x86_64.zip && \
rm -f android-ndk-r16-linux-x86_64.zip rm -f android-ndk-r16b-linux-x86_64.zip
## Download other NDK r17b ## Download other NDK r17b
RUN cd /opt/ && \ RUN cd /opt/ && \
wget -q https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip && \ wget -q https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip && \
unzip -q 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 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://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
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_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
# install protoc
RUN cd opt/ && \
wget -q https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip && \
unzip protoc-3.6.1-linux-x86_64.zip -d protoc-3.6.1 && \
rm -rf protoc-3.6.1-linux-x86_64.zip
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
ENV PATH /opt/protoc-3.6.1/bin:${PATH}
...@@ -11,18 +11,16 @@ if [ $BUILD_DIR_NAME != $CURRENT_DIR_NAME ]; then ...@@ -11,18 +11,16 @@ if [ $BUILD_DIR_NAME != $CURRENT_DIR_NAME ]; then
fi fi
# build images # build images
docker build -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite ./mace-dev-lite || exit 1 docker build --network host -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite ./mace-dev-lite
docker build -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev ./mace-dev-lite || exit 1 docker build --network host -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev ./mace-dev
docker build -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/gitlab-runner ./gitlab-runner || exit 1 docker build --network host -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/gitlab-runner ./gitlab-runner
if grep -lq registry.cn-hangzhou.aliyuncs.com ~/.docker/config.json; then if grep -lq registry.cn-hangzhou.aliyuncs.com ~/.docker/config.json; then
# update images to repository # update images to repository
docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite || exit 1 docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite
docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev || exit 1 docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev
docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/gitlab-runner || exit 1 docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/gitlab-runner
else else
echo "Login docker registry server is needed!" echo "Login docker registry server is needed!"
exit 1 exit 1
fi fi
...@@ -72,7 +72,7 @@ If model's output is suspected to be incorrect, it might be useful to debug your ...@@ -72,7 +72,7 @@ If model's output is suspected to be incorrect, it might be useful to debug your
or use binary search method until suspicious layer is found. or use binary search method until suspicious layer is found.
You can also specify `--layers` after `--validate` to validate all or some of the layers of the model(excluding some layers changed by MACE, e.g., BatchToSpaceND), You can also specify `--layers` after `--validate` to validate all or some of the layers of the model(excluding some layers changed by MACE, e.g., BatchToSpaceND),
it only supports TensorFlow now. You can find validation results in `builds/your_model/model/runtime_in_yaml/log.csv`. it only supports TensorFlow now. You can find validation results in `build/your_model/model/runtime_in_yaml/log.csv`.
For quantized model, if you want to check one layer, you can add `check_tensors` and `check_shapes` like in the yaml above. You can only specify For quantized model, if you want to check one layer, you can add `check_tensors` and `check_shapes` like in the yaml above. You can only specify
MACE op's output. MACE op's output.
...@@ -113,7 +113,7 @@ Debug model conversion ...@@ -113,7 +113,7 @@ Debug model conversion
After model is converted to MACE model, a literal model graph is generated in directory `mace/codegen/models/your_model`. After model is converted to MACE model, a literal model graph is generated in directory `mace/codegen/models/your_model`.
You can refer to it when debugging model conversion. You can refer to it when debugging model conversion.
MACE also provides model visualization HTML generated in `builds` directory, generated after converting model. MACE also provides model visualization HTML generated in `build` directory, generated after converting model.
Debug engine using log Debug engine using log
......
...@@ -12,10 +12,10 @@ Run unit tests ...@@ -12,10 +12,10 @@ Run unit tests
MACE use [gtest](https://github.com/google/googletest) for unit tests. MACE use [gtest](https://github.com/google/googletest) for unit tests.
* Run all unit tests defined in a Bazel target, for example, run `ops_test`: * Run all unit tests defined in a Bazel target, for example, run `mace_cc_test`:
```sh ```sh
python tools/bazel_adb_run.py --target="//mace/ops:ops_test" \ python tools/bazel_adb_run.py --target="//test/ccunit:mace_cc_test" \
--run_target=True --run_target=True
``` ```
...@@ -23,7 +23,7 @@ MACE use [gtest](https://github.com/google/googletest) for unit tests. ...@@ -23,7 +23,7 @@ MACE use [gtest](https://github.com/google/googletest) for unit tests.
for example, run `Conv2dOpTest` unit tests: for example, run `Conv2dOpTest` unit tests:
```sh ```sh
python tools/bazel_adb_run.py --target="//mace/ops:ops_test" \ python tools/bazel_adb_run.py --target="//test/ccunit:mace_cc_test" \
--run_target=True \ --run_target=True \
--args="--gtest_filter=Conv2dOpTest*" --args="--gtest_filter=Conv2dOpTest*"
``` ```
...@@ -34,10 +34,10 @@ Run micro benchmarks ...@@ -34,10 +34,10 @@ Run micro benchmarks
MACE provides a micro benchmark framework for performance tuning. MACE provides a micro benchmark framework for performance tuning.
* Run all micro benchmarks defined in a Bazel target, for example, run all * Run all micro benchmarks defined in a Bazel target, for example, run all
`ops_benchmark` micro benchmarks: `mace_cc_benchmark` micro benchmarks:
```sh ```sh
python tools/bazel_adb_run.py --target="//mace/ops:ops_benchmark" \ python tools/bazel_adb_run.py --target="//test/ccbenchmark:mace_cc_benchmark" \
--run_target=True --run_target=True
``` ```
...@@ -45,7 +45,7 @@ MACE provides a micro benchmark framework for performance tuning. ...@@ -45,7 +45,7 @@ MACE provides a micro benchmark framework for performance tuning.
micro benchmarks: micro benchmarks:
```sh ```sh
python tools/bazel_adb_run.py --target="//mace/ops:ops_benchmark" \ python tools/bazel_adb_run.py --target="//test/ccbenchmark:mace_cc_benchmark" \
--run_target=True \ --run_target=True \
--args="--filter=MACE_BM_CONV_2D_.*_GPU" --args="--filter=MACE_BM_CONV_2D_.*_GPU"
``` ```
...@@ -204,15 +204,15 @@ Convert model(s) to C++ code ...@@ -204,15 +204,15 @@ Convert model(s) to C++ code
python tools/converter.py convert --config=/path/to/model_deployment_file.yml python tools/converter.py convert --config=/path/to/model_deployment_file.yml
The command will generate **${library_name}.a** in **builds/${library_name}/model** directory and The command will generate **${library_name}.a** in **build/${library_name}/model** directory and
** *.h ** in **builds/${library_name}/include** like the following dir-tree. ** *.h ** in **build/${library_name}/include** like the following dir-tree.
.. code:: .. code::
# model_graph_format: code # model_graph_format: code
# model_data_format: file # model_data_format: file
builds build
├── include ├── include
│   └── mace │   └── mace
│   └── public │   └── public
...@@ -225,7 +225,7 @@ Convert model(s) to C++ code ...@@ -225,7 +225,7 @@ Convert model(s) to C++ code
# model_graph_format: code # model_graph_format: code
# model_data_format: code # model_data_format: code
builds build
├── include ├── include
│   └── mace │   └── mace
│   └── public │   └── public
...@@ -305,11 +305,11 @@ Tuning for specific SoC's GPU ...@@ -305,11 +305,11 @@ Tuning for specific SoC's GPU
python tools/converter.py run --config=/path/to/model_deployment_file.yml --validate python tools/converter.py run --config=/path/to/model_deployment_file.yml --validate
The command will generate two files in `builds/${library_name}/opencl`, like the following dir-tree. The command will generate two files in `build/${library_name}/opencl`, like the following dir-tree.
.. code:: .. code::
builds build
└── mobilenet-v2 └── mobilenet-v2
├── model ├── model
│   ├── mobilenet_v2.data │   ├── mobilenet_v2.data
......
...@@ -44,17 +44,17 @@ Here we use the mobilenet-v2 model as an example. ...@@ -44,17 +44,17 @@ Here we use the mobilenet-v2 model as an example.
cd path/to/mace cd path/to/mace
# Build library # Build library
# output lib path: builds/lib # output lib path: build/lib
bash tools/build-standalone-lib.sh bash tools/bazel-build-standalone-lib.sh
.. note:: .. note::
- This step can be skipped if you just want to run a model using ``tools/converter.py``, such as commands in step 5. - This step can be skipped if you just want to run a model using ``tools/converter.py``, such as commands in step 5.
- Libraries in ``builds/lib/armeabi-v7a/cpu_gpu/`` means it can run on ``cpu`` or ``gpu`` devices. - Libraries in ``build/lib/armeabi-v7a/cpu_gpu/`` means it can run on ``cpu`` or ``gpu`` devices.
- The results in ``builds/lib/armeabi-v7a/cpu_gpu_dsp/`` need HVX supported. - The results in ``build/lib/armeabi-v7a/cpu_gpu_dsp/`` need HVX supported.
4. Convert the pre-trained mobilenet-v2 model to MACE format model. 4. Convert the pre-trained mobilenet-v2 model to MACE format model.
...@@ -170,7 +170,7 @@ When the deployment file is ready, you can use MACE converter tool to convert yo ...@@ -170,7 +170,7 @@ When the deployment file is ready, you can use MACE converter tool to convert yo
python tools/converter.py convert --config=/path/to/your/model_deployment_file.yml python tools/converter.py convert --config=/path/to/your/model_deployment_file.yml
This command will download or load your pre-trained model and convert it to a MACE model proto file and weights data file. This command will download or load your pre-trained model and convert it to a MACE model proto file and weights data file.
The generated model files will be stored in ``builds/${library_name}/model`` folder. The generated model files will be stored in ``build/${library_name}/model`` folder.
.. warning:: .. warning::
...@@ -188,10 +188,10 @@ Or use bazel to build MACE source code into a library. ...@@ -188,10 +188,10 @@ Or use bazel to build MACE source code into a library.
cd path/to/mace cd path/to/mace
# Build library # Build library
# output lib path: builds/lib # output lib path: build/lib
bash tools/build-standalone-lib.sh bash tools/bazel-build-standalone-lib.sh
The above command will generate dynamic library ``builds/lib/${ABI}/${DEVICES}/libmace.so`` and static library ``builds/lib/${ABI}/${DEVICES}/libmace.a``. The above command will generate dynamic library ``build/lib/${ABI}/${DEVICES}/libmace.so`` and static library ``build/lib/${ABI}/${DEVICES}/libmace.a``.
.. warning:: .. warning::
...@@ -278,7 +278,7 @@ header files. ...@@ -278,7 +278,7 @@ header files.
.. code:: .. code::
builds build
├── include ├── include
│   └── mace │   └── mace
│   └── public │   └── public
......
...@@ -20,7 +20,7 @@ Usage ...@@ -20,7 +20,7 @@ Usage
.. code:: bash .. code:: bash
python tools/bazel_adb_run.py --target="//mace/ops:ops_benchmark" --run_target=True --args="--filter=.*BM_CONV.*" python tools/bazel_adb_run.py --target="//test/ccbenchmark:mace_cc_benchmark" --run_target=True --args="--filter=.*BM_CONV.*"
====== ======
Output Output
......
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)
...@@ -20,12 +20,12 @@ fi ...@@ -20,12 +20,12 @@ fi
MACE_LINK_TYPE=$1 MACE_LINK_TYPE=$1
pushd ../../../ pushd ../..
TARGET_ABI=arm64-v8a TARGET_ABI=arm64-v8a
ANDROID_DEMO_DIR=mace/examples/android/ ANDROID_DEMO_DIR=examples/android/
LIBRARY_DIR=$ANDROID_DEMO_DIR/macelibrary/src/main/cpp/ LIBRARY_DIR=$ANDROID_DEMO_DIR/macelibrary/src/main/cpp/
INCLUDE_DIR=$LIBRARY_DIR/include/mace/public/ INCLUDE_DIR=$LIBRARY_DIR/include
LIBMACE_DIR=$LIBRARY_DIR/lib/$TARGET_ABI/ LIBMACE_DIR=$LIBRARY_DIR/lib/$TARGET_ABI/
LIBGNUSTL_SHARED_SO=libgnustl_shared.so LIBGNUSTL_SHARED_SO=libgnustl_shared.so
LIBCPP_SHARED_SO=libc++_shared.so LIBCPP_SHARED_SO=libc++_shared.so
...@@ -44,20 +44,17 @@ else ...@@ -44,20 +44,17 @@ else
exit 1 exit 1
fi fi
rm -rf $LIBRARY_DIR/include/ python tools/converter.py convert --config=examples/android/mobilenet.yml --target_abis=$TARGET_ABI
mkdir -p $INCLUDE_DIR
rm -rf $LIBRARY_DIR/lib/
mkdir -p $LIBMACE_DIR
rm -rf $INCLUDE_DIR && mkdir -p $INCLUDE_DIR
rm -rf $LIBMACE_DIR && mkdir -p $LIBMACE_DIR
rm -rf $LIBRARY_DIR/model/ rm -rf $LIBRARY_DIR/model/
python tools/converter.py convert --config=mace/examples/android/mobilenet.yml --target_abis=$TARGET_ABI cp -rf include/mace $INCLUDE_DIR
cp -rf builds/mobilenet/include/mace/public/*.h $INCLUDE_DIR cp -rf build/mobilenet/include/mace/public/*.h $INCLUDE_DIR/mace/public/
cp -rf builds/mobilenet/model $LIBRARY_DIR cp -rf build/mobilenet/model $LIBRARY_DIR
bazel build --config android --config optimization $BAZEL_LIBMACE_TARGET --define neon=true --define openmp=true --define opencl=true --define quantize=true --cpu=$TARGET_ABI bazel build --config android --config optimization $BAZEL_LIBMACE_TARGET --define neon=true --define openmp=true --define opencl=true --define quantize=true --cpu=$TARGET_ABI
cp -rf mace/public/*.h $INCLUDE_DIR
cp -rf $BAZEL_GEN_LIBMACE_PATH $LIBMACE_DIR cp -rf $BAZEL_GEN_LIBMACE_PATH $LIBMACE_DIR
if [ $MACE_LINK_TYPE == "dynamic" ]; then if [ $MACE_LINK_TYPE == "dynamic" ]; then
......
...@@ -13,6 +13,7 @@ cmake_minimum_required(VERSION 3.4.1) ...@@ -13,6 +13,7 @@ cmake_minimum_required(VERSION 3.4.1)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../app/libs/${ANDROID_ABI}) #set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../app/libs/${ANDROID_ABI})
include_directories(${CMAKE_SOURCE_DIR}/) include_directories(${CMAKE_SOURCE_DIR}/)
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp)
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/include) include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/include)
file(GLOB LIBMACE "${CMAKE_SOURCE_DIR}/src/main/cpp/lib/arm64-v8a/*") file(GLOB LIBMACE "${CMAKE_SOURCE_DIR}/src/main/cpp/lib/arm64-v8a/*")
set(mace_lib ${LIBMACE}) set(mace_lib ${LIBMACE})
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "src/main/cpp/image_classify.h" #include "image_classify.h"
#include <android/log.h> #include <android/log.h>
#include <jni.h> #include <jni.h>
...@@ -25,9 +25,8 @@ ...@@ -25,9 +25,8 @@
#include <vector> #include <vector>
#include <numeric> #include <numeric>
#include "src/main/cpp/include/mace/public/mace.h"
#include "src/main/cpp/include/mace/public/mace_engine_factory.h"
#include "mace/public/mace.h" #include "mace/public/mace.h"
#include "mace/public/mace_engine_factory.h"
namespace { namespace {
......
...@@ -35,8 +35,8 @@ cc_binary( ...@@ -35,8 +35,8 @@ cc_binary(
deps = [ deps = [
"//external:gflags_nothreads", "//external:gflags_nothreads",
"//mace/codegen:generated_mace_engine_factory", "//mace/codegen:generated_mace_engine_factory",
"//mace/codegen:generated_libmace", "//mace/codegen:generated_models",
"//mace/utils:utils_hdrs", "//mace/libmace",
] + if_opencl_enabled([ ] + if_opencl_enabled([
"//mace/codegen:generated_opencl_binary", "//mace/codegen:generated_opencl_binary",
"//mace/codegen:generated_opencl_parameter", "//mace/codegen:generated_opencl_parameter",
...@@ -70,9 +70,9 @@ cc_binary( ...@@ -70,9 +70,9 @@ cc_binary(
linkstatic = 0, linkstatic = 0,
deps = [ deps = [
"//external:gflags_nothreads", "//external:gflags_nothreads",
"//mace/codegen:generated_libmace",
"//mace/codegen:generated_mace_engine_factory", "//mace/codegen:generated_mace_engine_factory",
"//mace/utils:utils_hdrs", "//mace/codegen:generated_models",
"//mace/libmace:libmace_dynamic",
] + if_opencl_enabled([ ] + if_opencl_enabled([
"//mace/codegen:generated_opencl_binary", "//mace/codegen:generated_opencl_binary",
"//mace/codegen:generated_opencl_parameter", "//mace/codegen:generated_opencl_parameter",
......
...@@ -102,17 +102,20 @@ DEFINE_string(model_name, ...@@ -102,17 +102,20 @@ DEFINE_string(model_name,
"", "",
"model name in model deployment file"); "model name in model deployment file");
DEFINE_string(input_node, DEFINE_string(input_node,
"input_node0,input_node1", "",
"input nodes, separated by comma"); "input nodes, separated by comma,"
"example: input_node0,input_node1");
DEFINE_string(input_shape, DEFINE_string(input_shape,
"1,224,224,3:1,1,1,10", "",
"input shapes, separated by colon and comma"); "input shapes, separated by colon and comma, "
"example: 1,224,224,3:1,1,1,10");
DEFINE_string(output_node, DEFINE_string(output_node,
"output_node0,output_node1", "output_node0,output_node1",
"output nodes, separated by comma"); "output nodes, separated by comma");
DEFINE_string(output_shape, DEFINE_string(output_shape,
"1,224,224,2:1,1,1,10", "",
"output shapes, separated by colon and comma"); "output shapes, separated by colon and comma, "
"example: 1,224,224,2:1,1,1,10");
DEFINE_string(input_data_format, DEFINE_string(input_data_format,
"NHWC", "NHWC",
"input data formats, NONE|NHWC|NCHW"); "input data formats, NONE|NHWC|NCHW");
......
# Description:
# MACE public API.
#
package( package(
default_visibility = ["//visibility:public"], default_visibility = ["//visibility:public"],
) )
...@@ -8,12 +5,12 @@ package( ...@@ -8,12 +5,12 @@ package(
licenses(["notice"]) # Apache 2.0 licenses(["notice"]) # Apache 2.0
cc_library( cc_library(
name = "public", name = "public_headers",
hdrs = [ hdrs = glob([
"mace.h", "mace/public/*.h",
], "mace/port/*.h",
srcs = [ "mace/utils/*.h",
"status.cc", ]),
], strip_include_prefix = "",
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"],
) )
install(DIRECTORY mace DESTINATION include)
...@@ -16,11 +16,18 @@ ...@@ -16,11 +16,18 @@
#define MACE_PORT_ENV_H_ #define MACE_PORT_ENV_H_
#include <cstdint> #include <cstdint>
#include <cstdlib>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#ifdef _WIN32
#include <malloc.h>
#endif
#include <sys/stat.h>
#include "mace/public/mace.h" #include "mace/public/mace.h"
namespace mace { namespace mace {
...@@ -38,6 +45,7 @@ class LogWriter; ...@@ -38,6 +45,7 @@ class LogWriter;
class Env { class Env {
public: public:
virtual int64_t NowMicros() = 0; virtual int64_t NowMicros() = 0;
virtual MaceStatus AdviseFree(void *addr, size_t length);
virtual MaceStatus GetCPUMaxFreq(std::vector<float> *max_freqs); virtual MaceStatus GetCPUMaxFreq(std::vector<float> *max_freqs);
virtual MaceStatus SchedSetAffinity(const std::vector<size_t> &cpu_ids); virtual MaceStatus SchedSetAffinity(const std::vector<size_t> &cpu_ids);
virtual FileSystem *GetFileSystem() = 0; virtual FileSystem *GetFileSystem() = 0;
...@@ -58,6 +66,10 @@ inline int64_t NowMicros() { ...@@ -58,6 +66,10 @@ inline int64_t NowMicros() {
return port::Env::Default()->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) { inline MaceStatus GetCPUMaxFreq(std::vector<float> *max_freqs) {
return port::Env::Default()->GetCPUMaxFreq(max_freqs); return port::Env::Default()->GetCPUMaxFreq(max_freqs);
} }
...@@ -70,6 +82,63 @@ inline port::FileSystem *GetFileSystem() { ...@@ -70,6 +82,63 @@ inline port::FileSystem *GetFileSystem() {
return port::Env::Default()->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 {
if (val != nullptr) {
*value = std::string(val);
free(val);
}
return MaceStatus::MACE_SUCCESS;
}
#else
char *val = getenv(name);
if (val != nullptr) {
*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 } // namespace mace
#endif // MACE_PORT_ENV_H_ #endif // MACE_PORT_ENV_H_
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <memory> #include <memory>
#include "mace/public/mace.h" #include "mace/public/mace.h"
#include "mace/utils/macros.h"
namespace mace { namespace mace {
namespace port { namespace port {
...@@ -29,6 +30,8 @@ class ReadOnlyMemoryRegion { ...@@ -29,6 +30,8 @@ class ReadOnlyMemoryRegion {
virtual ~ReadOnlyMemoryRegion() = default; virtual ~ReadOnlyMemoryRegion() = default;
virtual const void *data() const = 0; virtual const void *data() const = 0;
virtual uint64_t length() const = 0; virtual uint64_t length() const = 0;
private:
MACE_DISABLE_COPY_AND_ASSIGN(ReadOnlyMemoryRegion);
}; };
class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion { class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion {
...@@ -44,12 +47,25 @@ class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion { ...@@ -44,12 +47,25 @@ class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion {
uint64_t length_; 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 { class FileSystem {
public: public:
FileSystem() = default; FileSystem() = default;
virtual ~FileSystem() = default; virtual ~FileSystem() = default;
virtual MaceStatus NewReadOnlyMemoryRegionFromFile(const char *fname, virtual MaceStatus NewReadOnlyMemoryRegionFromFile(const char *fname,
std::unique_ptr<ReadOnlyMemoryRegion>* result) = 0; std::unique_ptr<ReadOnlyMemoryRegion>* result) = 0;
virtual MaceStatus NewWritableFile(const char *fname,
std::unique_ptr<WritableFile>* result);
}; };
} // namespace port } // namespace port
......
...@@ -25,8 +25,20 @@ ...@@ -25,8 +25,20 @@
#include <vector> #include <vector>
#ifndef MACE_API #ifndef MACE_API
#ifdef _MSC_VER
#define MACE_API
#else
#define MACE_API __attribute__((visibility("default"))) #define MACE_API __attribute__((visibility("default")))
#endif #endif
#endif
#ifndef MACE_DEPRECATED
#ifdef _MSC_VER
#define MACE_DEPRECATED
#else
#define MACE_DEPRECATED __attribute__((deprecated))
#endif
#endif
namespace mace { namespace mace {
...@@ -435,7 +447,8 @@ MACE_API MaceStatus CreateMaceEngineFromProto( ...@@ -435,7 +447,8 @@ MACE_API MaceStatus CreateMaceEngineFromProto(
const std::vector<std::string> &input_nodes, const std::vector<std::string> &input_nodes,
const std::vector<std::string> &output_nodes, const std::vector<std::string> &output_nodes,
const MaceEngineConfig &config, const MaceEngineConfig &config,
std::shared_ptr<MaceEngine> *engine) __attribute__((deprecated)); std::shared_ptr<MaceEngine> *engine) MACE_DEPRECATED;
} // namespace mace } // namespace mace
......
...@@ -75,6 +75,15 @@ T &&CheckNotNull(const char *file, int line, const char *exprtext, T &&t) { ...@@ -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_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) \ #define MACE_RETURN_IF_ERROR(stmt) \
{ \ { \
MaceStatus status = (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)
...@@ -8,26 +8,19 @@ package( ...@@ -8,26 +8,19 @@ package(
load("//mace:mace.bzl", "mace_version_genrule", "encrypt_opencl_kernel_genrule") load("//mace:mace.bzl", "mace_version_genrule", "encrypt_opencl_kernel_genrule")
cc_library( cc_library(
name = "libmodels", name = "generated_models",
srcs = glob(["models/*/*.cc"]), srcs = glob(["models/*/*.cc"]),
hdrs = glob(["models/*/*.h"]), hdrs = glob(["models/*/*.h"]),
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
],
deps = [ deps = [
"//mace/core", "//mace/core",
], ],
) )
genrule(
name = "generated_models",
srcs = [
":libmodels",
],
outs = ["libgenerated_models.a"],
cmd = "binary=`echo $(locations :libmodels) | xargs -n 1 | grep libmodels.a`;" +
"$(STRIP) -x $$binary -o $@",
visibility = ["//visibility:public"],
)
mace_version_genrule() mace_version_genrule()
encrypt_opencl_kernel_genrule() encrypt_opencl_kernel_genrule()
...@@ -35,39 +28,52 @@ encrypt_opencl_kernel_genrule() ...@@ -35,39 +28,52 @@ encrypt_opencl_kernel_genrule()
cc_library( cc_library(
name = "generated_opencl", name = "generated_opencl",
srcs = ["opencl/encrypt_opencl_kernel.cc"], srcs = ["opencl/encrypt_opencl_kernel.cc"],
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
],
) )
cc_library( cc_library(
name = "generated_opencl_binary", name = "generated_opencl_binary",
srcs = ["opencl/opencl_binary.cc"], srcs = ["opencl/opencl_binary.cc"],
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
],
) )
cc_library( cc_library(
name = "generated_opencl_parameter", name = "generated_opencl_parameter",
srcs = ["opencl/opencl_parameter.cc"], srcs = ["opencl/opencl_parameter.cc"],
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
],
) )
cc_library( cc_library(
name = "generated_version", name = "generated_version",
srcs = ["version/version.cc"], srcs = ["version/version.cc"],
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
],
) )
cc_library( cc_library(
name = "generated_mace_engine_factory", name = "generated_mace_engine_factory",
hdrs = glob(["engine/*.h"]), hdrs = glob(["engine/*.h"]),
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
],
deps = [ deps = [
"//mace/public", "//include:public_headers",
], ],
) )
cc_library(
name = "generated_libmace",
srcs = glob(["lib/*"]),
linkstatic = 1,
visibility = ["//visibility:public"],
)
# 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,27 @@ ...@@ -13,29 +13,27 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
MACE_SOURCE_DIR=$(dirname $(dirname $(dirname $(dirname $0))))
OUTPUT_FILENAME=$1 OUTPUT_FILENAME=$1
if [[ -z "${OUTPUT_FILENAME}}" ]]; then if [[ -z "${OUTPUT_FILENAME}" ]]; then
echo "Usage: $0 <filename>" echo "Usage: $0 <filename>"
exit 1 exit 1
fi fi
OUTPUT_DIR=$(dirname $OUTPUT_FILENAME) mkdir -p $(dirname $OUTPUT_FILENAME)
if [ -d $OUTPUT_DIR ]; then
rm -rf $OUTPUT_DIR
fi
mkdir -p $OUTPUT_DIR
MACE_SOURCE_DIR=$(dirname $(dirname $(dirname $(dirname $0))))
GIT_VERSION=$(git --git-dir=${MACE_SOURCE_DIR}/.git --work-tree=${MACE_SOURCE_DIR} describe --long --tags) GIT_VERSION=$(git --git-dir=${MACE_SOURCE_DIR}/.git --work-tree=${MACE_SOURCE_DIR} describe --long --tags)
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
GIT_VERSION=$(git describe --long --tags)
if [[ $? != 0 ]]; then
GIT_VERSION=unknown GIT_VERSION=unknown
fi
else else
GIT_VERSION=${GIT_VERSION} GIT_VERSION=${GIT_VERSION}
fi fi
echo $GIT_VERSION echo write version $GIT_VERSION to ${OUTPUT_FILENAME}
cat <<EOF > ${OUTPUT_FILENAME} cat <<EOF > ${OUTPUT_FILENAME}
// Copyright 2018 The MACE Authors. All Rights Reserved. // Copyright 2018 The MACE Authors. All Rights Reserved.
...@@ -55,7 +53,9 @@ cat <<EOF > ${OUTPUT_FILENAME} ...@@ -55,7 +53,9 @@ cat <<EOF > ${OUTPUT_FILENAME}
// This is a generated file. DO NOT EDIT! // This is a generated file. DO NOT EDIT!
namespace mace { namespace mace {
#ifndef _MSC_VER
__attribute__((visibility("default"))) __attribute__((visibility("default")))
#endif
const char *MaceVersion() { return "MACEVER-${GIT_VERSION}" + 8; } const char *MaceVersion() { return "MACEVER-${GIT_VERSION}" + 8; }
} // namespace mace } // namespace mace
EOF EOF
......
# Description:
# Mace core.
#
package( package(
default_visibility = ["//visibility:public"], default_visibility = ["//visibility:public"],
) )
...@@ -30,9 +27,6 @@ cc_library( ...@@ -30,9 +27,6 @@ cc_library(
"*.cc", "*.cc",
"runtime/cpu/*.cc", "runtime/cpu/*.cc",
], ],
exclude = [
"*_test.cc",
],
) + if_opencl_enabled(glob( ) + if_opencl_enabled(glob(
[ [
"runtime/opencl/*.cc", "runtime/opencl/*.cc",
...@@ -118,28 +112,3 @@ cc_library( ...@@ -118,28 +112,3 @@ cc_library(
"@opencl_headers//:opencl20_headers", "@opencl_headers//:opencl20_headers",
], ],
) )
cc_library(
name = "test_benchmark_main",
testonly = 1,
srcs = [
"testing/test_benchmark.cc",
"testing/test_benchmark_main.cc",
],
hdrs = [
"testing/test_benchmark.h",
],
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
] + if_openmp_enabled(["-fopenmp"]) + if_opencl_enabled([
"-DMACE_ENABLE_OPENCL",
]),
deps = [
":core",
"//external:gflags_nothreads",
"//mace/ops:test",
"//mace/utils",
],
)
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 @@ ...@@ -14,10 +14,6 @@
#include "mace/core/allocator.h" #include "mace/core/allocator.h"
#include <unistd.h>
#include <sys/mman.h>
#include <memory>
namespace mace { namespace mace {
Allocator *GetCPUAllocator() { Allocator *GetCPUAllocator() {
...@@ -25,22 +21,4 @@ Allocator *GetCPUAllocator() { ...@@ -25,22 +21,4 @@ Allocator *GetCPUAllocator() {
return &allocator; 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 } // namespace mace
...@@ -74,32 +74,9 @@ class CPUAllocator : public Allocator { ...@@ -74,32 +74,9 @@ class CPUAllocator : public Allocator {
return MaceStatus::MACE_OUT_OF_RESOURCES; return MaceStatus::MACE_OUT_OF_RESOURCES;
} }
void *data = nullptr; MACE_RETURN_IF_ERROR(Memalign(result, kMaceAlignment, nbytes));
#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
// TODO(heliangliang) This should be avoided sometimes // TODO(heliangliang) This should be avoided sometimes
memset(data, 0, nbytes); memset(*result, 0, nbytes);
*result = data;
return MaceStatus::MACE_SUCCESS; return MaceStatus::MACE_SUCCESS;
} }
...@@ -143,8 +120,6 @@ class CPUAllocator : public Allocator { ...@@ -143,8 +120,6 @@ class CPUAllocator : public Allocator {
// Global CPU allocator used for CPU/GPU/DSP // Global CPU allocator used for CPU/GPU/DSP
Allocator *GetCPUAllocator(); Allocator *GetCPUAllocator();
void AdviseFree(void *addr, size_t length);
} // namespace mace } // namespace mace
#endif // MACE_CORE_ALLOCATOR_H_ #endif // MACE_CORE_ALLOCATOR_H_
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "mace/port/env.h"
namespace mace { namespace mace {
namespace { namespace {
......
...@@ -12,11 +12,6 @@ ...@@ -12,11 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <climits> #include <climits>
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
...@@ -26,6 +21,8 @@ ...@@ -26,6 +21,8 @@
#include "mace/core/kv_storage.h" #include "mace/core/kv_storage.h"
#include "mace/utils/macros.h" #include "mace/utils/macros.h"
#include "mace/utils/logging.h" #include "mace/utils/logging.h"
#include "mace/port/env.h"
#include "mace/port/file_system.h"
namespace mace { namespace mace {
...@@ -98,69 +95,24 @@ FileStorage::FileStorage(const std::string &file_path): ...@@ -98,69 +95,24 @@ FileStorage::FileStorage(const std::string &file_path):
loaded_(false), data_changed_(false), file_path_(file_path) {} loaded_(false), data_changed_(false), file_path_(file_path) {}
int FileStorage::Load() { 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_); utils::WriteLock lock(&data_mutex_);
if (loaded_) { if (loaded_) {
return 0; 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); std::unique_ptr<mace::port::ReadOnlyMemoryRegion> kv_data =
if (res != 0) { make_unique<mace::port::ReadOnlyBufferMemoryRegion>();
LOG(WARNING) << "close file " << file_path_ auto fs = GetFileSystem();
<< " failed, error code: " << strerror(errno); 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; 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; loaded_ = true;
return 0; return 0;
} }
...@@ -196,8 +148,10 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) { ...@@ -196,8 +148,10 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) {
int FileStorage::Flush() { int FileStorage::Flush() {
utils::WriteLock lock(&data_mutex_); utils::WriteLock lock(&data_mutex_);
if (!data_changed_) return 0; if (!data_changed_) return 0;
int fd = open(file_path_.c_str(), O_WRONLY | O_CREAT, 0600); auto fs = GetFileSystem();
if (fd < 0) { 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_ LOG(WARNING) << "open file " << file_path_
<< " failed, error code: " << strerror(errno); << " failed, error code: " << strerror(errno);
return -1; return -1;
...@@ -209,8 +163,8 @@ int FileStorage::Flush() { ...@@ -209,8 +163,8 @@ int FileStorage::Flush() {
for (auto &kv : data_) { for (auto &kv : data_) {
data_size += 2 * int_size + kv.first.size() + kv.second.size(); data_size += 2 * int_size + kv.first.size() + kv.second.size();
} }
std::unique_ptr<unsigned char[]> buffer(new unsigned char[data_size]); std::unique_ptr<char[]> buffer = make_unique<char[]>(data_size);
unsigned char *buffer_ptr = &buffer[0]; char *buffer_ptr = buffer.get();
int64_t num_of_data = data_.size(); int64_t num_of_data = data_.size();
memcpy(buffer_ptr, &num_of_data, sizeof(int64_t)); memcpy(buffer_ptr, &num_of_data, sizeof(int64_t));
...@@ -230,32 +184,16 @@ int FileStorage::Flush() { ...@@ -230,32 +184,16 @@ int FileStorage::Flush() {
memcpy(buffer_ptr, kv.second.data(), kv.second.size()); memcpy(buffer_ptr, kv.second.data(), kv.second.size());
buffer_ptr += kv.second.size(); buffer_ptr += kv.second.size();
} }
int res = 0; s = file->Append(buffer.get(), data_size);
buffer_ptr = &buffer[0]; if (s != MaceStatus::MACE_SUCCESS) {
int64_t remain_size = data_size; file->Close();
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; return -1;
} }
remain_size -= buffer_size; s = file->Close();
buffer_ptr += buffer_size; if (s != MaceStatus::MACE_SUCCESS) {
}
res = close(fd);
if (res != 0) {
LOG(WARNING) << "close file " << file_path_
<< " failed, error code: " << strerror(errno);
return -1; return -1;
} }
data_changed_ = false; data_changed_ = false;
return 0; return 0;
} }
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
namespace mace { namespace mace {
HexagonHTAWrapper::HexagonHTAWrapper(Device *device) HexagonHTAWrapper::HexagonHTAWrapper(Device *device)
: device_(device), quantize_util_(&device->cpu_runtime()->thread_pool()) { : quantize_util_(&device->cpu_runtime()->thread_pool()) {
} }
int HexagonHTAWrapper::GetVersion() { int HexagonHTAWrapper::GetVersion() {
......
...@@ -50,7 +50,6 @@ class HexagonHTAWrapper : public HexagonControlWrapper { ...@@ -50,7 +50,6 @@ class HexagonHTAWrapper : public HexagonControlWrapper {
void SetDebugLevel(int level) override; void SetDebugLevel(int level) override;
private: private:
Device *device_;
QuantizeUtil<uint8_t> quantize_util_; QuantizeUtil<uint8_t> quantize_util_;
MACE_DISABLE_COPY_AND_ASSIGN(HexagonHTAWrapper); MACE_DISABLE_COPY_AND_ASSIGN(HexagonHTAWrapper);
}; };
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#pragma GCC diagnostic ignored "-Wignored-attributes" #pragma GCC diagnostic ignored "-Wignored-attributes"
#endif // MACE_OS_MAC #endif // MACE_OS_MAC
#include "include/CL/cl2.hpp" #include "CL/cl2.hpp"
#ifdef MACE_OS_MAC #ifdef MACE_OS_MAC
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
......
...@@ -147,8 +147,8 @@ void *OpenCLAllocator::MapImage(void *buffer, ...@@ -147,8 +147,8 @@ void *OpenCLAllocator::MapImage(void *buffer,
VLOG(3) << "Map OpenCL Image"; VLOG(3) << "Map OpenCL Image";
MACE_CHECK(image_shape.size() == 2) << "Just support map 2d image"; MACE_CHECK(image_shape.size() == 2) << "Just support map 2d image";
auto cl_image = static_cast<cl::Image2D *>(buffer); auto cl_image = static_cast<cl::Image2D *>(buffer);
std::array<size_t, 3> origin = {0, 0, 0}; 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> region = {{image_shape[0], image_shape[1], 1}};
mapped_image_pitch->resize(2); mapped_image_pitch->resize(2);
cl_int error; cl_int error;
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "mace/core/runtime/opencl/opencl_runtime.h" #include "mace/core/runtime/opencl/opencl_runtime.h"
#include <sys/stat.h>
#include <cstdlib> #include <cstdlib>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
......
...@@ -50,7 +50,7 @@ cc_library( ...@@ -50,7 +50,7 @@ cc_library(
]), ]),
deps = [ deps = [
"//mace/ops", "//mace/ops",
"//mace/public", "//include:public_headers",
], ],
alwayslink = 1, alwayslink = 1,
) )
...@@ -91,6 +91,7 @@ cc_library( ...@@ -91,6 +91,7 @@ cc_library(
genrule( genrule(
name = "libmace_static", name = "libmace_static",
srcs = [ srcs = [
"//include:public_headers",
"//mace/codegen:generated_version", "//mace/codegen:generated_version",
"//mace/core", "//mace/core",
"//mace/ops:common", "//mace/ops:common",
...@@ -100,7 +101,6 @@ genrule( ...@@ -100,7 +101,6 @@ genrule(
"//mace/libmace", "//mace/libmace",
"//mace/port:port_base", "//mace/port:port_base",
"//mace/port/posix:port_posix", "//mace/port/posix:port_posix",
"//mace/public",
"//mace/utils", "//mace/utils",
"//mace/proto:mace_cc", "//mace/proto:mace_cc",
"@com_google_protobuf//:protobuf_lite", "@com_google_protobuf//:protobuf_lite",
...@@ -155,7 +155,6 @@ genrule( ...@@ -155,7 +155,6 @@ genrule(
"$(locations //mace/port/darwin:port_darwin) ", "$(locations //mace/port/darwin:port_darwin) ",
default_value = "", default_value = "",
) + ) +
"$(locations //mace/public:public) " +
"$(locations //mace/utils:utils) " + "$(locations //mace/utils:utils) " +
"$(locations //mace/proto:mace_cc) " + "$(locations //mace/proto:mace_cc) " +
"$(locations @com_google_protobuf//:protobuf_lite) " + "$(locations @com_google_protobuf//:protobuf_lite) " +
......
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 @@ ...@@ -19,7 +19,7 @@
#include "mace/core/device_context.h" #include "mace/core/device_context.h"
#include "mace/core/memory_optimizer.h" #include "mace/core/memory_optimizer.h"
#include "mace/core/net.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/ops/common/transpose.h"
#include "mace/utils/math.h" #include "mace/utils/math.h"
#include "mace/utils/memory.h" #include "mace/utils/memory.h"
......
...@@ -52,35 +52,6 @@ cc_library( ...@@ -52,35 +52,6 @@ cc_library(
], ],
) )
cc_library(
name = "testing",
hdrs = [
"testing/test_utils.h",
],
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
] + if_openmp_enabled([
"-fopenmp",
]) + if_neon_enabled([
"-DMACE_ENABLE_NEON",
]) + if_android_armv7([
"-mfpu=neon-fp16",
"-mfloat-abi=softfp",
]) + if_opencl_enabled([
"-DMACE_ENABLE_OPENCL",
]) + if_quantize_enabled([
"-DMACE_ENABLE_QUANTIZE",
]) + if_hexagon_enabled([
"-DMACE_ENABLE_HEXAGON",
]),
deps = [
"//mace/core",
"@gtest",
],
)
cc_library( cc_library(
name = "ref_kernels", name = "ref_kernels",
srcs = glob( srcs = glob(
...@@ -178,11 +149,6 @@ cc_library( ...@@ -178,11 +149,6 @@ cc_library(
[ [
"opencl/*.cc", "opencl/*.cc",
"opencl/**/*.cc", "opencl/**/*.cc",
"buffer_transform.cc",
"lstm_cell.cc",
],
exclude = [
"opencl/*_test.cc",
], ],
), ),
hdrs = glob( hdrs = glob(
...@@ -215,78 +181,6 @@ cc_library( ...@@ -215,78 +181,6 @@ cc_library(
], ],
) )
cc_library(
name = "arm_neon_kernels_test",
srcs = glob(
[
"arm/fp32/*_test.cc",
],
) + if_quantize_enabled(glob(
[
"arm/q8/*_test.cc",
],
)),
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
] + if_openmp_enabled([
"-fopenmp",
]) + if_neon_enabled([
"-DMACE_ENABLE_NEON",
]) + if_android_armv7([
"-mfpu=neon-fp16",
"-mfloat-abi=softfp",
]) + if_opencl_enabled([
"-DMACE_ENABLE_OPENCL",
]) + if_quantize_enabled([
"-DMACE_ENABLE_QUANTIZE",
]) + if_hexagon_enabled([
"-DMACE_ENABLE_HEXAGON",
]),
deps = [
":arm_neon_kernels",
":ref_kernels",
":testing",
"@gtest",
],
alwayslink = 1,
)
cc_library(
name = "opencl_kernels_test",
srcs = glob(
[
"opencl/*_test.cc",
"opencl/**/*_test.cc",
],
),
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
] + if_openmp_enabled([
"-fopenmp",
]) + if_neon_enabled([
"-DMACE_ENABLE_NEON",
]) + if_android_armv7([
"-mfpu=neon-fp16",
"-mfloat-abi=softfp",
]) + if_opencl_enabled([
"-DMACE_ENABLE_OPENCL",
]) + if_quantize_enabled([
"-DMACE_ENABLE_QUANTIZE",
]) + if_hexagon_enabled([
"-DMACE_ENABLE_HEXAGON",
]),
deps = [
":opencl_kernels",
":ref_kernels",
":testing",
"@gtest",
],
alwayslink = 1,
)
cc_library( cc_library(
name = "internal_ops", name = "internal_ops",
...@@ -294,32 +188,12 @@ cc_library( ...@@ -294,32 +188,12 @@ cc_library(
[ [
"*.cc", "*.cc",
], ],
exclude = [
"*_test.cc",
"*_benchmark.cc",
"ops_registry.cc",
"ops_test_util.cc",
"lstm_cell.cc", # TODO: move it into opencl
"buffer_transform.cc", # TODO: move it into opencl
"quantize.cc",
"quantization_util.cc",
"arm/*_test.cc", # remove it after refactor
],
) + if_quantize_enabled(
glob(
[
"quantize.cc",
"quantization_util.cc",
],
),
), ),
hdrs = glob( hdrs = glob(
[ [
"*.h", "*.h",
], ],
exclude = [ exclude = [
"ops_registry.h",
"ops_test_util.h",
"fixpoint.h", "fixpoint.h",
"common/gemmlowp_util.h", "common/gemmlowp_util.h",
"quantization_util.h", "quantization_util.h",
...@@ -363,16 +237,12 @@ cc_library( ...@@ -363,16 +237,12 @@ cc_library(
cc_library( cc_library(
name = "ops", name = "ops",
srcs = glob( srcs = [
[ "registry/ops_registry.cc",
"ops_registry.cc",
], ],
), hdrs = [
hdrs = glob( "registry/ops_registry.h",
[
"ops_registry.h",
], ],
),
copts = [ copts = [
"-Werror", "-Werror",
"-Wextra", "-Wextra",
...@@ -396,118 +266,3 @@ cc_library( ...@@ -396,118 +266,3 @@ cc_library(
"internal_ops", "internal_ops",
], ],
) )
cc_library(
name = "test",
testonly = 1,
srcs = [
"ops_test_util.cc",
],
hdrs = glob([
"*_test_util.h",
]),
copts = [
"-Werror",
"-Wextra",
] + if_openmp_enabled(["-fopenmp"]) + if_neon_enabled([
"-DMACE_ENABLE_NEON",
]) + if_android_armv7([
"-mfpu=neon-fp16",
]) + if_android_armv7([
"-mfloat-abi=softfp",
]) + if_opencl_enabled([
"-DMACE_ENABLE_OPENCL",
]) + if_hexagon_enabled([
"-DMACE_ENABLE_HEXAGON",
]),
deps = [
"ops",
"testing",
"@gtest",
],
)
cc_test(
name = "ops_test",
testonly = 1,
srcs = glob(
[
"*_test.cc",
"arm/*_test.cc", # remove it after refactor
"ops_test_util.cc",
],
exclude = [
"fixpoint_test.cc",
],
) + if_quantize_enabled(glob(
[
"fixpoint_test.cc",
],
)),
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
] + if_openmp_enabled([
"-fopenmp",
]) + if_neon_enabled([
"-DMACE_ENABLE_NEON",
]) + if_android_armv7([
"-mfpu=neon-fp16",
"-mfloat-abi=softfp",
]) + if_opencl_enabled([
"-DMACE_ENABLE_OPENCL",
]) + if_quantize_enabled([
"-DMACE_ENABLE_QUANTIZE",
]) + if_hexagon_enabled([
"-DMACE_ENABLE_HEXAGON",
]),
linkopts = if_openmp_enabled([
"-fopenmp",
]),
linkstatic = 1,
deps = [
":ops",
":test",
"@gtest//:gtest_main",
] + if_neon_enabled([
":arm_neon_kernels_test",
]) + if_opencl_enabled([
":opencl_kernels_test",
]),
)
cc_test(
name = "ops_benchmark",
testonly = 1,
srcs = glob(["*_benchmark.cc"]),
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
] + if_openmp_enabled([
"-fopenmp",
]) + if_neon_enabled([
"-DMACE_ENABLE_NEON",
]) + if_android_armv7([
"-mfpu=neon-fp16",
"-mfloat-abi=softfp",
]) + if_opencl_enabled([
"-DMACE_ENABLE_OPENCL",
]) + if_quantize_enabled([
"-DMACE_ENABLE_QUANTIZE",
]) + if_hexagon_enabled([
"-DMACE_ENABLE_HEXAGON",
]),
linkopts = if_openmp_enabled([
"-fopenmp",
]),
linkstatic = 1,
deps = [
":ops",
"//mace/benchmark:statistics",
"//mace/core:test_benchmark_main",
"//third_party/eigen3",
"@gemmlowp",
],
)
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 @@ ...@@ -17,14 +17,12 @@
#if defined(MACE_ENABLE_NEON) #if defined(MACE_ENABLE_NEON)
#include <arm_neon.h> #include <arm_neon.h>
#endif
namespace mace { namespace mace {
namespace ops { namespace ops {
namespace arm { namespace arm {
namespace fp32 { namespace fp32 {
#ifdef MACE_ENABLE_NEON
inline float32x4_t neon_vfma_lane_0(float32x4_t a, inline float32x4_t neon_vfma_lane_0(float32x4_t a,
float32x4_t b, float32x4_t b,
float32x4_t c) { float32x4_t c) {
...@@ -64,11 +62,11 @@ inline float32x4_t neon_vfma_lane_3(float32x4_t a, ...@@ -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); return vmlaq_lane_f32(a, b, vget_high_f32(c), 1);
#endif #endif
} }
#endif
} // namespace fp32 } // namespace fp32
} // namespace arm } // namespace arm
} // namespace ops } // namespace ops
} // namespace mace } // namespace mace
#endif // MACE_ENABLE_NEON
#endif // MACE_OPS_ARM_FP32_COMMON_NEON_H_ #endif // MACE_OPS_ARM_FP32_COMMON_NEON_H_
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include "mace/port/env.h"
namespace mace { namespace mace {
namespace ops { namespace ops {
namespace arm { namespace arm {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "mace/ops/quantization_util.h" #include "mace/ops/arm/q8/quantization_util.h"
namespace mace { namespace mace {
namespace ops { namespace ops {
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef MACE_OPS_QUANTIZATION_UTIL_H_ #ifndef MACE_OPS_ARM_Q8_QUANTIZATION_UTIL_H_
#define MACE_OPS_QUANTIZATION_UTIL_H_ #define MACE_OPS_ARM_Q8_QUANTIZATION_UTIL_H_
#include <vector> #include <vector>
...@@ -30,4 +30,4 @@ const int32_t *GetBiasData(const Tensor *bias, ...@@ -30,4 +30,4 @@ const int32_t *GetBiasData(const Tensor *bias,
} // namespace ops } // namespace ops
} // namespace mace } // namespace mace
#endif // MACE_OPS_QUANTIZATION_UTIL_H_ #endif // MACE_OPS_ARM_Q8_QUANTIZATION_UTIL_H_
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
#ifdef MACE_ENABLE_QUANTIZE #ifdef MACE_ENABLE_QUANTIZE
#include "mace/ops/common/gemmlowp_util.h" #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 #endif // MACE_ENABLE_QUANTIZE
#ifdef MACE_ENABLE_OPENCL #ifdef MACE_ENABLE_OPENCL
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#endif // MACE_ENABLE_NEON #endif // MACE_ENABLE_NEON
#ifdef MACE_ENABLE_QUANTIZE #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 // We reuse TensorFlow Lite's optimized depthwiseconv_uint8 and parallelized it
// using OpenMP for MACE's quantized depthwise_conv2d. // using OpenMP for MACE's quantized depthwise_conv2d.
#include "tensorflow/contrib/lite/kernels/internal/optimized/depthwiseconv_uint8.h" #include "tensorflow/contrib/lite/kernels/internal/optimized/depthwiseconv_uint8.h"
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "mace/ops/opencl/lstm_cell.h"
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "mace/ops/ops_registry.h" #include "mace/ops/registry/ops_registry.h"
namespace mace { namespace mace {
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef MACE_OPS_OPS_REGISTRY_H_ #ifndef MACE_OPS_REGISTRY_OPS_REGISTRY_H_
#define MACE_OPS_OPS_REGISTRY_H_ #define MACE_OPS_REGISTRY_OPS_REGISTRY_H_
#include "mace/core/operator.h" #include "mace/core/operator.h"
...@@ -27,4 +27,4 @@ class OpRegistry : public OpRegistryBase { ...@@ -27,4 +27,4 @@ class OpRegistry : public OpRegistryBase {
} // namespace mace } // namespace mace
#endif // MACE_OPS_OPS_REGISTRY_H_ #endif // MACE_OPS_REGISTRY_OPS_REGISTRY_H_
...@@ -13,42 +13,15 @@ cc_library( ...@@ -13,42 +13,15 @@ cc_library(
], ],
) )
cc_library(
name = "port_api",
hdrs = [
"env.h",
"file_system.h",
"logger.h",
"port.h",
"port-arch.h",
],
deps = [
"//mace/public",
],
)
cc_library( cc_library(
name = "port_base", name = "port_base",
srcs = [ srcs = [
"env.cc", "env.cc",
"logger.cc", "logger.cc",
"file_system.cc",
], ],
deps = [ deps = [
":port_api",
"//mace/utils", "//mace/utils",
], "//include:public_headers",
)
cc_test(
name = "port_test",
testonly = 1,
srcs = glob([
"*_test.cc",
]),
linkstatic = 1,
deps = [
":port",
"@gtest",
"@gtest//:gtest_main",
], ],
) )
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 @@ ...@@ -22,6 +22,10 @@
namespace mace { namespace mace {
namespace port { namespace port {
MaceStatus Env::AdviseFree(void *addr, size_t length) {
return MaceStatus::MACE_UNSUPPORTED;
}
MaceStatus Env::GetCPUMaxFreq(std::vector<float> *max_freqs) { MaceStatus Env::GetCPUMaxFreq(std::vector<float> *max_freqs) {
return MaceStatus::MACE_UNSUPPORTED; 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 @@ ...@@ -17,6 +17,7 @@
#include <errno.h> #include <errno.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
#include <cstddef> #include <cstddef>
...@@ -121,5 +122,26 @@ MaceStatus LinuxBaseEnv::SchedSetAffinity(const std::vector<size_t> &cpu_ids) { ...@@ -121,5 +122,26 @@ MaceStatus LinuxBaseEnv::SchedSetAffinity(const std::vector<size_t> &cpu_ids) {
return MaceStatus::MACE_SUCCESS; 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 port
} // namespace mace } // namespace mace
...@@ -26,6 +26,7 @@ namespace port { ...@@ -26,6 +26,7 @@ namespace port {
class LinuxBaseEnv : public Env { class LinuxBaseEnv : public Env {
public: public:
int64_t NowMicros() override; int64_t NowMicros() override;
MaceStatus AdviseFree(void *addr, size_t length) override;
MaceStatus GetCPUMaxFreq(std::vector<float> *max_freqs) override; MaceStatus GetCPUMaxFreq(std::vector<float> *max_freqs) override;
FileSystem *GetFileSystem() override; FileSystem *GetFileSystem() override;
MaceStatus SchedSetAffinity(const std::vector<size_t> &cpu_ids) 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 { ...@@ -37,9 +37,9 @@ class PosixReadOnlyMemoryRegion : public ReadOnlyMemoryRegion {
if (length_ > 0) { if (length_ > 0) {
munmap(const_cast<void *>(addr_), length_); munmap(const_cast<void *>(addr_), length_);
} }
}; }
const void *data() const override { return addr_; }; const void *data() const override { return addr_; }
uint64_t length() const override { return length_; }; uint64_t length() const override { return length_; }
private: private:
const void *addr_; const void *addr_;
...@@ -50,11 +50,11 @@ class PosixReadOnlyMemoryRegion : public ReadOnlyMemoryRegion { ...@@ -50,11 +50,11 @@ class PosixReadOnlyMemoryRegion : public ReadOnlyMemoryRegion {
MaceStatus PosixFileSystem::NewReadOnlyMemoryRegionFromFile( MaceStatus PosixFileSystem::NewReadOnlyMemoryRegionFromFile(
const char *fname, const char *fname,
std::unique_ptr<ReadOnlyMemoryRegion>* result) { std::unique_ptr<ReadOnlyMemoryRegion>* result) {
MaceStatus s = MaceStatus(MaceStatus::MACE_SUCCESS); MaceStatus s = MaceStatus::MACE_SUCCESS;
int fd = open(fname, O_RDONLY); int fd = open(fname, O_RDONLY);
if (fd < 0) { if (fd < 0) {
// TODO(heliangliang) check errno // TODO(heliangliang) check errno
s = MaceStatus(MaceStatus::MACE_RUNTIME_ERROR); s = MaceStatus::MACE_RUNTIME_ERROR;
} else { } else {
struct stat st; struct stat st;
fstat(fd, &st); fstat(fd, &st);
...@@ -63,7 +63,7 @@ MaceStatus PosixFileSystem::NewReadOnlyMemoryRegionFromFile( ...@@ -63,7 +63,7 @@ MaceStatus PosixFileSystem::NewReadOnlyMemoryRegionFromFile(
mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (address == MAP_FAILED) { if (address == MAP_FAILED) {
// TODO(heliangliang) check errno // TODO(heliangliang) check errno
s = MaceStatus(MaceStatus::MACE_RUNTIME_ERROR); s = MaceStatus::MACE_RUNTIME_ERROR;
} else { } else {
*result = make_unique<PosixReadOnlyMemoryRegion>(address, st.st_size); *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)
...@@ -86,7 +86,6 @@ message OperatorDef { ...@@ -86,7 +86,6 @@ message OperatorDef {
repeated int32 out_max_byte_size = 104; // only support 32-bit len repeated int32 out_max_byte_size = 104; // only support 32-bit len
} }
// for hexagon mace-nnlib
message InputOutputInfo { message InputOutputInfo {
optional string name = 1; optional string name = 1;
optional int32 node_id = 2; optional int32 node_id = 2;
...@@ -103,7 +102,6 @@ message NetDef { ...@@ -103,7 +102,6 @@ message NetDef {
repeated Argument arg = 2; repeated Argument arg = 2;
repeated ConstTensor tensors = 3; repeated ConstTensor tensors = 3;
// for hexagon mace-nnlib
repeated InputOutputInfo input_info = 100; repeated InputOutputInfo input_info = 100;
repeated InputOutputInfo output_info = 101; repeated InputOutputInfo output_info = 101;
} }
...@@ -20,7 +20,7 @@ class NPEncoder(json.JSONEncoder): ...@@ -20,7 +20,7 @@ class NPEncoder(json.JSONEncoder):
class ModelVisualizer(object): class ModelVisualizer(object):
def __init__(self, model_name, proto): def __init__(self, model_name, proto):
self._output_file = "builds/%s_index.html" % model_name self._output_file = "build/%s_index.html" % model_name
self._proto = proto self._proto = proto
def render_html(self): def render_html(self):
......
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)
...@@ -10,17 +10,6 @@ load( ...@@ -10,17 +10,6 @@ load(
licenses(["notice"]) # Apache 2.0 licenses(["notice"]) # Apache 2.0
cc_library(
name = "statistics",
srcs = ["statistics.cc"],
hdrs = ["statistics.h"],
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"],
visibility = ["//visibility:public"],
deps = [
"//mace/utils",
],
)
cc_binary( cc_binary(
name = "benchmark_model_static", name = "benchmark_model_static",
srcs = [ srcs = [
...@@ -34,12 +23,15 @@ cc_binary( ...@@ -34,12 +23,15 @@ cc_binary(
linkopts = if_openmp_enabled(["-fopenmp"]), linkopts = if_openmp_enabled(["-fopenmp"]),
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
":statistics",
"//external:gflags_nothreads", "//external:gflags_nothreads",
"//mace/codegen:libmodels",
"//mace/codegen:generated_mace_engine_factory", "//mace/codegen:generated_mace_engine_factory",
"//mace/libmace:libmace", "//mace/codegen:generated_models",
], "//mace/libmace",
"//mace/utils",
] + if_opencl_enabled([
"//mace/codegen:generated_opencl_binary",
"//mace/codegen:generated_opencl_parameter",
]),
) )
cc_binary( cc_binary(
...@@ -55,7 +47,7 @@ cc_binary( ...@@ -55,7 +47,7 @@ cc_binary(
linkopts = [ linkopts = [
"-lm", "-lm",
] + if_openmp_enabled([ ] + if_openmp_enabled([
"-fopenmp" "-fopenmp",
]) + if_android([ ]) + if_android([
"-ldl", "-ldl",
"-pie", "-pie",
...@@ -66,9 +58,12 @@ cc_binary( ...@@ -66,9 +58,12 @@ cc_binary(
":statistics", ":statistics",
"//external:gflags_nothreads", "//external:gflags_nothreads",
"//mace/codegen:generated_mace_engine_factory", "//mace/codegen:generated_mace_engine_factory",
"//mace/codegen:libmodels", "//mace/codegen:generated_models",
"//mace/libmace:libmace_dynamic", "//mace/libmace:libmace_dynamic",
], ] + if_opencl_enabled([
"//mace/codegen:generated_opencl_binary",
"//mace/codegen:generated_opencl_parameter",
]),
) )
cc_library( cc_library(
...@@ -82,9 +77,13 @@ cc_library( ...@@ -82,9 +77,13 @@ cc_library(
cc_binary( cc_binary(
name = "model_throughput_test", name = "model_throughput_test",
srcs = ["model_throughput_test.cc"], srcs = ["model_throughput_test.cc"],
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
],
linkopts = if_openmp_enabled(["-fopenmp"]), linkopts = if_openmp_enabled(["-fopenmp"]),
linkstatic = 1, linkstatic = 1,
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"],
deps = [ deps = [
":libmace_merged", ":libmace_merged",
"//external:gflags_nothreads", "//external:gflags_nothreads",
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <sys/time.h>
#include <cstdlib> #include <cstdlib>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
...@@ -27,7 +25,7 @@ ...@@ -27,7 +25,7 @@
#include "mace/utils/logging.h" #include "mace/utils/logging.h"
#include "mace/utils/memory.h" #include "mace/utils/memory.h"
#include "mace/utils/math.h" #include "mace/utils/math.h"
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#ifdef MODEL_GRAPH_FORMAT_CODE #ifdef MODEL_GRAPH_FORMAT_CODE
#include "mace/codegen/engine/mace_engine_factory.h" #include "mace/codegen/engine/mace_engine_factory.h"
#endif #endif
...@@ -57,12 +55,6 @@ std::string FormatName(const std::string input) { ...@@ -57,12 +55,6 @@ std::string FormatName(const std::string input) {
return res; 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) { DeviceType ParseDeviceType(const std::string &device_str) {
if (device_str.compare("CPU") == 0) { if (device_str.compare("CPU") == 0) {
return DeviceType::CPU; return DeviceType::CPU;
......
...@@ -249,7 +249,12 @@ int Main(int argc, char **argv) { ...@@ -249,7 +249,12 @@ int Main(int argc, char **argv) {
buffer_out); buffer_out);
} }
#if defined(MACE_CPU_MODEL_TAG) || \
defined(MACE_GPU_MODEL_TAG) || \
defined(MACE_DSP_MODEL_TAG)
int64_t t0, t1, init_micros; int64_t t0, t1, init_micros;
#endif
#ifdef MACE_CPU_MODEL_TAG #ifdef MACE_CPU_MODEL_TAG
/* --------------------- CPU init ----------------------- */ /* --------------------- CPU init ----------------------- */
LOG(INFO) << "Load & init cpu model and warm up"; LOG(INFO) << "Load & init cpu model and warm up";
...@@ -306,10 +311,14 @@ int Main(int argc, char **argv) { ...@@ -306,10 +311,14 @@ int Main(int argc, char **argv) {
LOG(INFO) << "DSP 1st warm up run latency: " << t1 - t0 << " us"; LOG(INFO) << "DSP 1st warm up run latency: " << t1 - t0 << " us";
#endif #endif
#if defined(MACE_CPU_MODEL_TAG) || \
defined(MACE_GPU_MODEL_TAG) || \
defined(MACE_DSP_MODEL_TAG)
double cpu_throughput = 0; double cpu_throughput = 0;
double gpu_throughput = 0; double gpu_throughput = 0;
double dsp_throughput = 0; double dsp_throughput = 0;
int64_t run_micros = FLAGS_run_seconds * 1000000; int64_t run_micros = FLAGS_run_seconds * 1000000;
#endif
#ifdef MACE_CPU_MODEL_TAG #ifdef MACE_CPU_MODEL_TAG
std::thread cpu_thread([&]() { std::thread cpu_thread([&]() {
......
...@@ -26,7 +26,7 @@ cc_binary( ...@@ -26,7 +26,7 @@ cc_binary(
deps = [ deps = [
"//external:gflags_nothreads", "//external:gflags_nothreads",
"//mace/codegen:generated_mace_engine_factory", "//mace/codegen:generated_mace_engine_factory",
"//mace/codegen:libmodels", "//mace/codegen:generated_models",
"//mace/libmace", "//mace/libmace",
], ],
) )
...@@ -50,7 +50,7 @@ cc_binary( ...@@ -50,7 +50,7 @@ cc_binary(
deps = [ deps = [
"//external:gflags_nothreads", "//external:gflags_nothreads",
"//mace/codegen:generated_mace_engine_factory", "//mace/codegen:generated_mace_engine_factory",
"//mace/codegen:libmodels", "//mace/codegen:generated_models",
"//mace/libmace:libmace_dynamic", "//mace/libmace:libmace_dynamic",
], ],
) )
...@@ -26,8 +26,7 @@ cc_library( ...@@ -26,8 +26,7 @@ cc_library(
"-Wno-missing-field-initializers", "-Wno-missing-field-initializers",
], ],
deps = [ deps = [
"//mace/port:port_api", "//include:public_headers",
"//mace/public",
], ],
) )
...@@ -37,9 +36,6 @@ cc_library( ...@@ -37,9 +36,6 @@ cc_library(
[ [
"*.cc", "*.cc",
], ],
exclude = [
"*_test.cc",
],
), ),
copts = [ copts = [
"-Werror", "-Werror",
...@@ -61,25 +57,3 @@ cc_library( ...@@ -61,25 +57,3 @@ cc_library(
], ],
alwayslink = 1, alwayslink = 1,
) )
cc_test(
name = "utils_test",
testonly = 1,
srcs = glob(
[
"*_test.cc",
],
),
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
],
linkstatic = 1,
deps = [
":utils",
"//mace/port",
"@gtest//:gtest",
"@gtest//:gtest_main",
],
)
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 @@ ...@@ -17,7 +17,7 @@
#include <functional> #include <functional>
#include <set> #include <set>
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#include "mace/utils/logging.h" #include "mace/utils/logging.h"
#include "mace/utils/string_util.h" #include "mace/utils/string_util.h"
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef MACE_BENCHMARK_STATISTICS_H_ #ifndef MACE_UTILS_STATISTICS_H_
#define MACE_BENCHMARK_STATISTICS_H_ #define MACE_UTILS_STATISTICS_H_
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
...@@ -182,4 +182,4 @@ class OpStat { ...@@ -182,4 +182,4 @@ class OpStat {
} // namespace benchmark } // namespace benchmark
} // namespace mace } // namespace mace
#endif // MACE_BENCHMARK_STATISTICS_H_ #endif // MACE_UTILS_STATISTICS_H_
...@@ -179,7 +179,7 @@ void ThreadPool::Init() { ...@@ -179,7 +179,7 @@ void ThreadPool::Init() {
if (threads_.size() <= 1) { if (threads_.size() <= 1) {
return; return;
} }
count_down_latch_.Reset(threads_.size() - 1); count_down_latch_.Reset(static_cast<int>(threads_.size() - 1));
event_ = kThreadPoolInit; event_ = kThreadPoolInit;
for (size_t i = 1; i < threads_.size(); ++i) { for (size_t i = 1; i < threads_.size(); ++i) {
threads_[i] = std::thread(&ThreadPool::ThreadLoop, this, i); threads_[i] = std::thread(&ThreadPool::ThreadLoop, this, i);
...@@ -206,7 +206,7 @@ void ThreadPool::Run(const std::function<void(const int64_t)> &func, ...@@ -206,7 +206,7 @@ void ThreadPool::Run(const std::function<void(const int64_t)> &func,
iters_offset = thread_infos_[i].range_end; 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_); std::unique_lock<std::mutex> m(event_mutex_);
event_.store(kThreadPoolRun | ~(event_ | kThreadPoolEventMask), event_.store(kThreadPoolRun | ~(event_ | kThreadPoolEventMask),
......
...@@ -15,31 +15,30 @@ ...@@ -15,31 +15,30 @@
#ifndef MACE_UTILS_TUNER_H_ #ifndef MACE_UTILS_TUNER_H_
#define 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 <cstdlib>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <limits> #include <limits>
#include <map> #include <map>
#include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "mace/port/env.h"
#include "mace/port/file_system.h"
#include "mace/utils/logging.h" #include "mace/utils/logging.h"
#include "mace/utils/memory.h"
#include "mace/utils/string_util.h" #include "mace/utils/string_util.h"
#include "mace/utils/timer.h" #include "mace/utils/timer.h"
namespace mace { namespace mace {
inline bool IsTuning() { inline bool IsTuning() {
const char *tuning = getenv("MACE_TUNING"); std::string tuning;
return tuning != nullptr && strlen(tuning) == 1 && tuning[0] == '1'; GetEnv("MACE_TUNING", &tuning);
return tuning.size() == 1 && tuning[0] == '1';
} }
template <typename param_type> template <typename param_type>
...@@ -49,7 +48,7 @@ class Tuner { ...@@ -49,7 +48,7 @@ class Tuner {
const unsigned char *param_byte_stream = nullptr, const unsigned char *param_byte_stream = nullptr,
const size_t param_byte_stream_size = 0): const size_t param_byte_stream_size = 0):
tuned_param_file_path_(tuned_param_file_path) { 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) { if (param_byte_stream != nullptr && param_byte_stream_size != 0) {
ParseData(param_byte_stream, param_byte_stream_size); ParseData(param_byte_stream, param_byte_stream_size);
} else { } else {
...@@ -94,10 +93,10 @@ class Tuner { ...@@ -94,10 +93,10 @@ class Tuner {
} }
private: private:
inline void WriteRunParameters() { void WriteRunParameters() {
if (path_ != nullptr) { if (!path_.empty()) {
VLOG(3) << "Write tuning result to " << path_; 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()) { if (ofs.is_open()) {
int64_t num_pramas = param_table_.size(); int64_t num_pramas = param_table_.size();
ofs.write(reinterpret_cast<char *>(&num_pramas), sizeof(num_pramas)); ofs.write(reinterpret_cast<char *>(&num_pramas), sizeof(num_pramas));
...@@ -124,7 +123,7 @@ class Tuner { ...@@ -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 int_size = sizeof(int32_t);
const size_t param_type_size = sizeof(param_type); const size_t param_type_size = sizeof(param_type);
...@@ -160,68 +159,20 @@ class Tuner { ...@@ -160,68 +159,20 @@ class Tuner {
} }
} }
inline void ReadRunParamters() { void ReadRunParamters() {
if (!tuned_param_file_path_.empty()) { if (!tuned_param_file_path_.empty()) {
struct stat st; std::unique_ptr<mace::port::ReadOnlyMemoryRegion> param_data =
if (stat(tuned_param_file_path_.c_str(), &st) == -1) { make_unique<mace::port::ReadOnlyBufferMemoryRegion>();
if (errno == ENOENT) { auto fs = GetFileSystem();
VLOG(1) << "File " << tuned_param_file_path_ auto status = fs->NewReadOnlyMemoryRegionFromFile(
<< " does not exist"; tuned_param_file_path_.c_str(), &param_data);
} else { if (status != MaceStatus::MACE_SUCCESS) {
LOG(WARNING) << "Stat file " << tuned_param_file_path_ LOG(ERROR) << "Failed to read tuned param file: "
<< " failed, error code: " << strerror(errno); << tuned_param_file_path_;
}
return; 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 { } else {
LOG(WARNING) << "open file " << tuned_param_file_path_ ParseData(static_cast<const unsigned char *>(param_data->data()),
<< " failed, error code: " << strerror(errno); param_data->length());
}
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);
return;
} }
} else { } else {
VLOG(1) << "There is no tuned parameters."; VLOG(1) << "There is no tuned parameters.";
...@@ -229,8 +180,7 @@ class Tuner { ...@@ -229,8 +180,7 @@ class Tuner {
} }
template <typename RetType> template <typename RetType>
inline RetType Run( RetType Run(const std::function<RetType(const std::vector<param_type> &,
const std::function<RetType(const std::vector<param_type> &,
Timer *, Timer *,
std::vector<param_type> *)> &func, std::vector<param_type> *)> &func,
const std::vector<param_type> &params, const std::vector<param_type> &params,
...@@ -255,8 +205,7 @@ class Tuner { ...@@ -255,8 +205,7 @@ class Tuner {
} }
template <typename RetType> template <typename RetType>
inline RetType Tune( RetType Tune(const std::function<std::vector<std::vector<param_type>>()>
const std::function<std::vector<std::vector<param_type>>()>
&param_generator, &param_generator,
const std::function<RetType(const std::vector<param_type> &, const std::function<RetType(const std::vector<param_type> &,
Timer *, Timer *,
...@@ -288,7 +237,7 @@ class Tuner { ...@@ -288,7 +237,7 @@ class Tuner {
private: private:
std::string tuned_param_file_path_; std::string tuned_param_file_path_;
const char *path_; std::string path_;
std::unordered_map<std::string, std::vector<param_type>> param_table_; std::unordered_map<std::string, std::vector<param_type>> param_table_;
}; };
......
...@@ -20,7 +20,7 @@ def _git_version_conf_impl(repository_ctx): ...@@ -20,7 +20,7 @@ def _git_version_conf_impl(repository_ctx):
unused_var = repository_ctx.path(Label("//:.git/refs/heads/master")) unused_var = repository_ctx.path(Label("//:.git/refs/heads/master"))
repository_ctx.execute([ 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 , '%s/version' % generated_files_path
], quiet=False) ], quiet=False)
......
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/ccutils")
add_subdirectory(ccutils)
if(MACE_ENABLE_TESTS)
add_subdirectory(ccunit)
endif()
if(MACE_ENABLE_BENCHMARKS)
add_subdirectory(ccbenchmark)
endif()
package(
default_visibility = ["//visibility:public"],
)
licenses(["notice"]) # Apache 2.0
load(
"//mace:mace.bzl",
"if_android",
"if_android_armv7",
"if_hexagon_enabled",
"if_neon_enabled",
"if_opencl_enabled",
"if_openmp_enabled",
"if_quantize_enabled",
)
cc_library(
name = "benchmark_utils",
testonly = 1,
hdrs = glob([
"mace/benchmark_utils/*.h",
]),
srcs = glob([
"mace/benchmark_utils/*.cc",
]),
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
],
strip_include_prefix = "",
deps = [
"//mace/core",
"//test/ccutils",
"//external:gflags_nothreads",
],
)
cc_test(
name = "mace_cc_benchmark",
testonly = 1,
srcs = glob(
[
"mace/ops/*.cc",
],
),
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
"-fopenmp",
] + if_neon_enabled([
"-DMACE_ENABLE_NEON",
]) + if_android_armv7([
"-mfpu=neon-fp16",
"-mfloat-abi=softfp",
]) + if_opencl_enabled([
"-DMACE_ENABLE_OPENCL",
]) + if_quantize_enabled([
"-DMACE_ENABLE_QUANTIZE",
]) + if_hexagon_enabled([
"-DMACE_ENABLE_HEXAGON",
]),
linkopts = [
"-fopenmp",
],
linkstatic = 1,
deps = [
"benchmark_utils",
"//mace/ops",
"//third_party/eigen3",
"@gemmlowp",
],
)
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 @@ ...@@ -19,7 +19,7 @@
#include <regex> // NOLINT(build/c++11) #include <regex> // NOLINT(build/c++11)
#include <vector> #include <vector>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/port/env.h" #include "mace/port/env.h"
#include "mace/utils/logging.h" #include "mace/utils/logging.h"
......
...@@ -13,15 +13,13 @@ ...@@ -13,15 +13,13 @@
// limitations under the License. // limitations under the License.
// Simple benchmarking facility. // Simple benchmarking facility.
#ifndef MACE_CORE_TESTING_TEST_BENCHMARK_H_ #ifndef MACE_BENCHMARK_UTILS_TEST_BENCHMARK_H_
#define MACE_CORE_TESTING_TEST_BENCHMARK_H_ #define MACE_BENCHMARK_UTILS_TEST_BENCHMARK_H_
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "mace/core/types.h"
#define MACE_BENCHMARK(n) \ #define MACE_BENCHMARK(n) \
static ::mace::testing::Benchmark *__benchmark_##n = \ static ::mace::testing::Benchmark *__benchmark_##n = \
(new ::mace::testing::Benchmark(#n, (n))) (new ::mace::testing::Benchmark(#n, (n)))
...@@ -52,4 +50,4 @@ void StopTiming(); ...@@ -52,4 +50,4 @@ void StopTiming();
} // namespace testing } // namespace testing
} // namespace mace } // namespace mace
#endif // MACE_CORE_TESTING_TEST_BENCHMARK_H_ #endif // MACE_BENCHMARK_UTILS_TEST_BENCHMARK_H_
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "gflags/gflags.h" #include "gflags/gflags.h"
#include "mace/core/runtime/cpu/cpu_runtime.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" #include "mace/ops/ops_test_util.h"
DEFINE_string(filter, "all", "op benchmark regex filter, eg:.*CONV.*"); DEFINE_string(filter, "all", "op benchmark regex filter, eg:.*CONV.*");
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <string> #include <string>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <string> #include <string>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifdef MACE_ENABLE_OPENCL #ifdef MACE_ENABLE_OPENCL
#include "mace/core/runtime/opencl/opencl_runtime.h" #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/opencl/buffer_transformer.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <algorithm> #include <algorithm>
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#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/common/conv_pool_2d_util.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <algorithm> #include <algorithm>
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#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/common/conv_pool_2d_util.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <algorithm> #include <algorithm>
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#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/common/conv_pool_2d_util.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
#include <algorithm> #include <algorithm>
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#include "mace/core/operator.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" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/lstmcell_test_util.h" #include "mace/ops/lstmcell_test_util.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <string> #include <string>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/eltwise.h" #include "mace/ops/eltwise.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <string> #include <string>
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <string> #include <string>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/lstmcell_test_util.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/lstmcell_test_util.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
#include <vector> #include <vector>
#include "public/gemmlowp.h" #include "public/gemmlowp.h"
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace gemmlowp { namespace gemmlowp {
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
namespace mace { namespace mace {
namespace ops { namespace ops {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
#include "mace/ops/pad.h" #include "mace/ops/pad.h"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <string> #include <string>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/common/conv_pool_2d_util.h"
#include "mace/ops/pooling.h" #include "mace/ops/pooling.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifdef MACE_ENABLE_QUANTIZE #ifdef MACE_ENABLE_QUANTIZE
#include "mace/core/operator.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" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <string> #include <string>
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <string> #include <string>
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <string> #include <string>
#include "mace/benchmark/statistics.h" #include "mace/utils/statistics.h"
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <string> #include <string>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
#include "mace/core/operator.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" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <string> #include <string>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <string> #include <string>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
#include <string> #include <string>
#include <vector> #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" #include "mace/utils/thread_pool.h"
#define MACE_EMPTY_STATEMENT asm volatile("":::"memory"); #define MACE_EMPTY_STATEMENT asm volatile("":::"memory");
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "mace/core/testing/test_benchmark.h" #include "mace/benchmark_utils/test_benchmark.h"
#include "mace/ops/ops_test_util.h" #include "mace/ops/ops_test_util.h"
namespace mace { namespace mace {
......
package(
default_visibility = ["//visibility:public"],
)
licenses(["notice"]) # Apache 2.0
load(
"//mace:mace.bzl",
"if_android",
"if_android_armv7",
"if_hexagon_enabled",
"if_neon_enabled",
"if_opencl_enabled",
"if_openmp_enabled",
"if_quantize_enabled",
)
cc_test(
name = "mace_cc_test",
testonly = 1,
srcs = glob(
[
"mace/libmace/*.cc",
"mace/ops/*.cc",
"mace/port/*.cc",
"mace/utils/*.cc",
],
exclude = [
"mace/ops/fixpoint_test.cc",
],
) + if_neon_enabled(glob(
[
"mace/ops/arm/fp32/*.cc",
]
)) + if_quantize_enabled(glob(
[
"mace/ops/arm/q8/*.cc",
"mace/ops/fixpoint_test.cc",
]
)) + if_opencl_enabled(glob(
[
"mace/ops/opencl/*.cc",
]
)),
copts = [
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
] + if_openmp_enabled([
"-fopenmp",
]) + if_neon_enabled([
"-DMACE_ENABLE_NEON",
]) + if_android_armv7([
"-mfpu=neon-fp16",
"-mfloat-abi=softfp",
]) + if_opencl_enabled([
"-DMACE_ENABLE_OPENCL",
]) + if_quantize_enabled([
"-DMACE_ENABLE_QUANTIZE",
]) + if_hexagon_enabled([
"-DMACE_ENABLE_HEXAGON",
]),
linkopts = if_openmp_enabled([
"-fopenmp",
]),
linkstatic = 1,
deps = [
"//mace/ops",
"//test/ccutils",
"@gtest//:gtest_main",
],
)
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 @@ ...@@ -16,7 +16,7 @@
#include <thread> // NOLINT(build/c++11) #include <thread> // NOLINT(build/c++11)
#include "mace/test/mace_api_test.h" #include "mace/libmace/mace_api_test.h"
namespace mace { namespace mace {
namespace test { namespace test {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "mace/test/mace_api_test.h" #include "mace/libmace/mace_api_test.h"
namespace mace { namespace mace {
namespace test { namespace test {
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef MACE_TEST_MACE_API_TEST_H_ #ifndef MACE_LIBMACE_MACE_API_TEST_H_
#define MACE_TEST_MACE_API_TEST_H_ #define MACE_LIBMACE_MACE_API_TEST_H_
#include <functional> #include <functional>
#include <map> #include <map>
...@@ -187,4 +187,4 @@ void CheckOutputs(const NetDef &net_def, ...@@ -187,4 +187,4 @@ void CheckOutputs(const NetDef &net_def,
} }
} // namespace test } // namespace test
} // namespace mace } // namespace mace
#endif // MACE_TEST_MACE_API_TEST_H_ #endif // MACE_LIBMACE_MACE_API_TEST_H_
package(
default_visibility = ["//visibility:public"],
)
licenses(["notice"]) # Apache 2.0
load(
"//mace:mace.bzl",
"if_android",
"if_android_armv7",
"if_hexagon_enabled",
"if_neon_enabled",
"if_opencl_enabled",
"if_openmp_enabled",
"if_quantize_enabled",
)
cc_library(
name = "ccutils",
testonly = 1,
srcs = glob([
"mace/ops/*.cc",
]),
hdrs = glob([
"mace/ops/*.h",
"mace/ops/testing/*.h",
]),
strip_include_prefix = "",
copts = [
"-Werror",
"-Wextra",
] + if_openmp_enabled(["-fopenmp"]) + if_neon_enabled([
"-DMACE_ENABLE_NEON",
]) + if_android_armv7([
"-mfpu=neon-fp16",
]) + if_android_armv7([
"-mfloat-abi=softfp",
]) + if_opencl_enabled([
"-DMACE_ENABLE_OPENCL",
]) + if_hexagon_enabled([
"-DMACE_ENABLE_HEXAGON",
]),
deps = [
"//mace/ops",
"@gtest",
],
)
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 @@ ...@@ -31,7 +31,7 @@
#include "mace/core/device_context.h" #include "mace/core/device_context.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
#include "mace/core/workspace.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/public/mace.h"
#include "mace/utils/memory.h" #include "mace/utils/memory.h"
#include "mace/utils/math.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)
...@@ -15,5 +15,6 @@ genrule( ...@@ -15,5 +15,6 @@ genrule(
cc_library( cc_library(
name = "opencl_clhpp", name = "opencl_clhpp",
hdrs = ["include/CL/cl.hpp", "include/CL/cl2.hpp"], hdrs = ["include/CL/cl.hpp", "include/CL/cl2.hpp"],
strip_include_prefix = "include",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
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)
set(BUILD_PROTOC TRUE)
if(COMMAND protoc)
execute_process(COMMAND protoc OUTPUT_VARIABLE PROTOC_VER)
if(${PROTOC_VER} STREQUAL "libprotoc 3.6.1")
set(PROTOC_BIN protoc CACHE FILEPATH "protoc compiler." FORCE)
set(BUILD_PROTOC FALSE)
add_custom_target(protoc_bin COMMENT "protoc noop target")
endif(${PROTOC_VER} STREQUAL "libprotoc 3.6.1")
endif(COMMAND protoc)
if(BUILD_PROTOC)
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)
endif(BUILD_PROTOC)
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)
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
set -e set -e
LIB_DIR=builds/lib LIB_DIR=build/lib
INCLUDE_DIR=builds/include/mace/public INCLUDE_DIR=build/include
mkdir -p $LIB_DIR mkdir -p $LIB_DIR
mkdir -p $INCLUDE_DIR mkdir -p $INCLUDE_DIR
# copy include headers # copy include headers
cp mace/public/*.h $INCLUDE_DIR/ cp -R include/mace $INCLUDE_DIR/
# make directories # make directories
rm -rf $LIB_DIR/armeabi-v7a rm -rf $LIB_DIR/armeabi-v7a
...@@ -19,7 +19,6 @@ mkdir -p $LIB_DIR/armeabi-v7a/cpu_gpu ...@@ -19,7 +19,6 @@ mkdir -p $LIB_DIR/armeabi-v7a/cpu_gpu
rm -rf $LIB_DIR/arm64-v8a rm -rf $LIB_DIR/arm64-v8a
mkdir -p $LIB_DIR/arm64-v8a/cpu_gpu_dsp mkdir -p $LIB_DIR/arm64-v8a/cpu_gpu_dsp
mkdir -p $LIB_DIR/arm64-v8a/cpu_gpu mkdir -p $LIB_DIR/arm64-v8a/cpu_gpu
mkdir -p $LIB_DIR/arm64-v8a/cpu_gpu_apu
rm -rf $LIB_DIR/linux-x86-64 rm -rf $LIB_DIR/linux-x86-64
mkdir -p $LIB_DIR/linux-x86-64 mkdir -p $LIB_DIR/linux-x86-64
...@@ -51,11 +50,6 @@ echo "build shared lib for arm64-v8a + cpu_gpu" ...@@ -51,11 +50,6 @@ echo "build shared lib for arm64-v8a + cpu_gpu"
bazel build --config android --config optimization mace/libmace:libmace_dynamic --define neon=true --define openmp=false --define opencl=true --define quantize=true --cpu=arm64-v8a bazel build --config android --config optimization mace/libmace:libmace_dynamic --define neon=true --define openmp=false --define opencl=true --define quantize=true --cpu=arm64-v8a
cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/arm64-v8a/cpu_gpu/ cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/arm64-v8a/cpu_gpu/
echo "build shared lib for arm64-v8a + cpu_gpu_apu"
bazel build --config android --config optimization mace/libmace:libmace_dynamic --define neon=true --define openmp=false --define opencl=true --define apu=true --define quantize=true --cpu=arm64-v8a
cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/arm64-v8a/cpu_gpu_apu/
cp third_party/apu/libapu-frontend.so $LIB_DIR/arm64-v8a/cpu_gpu_apu/
echo "build shared lib for arm_linux_gnueabihf + cpu_gpu" echo "build shared lib for arm_linux_gnueabihf + cpu_gpu"
bazel build --config arm_linux_gnueabihf --config optimization mace/libmace:libmace_dynamic --define neon=true --define openmp=false --define opencl=true --define quantize=true bazel build --config arm_linux_gnueabihf --config optimization mace/libmace:libmace_dynamic --define neon=true --define openmp=false --define opencl=true --define quantize=true
cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/arm_linux_gnueabihf/cpu_gpu/ cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/arm_linux_gnueabihf/cpu_gpu/
...@@ -66,7 +60,7 @@ cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/aarch64_linux_gnu/cpu_gpu/ ...@@ -66,7 +60,7 @@ cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/aarch64_linux_gnu/cpu_gpu/
if [[ "$OSTYPE" != "darwin"* ]];then if [[ "$OSTYPE" != "darwin"* ]];then
echo "build shared lib for linux-x86-64" echo "build shared lib for linux-x86-64"
bazel build mace/libmace:libmace_dynamic --config optimization --define quantize=true --define openmp=false bazel build mace/libmace:libmace_dynamic --config optimization --define openmp=false
cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/linux-x86-64/ cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/linux-x86-64/
fi fi
...@@ -89,11 +83,6 @@ echo "build static lib for arm64-v8a + cpu_gpu" ...@@ -89,11 +83,6 @@ echo "build static lib for arm64-v8a + cpu_gpu"
bazel build --config android --config optimization mace/libmace:libmace_static --config symbol_hidden --define neon=true --define openmp=false --define opencl=true --define quantize=true --cpu=arm64-v8a bazel build --config android --config optimization mace/libmace:libmace_static --config symbol_hidden --define neon=true --define openmp=false --define opencl=true --define quantize=true --cpu=arm64-v8a
cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/arm64-v8a/cpu_gpu/ cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/arm64-v8a/cpu_gpu/
echo "build static lib for arm64-v8a + cpu_gpu_apu"
bazel build --config android --config optimization mace/libmace:libmace_static --config symbol_hidden --define neon=true --define openmp=false --define opencl=true --define apu=true --define quantize=true --cpu=arm64-v8a
cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/arm64-v8a/cpu_gpu_apu/
cp third_party/apu/libapu-frontend.so $LIB_DIR/arm64-v8a/cpu_gpu_apu/
echo "build static lib for arm_linux_gnueabihf + cpu_gpu" echo "build static lib for arm_linux_gnueabihf + cpu_gpu"
bazel build --config arm_linux_gnueabihf --config optimization mace/libmace:libmace_static --config symbol_hidden --define neon=true --define openmp=false --define opencl=true --define quantize=true bazel build --config arm_linux_gnueabihf --config optimization mace/libmace:libmace_static --config symbol_hidden --define neon=true --define openmp=false --define opencl=true --define quantize=true
cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/arm_linux_gnueabihf/cpu_gpu/ cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/arm_linux_gnueabihf/cpu_gpu/
...@@ -104,7 +93,7 @@ cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/aarch64_linux_gnu/cpu_gpu/ ...@@ -104,7 +93,7 @@ cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/aarch64_linux_gnu/cpu_gpu/
if [[ "$OSTYPE" != "darwin"* ]];then if [[ "$OSTYPE" != "darwin"* ]];then
echo "build static lib for linux-x86-64" echo "build static lib for linux-x86-64"
bazel build mace/libmace:libmace_static --config optimization --define quantize=true --define openmp=false bazel build mace/libmace:libmace_static --config optimization --define openmp=false
cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/linux-x86-64/ cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/linux-x86-64/
fi fi
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# By default, we don't distinct target and host platfroms. # By default, we don't distinct target and host platfroms.
build --distinct_host_configuration=false build --distinct_host_configuration=false
build -s
build --verbose_failures build --verbose_failures
build --copt=-std=c++11 build --copt=-std=c++11
build --copt=-fPIC build --copt=-fPIC
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# python tools/bazel_adb_run.py \ # python tools/bazel_adb_run.py \
# --target_abis=armeabi-v7a \ # --target_abis=armeabi-v7a \
# --target_socs=sdm845 # --target_socs=sdm845
# --target=//mace/ops:ops_test # --target=//test/ccunit:mace_cc_test
# --stdout_processor=stdout_processor # --stdout_processor=stdout_processor
import argparse import argparse
...@@ -43,22 +43,6 @@ def ops_benchmark_stdout_processor(stdout, dev, abi): ...@@ -43,22 +43,6 @@ def ops_benchmark_stdout_processor(stdout, dev, abi):
for line in stdout_lines: for line in stdout_lines:
if "Aborted" in line or "Segmentation fault" in line: if "Aborted" in line or "Segmentation fault" in line:
raise Exception("Command failed") raise Exception("Command failed")
line = line.strip()
parts = line.split()
if len(parts) == 5 and parts[0].startswith("BM_"):
metrics["%s.time_ms" % parts[0]] = str(float(parts[1]) / 1e6)
metrics["%s.input_mb_per_sec" % parts[0]] = parts[3]
metrics["%s.gmac_per_sec" % parts[0]] = parts[4]
# platform = dev[YAMLKeyword.target_socs]
# model = dev[YAMLKeyword.device_name]
# tags = {
# "ro.board.platform": platform,
# "ro.product.model": model,
# "abi": abi
# }
# sh_commands.falcon_push_metrics(server,
# metrics, tags=tags, endpoint="mace_ops_benchmark")
# TODO: after merge mace/python/tools and tools are merged, # TODO: after merge mace/python/tools and tools are merged,
......
#!/usr/bin/env sh
set -e
# build for arm linux aarch64
BUILD_DIR=cmake-build/aarch64-linux-gnu-full
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DCROSSTOOL_ROOT=${LINARO_AARCH64_LINUX_GNU} \
-DCMAKE_TOOLCHAIN_FILE=../../cmake/toolchains/aarch64-linux-gnu.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=ON \
-DMACE_ENABLE_OPENCL=ON \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android arm64-v8a
BUILD_DIR=cmake-build/android-arm64-v8a-cpu
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DANDROID_ABI="arm64-v8a" \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_NATIVE_API_LEVEL=14 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=OFF \
-DMACE_ENABLE_OPENCL=OFF \
-DMACE_ENABLE_HEXAGON_DSP=OFF \
-DMACE_ENABLE_HEXAGON_HTA=OFF \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android arm64-v8a
BUILD_DIR=cmake-build/android-arm64-v8a-full
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DANDROID_ABI="arm64-v8a" \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_NATIVE_API_LEVEL=28 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=ON \
-DMACE_ENABLE_OPENCL=ON \
-DMACE_ENABLE_HEXAGON_DSP=ON \
-DMACE_ENABLE_HEXAGON_HTA=ON \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android armeabi-v7a
BUILD_DIR=cmake-build/android-armeabi-v7a-cpu
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DANDROID_ABI="armeabi-v7a" \
-DANDROID_ARM_NEON=ON \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_NATIVE_API_LEVEL=14 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=OFF \
-DMACE_ENABLE_OPENCL=OFF \
-DMACE_ENABLE_HEXAGON_DSP=OFF \
-DMACE_ENABLE_HEXAGON_HTA=OFF \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android armeabi-v7a
BUILD_DIR=cmake-build/android-armeabi-v7a-full
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DANDROID_ABI="armeabi-v7a" \
-DANDROID_ARM_NEON=ON \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_NATIVE_API_LEVEL=28 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=ON \
-DMACE_ENABLE_OPENCL=ON \
-DMACE_ENABLE_HEXAGON_DSP=ON \
-DMACE_ENABLE_HEXAGON_HTA=ON \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for arm linux gnueabihf
BUILD_DIR=cmake-build/arm-linux-gnueabihf-full
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DCROSSTOOL_ROOT=${LINARO_ARM_LINUX_GNUEABIHF} \
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/arm-linux-gnueabihf.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=ON \
-DMACE_ENABLE_OPENCL=ON \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for host
BUILD_DIR=cmake-build/host
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DMACE_ENABLE_NEON=OFF \
-DMACE_ENABLE_QUANTIZE=OFF \
-DMACE_ENABLE_OPENCL=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for local host
sh tools/cmake-build-host.sh
# Nuild for Android arm64-v8a with NEON
sh tools/cmake-build-android-arm64-v8a-cpu.sh
# Build for Android arm64-v8a with NEON, Quantize, OpenCL, Hexagon HTA, Hexagon DSP
sh tools/cmake-build-android-arm64-v8a-full.sh
# Nuild for Android armeabi-v7a with NEON
sh tools/cmake-build-android-armeabi-v7a-cpu.sh
# Build for Android armeabi-v7a with NEON, Quantize, OpenCL, Hexagon HTA, Hexagon DSP
sh tools/cmake-build-android-armeabi-v7a-full.sh
# Build for arm-linux-gnueabihf with NEON, Quantize, OpenCL
sh tools/cmake-build-arm-linux-gnueabihf-full.sh
# Build for aarch64-linux-gnu with NEON, Quantize, OpenCL
sh tools/cmake-build-aarch64-linux-gnu-full.sh
...@@ -438,15 +438,15 @@ class SystemType: ...@@ -438,15 +438,15 @@ class SystemType:
PHONE_DATA_DIR = '/data/local/tmp/mace_run' PHONE_DATA_DIR = '/data/local/tmp/mace_run'
DEVICE_DATA_DIR = '/tmp/data/mace_run' DEVICE_DATA_DIR = '/tmp/data/mace_run'
DEVICE_INTERIOR_DIR = PHONE_DATA_DIR + "/interior" DEVICE_INTERIOR_DIR = PHONE_DATA_DIR + "/interior"
BUILD_OUTPUT_DIR = 'builds' BUILD_OUTPUT_DIR = 'build'
BUILD_TMP_DIR_NAME = '_tmp' BUILD_TMP_DIR_NAME = '_tmp'
BUILD_DOWNLOADS_DIR = BUILD_OUTPUT_DIR + '/downloads' BUILD_DOWNLOADS_DIR = BUILD_OUTPUT_DIR + '/downloads'
BUILD_TMP_GENERAL_OUTPUT_DIR_NAME = 'general' BUILD_TMP_GENERAL_OUTPUT_DIR_NAME = 'general'
MODEL_OUTPUT_DIR_NAME = 'model' MODEL_OUTPUT_DIR_NAME = 'model'
EXAMPLE_STATIC_NAME = "example_static" EXAMPLE_STATIC_NAME = "example_static"
EXAMPLE_DYNAMIC_NAME = "example_dynamic" EXAMPLE_DYNAMIC_NAME = "example_dynamic"
EXAMPLE_STATIC_TARGET = "//mace/examples/cli:" + EXAMPLE_STATIC_NAME EXAMPLE_STATIC_TARGET = "//examples/cli:" + EXAMPLE_STATIC_NAME
EXAMPLE_DYNAMIC_TARGET = "//mace/examples/cli:" + EXAMPLE_DYNAMIC_NAME EXAMPLE_DYNAMIC_TARGET = "//examples/cli:" + EXAMPLE_DYNAMIC_NAME
MACE_RUN_STATIC_NAME = "mace_run_static" MACE_RUN_STATIC_NAME = "mace_run_static"
MACE_RUN_DYNAMIC_NAME = "mace_run_dynamic" MACE_RUN_DYNAMIC_NAME = "mace_run_dynamic"
MACE_RUN_STATIC_TARGET = "//mace/tools/validation:" + MACE_RUN_STATIC_NAME MACE_RUN_STATIC_TARGET = "//mace/tools/validation:" + MACE_RUN_STATIC_NAME
...@@ -469,12 +469,12 @@ LIBMACE_SO_TARGET = "//mace/libmace:libmace.so" ...@@ -469,12 +469,12 @@ LIBMACE_SO_TARGET = "//mace/libmace:libmace.so"
LIBMACE_STATIC_TARGET = "//mace/libmace:libmace_static" LIBMACE_STATIC_TARGET = "//mace/libmace:libmace_static"
LIBMACE_STATIC_PATH = "bazel-genfiles/mace/libmace/libmace.a" LIBMACE_STATIC_PATH = "bazel-genfiles/mace/libmace/libmace.a"
MODEL_LIB_TARGET = "//mace/codegen:generated_models" MODEL_LIB_TARGET = "//mace/codegen:generated_models"
MODEL_LIB_PATH = "bazel-genfiles/mace/codegen/libgenerated_models.a" MODEL_LIB_PATH = "bazel-bin/mace/codegen/libgenerated_models.a"
QUANTIZE_STAT_TARGET = "//mace/tools/quantization:quantize_stat" QUANTIZE_STAT_TARGET = "//mace/tools/quantization:quantize_stat"
BM_MODEL_STATIC_NAME = "benchmark_model_static" BM_MODEL_STATIC_NAME = "benchmark_model_static"
BM_MODEL_DYNAMIC_NAME = "benchmark_model_dynamic" BM_MODEL_DYNAMIC_NAME = "benchmark_model_dynamic"
BM_MODEL_STATIC_TARGET = "//mace/benchmark:" + BM_MODEL_STATIC_NAME BM_MODEL_STATIC_TARGET = "//mace/tools/benchmark:" + BM_MODEL_STATIC_NAME
BM_MODEL_DYNAMIC_TARGET = "//mace/benchmark:" + BM_MODEL_DYNAMIC_NAME BM_MODEL_DYNAMIC_TARGET = "//mace/tools/benchmark:" + BM_MODEL_DYNAMIC_NAME
################################ ################################
......
...@@ -949,7 +949,7 @@ def build_example(configs, target_abi, toolchain, enable_openmp, mace_lib_type, ...@@ -949,7 +949,7 @@ def build_example(configs, target_abi, toolchain, enable_openmp, mace_lib_type,
model_lib_path = get_model_lib_output_path(library_name, model_lib_path = get_model_lib_output_path(library_name,
target_abi) target_abi)
sh.cp("-f", model_lib_path, LIB_CODEGEN_DIR) sh.cp("-f", model_lib_path, LIB_CODEGEN_DIR)
build_arg = "--per_file_copt=mace/examples/cli/example.cc@-DMODEL_GRAPH_FORMAT_CODE" # noqa build_arg = "--per_file_copt=examples/cli/example.cc@-DMODEL_GRAPH_FORMAT_CODE" # noqa
if mace_lib_type == MACELibType.dynamic: if mace_lib_type == MACELibType.dynamic:
example_target = EXAMPLE_DYNAMIC_TARGET example_target = EXAMPLE_DYNAMIC_TARGET
...@@ -1064,7 +1064,7 @@ def build_benchmark_model(configs, ...@@ -1064,7 +1064,7 @@ def build_benchmark_model(configs,
mace_check(os.path.exists(ENGINE_CODEGEN_DIR), mace_check(os.path.exists(ENGINE_CODEGEN_DIR),
ModuleName.BENCHMARK, ModuleName.BENCHMARK,
"You should convert model first.") "You should convert model first.")
build_arg = "--per_file_copt=mace/benchmark/benchmark_model.cc@-DMODEL_GRAPH_FORMAT_CODE" # noqa build_arg = "--per_file_copt=mace/tools/benchmark/benchmark_model.cc@-DMODEL_GRAPH_FORMAT_CODE" # noqa
sh_commands.bazel_build(benchmark_target, sh_commands.bazel_build(benchmark_target,
abi=target_abi, abi=target_abi,
......
#!/usr/bin/env sh
set -e
cpplint --linelength=80 --counting=detailed $(find mace -name "*.h" -or -name "*.cc")
cpplint --linelength=80 --counting=detailed --root=include $(find include -name "*.h" -or -name "*.cc")
cpplint --linelength=80 --counting=detailed --root=test/ccutils $(find test/ccutils -name "*.h" -or -name "*.cc")
cpplint --linelength=80 --counting=detailed --root=test/ccunit $(find test/ccunit -name "*.h" -or -name "*.cc")
cpplint --linelength=80 --counting=detailed --root=test/ccbenchmark $(find test/ccbenchmark -name "*.h" -or -name "*.cc")
# 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 @@ ...@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import falcon_cli
import glob import glob
import logging import logging
import numpy as np import numpy as np
...@@ -972,31 +971,3 @@ def build_run_throughput_test(abi, ...@@ -972,31 +971,3 @@ def build_run_throughput_test(abi,
_fg=True) _fg=True)
six.print_("throughput_test done!\n") 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.
先完成此消息的编辑!
想要评论请 注册