diff --git a/.clang-format b/.clang-format new file mode 100755 index 0000000000000000000000000000000000000000..1561c7c138696911adbeeb813b426d2bba4c9b87 --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +BasedOnStyle: google +MaxEmptyLinesToKeep: 3 +DerivePointerAlignment: false +PointerAlignment: Right +BinPackParameters: false diff --git a/.gitignore b/.gitignore index c7866876efb3bf00acc2546207d2393b27efbf6c..35bc30ac45fc5a6b4b801762789a2e75363848c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,29 @@ 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/ +cmake-build/ +cmake-build-debug/ docs/_build/ *.a +.idea/ .vscode/ -builds/ -mace/examples/android/macelibrary/src/main/cpp/mace/ +tags \.project/ *swp *~ +*.pyc .python-version -mace/examples/android/macelibrary/src/main/cpp/include/mace/public/ - -mace/examples/android/macelibrary/src/main/cpp/lib/arm64-v8a/ +mace/codegen/models/ +mace/codegen/opencl/ +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/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b709d57fab731f78fb003ca7297a4afa760767fe..c06216607e7d5fcb4cca24413fe252e34c31e1e6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,35 +1,21 @@ stages: - - cpplint - - pycodestyle - - docs - - platform_compatible_tests - - build_libraries - - ndk_versions_compatible_tests - - ops_test_disable_neon - - ops_test - - api_test - - model_tests - - quantization_tests - - build_android_demo - - ops_benchmark - - extra_tests - - so_size_check - - dynamic_link_test - - python3_test + - linting + - build + - test + - extra cpplint: - stage: cpplint + stage: linting script: - - curl -o cpplint.py https://raw.githubusercontent.com/google/styleguide/gh-pages/cpplint/cpplint.py - - python cpplint.py --linelength=80 --counting=detailed $(find mace -name "*.h" -or -name "*.cc") + - sh tools/cpplint.sh -pycodestyle: - stage: pycodestyle +pylint: + stage: linting script: - pycodestyle $(find -name "*.py") -docs: - stage: docs +build_docs: + stage: build script: - cd docs - make html @@ -46,58 +32,46 @@ docs: paths: - docs/_build -platform_compatible_tests: - stage: platform_compatible_tests +cmake_build_android-armeabi-v7a: + stage: build script: - - bazel build mace/core:core --define openmp=false - - bazel build --config arm_linux_gnueabihf --define openmp=false --define opencl=true --define neon=true //mace/libmace:libmace.so - - bazel build --config aarch64_linux_gnu --define openmp=false --define opencl=true --define neon=true //mace/libmace:libmace.so + - sh tools/cmake-build-android-armeabi-v7a-full.sh + - LIBMACE32_FULL_SIZE=`stat -c%s cmake-build/android-armeabi-v7a-full/install/lib/libmace.so` + - if (( LIBMACE32_FULL_SIZE > 2200000 )) ; then echo "The libmace.so size too large"; exit 1; fi -build_libraries: - stage: build_libraries +cmake_build_android-arm64-v8: + stage: build 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: - stage: ndk_versions_compatible_tests +bazel_build: + stage: build script: - - DEFAULT_NDK_PATH=$ANDROID_NDK_HOME - - prefix_path=${DEFAULT_NDK_PATH%android-ndk-*} - - if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - - > - if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then - GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git - DEVICE_CONF_FILE=generic-mobile-devices/devices.yml - fi - - > - for ndk in android-ndk-r15c android-ndk-r16 android-ndk-r17b; - do - new_ndk_path=${prefix_path}${ndk}; - if [ "$new_ndk_path" != "$DEFAULT_NDK_PATH" ]; then - export ANDROID_NDK_HOME=$new_ndk_path; - export PATH=$ANDROID_NDK_HOME:$PATH; - echo "ndk path: $ANDROID_NDK_HOME"; - python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a --target_socs=$TARGET_SOCS --enable_neon=false --args="--gtest_filter=ActivationOpTest*" || exit 1; - python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a --target_socs=$TARGET_SOCS --args="--gtest_filter=ActivationOpTest*" || exit 1; - python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=arm64-v8a --target_socs=$TARGET_SOCS --args="--gtest_filter=ActivationOpTest*" || exit 1; - fi - done - - export ANDROID_NDK_HOME=$DEFAULT_NDK_PATH - - export PATH=$ANDROID_NDK_HOME:$PATH + - sh tools/bazel-build-standalone-lib.sh + only: + - triggers -ops_test_disable_neon: - stage: ops_test_disable_neon +cmake_build: + stage: build script: - - if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - - > - if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then - GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git - DEVICE_CONF_FILE=generic-mobile-devices/devices.yml - fi - - python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a,arm64 --target_socs=$TARGET_SOCS --enable_neon=false || exit 1; + - sh tools/cmake-build-standalone-lib.sh + only: + - triggers -ops_test: - stage: ops_test +build_android_demo: + 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: - if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - > @@ -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 DEVICE_CONF_FILE=generic-mobile-devices/devices.yml fi - - python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a,arm64 --target_socs=$TARGET_SOCS || exit 1; + - 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: - stage: api_test +mace_cc_benchmark: + stage: test script: - if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - - python tools/bazel_adb_run.py --target="//mace/test:mace_api_test" --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a --target_socs=$TARGET_SOCS || exit 1; - - python tools/bazel_adb_run.py --target="//mace/test:mace_api_mt_test" --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a --target_socs=$TARGET_SOCS || exit 1; - - python tools/bazel_adb_run.py --target="//mace/test:mace_api_exception_test" --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a,arm64-v8a --target_socs=$TARGET_SOCS || exit 1; - - > - if ping -c 1 v9.git.n.xiaomi.com 1>/dev/null 2>&1; then - GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/generic-mobile-devices.git - DEVICE_CONF_FILE=generic-mobile-devices/devices.yml - fi - - python tools/bazel_adb_run.py --target="//mace/test:mace_api_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=arm64 --target_socs=$TARGET_SOCS || exit 1; - - python tools/bazel_adb_run.py --target="//mace/test:mace_api_mt_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=arm64 --target_socs=$TARGET_SOCS || exit 1; - - python tools/bazel_adb_run.py --target="//mace/test:mace_api_exception_test" --device_yml=${DEVICE_CONF_FILE} --run_target=True --stdout_processor=unittest_stdout_processor --target_abis=arm64 --target_socs=$TARGET_SOCS || exit 1; + - 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.*" + only: + - triggers model_tests: - stage: model_tests + stage: test script: - pwd - rm -rf mace-models @@ -137,25 +103,22 @@ model_tests: DEVICE_CONF_FILE=generic-mobile-devices/devices.yml fi - if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - - > - python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file --cl_mem_type=buffer || exit 1; - python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --device_yml=${DEVICE_CONF_FILE} --round=1 --target_abis=armeabi-v7a,arm64 --validate --model_graph_format=file --model_data_format=file || exit 1; - python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --device_yml=${DEVICE_CONF_FILE} --example --target_abis=armeabi-v7a,arm64 --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1; + - 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 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} --example --target_abis=armeabi-v7a,arm64 --round=1 --validate --model_graph_format=file --model_data_format=file - CONF_FILE=mace-models/mobilenet-v2/mobilenet-v2-host.yml - - > - python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file || exit 1; - python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=1 --validate --model_graph_format=file --model_data_format=file --address_sanitizer || exit 1; - python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --example --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1; - python tools/converter.py benchmark --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=5 --model_graph_format=file --model_data_format=file || exit 1; - python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=code --model_data_format=file || exit 1; - python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=1 --validate --model_graph_format=code --model_data_format=file || exit 1; - python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --example --round=1 --validate --model_graph_format=code --model_data_format=file || exit 1; - python tools/converter.py benchmark --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=5 --model_graph_format=code --model_data_format=file || exit 1; - + - python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file + - 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 --example --round=1 --validate --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 + - python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --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 + - 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 benchmark --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=5 --model_graph_format=code --model_data_format=file - rm -rf mace-models quantization_tests: - stage: quantization_tests + stage: test script: - pwd - rm -rf mace-models @@ -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; done - rm -rf mace-models + only: + - triggers -build_android_demo: - stage: build_android_demo - 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 +dynamic_linking_test: + stage: extra script: - pwd - rm -rf mace-models @@ -230,21 +154,8 @@ dynamic_link_test: DEVICE_CONF_FILE=generic-mobile-devices/devices.yml fi - if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - - > - python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file --cl_mem_type=buffer || exit 1; - python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --device_yml=${DEVICE_CONF_FILE} --example --mace_lib_type=dynamic --target_abis=armeabi-v7a,arm64 --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1; + - 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 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 - rm -rf mace-models - -python3_test: - stage: python3_test - script: - - pyenv local 3.6.3 - - rm -rf mace-models - - GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@github.com:XiaoMi/mace-models.git - - CONF_FILE=mace-models/mobilenet-v1/mobilenet-v1.yml - - if [ -z "$TARGET_SOCS" ]; then TARGET_SOCS=random; fi - - > - python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file || exit 1; - python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1; - - python tools/bazel_adb_run.py --target="//mace/ops:ops_test" --run_target=False --stdout_processor=unittest_stdout_processor --target_abis=armeabi-v7a --target_socs=$TARGET_SOCS --validate || exit 1; - - pyenv local 2.7.14 + only: + - triggers diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c29745fe94193518e0d872140adea40d658dce9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,117 @@ +# 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) diff --git a/README.md b/README.md index 5c48b5eefcbea203e4830170b9d847bd4be59a53..3595ce07e41f5eb315b8f4b63b72707e6c3231ba 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ [中文](README_zh.md) **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: * Performance * Runtime is optimized with NEON, OpenCL and Hexagon, and diff --git a/README_zh.md b/README_zh.md index b315f87042a4c6cd3601ad7eca2f9c47b6d288bb..748024342abcbe4ca52822b56fc7d2cea3a7b013 100644 --- a/README_zh.md +++ b/README_zh.md @@ -15,7 +15,7 @@ [加入我们](JOBS.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专门优化,并且采用 diff --git a/WORKSPACE b/WORKSPACE index d7472c7b270b1d22e9db58718ea7a8434ce10a03..e07d66b93229039e6729a1a327689a6288e1c146 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -61,7 +61,6 @@ new_http_archive( strip_prefix = "half-code-356-trunk", urls = [ "https://cnbj1.fds.api.xiaomi.com/mace/third-party/half/half-code-356-trunk.zip", - "https://sourceforge.net/code-snapshots/svn/h/ha/half/code/half-code-356-trunk.zip", ], ) diff --git a/cmake/toolchains/aarch64-linux-gnu.cmake b/cmake/toolchains/aarch64-linux-gnu.cmake new file mode 100644 index 0000000000000000000000000000000000000000..aff7afab190d3a95f825da93cdcbc98fa9cadbbd --- /dev/null +++ b/cmake/toolchains/aarch64-linux-gnu.cmake @@ -0,0 +1,15 @@ +# 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}") diff --git a/cmake/toolchains/arm-linux-gnueabi.cmake b/cmake/toolchains/arm-linux-gnueabi.cmake new file mode 100644 index 0000000000000000000000000000000000000000..809275c89bccdc434977ea079b0f2f0ce7d4d08c --- /dev/null +++ b/cmake/toolchains/arm-linux-gnueabi.cmake @@ -0,0 +1,15 @@ +# 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}") diff --git a/cmake/toolchains/arm-linux-gnueabihf.cmake b/cmake/toolchains/arm-linux-gnueabihf.cmake new file mode 100644 index 0000000000000000000000000000000000000000..9c49d346bcf9517ba4a1e6006aa07bed6d60a1ac --- /dev/null +++ b/cmake/toolchains/arm-linux-gnueabihf.cmake @@ -0,0 +1,15 @@ +# 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}") diff --git a/cmake/toolchains/ios.toolchain.cmake b/cmake/toolchains/ios.toolchain.cmake new file mode 100644 index 0000000000000000000000000000000000000000..df6485b6081d479f3a0094fdc2b74632fab01daa --- /dev/null +++ b/cmake/toolchains/ios.toolchain.cmake @@ -0,0 +1,641 @@ +# 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 ") +set(CMAKE_CXX_CREATE_STATIC_LIBRARY + "${BUILD_LIBTOOL} -static -o ") +# 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) diff --git a/docker/mace-dev-lite/Dockerfile b/docker/mace-dev-lite/Dockerfile index 4169b2c22dd09ddf3d48c1195d4a210159f0d895..29c36b108f4ad87efb5ecefe60318593baba7958 100644 --- a/docker/mace-dev-lite/Dockerfile +++ b/docker/mace-dev-lite/Dockerfile @@ -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} RUN eval "$(pyenv init -)" RUN eval "$(pyenv virtualenv-init -)" -RUN pyenv install 2.7.14 && pyenv install 3.6.3 -RUN pyenv global 2.7.14 +RUN pyenv install 3.6.3 +RUN pyenv global 3.6.3 # Setup vim RUN apt-get install -y --no-install-recommends \ @@ -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} RUN ${ANDROID_HOME}/tools/bin/sdkmanager "cmake;3.6.4111459" -# Download NDK +# Download NDK 19c 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 + wget -q https://dl.google.com/android/repository/android-ndk-r19c-linux-x86_64.zip && \ + unzip -q android-ndk-r19c-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} -# add to PATH -ENV PATH ${PATH}:${ANDROID_NDK_HOME} - # Install tools RUN apt-get install -y --no-install-recommends \ android-tools-adb -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 \ +# fix docker in docker error: `error while loading shared libraries: libltdl.so.7` +# refer to: https://github.com/jenkinsci/docker/issues/506 +RUN apt-get install -y libltdl7 + +RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com --upgrade pip setuptools +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 \ pycodestyle==2.4.0 \ - filelock \ - PTable + filelock==3.0.10 \ + PTable==0.9.2 -# Install Tensorflow -RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \ +RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.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 +RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \ + future==0.17.1 \ + Pillow==5.4.1 \ + torch==1.1.0 \ + torchvision==0.2.2.post3 -# Install ONNX -RUN pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \ +RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \ onnx==1.3.0 \ onnx-tf==1.2.0 -# fix docker in docker error: `error while loading shared libraries: libltdl.so.7` -# refer to: https://github.com/jenkinsci/docker/issues/506 -RUN apt-get install -y libltdl7 +RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \ + cpplint==1.4.4 diff --git a/docker/mace-dev/Dockerfile b/docker/mace-dev/Dockerfile index 6ab7eb43fda0b64674b4541948c64873ab8cbf74..d65627c29294cf31ae950f20c15dfbb4c9469fea 100644 --- a/docker/mace-dev/Dockerfile +++ b/docker/mace-dev/Dockerfile @@ -9,78 +9,75 @@ RUN apt-get install -y --no-install-recommends \ screen \ 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 -# Install tools -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 \ +RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \ sphinx \ sphinx-autobuild \ sphinx_rtd_theme \ recommonmark -RUN pyenv global 2.7.14 -# ============ End installing same deps for python3 ============ - - # Customize vim -RUN mkdir -p ~/.vim/autoload ~/.vim/bundle && \ - curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim -RUN mkdir -p ~/.vim/bundle -RUN cd ~/.vim/bundle && \ - git clone https://github.com/scrooloose/nerdtree.git && \ - git clone https://github.com/vim-syntastic/syntastic.git && \ - 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 +RUN git clone --recursive https://github.com/llhe/vimrc.git && \ + cd vimrc && \ + rm -rf ~/.vim && \ + rm -rf ~/.vimrc && \ + ln -s `pwd`/vim ~/.vim && \ + ln -s `pwd`/vimrc ~/.vimrc + # 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/ && \ update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force && \ rm -f /tmp/cmake-3.11.3-Linux-x86_64.tar.gz -# mace-dev-lite image already included NDK r15c -## Download other NDK r16 +# mace-dev-lite image already included NDK r19c +## Download other NDK r15c +RUN cd /opt/ && \ + wget -q https://dl.google.com/android/repository/android-ndk-r15c-linux-x86_64.zip && \ + unzip -q android-ndk-r15c-linux-x86_64.zip && \ + rm -f android-ndk-r15c-linux-x86_64.zip + +## Download other NDK r16b RUN cd /opt/ && \ - wget -q https://dl.google.com/android/repository/android-ndk-r16-linux-x86_64.zip && \ - unzip -q android-ndk-r16-linux-x86_64.zip && \ - rm -f android-ndk-r16-linux-x86_64.zip + wget -q https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip && \ + unzip -q android-ndk-r16b-linux-x86_64.zip && \ + rm -f android-ndk-r16b-linux-x86_64.zip + ## Download other NDK r17b RUN cd /opt/ && \ wget -q https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip && \ unzip -q android-ndk-r17b-linux-x86_64.zip && \ rm -f android-ndk-r17b-linux-x86_64.zip + +## Download other NDK r18b +RUN cd /opt/ && \ + wget -q https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip && \ + unzip -q android-ndk-r18b-linux-x86_64.zip && \ + rm -f android-ndk-r18b-linux-x86_64.zip + +# Mirror of https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/arm-linux-gnueabihf/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz +RUN cd /opt && \ + wget -q https://cnbj1.fds.api.xiaomi.com/mace/third-party/gcc-linaro/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz && \ + tar xf gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz && \ + rm -rf gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz + +# Mirror of https://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} diff --git a/docker/update_images.sh b/docker/update_images.sh index 1af9564eed966b774a1bc084a983943c9a93f8d0..022cb9efd688a3462f2c895968faea6956d50742 100755 --- a/docker/update_images.sh +++ b/docker/update_images.sh @@ -11,18 +11,16 @@ if [ $BUILD_DIR_NAME != $CURRENT_DIR_NAME ]; then fi # build images -docker build -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite ./mace-dev-lite || exit 1 -docker build -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev ./mace-dev-lite || exit 1 -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/mace-dev-lite ./mace-dev-lite +docker build --network host -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev ./mace-dev +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 # 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 || exit 1 - docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/gitlab-runner || exit 1 + docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite + docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev + docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/gitlab-runner else echo "Login docker registry server is needed!" exit 1 fi - - diff --git a/docs/development/how_to_debug.rst b/docs/development/how_to_debug.rst index 6f73407e0f70c51109f4a8529cb354d930e6ef65..fe3012641f642e23d5230bdafd5fe3aa1b24caf6 100644 --- a/docs/development/how_to_debug.rst +++ b/docs/development/how_to_debug.rst @@ -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. 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 MACE op's output. @@ -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`. 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 diff --git a/docs/development/how_to_run_tests.md b/docs/development/how_to_run_tests.md index 8547c0ce0b773caa14d6956546074c8e1aa11fba..393324298a2359493ef6bcf9d1d6ad3b7704cfd7 100644 --- a/docs/development/how_to_run_tests.md +++ b/docs/development/how_to_run_tests.md @@ -12,10 +12,10 @@ Run 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 - 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 ``` @@ -23,7 +23,7 @@ MACE use [gtest](https://github.com/google/googletest) for unit tests. for example, run `Conv2dOpTest` unit tests: ```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 \ --args="--gtest_filter=Conv2dOpTest*" ``` @@ -34,10 +34,10 @@ Run micro benchmarks MACE provides a micro benchmark framework for performance tuning. * Run all micro benchmarks defined in a Bazel target, for example, run all -`ops_benchmark` micro benchmarks: +`mace_cc_benchmark` micro benchmarks: ```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 ``` @@ -45,7 +45,7 @@ MACE provides a micro benchmark framework for performance tuning. micro benchmarks: ```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 \ --args="--filter=MACE_BM_CONV_2D_.*_GPU" ``` diff --git a/docs/user_guide/advanced_usage.rst b/docs/user_guide/advanced_usage.rst index 8c452d08b93e14c16b6c3b771dec7095a293cf89..7bd27d9640643a729b9f6b869f71c8480bf8cb56 100644 --- a/docs/user_guide/advanced_usage.rst +++ b/docs/user_guide/advanced_usage.rst @@ -204,15 +204,15 @@ Convert model(s) to C++ code 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 - ** *.h ** in **builds/${library_name}/include** like the following dir-tree. + The command will generate **${library_name}.a** in **build/${library_name}/model** directory and + ** *.h ** in **build/${library_name}/include** like the following dir-tree. .. code:: # model_graph_format: code # model_data_format: file - builds + build ├── include │   └── mace │   └── public @@ -225,7 +225,7 @@ Convert model(s) to C++ code # model_graph_format: code # model_data_format: code - builds + build ├── include │   └── mace │   └── public @@ -305,11 +305,11 @@ Tuning for specific SoC's GPU 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:: - builds + build └── mobilenet-v2 ├── model │   ├── mobilenet_v2.data diff --git a/docs/user_guide/basic_usage.rst b/docs/user_guide/basic_usage.rst index da7e1598c6814da70c60bbd2cac657c21d86cca8..3ec5886ef8836671c39600d20e227f78ac2903b6 100644 --- a/docs/user_guide/basic_usage.rst +++ b/docs/user_guide/basic_usage.rst @@ -44,17 +44,17 @@ Here we use the mobilenet-v2 model as an example. cd path/to/mace # Build library - # output lib path: builds/lib - bash tools/build-standalone-lib.sh + # output lib path: build/lib + bash tools/bazel-build-standalone-lib.sh .. note:: - 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. @@ -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 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:: @@ -188,10 +188,10 @@ Or use bazel to build MACE source code into a library. cd path/to/mace # Build library - # output lib path: builds/lib - bash tools/build-standalone-lib.sh + # output lib path: build/lib + 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:: @@ -278,7 +278,7 @@ header files. .. code:: - builds + build ├── include │   └── mace │   └── public diff --git a/docs/user_guide/benchmark.rst b/docs/user_guide/benchmark.rst index a190a7cc4443a8c8e9147bcd91dd8f765c43268d..7992c70f06375c9fc89ca64622a7ecf686d7ef67 100644 --- a/docs/user_guide/benchmark.rst +++ b/docs/user_guide/benchmark.rst @@ -20,7 +20,7 @@ Usage .. 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 diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..24b69cd3ea02f2b2a63bec9e98c0797957569cbf --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,10 @@ +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) diff --git a/mace/examples/android/.gitignore b/examples/android/.gitignore similarity index 100% rename from mace/examples/android/.gitignore rename to examples/android/.gitignore diff --git a/mace/examples/android/README.md b/examples/android/README.md similarity index 100% rename from mace/examples/android/README.md rename to examples/android/README.md diff --git a/mace/examples/android/app/.gitignore b/examples/android/app/.gitignore similarity index 100% rename from mace/examples/android/app/.gitignore rename to examples/android/app/.gitignore diff --git a/mace/examples/android/app/build.gradle b/examples/android/app/build.gradle similarity index 100% rename from mace/examples/android/app/build.gradle rename to examples/android/app/build.gradle diff --git a/mace/examples/android/app/mace_demo.jks b/examples/android/app/mace_demo.jks similarity index 100% rename from mace/examples/android/app/mace_demo.jks rename to examples/android/app/mace_demo.jks diff --git a/mace/examples/android/app/src/main/AndroidManifest.xml b/examples/android/app/src/main/AndroidManifest.xml similarity index 100% rename from mace/examples/android/app/src/main/AndroidManifest.xml rename to examples/android/app/src/main/AndroidManifest.xml diff --git a/mace/examples/android/app/src/main/assets/cacheLabel.txt b/examples/android/app/src/main/assets/cacheLabel.txt similarity index 100% rename from mace/examples/android/app/src/main/assets/cacheLabel.txt rename to examples/android/app/src/main/assets/cacheLabel.txt diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/AppModel.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/AppModel.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/AppModel.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/AppModel.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/CameraActivity.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/CameraActivity.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/CameraActivity.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/CameraActivity.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/CameraFactory.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/CameraFactory.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/CameraFactory.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/CameraFactory.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/Constant.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/Constant.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/Constant.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/Constant.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/MaceApp.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/MaceApp.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/MaceApp.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/MaceApp.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiLessM.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiLessM.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiLessM.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiLessM.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiMoreM.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiMoreM.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiMoreM.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiMoreM.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraEngage.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraEngage.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraEngage.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraEngage.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraTextureView.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraTextureView.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraTextureView.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraTextureView.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/ContextMenuDialog.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/ContextMenuDialog.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/ContextMenuDialog.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/ContextMenuDialog.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/ItemAdapter.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/ItemAdapter.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/ItemAdapter.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/ItemAdapter.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/MessageEvent.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/MessageEvent.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/MessageEvent.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/MessageEvent.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/MobilenetResultCallback.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/MobilenetResultCallback.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/MobilenetResultCallback.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/MobilenetResultCallback.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/result/InitData.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/result/InitData.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/result/InitData.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/result/InitData.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/result/LabelCache.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/result/LabelCache.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/result/LabelCache.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/result/LabelCache.java diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/result/ResultData.java b/examples/android/app/src/main/java/com/xiaomi/mace/demo/result/ResultData.java similarity index 100% rename from mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/result/ResultData.java rename to examples/android/app/src/main/java/com/xiaomi/mace/demo/result/ResultData.java diff --git a/mace/examples/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/examples/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml similarity index 100% rename from mace/examples/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml rename to examples/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml diff --git a/mace/examples/android/app/src/main/res/drawable/ic_launcher_background.xml b/examples/android/app/src/main/res/drawable/ic_launcher_background.xml similarity index 100% rename from mace/examples/android/app/src/main/res/drawable/ic_launcher_background.xml rename to examples/android/app/src/main/res/drawable/ic_launcher_background.xml diff --git a/mace/examples/android/app/src/main/res/layout/activity_camera.xml b/examples/android/app/src/main/res/layout/activity_camera.xml similarity index 100% rename from mace/examples/android/app/src/main/res/layout/activity_camera.xml rename to examples/android/app/src/main/res/layout/activity_camera.xml diff --git a/mace/examples/android/app/src/main/res/layout/layout_dialog.xml b/examples/android/app/src/main/res/layout/layout_dialog.xml similarity index 100% rename from mace/examples/android/app/src/main/res/layout/layout_dialog.xml rename to examples/android/app/src/main/res/layout/layout_dialog.xml diff --git a/mace/examples/android/app/src/main/res/layout/layout_item.xml b/examples/android/app/src/main/res/layout/layout_item.xml similarity index 100% rename from mace/examples/android/app/src/main/res/layout/layout_item.xml rename to examples/android/app/src/main/res/layout/layout_item.xml diff --git a/mace/examples/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/examples/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml rename to examples/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/mace/examples/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/examples/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml rename to examples/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml diff --git a/mace/examples/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/examples/android/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to examples/android/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/mace/examples/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/examples/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png rename to examples/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png diff --git a/mace/examples/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/examples/android/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to examples/android/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/mace/examples/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/examples/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png rename to examples/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png diff --git a/mace/examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/mace/examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png rename to examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png diff --git a/mace/examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/mace/examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png rename to examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png diff --git a/mace/examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/mace/examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png similarity index 100% rename from mace/examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png rename to examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png diff --git a/mace/examples/android/app/src/main/res/values/colors.xml b/examples/android/app/src/main/res/values/colors.xml similarity index 100% rename from mace/examples/android/app/src/main/res/values/colors.xml rename to examples/android/app/src/main/res/values/colors.xml diff --git a/mace/examples/android/app/src/main/res/values/strings.xml b/examples/android/app/src/main/res/values/strings.xml similarity index 100% rename from mace/examples/android/app/src/main/res/values/strings.xml rename to examples/android/app/src/main/res/values/strings.xml diff --git a/mace/examples/android/app/src/main/res/values/styles.xml b/examples/android/app/src/main/res/values/styles.xml similarity index 100% rename from mace/examples/android/app/src/main/res/values/styles.xml rename to examples/android/app/src/main/res/values/styles.xml diff --git a/mace/examples/android/build.gradle b/examples/android/build.gradle similarity index 100% rename from mace/examples/android/build.gradle rename to examples/android/build.gradle diff --git a/mace/examples/android/build.sh b/examples/android/build.sh similarity index 81% rename from mace/examples/android/build.sh rename to examples/android/build.sh index c1bf9cbbc0627e38f876449dc5d8e92e7ae0f6a7..e941ad32f32db4c9ee4c3b882ac9d7e08afef68f 100755 --- a/mace/examples/android/build.sh +++ b/examples/android/build.sh @@ -20,12 +20,12 @@ fi MACE_LINK_TYPE=$1 -pushd ../../../ +pushd ../.. TARGET_ABI=arm64-v8a -ANDROID_DEMO_DIR=mace/examples/android/ +ANDROID_DEMO_DIR=examples/android/ 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/ LIBGNUSTL_SHARED_SO=libgnustl_shared.so LIBCPP_SHARED_SO=libc++_shared.so @@ -44,20 +44,17 @@ else exit 1 fi -rm -rf $LIBRARY_DIR/include/ -mkdir -p $INCLUDE_DIR - -rm -rf $LIBRARY_DIR/lib/ -mkdir -p $LIBMACE_DIR +python tools/converter.py convert --config=examples/android/mobilenet.yml --target_abis=$TARGET_ABI +rm -rf $INCLUDE_DIR && mkdir -p $INCLUDE_DIR +rm -rf $LIBMACE_DIR && mkdir -p $LIBMACE_DIR rm -rf $LIBRARY_DIR/model/ -python tools/converter.py convert --config=mace/examples/android/mobilenet.yml --target_abis=$TARGET_ABI -cp -rf builds/mobilenet/include/mace/public/*.h $INCLUDE_DIR -cp -rf builds/mobilenet/model $LIBRARY_DIR +cp -rf include/mace $INCLUDE_DIR +cp -rf build/mobilenet/include/mace/public/*.h $INCLUDE_DIR/mace/public/ +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 -cp -rf mace/public/*.h $INCLUDE_DIR cp -rf $BAZEL_GEN_LIBMACE_PATH $LIBMACE_DIR if [ $MACE_LINK_TYPE == "dynamic" ]; then diff --git a/mace/examples/android/gradle.properties b/examples/android/gradle.properties similarity index 100% rename from mace/examples/android/gradle.properties rename to examples/android/gradle.properties diff --git a/mace/examples/android/gradle/wrapper/gradle-wrapper.jar b/examples/android/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from mace/examples/android/gradle/wrapper/gradle-wrapper.jar rename to examples/android/gradle/wrapper/gradle-wrapper.jar diff --git a/mace/examples/android/gradle/wrapper/gradle-wrapper.properties b/examples/android/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from mace/examples/android/gradle/wrapper/gradle-wrapper.properties rename to examples/android/gradle/wrapper/gradle-wrapper.properties diff --git a/mace/examples/android/gradlew b/examples/android/gradlew similarity index 100% rename from mace/examples/android/gradlew rename to examples/android/gradlew diff --git a/mace/examples/android/gradlew.bat b/examples/android/gradlew.bat similarity index 100% rename from mace/examples/android/gradlew.bat rename to examples/android/gradlew.bat diff --git a/mace/examples/android/macelibrary/.gitignore b/examples/android/macelibrary/.gitignore similarity index 100% rename from mace/examples/android/macelibrary/.gitignore rename to examples/android/macelibrary/.gitignore diff --git a/mace/examples/android/macelibrary/CMakeLists.txt b/examples/android/macelibrary/CMakeLists.txt similarity index 97% rename from mace/examples/android/macelibrary/CMakeLists.txt rename to examples/android/macelibrary/CMakeLists.txt index d91f77371381b1881cb96fbc5bfd5a2e56178f2f..be8fbca62c2f4cfe2a7e2e7b96b2dd08a67835e4 100644 --- a/mace/examples/android/macelibrary/CMakeLists.txt +++ b/examples/android/macelibrary/CMakeLists.txt @@ -13,6 +13,7 @@ cmake_minimum_required(VERSION 3.4.1) #set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../app/libs/${ANDROID_ABI}) include_directories(${CMAKE_SOURCE_DIR}/) +include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp) include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/include) file(GLOB LIBMACE "${CMAKE_SOURCE_DIR}/src/main/cpp/lib/arm64-v8a/*") set(mace_lib ${LIBMACE}) diff --git a/mace/examples/android/macelibrary/build.gradle b/examples/android/macelibrary/build.gradle similarity index 100% rename from mace/examples/android/macelibrary/build.gradle rename to examples/android/macelibrary/build.gradle diff --git a/mace/examples/android/macelibrary/proguard-rules.pro b/examples/android/macelibrary/proguard-rules.pro similarity index 100% rename from mace/examples/android/macelibrary/proguard-rules.pro rename to examples/android/macelibrary/proguard-rules.pro diff --git a/mace/examples/android/macelibrary/src/main/AndroidManifest.xml b/examples/android/macelibrary/src/main/AndroidManifest.xml similarity index 100% rename from mace/examples/android/macelibrary/src/main/AndroidManifest.xml rename to examples/android/macelibrary/src/main/AndroidManifest.xml diff --git a/mace/examples/android/macelibrary/src/main/cpp/image_classify.cc b/examples/android/macelibrary/src/main/cpp/image_classify.cc similarity index 98% rename from mace/examples/android/macelibrary/src/main/cpp/image_classify.cc rename to examples/android/macelibrary/src/main/cpp/image_classify.cc index f3aac339dc957f33432e7036e86c19a2951bfbfa..760030709f5ab900cd12b9196afb3d3fdeaba4a3 100755 --- a/mace/examples/android/macelibrary/src/main/cpp/image_classify.cc +++ b/examples/android/macelibrary/src/main/cpp/image_classify.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/main/cpp/image_classify.h" +#include "image_classify.h" #include #include @@ -25,9 +25,8 @@ #include #include -#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_engine_factory.h" namespace { diff --git a/mace/examples/android/macelibrary/src/main/cpp/image_classify.h b/examples/android/macelibrary/src/main/cpp/image_classify.h similarity index 100% rename from mace/examples/android/macelibrary/src/main/cpp/image_classify.h rename to examples/android/macelibrary/src/main/cpp/image_classify.h diff --git a/mace/examples/android/macelibrary/src/main/java/com/xiaomi/mace/JniMaceUtils.java b/examples/android/macelibrary/src/main/java/com/xiaomi/mace/JniMaceUtils.java similarity index 100% rename from mace/examples/android/macelibrary/src/main/java/com/xiaomi/mace/JniMaceUtils.java rename to examples/android/macelibrary/src/main/java/com/xiaomi/mace/JniMaceUtils.java diff --git a/mace/examples/android/macelibrary/src/main/res/values/strings.xml b/examples/android/macelibrary/src/main/res/values/strings.xml similarity index 100% rename from mace/examples/android/macelibrary/src/main/res/values/strings.xml rename to examples/android/macelibrary/src/main/res/values/strings.xml diff --git a/mace/examples/android/macelibrary/version_script.lds b/examples/android/macelibrary/version_script.lds similarity index 100% rename from mace/examples/android/macelibrary/version_script.lds rename to examples/android/macelibrary/version_script.lds diff --git a/mace/examples/android/mobilenet.yml b/examples/android/mobilenet.yml similarity index 100% rename from mace/examples/android/mobilenet.yml rename to examples/android/mobilenet.yml diff --git a/mace/examples/android/settings.gradle b/examples/android/settings.gradle similarity index 100% rename from mace/examples/android/settings.gradle rename to examples/android/settings.gradle diff --git a/mace/examples/cli/BUILD.bazel b/examples/cli/BUILD.bazel similarity index 91% rename from mace/examples/cli/BUILD.bazel rename to examples/cli/BUILD.bazel index edd9170d56399309c71b183f44e21ebffe7b3c6d..ce3c1ea79b3eaca2a39b31caca7bd2d7bc058407 100644 --- a/mace/examples/cli/BUILD.bazel +++ b/examples/cli/BUILD.bazel @@ -35,8 +35,8 @@ cc_binary( deps = [ "//external:gflags_nothreads", "//mace/codegen:generated_mace_engine_factory", - "//mace/codegen:generated_libmace", - "//mace/utils:utils_hdrs", + "//mace/codegen:generated_models", + "//mace/libmace", ] + if_opencl_enabled([ "//mace/codegen:generated_opencl_binary", "//mace/codegen:generated_opencl_parameter", @@ -70,9 +70,9 @@ cc_binary( linkstatic = 0, deps = [ "//external:gflags_nothreads", - "//mace/codegen:generated_libmace", "//mace/codegen:generated_mace_engine_factory", - "//mace/utils:utils_hdrs", + "//mace/codegen:generated_models", + "//mace/libmace:libmace_dynamic", ] + if_opencl_enabled([ "//mace/codegen:generated_opencl_binary", "//mace/codegen:generated_opencl_parameter", diff --git a/mace/examples/cli/README.md b/examples/cli/README.md similarity index 100% rename from mace/examples/cli/README.md rename to examples/cli/README.md diff --git a/mace/examples/cli/example.cc b/examples/cli/example.cc similarity index 97% rename from mace/examples/cli/example.cc rename to examples/cli/example.cc index 054231e9b23bdb321ec36608f87bb7e665ffb651..103138447cea0ed7a54f8374e88c4cdb0e69ca92 100644 --- a/mace/examples/cli/example.cc +++ b/examples/cli/example.cc @@ -102,17 +102,20 @@ DEFINE_string(model_name, "", "model name in model deployment file"); 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, - "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, "output_node0,output_node1", "output nodes, separated by comma"); 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, "NHWC", "input data formats, NONE|NHWC|NCHW"); diff --git a/include/BUILD.bazel b/include/BUILD.bazel new file mode 100644 index 0000000000000000000000000000000000000000..a1e929d11a60da1bb01076ff5d196e42a0ae23c4 --- /dev/null +++ b/include/BUILD.bazel @@ -0,0 +1,16 @@ +package( + default_visibility = ["//visibility:public"], +) + +licenses(["notice"]) # Apache 2.0 + +cc_library( + name = "public_headers", + hdrs = glob([ + "mace/public/*.h", + "mace/port/*.h", + "mace/utils/*.h", + ]), + strip_include_prefix = "", + copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], +) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..643cc03ed47f4e73ae4855777419099fb2d99b8c --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1 @@ +install(DIRECTORY mace DESTINATION include) diff --git a/mace/port/env.h b/include/mace/port/env.h similarity index 56% rename from mace/port/env.h rename to include/mace/port/env.h index af98cc5a5bc61e40fdc52edc04376aac80c2f740..7ac060d713ccf71b8563722b5a7eb56fea435dee 100644 --- a/mace/port/env.h +++ b/include/mace/port/env.h @@ -16,11 +16,18 @@ #define MACE_PORT_ENV_H_ #include +#include #include #include #include #include +#ifdef _WIN32 +#include +#endif + +#include + #include "mace/public/mace.h" namespace mace { @@ -38,6 +45,7 @@ class LogWriter; class Env { public: virtual int64_t NowMicros() = 0; + virtual MaceStatus AdviseFree(void *addr, size_t length); virtual MaceStatus GetCPUMaxFreq(std::vector *max_freqs); virtual MaceStatus SchedSetAffinity(const std::vector &cpu_ids); virtual FileSystem *GetFileSystem() = 0; @@ -58,6 +66,10 @@ inline int64_t NowMicros() { return port::Env::Default()->NowMicros(); } +inline MaceStatus AdviseFree(void *addr, size_t length) { + return port::Env::Default()->AdviseFree(addr, length); +} + inline MaceStatus GetCPUMaxFreq(std::vector *max_freqs) { return port::Env::Default()->GetCPUMaxFreq(max_freqs); } @@ -70,6 +82,63 @@ inline port::FileSystem *GetFileSystem() { return port::Env::Default()->GetFileSystem(); } +inline MaceStatus Memalign(void **memptr, size_t alignment, size_t size) { +#ifdef _WIN32 + *memptr = _aligned_malloc(size, alignment); + if (*memptr == nullptr) { + return MaceStatus::MACE_OUT_OF_RESOURCES; + } else { + return MaceStatus::MACE_SUCCESS; + } +#else +#if defined(__ANDROID__) || defined(__hexagon__) + *memptr = memalign(alignment, size); + if (*memptr == nullptr) { + return MaceStatus::MACE_OUT_OF_RESOURCES; + } else { + return MaceStatus::MACE_SUCCESS; + } +#else + int error = posix_memalign(memptr, alignment, size); + if (error != 0) { + if (*memptr != nullptr) { + free(*memptr); + *memptr = nullptr; + } + return MaceStatus::MACE_OUT_OF_RESOURCES; + } else { + return MaceStatus::MACE_SUCCESS; + } +#endif +#endif +} + +inline MaceStatus GetEnv(const char *name, std::string *value) { +#ifdef _WIN32 + char *val; + size_t len; + errno_t error = _dupenv_s(&val, &len, name); + if (error != 0) { + return MaceStatus::MACE_RUNTIME_ERROR; + } else { + 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 #endif // MACE_PORT_ENV_H_ diff --git a/mace/port/file_system.h b/include/mace/port/file_system.h similarity index 78% rename from mace/port/file_system.h rename to include/mace/port/file_system.h index 8ef35de85c62f4b4176c186a8dcb0a9eeaa6dee5..4de18fbbb90a0d9a89c63063ae38c287ebc9eaad 100644 --- a/mace/port/file_system.h +++ b/include/mace/port/file_system.h @@ -19,6 +19,7 @@ #include #include "mace/public/mace.h" +#include "mace/utils/macros.h" namespace mace { namespace port { @@ -29,6 +30,8 @@ class ReadOnlyMemoryRegion { virtual ~ReadOnlyMemoryRegion() = default; virtual const void *data() const = 0; virtual uint64_t length() const = 0; + private: + MACE_DISABLE_COPY_AND_ASSIGN(ReadOnlyMemoryRegion); }; class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion { @@ -44,12 +47,25 @@ class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion { uint64_t length_; }; +class WritableFile { + public: + WritableFile() {} + virtual ~WritableFile(); + virtual MaceStatus Append(const char *data, size_t length) = 0; + virtual MaceStatus Close() = 0; + virtual MaceStatus Flush() = 0; + private: + MACE_DISABLE_COPY_AND_ASSIGN(WritableFile); +}; + class FileSystem { public: FileSystem() = default; virtual ~FileSystem() = default; virtual MaceStatus NewReadOnlyMemoryRegionFromFile(const char *fname, std::unique_ptr* result) = 0; + virtual MaceStatus NewWritableFile(const char *fname, + std::unique_ptr* result); }; } // namespace port diff --git a/mace/port/logger.h b/include/mace/port/logger.h similarity index 100% rename from mace/port/logger.h rename to include/mace/port/logger.h diff --git a/mace/port/port-arch.h b/include/mace/port/port-arch.h similarity index 100% rename from mace/port/port-arch.h rename to include/mace/port/port-arch.h diff --git a/mace/port/port.h b/include/mace/port/port.h similarity index 100% rename from mace/port/port.h rename to include/mace/port/port.h diff --git a/mace/public/mace.h b/include/mace/public/mace.h similarity index 98% rename from mace/public/mace.h rename to include/mace/public/mace.h index cb4c4b2d8d4ef5e621c5ec97f00d615ce88c0bb4..be9bcf6f5c7a2c5d7acbaa380d609fc6807b86a6 100644 --- a/mace/public/mace.h +++ b/include/mace/public/mace.h @@ -25,8 +25,20 @@ #include #ifndef MACE_API +#ifdef _MSC_VER +#define MACE_API +#else #define MACE_API __attribute__((visibility("default"))) #endif +#endif + +#ifndef MACE_DEPRECATED +#ifdef _MSC_VER +#define MACE_DEPRECATED +#else +#define MACE_DEPRECATED __attribute__((deprecated)) +#endif +#endif namespace mace { @@ -435,7 +447,8 @@ MACE_API MaceStatus CreateMaceEngineFromProto( const std::vector &input_nodes, const std::vector &output_nodes, const MaceEngineConfig &config, - std::shared_ptr *engine) __attribute__((deprecated)); + std::shared_ptr *engine) MACE_DEPRECATED; + } // namespace mace diff --git a/mace/utils/logging.h b/include/mace/utils/logging.h similarity index 90% rename from mace/utils/logging.h rename to include/mace/utils/logging.h index a935105a43e4ebe525a3f5100206e5fb1fd3d16f..57fddc928206732e1614fcd638b011b8d7b99f14 100644 --- a/mace/utils/logging.h +++ b/include/mace/utils/logging.h @@ -75,6 +75,15 @@ T &&CheckNotNull(const char *file, int line, const char *exprtext, T &&t) { #define MACE_NOT_IMPLEMENTED MACE_CHECK(false, "not implemented") +#define MACE_CHECK_SUCCESS(stmt) \ + { \ + MaceStatus status = (stmt); \ + if (status != MaceStatus::MACE_SUCCESS) { \ + LOG(FATAL) << #stmt << " failed with error: " \ + << status.information(); \ + } \ + } + #define MACE_RETURN_IF_ERROR(stmt) \ { \ MaceStatus status = (stmt); \ diff --git a/mace/utils/macros.h b/include/mace/utils/macros.h similarity index 100% rename from mace/utils/macros.h rename to include/mace/utils/macros.h diff --git a/mace/utils/memory.h b/include/mace/utils/memory.h similarity index 100% rename from mace/utils/memory.h rename to include/mace/utils/memory.h diff --git a/mace/utils/string_util.h b/include/mace/utils/string_util.h similarity index 100% rename from mace/utils/string_util.h rename to include/mace/utils/string_util.h diff --git a/mace/CMakeLists.txt b/mace/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..45ba1b67015d5dd0efe03af23f53fc5d04a36bc4 --- /dev/null +++ b/mace/CMakeLists.txt @@ -0,0 +1,8 @@ +add_subdirectory(codegen) +add_subdirectory(core) +add_subdirectory(libmace) +add_subdirectory(ops) +add_subdirectory(port) +add_subdirectory(proto) +add_subdirectory(tools) +add_subdirectory(utils) diff --git a/mace/codegen/BUILD.bazel b/mace/codegen/BUILD.bazel index 2aaf28fa13109be44b915c5236f0dce2b15de526..0e5bad98a70cfdb6ebe37fc8112c535ef0ca6e8b 100644 --- a/mace/codegen/BUILD.bazel +++ b/mace/codegen/BUILD.bazel @@ -8,26 +8,19 @@ package( load("//mace:mace.bzl", "mace_version_genrule", "encrypt_opencl_kernel_genrule") cc_library( - name = "libmodels", + name = "generated_models", srcs = glob(["models/*/*.cc"]), hdrs = glob(["models/*/*.h"]), - copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], + copts = [ + "-Werror", + "-Wextra", + "-Wno-missing-field-initializers", + ], deps = [ "//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() encrypt_opencl_kernel_genrule() @@ -35,39 +28,52 @@ encrypt_opencl_kernel_genrule() cc_library( name = "generated_opencl", srcs = ["opencl/encrypt_opencl_kernel.cc"], - copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], + copts = [ + "-Werror", + "-Wextra", + "-Wno-missing-field-initializers", + ], ) cc_library( name = "generated_opencl_binary", srcs = ["opencl/opencl_binary.cc"], - copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], + copts = [ + "-Werror", + "-Wextra", + "-Wno-missing-field-initializers", + ], ) cc_library( name = "generated_opencl_parameter", srcs = ["opencl/opencl_parameter.cc"], - copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], + copts = [ + "-Werror", + "-Wextra", + "-Wno-missing-field-initializers", + ], ) cc_library( name = "generated_version", srcs = ["version/version.cc"], - copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], + copts = [ + "-Werror", + "-Wextra", + "-Wno-missing-field-initializers", + ], ) cc_library( name = "generated_mace_engine_factory", hdrs = glob(["engine/*.h"]), - copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], + copts = [ + "-Werror", + "-Wextra", + "-Wno-missing-field-initializers", + ], deps = [ - "//mace/public", + "//include:public_headers", ], ) - -cc_library( - name = "generated_libmace", - srcs = glob(["lib/*"]), - linkstatic = 1, - visibility = ["//visibility:public"], -) diff --git a/mace/codegen/CMakeLists.txt b/mace/codegen/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea9a0ed9db66dbb7e072c93e17e8dafd34251f53 --- /dev/null +++ b/mace/codegen/CMakeLists.txt @@ -0,0 +1,33 @@ +# 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) diff --git a/mace/tools/git/gen_version_source.sh b/mace/codegen/tools/gen_version_source.sh old mode 100644 new mode 100755 similarity index 87% rename from mace/tools/git/gen_version_source.sh rename to mace/codegen/tools/gen_version_source.sh index 5fd8c721333089904f8cf38578ac26489b6de33c..28a29848fdc6089797e1a9b84d620591b697cf23 --- a/mace/tools/git/gen_version_source.sh +++ b/mace/codegen/tools/gen_version_source.sh @@ -13,29 +13,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -MACE_SOURCE_DIR=$(dirname $(dirname $(dirname $(dirname $0)))) - OUTPUT_FILENAME=$1 -if [[ -z "${OUTPUT_FILENAME}}" ]]; then +if [[ -z "${OUTPUT_FILENAME}" ]]; then echo "Usage: $0 " exit 1 fi -OUTPUT_DIR=$(dirname $OUTPUT_FILENAME) -if [ -d $OUTPUT_DIR ]; then - rm -rf $OUTPUT_DIR -fi - -mkdir -p $OUTPUT_DIR +mkdir -p $(dirname $OUTPUT_FILENAME) +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) + if [[ $? != 0 ]]; then - GIT_VERSION=unknown + GIT_VERSION=$(git describe --long --tags) + if [[ $? != 0 ]]; then + GIT_VERSION=unknown + fi else GIT_VERSION=${GIT_VERSION} fi -echo $GIT_VERSION +echo write version $GIT_VERSION to ${OUTPUT_FILENAME} cat < ${OUTPUT_FILENAME} // Copyright 2018 The MACE Authors. All Rights Reserved. @@ -55,7 +53,9 @@ cat < ${OUTPUT_FILENAME} // This is a generated file. DO NOT EDIT! namespace mace { +#ifndef _MSC_VER __attribute__((visibility("default"))) +#endif const char *MaceVersion() { return "MACEVER-${GIT_VERSION}" + 8; } } // namespace mace EOF diff --git a/mace/core/BUILD.bazel b/mace/core/BUILD.bazel index bd03b19b33a2ee832b3d1fd19d4c84c630c1a474..f9cc96970974706e491ece91a0d0700b08b8c9d7 100644 --- a/mace/core/BUILD.bazel +++ b/mace/core/BUILD.bazel @@ -1,6 +1,3 @@ -# Description: -# Mace core. -# package( default_visibility = ["//visibility:public"], ) @@ -30,9 +27,6 @@ cc_library( "*.cc", "runtime/cpu/*.cc", ], - exclude = [ - "*_test.cc", - ], ) + if_opencl_enabled(glob( [ "runtime/opencl/*.cc", @@ -118,28 +112,3 @@ cc_library( "@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", - ], -) diff --git a/mace/core/CMakeLists.txt b/mace/core/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e4b3a0e06d9ea1ebb35b062b113bec91dd1d833c --- /dev/null +++ b/mace/core/CMakeLists.txt @@ -0,0 +1,62 @@ +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) diff --git a/mace/core/allocator.cc b/mace/core/allocator.cc index b5bffabc60fd77ef4b270fb2f68fb33fc3c8af8f..003b1c2c02e2907651c56193180439a08223f97a 100644 --- a/mace/core/allocator.cc +++ b/mace/core/allocator.cc @@ -14,10 +14,6 @@ #include "mace/core/allocator.h" -#include -#include -#include - namespace mace { Allocator *GetCPUAllocator() { @@ -25,22 +21,4 @@ Allocator *GetCPUAllocator() { return &allocator; } -void AdviseFree(void *addr, size_t length) { - int page_size = sysconf(_SC_PAGESIZE); - void *addr_aligned = - reinterpret_cast( - (reinterpret_cast(addr) + page_size - 1) - & (~(page_size - 1))); - uintptr_t delta = - reinterpret_cast(addr_aligned) - - reinterpret_cast(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 diff --git a/mace/core/allocator.h b/mace/core/allocator.h index c7499b92b51053436e61edabf4c93069c93f7a81..66987c46791d6500fa654a65afecbaea4800b16c 100644 --- a/mace/core/allocator.h +++ b/mace/core/allocator.h @@ -74,32 +74,9 @@ class CPUAllocator : public Allocator { return MaceStatus::MACE_OUT_OF_RESOURCES; } - void *data = nullptr; -#if defined(__ANDROID__) || defined(__hexagon__) - data = memalign(kMaceAlignment, nbytes); - if (data == NULL) { - LOG(WARNING) << "Allocate CPU Buffer with " - << nbytes << " bytes failed because of" - << strerror(errno); - *result = nullptr; - return MaceStatus::MACE_OUT_OF_RESOURCES; - } -#else - int ret = posix_memalign(&data, kMaceAlignment, nbytes); - if (ret != 0) { - LOG(WARNING) << "Allocate CPU Buffer with " - << nbytes << " bytes failed because of" - << strerror(errno); - if (data != NULL) { - free(data); - } - *result = nullptr; - return MaceStatus::MACE_OUT_OF_RESOURCES; - } -#endif + MACE_RETURN_IF_ERROR(Memalign(result, kMaceAlignment, nbytes)); // TODO(heliangliang) This should be avoided sometimes - memset(data, 0, nbytes); - *result = data; + memset(*result, 0, nbytes); return MaceStatus::MACE_SUCCESS; } @@ -143,8 +120,6 @@ class CPUAllocator : public Allocator { // Global CPU allocator used for CPU/GPU/DSP Allocator *GetCPUAllocator(); -void AdviseFree(void *addr, size_t length); - } // namespace mace #endif // MACE_CORE_ALLOCATOR_H_ diff --git a/mace/core/device_context.cc b/mace/core/device_context.cc index c68fd83f86c54341dc0319fd3aaedc7d6ddd5fb9..4da67d069925fbcb21eee347e9b08e158885f609 100644 --- a/mace/core/device_context.cc +++ b/mace/core/device_context.cc @@ -16,6 +16,8 @@ #include +#include "mace/port/env.h" + namespace mace { namespace { diff --git a/mace/core/kv_storage.cc b/mace/core/kv_storage.cc index e2feb8c827b5939098eb0b7d3a451b1ad62b44a6..9ff49688e29bc17f09d51692c0d4bcc683ba5223 100644 --- a/mace/core/kv_storage.cc +++ b/mace/core/kv_storage.cc @@ -12,11 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include -#include -#include - #include #include #include @@ -26,6 +21,8 @@ #include "mace/core/kv_storage.h" #include "mace/utils/macros.h" #include "mace/utils/logging.h" +#include "mace/port/env.h" +#include "mace/port/file_system.h" namespace mace { @@ -98,69 +95,24 @@ FileStorage::FileStorage(const std::string &file_path): loaded_(false), data_changed_(false), file_path_(file_path) {} int FileStorage::Load() { - struct stat st; - if (stat(file_path_.c_str(), &st) == -1) { - if (errno == ENOENT) { - VLOG(1) << "File " << file_path_ - << " does not exist"; - return 0; - } else { - LOG(WARNING) << "Stat file " << file_path_ - << " failed, error code: " << strerror(errno); - return -1; - } - } utils::WriteLock lock(&data_mutex_); if (loaded_) { return 0; } - int fd = open(file_path_.c_str(), O_RDONLY); - if (fd < 0) { - if (errno == ENOENT) { - LOG(INFO) << "File " << file_path_ - << " does not exist"; - return 0; - } else { - LOG(WARNING) << "open file " << file_path_ - << " failed, error code: " << strerror(errno); - return -1; - } - } - size_t file_size = st.st_size; - unsigned char *file_data = - static_cast(mmap(nullptr, file_size, PROT_READ, - MAP_PRIVATE, fd, 0)); - int res = 0; - if (file_data == MAP_FAILED) { - LOG(WARNING) << "mmap file " << file_path_ - << " failed, error code: " << strerror(errno); - res = close(fd); - if (res != 0) { - LOG(WARNING) << "close file " << file_path_ - << " failed, error code: " << strerror(errno); - } + std::unique_ptr kv_data = + make_unique(); + auto fs = GetFileSystem(); + auto status = fs->NewReadOnlyMemoryRegionFromFile( + file_path_.c_str(), &kv_data); + if (status != MaceStatus::MACE_SUCCESS) { + LOG(ERROR) << "Failed to read kv store file: " << file_path_; return -1; + } else { + ParseKVData(static_cast(kv_data->data()), + kv_data->length(), &data_); } - ParseKVData(file_data, file_size, &data_); - res = munmap(file_data, file_size); - if (res != 0) { - LOG(WARNING) << "munmap file " << file_path_ - << " failed, error code: " << strerror(errno); - res = close(fd); - if (res != 0) { - LOG(WARNING) << "close file " << file_path_ - << " failed, error code: " << strerror(errno); - } - return -1; - } - res = close(fd); - if (res != 0) { - LOG(WARNING) << "close file " << file_path_ - << " failed, error code: " << strerror(errno); - return -1; - } loaded_ = true; return 0; } @@ -196,8 +148,10 @@ const std::vector *FileStorage::Find(const std::string &key) { int FileStorage::Flush() { utils::WriteLock lock(&data_mutex_); if (!data_changed_) return 0; - int fd = open(file_path_.c_str(), O_WRONLY | O_CREAT, 0600); - if (fd < 0) { + auto fs = GetFileSystem(); + std::unique_ptr file; + MaceStatus s = fs->NewWritableFile(file_path_.c_str(), &file); + if (s != MaceStatus::MACE_SUCCESS) { LOG(WARNING) << "open file " << file_path_ << " failed, error code: " << strerror(errno); return -1; @@ -209,8 +163,8 @@ int FileStorage::Flush() { for (auto &kv : data_) { data_size += 2 * int_size + kv.first.size() + kv.second.size(); } - std::unique_ptr buffer(new unsigned char[data_size]); - unsigned char *buffer_ptr = &buffer[0]; + std::unique_ptr buffer = make_unique(data_size); + char *buffer_ptr = buffer.get(); int64_t num_of_data = data_.size(); memcpy(buffer_ptr, &num_of_data, sizeof(int64_t)); @@ -230,32 +184,16 @@ int FileStorage::Flush() { memcpy(buffer_ptr, kv.second.data(), kv.second.size()); buffer_ptr += kv.second.size(); } - int res = 0; - buffer_ptr = &buffer[0]; - int64_t remain_size = data_size; - while (remain_size > 0) { - size_t buffer_size = std::min(remain_size, SSIZE_MAX); - res = write(fd, buffer_ptr, buffer_size); - if (res == -1) { - LOG(WARNING) << "write file " << file_path_ - << " failed, error code: " << strerror(errno); - res = close(fd); - if (res != 0) { - LOG(WARNING) << "close file " << file_path_ - << " failed, error code: " << strerror(errno); - } - return -1; - } - remain_size -= buffer_size; - buffer_ptr += buffer_size; + s = file->Append(buffer.get(), data_size); + if (s != MaceStatus::MACE_SUCCESS) { + file->Close(); + return -1; } - - res = close(fd); - if (res != 0) { - LOG(WARNING) << "close file " << file_path_ - << " failed, error code: " << strerror(errno); + s = file->Close(); + if (s != MaceStatus::MACE_SUCCESS) { return -1; } + data_changed_ = false; return 0; } diff --git a/mace/core/runtime/hexagon/hexagon_hta_wrapper.cc b/mace/core/runtime/hexagon/hexagon_hta_wrapper.cc index 06dadc3a9ae986cf8da9d2da8e4e212edf3d93cd..08650c18830cad213898cded7a9dd83f093a3eee 100644 --- a/mace/core/runtime/hexagon/hexagon_hta_wrapper.cc +++ b/mace/core/runtime/hexagon/hexagon_hta_wrapper.cc @@ -32,7 +32,7 @@ namespace mace { HexagonHTAWrapper::HexagonHTAWrapper(Device *device) - : device_(device), quantize_util_(&device->cpu_runtime()->thread_pool()) { + : quantize_util_(&device->cpu_runtime()->thread_pool()) { } int HexagonHTAWrapper::GetVersion() { diff --git a/mace/core/runtime/hexagon/hexagon_hta_wrapper.h b/mace/core/runtime/hexagon/hexagon_hta_wrapper.h index af8294b1c2993111ba9f5d31986d6c8346a765a8..04e3f3e255a06df60f2606a374b250ca666450b0 100644 --- a/mace/core/runtime/hexagon/hexagon_hta_wrapper.h +++ b/mace/core/runtime/hexagon/hexagon_hta_wrapper.h @@ -50,7 +50,6 @@ class HexagonHTAWrapper : public HexagonControlWrapper { void SetDebugLevel(int level) override; private: - Device *device_; QuantizeUtil quantize_util_; MACE_DISABLE_COPY_AND_ASSIGN(HexagonHTAWrapper); }; diff --git a/mace/core/runtime/opencl/cl2_header.h b/mace/core/runtime/opencl/cl2_header.h index c97b600931b404abddee9d0b70c08418c995b76a..45063fca79150b8050e8754ad4367cbedbf1784f 100644 --- a/mace/core/runtime/opencl/cl2_header.h +++ b/mace/core/runtime/opencl/cl2_header.h @@ -37,7 +37,7 @@ #pragma GCC diagnostic ignored "-Wignored-attributes" #endif // MACE_OS_MAC -#include "include/CL/cl2.hpp" +#include "CL/cl2.hpp" #ifdef MACE_OS_MAC #pragma GCC diagnostic pop diff --git a/mace/core/runtime/opencl/opencl_allocator.cc b/mace/core/runtime/opencl/opencl_allocator.cc index 0a42e2957e543f8d604db808a08e2e0dbf29bb64..b0b4e9f477d51fea46b90f5f8f75dd236958983f 100644 --- a/mace/core/runtime/opencl/opencl_allocator.cc +++ b/mace/core/runtime/opencl/opencl_allocator.cc @@ -147,8 +147,8 @@ void *OpenCLAllocator::MapImage(void *buffer, VLOG(3) << "Map OpenCL Image"; MACE_CHECK(image_shape.size() == 2) << "Just support map 2d image"; auto cl_image = static_cast(buffer); - std::array origin = {0, 0, 0}; - std::array region = {image_shape[0], image_shape[1], 1}; + std::array origin = {{0, 0, 0}}; + std::array region = {{image_shape[0], image_shape[1], 1}}; mapped_image_pitch->resize(2); cl_int error; diff --git a/mace/core/runtime/opencl/opencl_runtime.cc b/mace/core/runtime/opencl/opencl_runtime.cc index e26c604869535ce856c78ea27b1463e36e20b28d..61fb5a0d409f1bc415816e455da1a582a59e4a9b 100644 --- a/mace/core/runtime/opencl/opencl_runtime.cc +++ b/mace/core/runtime/opencl/opencl_runtime.cc @@ -14,8 +14,6 @@ #include "mace/core/runtime/opencl/opencl_runtime.h" -#include - #include #include #include diff --git a/mace/libmace/BUILD.bazel b/mace/libmace/BUILD.bazel index 4b3d29995dd4849f0107c468ab703b0fb6711d4d..2d16fd94b17fbde485f0fa678a6fc74303e046c8 100644 --- a/mace/libmace/BUILD.bazel +++ b/mace/libmace/BUILD.bazel @@ -50,7 +50,7 @@ cc_library( ]), deps = [ "//mace/ops", - "//mace/public", + "//include:public_headers", ], alwayslink = 1, ) @@ -91,6 +91,7 @@ cc_library( genrule( name = "libmace_static", srcs = [ + "//include:public_headers", "//mace/codegen:generated_version", "//mace/core", "//mace/ops:common", @@ -100,7 +101,6 @@ genrule( "//mace/libmace", "//mace/port:port_base", "//mace/port/posix:port_posix", - "//mace/public", "//mace/utils", "//mace/proto:mace_cc", "@com_google_protobuf//:protobuf_lite", @@ -155,7 +155,6 @@ genrule( "$(locations //mace/port/darwin:port_darwin) ", default_value = "", ) + - "$(locations //mace/public:public) " + "$(locations //mace/utils:utils) " + "$(locations //mace/proto:mace_cc) " + "$(locations @com_google_protobuf//:protobuf_lite) " + diff --git a/mace/libmace/CMakeLists.txt b/mace/libmace/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a4ad42f060a01e0f9db29718f2e11c686262590 --- /dev/null +++ b/mace/libmace/CMakeLists.txt @@ -0,0 +1,14 @@ +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) diff --git a/mace/libmace/mace.cc b/mace/libmace/mace.cc index e6d11816d5f0ac097af905e3724a69faa3e752f9..6b566d181ff3a7074be3e31ef2eb5ed725bf30d7 100644 --- a/mace/libmace/mace.cc +++ b/mace/libmace/mace.cc @@ -19,7 +19,7 @@ #include "mace/core/device_context.h" #include "mace/core/memory_optimizer.h" #include "mace/core/net.h" -#include "mace/ops/ops_registry.h" +#include "mace/ops/registry/ops_registry.h" #include "mace/ops/common/transpose.h" #include "mace/utils/math.h" #include "mace/utils/memory.h" diff --git a/mace/ops/BUILD.bazel b/mace/ops/BUILD.bazel index 1d651c1b3274bab30a7adf30f9f63be2c57dca7f..a80b556dda4d759c8be28cffcb8ed4c1c45fea52 100644 --- a/mace/ops/BUILD.bazel +++ b/mace/ops/BUILD.bazel @@ -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( name = "ref_kernels", srcs = glob( @@ -178,11 +149,6 @@ cc_library( [ "opencl/*.cc", "opencl/**/*.cc", - "buffer_transform.cc", - "lstm_cell.cc", - ], - exclude = [ - "opencl/*_test.cc", ], ), hdrs = glob( @@ -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( name = "internal_ops", @@ -294,32 +188,12 @@ cc_library( [ "*.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( [ "*.h", ], exclude = [ - "ops_registry.h", - "ops_test_util.h", "fixpoint.h", "common/gemmlowp_util.h", "quantization_util.h", @@ -363,16 +237,12 @@ cc_library( cc_library( name = "ops", - srcs = glob( - [ - "ops_registry.cc", + srcs = [ + "registry/ops_registry.cc", ], - ), - hdrs = glob( - [ - "ops_registry.h", + hdrs = [ + "registry/ops_registry.h", ], - ), copts = [ "-Werror", "-Wextra", @@ -396,118 +266,3 @@ cc_library( "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", - ], -) diff --git a/mace/ops/CMakeLists.txt b/mace/ops/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7994b445a6bc7aabb82f3198c2c2405f857b4e1b --- /dev/null +++ b/mace/ops/CMakeLists.txt @@ -0,0 +1,45 @@ +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) diff --git a/mace/ops/arm/fp32/common_neon.h b/mace/ops/arm/fp32/common_neon.h index 8ac2cb7c787bf386fb15678bfd014ae760933dba..d4e61add21872e991c1947307f733ac404136738 100644 --- a/mace/ops/arm/fp32/common_neon.h +++ b/mace/ops/arm/fp32/common_neon.h @@ -17,14 +17,12 @@ #if defined(MACE_ENABLE_NEON) #include -#endif namespace mace { namespace ops { namespace arm { namespace fp32 { -#ifdef MACE_ENABLE_NEON inline float32x4_t neon_vfma_lane_0(float32x4_t a, float32x4_t b, float32x4_t c) { @@ -64,11 +62,11 @@ inline float32x4_t neon_vfma_lane_3(float32x4_t a, return vmlaq_lane_f32(a, b, vget_high_f32(c), 1); #endif } -#endif } // namespace fp32 } // namespace arm } // namespace ops } // namespace mace +#endif // MACE_ENABLE_NEON #endif // MACE_OPS_ARM_FP32_COMMON_NEON_H_ diff --git a/mace/ops/arm/fp32/gemm.cc b/mace/ops/arm/fp32/gemm.cc index aacb6636adf2bb9efb75879db7ca545c9e3a4daf..4b593c015e30204e8bf4fc26831bf61397d3d696 100644 --- a/mace/ops/arm/fp32/gemm.cc +++ b/mace/ops/arm/fp32/gemm.cc @@ -19,6 +19,8 @@ #include #include +#include "mace/port/env.h" + namespace mace { namespace ops { namespace arm { diff --git a/mace/ops/quantization_util.cc b/mace/ops/arm/q8/quantization_util.cc similarity index 97% rename from mace/ops/quantization_util.cc rename to mace/ops/arm/q8/quantization_util.cc index 9df5c6fdf2b0e87a08088799793941f47eb6f922..5709032b434b57bc2e24e510fdb3a68954e26269 100644 --- a/mace/ops/quantization_util.cc +++ b/mace/ops/arm/q8/quantization_util.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/ops/quantization_util.h" +#include "mace/ops/arm/q8/quantization_util.h" namespace mace { namespace ops { diff --git a/mace/ops/quantization_util.h b/mace/ops/arm/q8/quantization_util.h similarity index 87% rename from mace/ops/quantization_util.h rename to mace/ops/arm/q8/quantization_util.h index 3e6beeb0eea9439b54e8d9f90ecd8b3a74ac675b..fe4ceccbe1c36216297fd06a07a5cbc5be81afca 100644 --- a/mace/ops/quantization_util.h +++ b/mace/ops/arm/q8/quantization_util.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MACE_OPS_QUANTIZATION_UTIL_H_ -#define MACE_OPS_QUANTIZATION_UTIL_H_ +#ifndef MACE_OPS_ARM_Q8_QUANTIZATION_UTIL_H_ +#define MACE_OPS_ARM_Q8_QUANTIZATION_UTIL_H_ #include @@ -30,4 +30,4 @@ const int32_t *GetBiasData(const Tensor *bias, } // namespace ops } // namespace mace -#endif // MACE_OPS_QUANTIZATION_UTIL_H_ +#endif // MACE_OPS_ARM_Q8_QUANTIZATION_UTIL_H_ diff --git a/mace/ops/quantize.cc b/mace/ops/arm/q8/quantize.cc similarity index 100% rename from mace/ops/quantize.cc rename to mace/ops/arm/q8/quantize.cc diff --git a/mace/ops/conv_2d.cc b/mace/ops/conv_2d.cc index cc84b9632df9d4b6013d08d2381677bb38bd7d47..1963fc865af60c532754345278a9e0f85d9ebc38 100644 --- a/mace/ops/conv_2d.cc +++ b/mace/ops/conv_2d.cc @@ -52,7 +52,7 @@ #ifdef MACE_ENABLE_QUANTIZE #include "mace/ops/common/gemmlowp_util.h" -#include "mace/ops/quantization_util.h" +#include "mace/ops/arm/q8/quantization_util.h" #endif // MACE_ENABLE_QUANTIZE #ifdef MACE_ENABLE_OPENCL diff --git a/mace/ops/depthwise_conv2d.cc b/mace/ops/depthwise_conv2d.cc index ae2a4dfda760e2fe9d182a510fc353ef2d73c363..d53b67463996e8a27b9d0af62227cbc0c8cdbc1e 100644 --- a/mace/ops/depthwise_conv2d.cc +++ b/mace/ops/depthwise_conv2d.cc @@ -29,7 +29,7 @@ #endif // MACE_ENABLE_NEON #ifdef MACE_ENABLE_QUANTIZE -#include "mace/ops/quantization_util.h" +#include "mace/ops/arm/q8/quantization_util.h" // We reuse TensorFlow Lite's optimized depthwiseconv_uint8 and parallelized it // using OpenMP for MACE's quantized depthwise_conv2d. #include "tensorflow/contrib/lite/kernels/internal/optimized/depthwiseconv_uint8.h" diff --git a/mace/ops/buffer_transform.cc b/mace/ops/opencl/buffer_transform.cc similarity index 100% rename from mace/ops/buffer_transform.cc rename to mace/ops/opencl/buffer_transform.cc diff --git a/mace/ops/lstm_cell.cc b/mace/ops/opencl/lstm_cell.cc similarity index 98% rename from mace/ops/lstm_cell.cc rename to mace/ops/opencl/lstm_cell.cc index d43dbf6bd462da56cf73a7eedca8e8863a089dbf..563a53bcbd8ebedf5d694ecfd5d9a4252fd735ad 100644 --- a/mace/ops/lstm_cell.cc +++ b/mace/ops/opencl/lstm_cell.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "mace/ops/opencl/lstm_cell.h" + #include #include diff --git a/mace/ops/ops_registry.cc b/mace/ops/registry/ops_registry.cc similarity index 99% rename from mace/ops/ops_registry.cc rename to mace/ops/registry/ops_registry.cc index e975b265681e3f1fb897fbd64c580e6521c732ae..67660db9fefc0c7aebceb3b00e0727567094126a 100644 --- a/mace/ops/ops_registry.cc +++ b/mace/ops/registry/ops_registry.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/ops/ops_registry.h" +#include "mace/ops/registry/ops_registry.h" namespace mace { diff --git a/mace/ops/ops_registry.h b/mace/ops/registry/ops_registry.h similarity index 85% rename from mace/ops/ops_registry.h rename to mace/ops/registry/ops_registry.h index 5249970bbc76b523a73dcbdde3af5440b88e7ff9..01f013dc4c7d334be68b6d42a6a7abaa0c41e7a0 100644 --- a/mace/ops/ops_registry.h +++ b/mace/ops/registry/ops_registry.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MACE_OPS_OPS_REGISTRY_H_ -#define MACE_OPS_OPS_REGISTRY_H_ +#ifndef MACE_OPS_REGISTRY_OPS_REGISTRY_H_ +#define MACE_OPS_REGISTRY_OPS_REGISTRY_H_ #include "mace/core/operator.h" @@ -27,4 +27,4 @@ class OpRegistry : public OpRegistryBase { } // namespace mace -#endif // MACE_OPS_OPS_REGISTRY_H_ +#endif // MACE_OPS_REGISTRY_OPS_REGISTRY_H_ diff --git a/mace/port/BUILD.bazel b/mace/port/BUILD.bazel index 2c55ce7c42b1109bae946888ded101d8f18d37b3..feb6ea902d12212db8068c1c29cd1d64581b0fe0 100644 --- a/mace/port/BUILD.bazel +++ b/mace/port/BUILD.bazel @@ -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( name = "port_base", srcs = [ "env.cc", "logger.cc", + "file_system.cc", ], deps = [ - ":port_api", "//mace/utils", - ], -) - -cc_test( - name = "port_test", - testonly = 1, - srcs = glob([ - "*_test.cc", - ]), - linkstatic = 1, - deps = [ - ":port", - "@gtest", - "@gtest//:gtest_main", + "//include:public_headers", ], ) diff --git a/mace/port/CMakeLists.txt b/mace/port/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..57a50be8a83d1ed869900899efea09a82af8cd95 --- /dev/null +++ b/mace/port/CMakeLists.txt @@ -0,0 +1,28 @@ +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) diff --git a/mace/port/android/CMakeLists.txt b/mace/port/android/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b603cbbdf77918ee2b6e1b8cf92e25d95e436c4c --- /dev/null +++ b/mace/port/android/CMakeLists.txt @@ -0,0 +1,9 @@ +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) diff --git a/mace/port/darwin/CMakeLists.txt b/mace/port/darwin/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..60810fb6220d863c0db7f36101490d4626c70144 --- /dev/null +++ b/mace/port/darwin/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(port_darwin STATIC + env.cc +) + +target_link_libraries(port_darwin port_posix) + +install(TARGETS port_darwin ARCHIVE DESTINATION lib) diff --git a/mace/port/env.cc b/mace/port/env.cc index b78e1c82d4d417ccc2d2be9e2dc24cd3867e4cc1..4ecafce4d93481130bf663d3ca80923fe67b9ac7 100644 --- a/mace/port/env.cc +++ b/mace/port/env.cc @@ -22,6 +22,10 @@ namespace mace { namespace port { +MaceStatus Env::AdviseFree(void *addr, size_t length) { + return MaceStatus::MACE_UNSUPPORTED; +} + MaceStatus Env::GetCPUMaxFreq(std::vector *max_freqs) { return MaceStatus::MACE_UNSUPPORTED; } diff --git a/mace/port/file_system.cc b/mace/port/file_system.cc new file mode 100644 index 0000000000000000000000000000000000000000..624adb84994bebb0ca403fb99f96b2be13b7f4da --- /dev/null +++ b/mace/port/file_system.cc @@ -0,0 +1,93 @@ +// 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 +#include + +#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* 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(fname, f); + } + return MaceStatus::MACE_SUCCESS; +} + +} // namespace port +} // namespace mace diff --git a/mace/port/linux/CMakeLists.txt b/mace/port/linux/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5741a21e745074972dc6b9f0e624ec91b7546206 --- /dev/null +++ b/mace/port/linux/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(port_linux STATIC + env.cc +) + +target_link_libraries(port_linux port_linux_base) + +install(TARGETS port_linux ARCHIVE DESTINATION lib) diff --git a/mace/port/linux_base/CMakeLists.txt b/mace/port/linux_base/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1d19a41b068a875746be5634edd946d06026d1ac --- /dev/null +++ b/mace/port/linux_base/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(port_linux_base STATIC + env.cc +) + +target_link_libraries(port_linux_base port_posix) + +install(TARGETS port_linux_base ARCHIVE DESTINATION lib) diff --git a/mace/port/linux_base/env.cc b/mace/port/linux_base/env.cc index 10b946ac62de806ddc7f1f1cf113530b6e4d1924..19c76364a5fbef639f4da57dc9cd3fb7c6943f1b 100644 --- a/mace/port/linux_base/env.cc +++ b/mace/port/linux_base/env.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -121,5 +122,26 @@ MaceStatus LinuxBaseEnv::SchedSetAffinity(const std::vector &cpu_ids) { return MaceStatus::MACE_SUCCESS; } +MaceStatus LinuxBaseEnv::AdviseFree(void *addr, size_t length) { + int page_size = sysconf(_SC_PAGESIZE); + void *addr_aligned = + reinterpret_cast( + (reinterpret_cast(addr) + page_size - 1) + & (~(page_size - 1))); + uintptr_t delta = + reinterpret_cast(addr_aligned) + - reinterpret_cast(addr); + if (length >= delta + page_size) { + size_t len_aligned = (length - delta) & (~(page_size - 1)); + int error = madvise(addr_aligned, len_aligned, MADV_DONTNEED); + if (error != 0) { + LOG(ERROR) << "Advise free failed: " << strerror(errno); + return MaceStatus::MACE_RUNTIME_ERROR; + } + } + return MaceStatus::MACE_SUCCESS; +} + + } // namespace port } // namespace mace diff --git a/mace/port/linux_base/env.h b/mace/port/linux_base/env.h index 7ef0e9fcd3149cb681b4d8ccafe0ecf9dee7bc2a..9b4b6ce226df01d725673796c17f81a75223112e 100644 --- a/mace/port/linux_base/env.h +++ b/mace/port/linux_base/env.h @@ -26,6 +26,7 @@ namespace port { class LinuxBaseEnv : public Env { public: int64_t NowMicros() override; + MaceStatus AdviseFree(void *addr, size_t length) override; MaceStatus GetCPUMaxFreq(std::vector *max_freqs) override; FileSystem *GetFileSystem() override; MaceStatus SchedSetAffinity(const std::vector &cpu_ids) override; diff --git a/mace/port/posix/CMakeLists.txt b/mace/port/posix/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6f3870c35390ed0005cc02432b61015d14b9bacf --- /dev/null +++ b/mace/port/posix/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(port_posix STATIC + file_system.cc +) + +target_link_libraries(port_posix port_base) + +install(TARGETS port_posix ARCHIVE DESTINATION lib) diff --git a/mace/port/posix/file_system.cc b/mace/port/posix/file_system.cc index 75055e45978aea432844cc092f9367eb7e2750ed..5b8a266b4cf9153093f922f4ac98ce02511b446d 100644 --- a/mace/port/posix/file_system.cc +++ b/mace/port/posix/file_system.cc @@ -37,9 +37,9 @@ class PosixReadOnlyMemoryRegion : public ReadOnlyMemoryRegion { if (length_ > 0) { munmap(const_cast(addr_), length_); } - }; - const void *data() const override { return addr_; }; - uint64_t length() const override { return length_; }; + } + const void *data() const override { return addr_; } + uint64_t length() const override { return length_; } private: const void *addr_; @@ -50,11 +50,11 @@ class PosixReadOnlyMemoryRegion : public ReadOnlyMemoryRegion { MaceStatus PosixFileSystem::NewReadOnlyMemoryRegionFromFile( const char *fname, std::unique_ptr* result) { - MaceStatus s = MaceStatus(MaceStatus::MACE_SUCCESS); + MaceStatus s = MaceStatus::MACE_SUCCESS; int fd = open(fname, O_RDONLY); if (fd < 0) { // TODO(heliangliang) check errno - s = MaceStatus(MaceStatus::MACE_RUNTIME_ERROR); + s = MaceStatus::MACE_RUNTIME_ERROR; } else { struct stat st; fstat(fd, &st); @@ -63,7 +63,7 @@ MaceStatus PosixFileSystem::NewReadOnlyMemoryRegionFromFile( mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (address == MAP_FAILED) { // TODO(heliangliang) check errno - s = MaceStatus(MaceStatus::MACE_RUNTIME_ERROR); + s = MaceStatus::MACE_RUNTIME_ERROR; } else { *result = make_unique(address, st.st_size); } diff --git a/mace/port/windows/CMakeLists.txt b/mace/port/windows/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..886d1cb1ba5a576b8b0a81191fdc3ed771eff219 --- /dev/null +++ b/mace/port/windows/CMakeLists.txt @@ -0,0 +1,8 @@ +add_library(port_windows STATIC + env.cc + file_system.cc +) + +target_link_libraries(port_windows port_base) + +install(TARGETS port_windows ARCHIVE DESTINATION lib) diff --git a/mace/port/windows/env.cc b/mace/port/windows/env.cc new file mode 100644 index 0000000000000000000000000000000000000000..d11e81ac8998e75d988a445b0ea3488af0acf5b0 --- /dev/null +++ b/mace/port/windows/env.cc @@ -0,0 +1,53 @@ +// 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 + +#include +#include +#include + +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 WindowsEnv::GetBackTraceUnsafe(int max_steps) { + std::vector empty; + return empty; +} + +Env *Env::Default() { + static WindowsEnv windows_env; + return &windows_env; +} + +} // namespace port +} // namespace mace diff --git a/mace/port/windows/env.h b/mace/port/windows/env.h new file mode 100644 index 0000000000000000000000000000000000000000..646cb573729b4972a12ca50c0ef2ced3313abea1 --- /dev/null +++ b/mace/port/windows/env.h @@ -0,0 +1,44 @@ +// 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 +#include + +#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 GetBackTraceUnsafe(int max_steps) override; + + private: + LogWriter log_writer_; + WindowsFileSystem windows_file_system_; +}; + +} // namespace port +} // namespace mace + +#endif // MACE_PORT_WINDOWS_ENV_H_ diff --git a/mace/port/windows/file_system.cc b/mace/port/windows/file_system.cc new file mode 100644 index 0000000000000000000000000000000000000000..d6bc3ffb80c9f3e5d83dfa8356f3fad812e29e89 --- /dev/null +++ b/mace/port/windows/file_system.cc @@ -0,0 +1,66 @@ +// 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 +#include +#include +#include + +#include "mace/utils/memory.h" + +namespace mace { +namespace port { + +namespace { +class WindowsReadOnlyMemoryRegion : public ReadOnlyMemoryRegion { + public: + WindowsReadOnlyMemoryRegion() = delete; + explicit WindowsReadOnlyMemoryRegion(std::vector &&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 buffer_; +}; +} // namespace + +MaceStatus WindowsFileSystem::NewReadOnlyMemoryRegionFromFile( + const char *fname, std::unique_ptr *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 buffer(length); + ifs.read(reinterpret_cast(buffer.data()), length); + + if (ifs.fail()) { + return MaceStatus::MACE_RUNTIME_ERROR; + } + ifs.close(); + *result = make_unique(std::move(buffer)); + return MaceStatus::MACE_SUCCESS; +} + +} // namespace port +} // namespace mace diff --git a/mace/port/windows/file_system.h b/mace/port/windows/file_system.h new file mode 100644 index 0000000000000000000000000000000000000000..0c16c2a7ab9586a2b72b48dc9aa11ea3ca7e7bdf --- /dev/null +++ b/mace/port/windows/file_system.h @@ -0,0 +1,37 @@ +// 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 +#include + +#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* result) override; +}; + +} // namespace port +} // namespace mace + +#endif // MACE_PORT_WINDOWS_FILE_SYSTEM_H_ diff --git a/mace/proto/CMakeLists.txt b/mace/proto/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..db875de4b4214f0965ef62d73ac9aa9ff4872376 --- /dev/null +++ b/mace/proto/CMakeLists.txt @@ -0,0 +1,28 @@ +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) diff --git a/mace/proto/mace.proto b/mace/proto/mace.proto index 540b1b1a234d5ba946b0d4e41b04b9c52192c0d1..369c814a609de9a6ee8e0b9c1150d544ae141670 100644 --- a/mace/proto/mace.proto +++ b/mace/proto/mace.proto @@ -86,7 +86,6 @@ message OperatorDef { repeated int32 out_max_byte_size = 104; // only support 32-bit len } -// for hexagon mace-nnlib message InputOutputInfo { optional string name = 1; optional int32 node_id = 2; @@ -103,7 +102,6 @@ message NetDef { repeated Argument arg = 2; repeated ConstTensor tensors = 3; - // for hexagon mace-nnlib repeated InputOutputInfo input_info = 100; repeated InputOutputInfo output_info = 101; } diff --git a/mace/public/BUILD.bazel b/mace/public/BUILD.bazel deleted file mode 100644 index 158bc564dff7c4118ff368d0dfd1cb6a0eb0547f..0000000000000000000000000000000000000000 --- a/mace/public/BUILD.bazel +++ /dev/null @@ -1,19 +0,0 @@ -# Description: -# MACE public API. -# -package( - default_visibility = ["//visibility:public"], -) - -licenses(["notice"]) # Apache 2.0 - -cc_library( - name = "public", - hdrs = [ - "mace.h", - ], - srcs = [ - "status.cc", - ], - copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], -) diff --git a/mace/python/tools/visualization/visualize_model.py b/mace/python/tools/visualization/visualize_model.py index 19841db7f505399005ce95bb31367f07fc0acc6c..9eee368600c631617e511021b0051151870c356d 100644 --- a/mace/python/tools/visualization/visualize_model.py +++ b/mace/python/tools/visualization/visualize_model.py @@ -20,7 +20,7 @@ class NPEncoder(json.JSONEncoder): class ModelVisualizer(object): 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 def render_html(self): diff --git a/mace/tools/CMakeLists.txt b/mace/tools/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a23460711dc66033a21c2b84ef6caf1caec7c9cb --- /dev/null +++ b/mace/tools/CMakeLists.txt @@ -0,0 +1,31 @@ +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) diff --git a/mace/benchmark/BUILD.bazel b/mace/tools/benchmark/BUILD.bazel similarity index 76% rename from mace/benchmark/BUILD.bazel rename to mace/tools/benchmark/BUILD.bazel index 3fe9a006b942f79274bdaf72f6e75845cde59d0c..425d256697a5c4108c6626e17599d86c6055e23f 100644 --- a/mace/benchmark/BUILD.bazel +++ b/mace/tools/benchmark/BUILD.bazel @@ -10,17 +10,6 @@ load( 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( name = "benchmark_model_static", srcs = [ @@ -34,12 +23,15 @@ cc_binary( linkopts = if_openmp_enabled(["-fopenmp"]), linkstatic = 1, deps = [ - ":statistics", "//external:gflags_nothreads", - "//mace/codegen:libmodels", "//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( @@ -55,7 +47,7 @@ cc_binary( linkopts = [ "-lm", ] + if_openmp_enabled([ - "-fopenmp" + "-fopenmp", ]) + if_android([ "-ldl", "-pie", @@ -66,9 +58,12 @@ cc_binary( ":statistics", "//external:gflags_nothreads", "//mace/codegen:generated_mace_engine_factory", - "//mace/codegen:libmodels", + "//mace/codegen:generated_models", "//mace/libmace:libmace_dynamic", - ], + ] + if_opencl_enabled([ + "//mace/codegen:generated_opencl_binary", + "//mace/codegen:generated_opencl_parameter", + ]), ) cc_library( @@ -82,9 +77,13 @@ cc_library( cc_binary( name = "model_throughput_test", srcs = ["model_throughput_test.cc"], + copts = [ + "-Werror", + "-Wextra", + "-Wno-missing-field-initializers", + ], linkopts = if_openmp_enabled(["-fopenmp"]), linkstatic = 1, - copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], deps = [ ":libmace_merged", "//external:gflags_nothreads", diff --git a/mace/benchmark/benchmark_model.cc b/mace/tools/benchmark/benchmark_model.cc similarity index 98% rename from mace/benchmark/benchmark_model.cc rename to mace/tools/benchmark/benchmark_model.cc index 98807b6789b07355da7fe02260b788f02f36b9fc..a81c74720e92f95eacb5f4b0fe6f60084c54dbb1 100644 --- a/mace/benchmark/benchmark_model.cc +++ b/mace/tools/benchmark/benchmark_model.cc @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include #include #include @@ -27,7 +25,7 @@ #include "mace/utils/logging.h" #include "mace/utils/memory.h" #include "mace/utils/math.h" -#include "mace/benchmark/statistics.h" +#include "mace/utils/statistics.h" #ifdef MODEL_GRAPH_FORMAT_CODE #include "mace/codegen/engine/mace_engine_factory.h" #endif @@ -57,12 +55,6 @@ std::string FormatName(const std::string input) { return res; } -inline int64_t NowMicros() { - struct timeval tv; - gettimeofday(&tv, nullptr); - return static_cast(tv.tv_sec) * 1000000 + tv.tv_usec; -} - DeviceType ParseDeviceType(const std::string &device_str) { if (device_str.compare("CPU") == 0) { return DeviceType::CPU; diff --git a/mace/benchmark/model_throughput_test.cc b/mace/tools/benchmark/benchmark_model_throughput.cc similarity index 98% rename from mace/benchmark/model_throughput_test.cc rename to mace/tools/benchmark/benchmark_model_throughput.cc index cdc4639155cdab36f45eb038907e7ac71e069f2e..a8fcf7596da4600e88d41c6ce9c5d54777a8e91b 100644 --- a/mace/benchmark/model_throughput_test.cc +++ b/mace/tools/benchmark/benchmark_model_throughput.cc @@ -249,7 +249,12 @@ int Main(int argc, char **argv) { buffer_out); } +#if defined(MACE_CPU_MODEL_TAG) || \ + defined(MACE_GPU_MODEL_TAG) || \ + defined(MACE_DSP_MODEL_TAG) int64_t t0, t1, init_micros; +#endif + #ifdef MACE_CPU_MODEL_TAG /* --------------------- CPU init ----------------------- */ LOG(INFO) << "Load & init cpu model and warm up"; @@ -306,10 +311,14 @@ int Main(int argc, char **argv) { LOG(INFO) << "DSP 1st warm up run latency: " << t1 - t0 << " us"; #endif +#if defined(MACE_CPU_MODEL_TAG) || \ + defined(MACE_GPU_MODEL_TAG) || \ + defined(MACE_DSP_MODEL_TAG) double cpu_throughput = 0; double gpu_throughput = 0; double dsp_throughput = 0; int64_t run_micros = FLAGS_run_seconds * 1000000; +#endif #ifdef MACE_CPU_MODEL_TAG std::thread cpu_thread([&]() { diff --git a/mace/tools/validation/BUILD.bazel b/mace/tools/validation/BUILD.bazel index 3d49f635465d15928625586cfb152565c67fc39d..476fc15a66ec0792d657b0ad2250730ea0ff05fe 100644 --- a/mace/tools/validation/BUILD.bazel +++ b/mace/tools/validation/BUILD.bazel @@ -26,7 +26,7 @@ cc_binary( deps = [ "//external:gflags_nothreads", "//mace/codegen:generated_mace_engine_factory", - "//mace/codegen:libmodels", + "//mace/codegen:generated_models", "//mace/libmace", ], ) @@ -50,7 +50,7 @@ cc_binary( deps = [ "//external:gflags_nothreads", "//mace/codegen:generated_mace_engine_factory", - "//mace/codegen:libmodels", + "//mace/codegen:generated_models", "//mace/libmace:libmace_dynamic", ], ) diff --git a/mace/utils/BUILD.bazel b/mace/utils/BUILD.bazel index 378210a3905e68188a8de35d2b1a8b1dacdefd39..e28fb04d6ab93da8d8f789c9dc39cbfbdf02d929 100644 --- a/mace/utils/BUILD.bazel +++ b/mace/utils/BUILD.bazel @@ -26,8 +26,7 @@ cc_library( "-Wno-missing-field-initializers", ], deps = [ - "//mace/port:port_api", - "//mace/public", + "//include:public_headers", ], ) @@ -37,9 +36,6 @@ cc_library( [ "*.cc", ], - exclude = [ - "*_test.cc", - ], ), copts = [ "-Werror", @@ -61,25 +57,3 @@ cc_library( ], 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", - ], -) diff --git a/mace/utils/CMakeLists.txt b/mace/utils/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7881cf738e77cdbdf18d04c1b67a95d60e6ac940 --- /dev/null +++ b/mace/utils/CMakeLists.txt @@ -0,0 +1,12 @@ +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) diff --git a/mace/benchmark/statistics.cc b/mace/utils/statistics.cc similarity index 99% rename from mace/benchmark/statistics.cc rename to mace/utils/statistics.cc index 9af7fcb30bf343f82232a5d240b5b78536d3949c..7ff43664ddb525b944efa7153d034861980ba793 100644 --- a/mace/benchmark/statistics.cc +++ b/mace/utils/statistics.cc @@ -17,7 +17,7 @@ #include #include -#include "mace/benchmark/statistics.h" +#include "mace/utils/statistics.h" #include "mace/utils/logging.h" #include "mace/utils/string_util.h" diff --git a/mace/benchmark/statistics.h b/mace/utils/statistics.h similarity index 97% rename from mace/benchmark/statistics.h rename to mace/utils/statistics.h index e21632daaf2c289d2daf8fd6676b918f8b6a5b67..3162c38c0375257c527c4378edca61b31ab05dc7 100644 --- a/mace/benchmark/statistics.h +++ b/mace/utils/statistics.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MACE_BENCHMARK_STATISTICS_H_ -#define MACE_BENCHMARK_STATISTICS_H_ +#ifndef MACE_UTILS_STATISTICS_H_ +#define MACE_UTILS_STATISTICS_H_ #include #include @@ -182,4 +182,4 @@ class OpStat { } // namespace benchmark } // namespace mace -#endif // MACE_BENCHMARK_STATISTICS_H_ +#endif // MACE_UTILS_STATISTICS_H_ diff --git a/mace/public/status.cc b/mace/utils/status.cc similarity index 100% rename from mace/public/status.cc rename to mace/utils/status.cc diff --git a/mace/utils/thread_pool.cc b/mace/utils/thread_pool.cc index 5fa3ad6e419b8f597c803d173bf9ec47b94c6fd2..c6596e5c52b991c1f198d93ba369b8d10e5a7d62 100644 --- a/mace/utils/thread_pool.cc +++ b/mace/utils/thread_pool.cc @@ -179,7 +179,7 @@ void ThreadPool::Init() { if (threads_.size() <= 1) { return; } - count_down_latch_.Reset(threads_.size() - 1); + count_down_latch_.Reset(static_cast(threads_.size() - 1)); event_ = kThreadPoolInit; for (size_t i = 1; i < threads_.size(); ++i) { threads_[i] = std::thread(&ThreadPool::ThreadLoop, this, i); @@ -206,7 +206,7 @@ void ThreadPool::Run(const std::function &func, iters_offset = thread_infos_[i].range_end; } - count_down_latch_.Reset(thread_count - 1); + count_down_latch_.Reset(static_cast(thread_count - 1)); { std::unique_lock m(event_mutex_); event_.store(kThreadPoolRun | ~(event_ | kThreadPoolEventMask), diff --git a/mace/utils/tuner.h b/mace/utils/tuner.h index 5d381b048a68ee9c728b656e8efdcd72d6971d5a..41a185fd836ca30e23c4758237a5fb826d59d7f2 100644 --- a/mace/utils/tuner.h +++ b/mace/utils/tuner.h @@ -15,31 +15,30 @@ #ifndef MACE_UTILS_TUNER_H_ #define MACE_UTILS_TUNER_H_ -// TODO(heliangliang) Fix portability -#include -#include -#include -#include - #include #include #include #include #include #include +#include #include #include #include +#include "mace/port/env.h" +#include "mace/port/file_system.h" #include "mace/utils/logging.h" +#include "mace/utils/memory.h" #include "mace/utils/string_util.h" #include "mace/utils/timer.h" namespace mace { inline bool IsTuning() { - const char *tuning = getenv("MACE_TUNING"); - return tuning != nullptr && strlen(tuning) == 1 && tuning[0] == '1'; + std::string tuning; + GetEnv("MACE_TUNING", &tuning); + return tuning.size() == 1 && tuning[0] == '1'; } template @@ -49,7 +48,7 @@ class Tuner { const unsigned char *param_byte_stream = nullptr, const size_t param_byte_stream_size = 0): tuned_param_file_path_(tuned_param_file_path) { - path_ = getenv("MACE_RUN_PARAMETER_PATH"); + GetEnv("MACE_RUN_PARAMETER_PATH", &path_); if (param_byte_stream != nullptr && param_byte_stream_size != 0) { ParseData(param_byte_stream, param_byte_stream_size); } else { @@ -94,10 +93,10 @@ class Tuner { } private: - inline void WriteRunParameters() { - if (path_ != nullptr) { + void WriteRunParameters() { + if (!path_.empty()) { VLOG(3) << "Write tuning result to " << path_; - std::ofstream ofs(path_, std::ios::binary | std::ios::out); + std::ofstream ofs(path_.c_str(), std::ios::binary | std::ios::out); if (ofs.is_open()) { int64_t num_pramas = param_table_.size(); ofs.write(reinterpret_cast(&num_pramas), sizeof(num_pramas)); @@ -124,7 +123,7 @@ class Tuner { } } - inline void ParseData(const unsigned char *data, size_t data_size) { + void ParseData(const unsigned char *data, size_t data_size) { const size_t int_size = sizeof(int32_t); const size_t param_type_size = sizeof(param_type); @@ -160,68 +159,20 @@ class Tuner { } } - inline void ReadRunParamters() { + void ReadRunParamters() { if (!tuned_param_file_path_.empty()) { - struct stat st; - if (stat(tuned_param_file_path_.c_str(), &st) == -1) { - if (errno == ENOENT) { - VLOG(1) << "File " << tuned_param_file_path_ - << " does not exist"; - } else { - LOG(WARNING) << "Stat file " << tuned_param_file_path_ - << " failed, error code: " << strerror(errno); - } - return; - } else if (!S_ISREG(st.st_mode)) { - VLOG(1) << "The path " << tuned_param_file_path_ - << " is not a file"; - return; - } - int fd = open(tuned_param_file_path_.c_str(), O_RDONLY); - if (fd < 0) { - if (errno == ENOENT) { - LOG(INFO) << "File " << tuned_param_file_path_ - << " does not exist"; - } else { - LOG(WARNING) << "open file " << tuned_param_file_path_ - << " failed, error code: " << strerror(errno); - } - return; - } - size_t file_size = st.st_size; - unsigned char *file_data = - static_cast(mmap(nullptr, file_size, PROT_READ, - MAP_PRIVATE, fd, 0)); - int res = 0; - if (file_data == MAP_FAILED) { - LOG(WARNING) << "mmap file " << tuned_param_file_path_ - << " failed, error code: " << strerror(errno); - - res = close(fd); - if (res != 0) { - LOG(WARNING) << "close file " << tuned_param_file_path_ - << " failed, error code: " << strerror(errno); - } - return; - } - - ParseData(file_data, file_size); - res = munmap(file_data, file_size); - if (res != 0) { - LOG(WARNING) << "munmap file " << tuned_param_file_path_ - << " failed, error code: " << strerror(errno); - res = close(fd); - if (res != 0) { - LOG(WARNING) << "close file " << tuned_param_file_path_ - << " failed, error code: " << strerror(errno); - } - return; - } - res = close(fd); - if (res != 0) { - LOG(WARNING) << "close file " << tuned_param_file_path_ - << " failed, error code: " << strerror(errno); + std::unique_ptr param_data = + make_unique(); + auto fs = GetFileSystem(); + auto status = fs->NewReadOnlyMemoryRegionFromFile( + tuned_param_file_path_.c_str(), ¶m_data); + if (status != MaceStatus::MACE_SUCCESS) { + LOG(ERROR) << "Failed to read tuned param file: " + << tuned_param_file_path_; return; + } else { + ParseData(static_cast(param_data->data()), + param_data->length()); } } else { VLOG(1) << "There is no tuned parameters."; @@ -229,15 +180,14 @@ class Tuner { } template - inline RetType Run( - const std::function &, - Timer *, - std::vector *)> &func, - const std::vector ¶ms, - Timer *timer, - int num_runs, - double *time_us, - std::vector *tuning_result) { + RetType Run(const std::function &, + Timer *, + std::vector *)> &func, + const std::vector ¶ms, + Timer *timer, + int num_runs, + double *time_us, + std::vector *tuning_result) { RetType res = 0; int iter = 0; int64_t total_time_us = 0; @@ -255,14 +205,13 @@ class Tuner { } template - inline RetType Tune( - const std::function>()> - ¶m_generator, - const std::function &, - Timer *, - std::vector *)> &func, - Timer *timer, - std::vector *opt_params) { + RetType Tune(const std::function>()> + ¶m_generator, + const std::function &, + Timer *, + std::vector *)> &func, + Timer *timer, + std::vector *opt_params) { RetType res = 0; double opt_time = std::numeric_limits::max(); auto params = param_generator(); @@ -288,7 +237,7 @@ class Tuner { private: std::string tuned_param_file_path_; - const char *path_; + std::string path_; std::unordered_map> param_table_; }; diff --git a/repository/git/git_configure.bzl b/repository/git/git_configure.bzl index aa1ea598970b60b4f3a0b8d79d6e35cf282565e9..aa01530606f6f6f7624c76338dadddcaeefd90a3 100644 --- a/repository/git/git_configure.bzl +++ b/repository/git/git_configure.bzl @@ -20,7 +20,7 @@ def _git_version_conf_impl(repository_ctx): unused_var = repository_ctx.path(Label("//:.git/refs/heads/master")) repository_ctx.execute([ - 'bash', '%s/mace/tools/git/gen_version_source.sh' % mace_root_path + 'bash', '%s/mace/codegen/tools/gen_version_source.sh' % mace_root_path , '%s/version' % generated_files_path ], quiet=False) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2c492593fd59b866f6ae56edb7d55b7c2335d762 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,11 @@ +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() diff --git a/test/ccbenchmark/BUILD.bazel b/test/ccbenchmark/BUILD.bazel new file mode 100644 index 0000000000000000000000000000000000000000..4b8eefb6eeea5b333c382fba798a86c62b128fb9 --- /dev/null +++ b/test/ccbenchmark/BUILD.bazel @@ -0,0 +1,75 @@ +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", + ], +) diff --git a/test/ccbenchmark/CMakeLists.txt b/test/ccbenchmark/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a4278dbed5c06746034a991b80541771107d3a45 --- /dev/null +++ b/test/ccbenchmark/CMakeLists.txt @@ -0,0 +1,19 @@ +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) diff --git a/mace/core/testing/test_benchmark.cc b/test/ccbenchmark/mace/benchmark_utils/test_benchmark.cc similarity index 98% rename from mace/core/testing/test_benchmark.cc rename to test/ccbenchmark/mace/benchmark_utils/test_benchmark.cc index a7cd149579bc6d6bf875a7b993010d6243a4d49a..a41fd55d060fbb5b9bd3ca9abe137d59a6202155 100644 --- a/mace/core/testing/test_benchmark.cc +++ b/test/ccbenchmark/mace/benchmark_utils/test_benchmark.cc @@ -19,7 +19,7 @@ #include // NOLINT(build/c++11) #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/port/env.h" #include "mace/utils/logging.h" diff --git a/mace/core/testing/test_benchmark.h b/test/ccbenchmark/mace/benchmark_utils/test_benchmark.h similarity index 88% rename from mace/core/testing/test_benchmark.h rename to test/ccbenchmark/mace/benchmark_utils/test_benchmark.h index 1082510ac33e067c5ef27c0bc45cce7a9b978540..12c7672bd5c80bcfff9397668168c5a5df48237b 100644 --- a/mace/core/testing/test_benchmark.h +++ b/test/ccbenchmark/mace/benchmark_utils/test_benchmark.h @@ -13,15 +13,13 @@ // limitations under the License. // Simple benchmarking facility. -#ifndef MACE_CORE_TESTING_TEST_BENCHMARK_H_ -#define MACE_CORE_TESTING_TEST_BENCHMARK_H_ +#ifndef MACE_BENCHMARK_UTILS_TEST_BENCHMARK_H_ +#define MACE_BENCHMARK_UTILS_TEST_BENCHMARK_H_ #include #include #include -#include "mace/core/types.h" - #define MACE_BENCHMARK(n) \ static ::mace::testing::Benchmark *__benchmark_##n = \ (new ::mace::testing::Benchmark(#n, (n))) @@ -52,4 +50,4 @@ void StopTiming(); } // namespace testing } // namespace mace -#endif // MACE_CORE_TESTING_TEST_BENCHMARK_H_ +#endif // MACE_BENCHMARK_UTILS_TEST_BENCHMARK_H_ diff --git a/mace/core/testing/test_benchmark_main.cc b/test/ccbenchmark/mace/benchmark_utils/test_benchmark_main.cc similarity index 96% rename from mace/core/testing/test_benchmark_main.cc rename to test/ccbenchmark/mace/benchmark_utils/test_benchmark_main.cc index 9da650f8192f5e384a2367098938deff19902d81..43059577d6ad363aba7432b5df600bcd81adcde3 100644 --- a/mace/core/testing/test_benchmark_main.cc +++ b/test/ccbenchmark/mace/benchmark_utils/test_benchmark_main.cc @@ -16,7 +16,7 @@ #include "gflags/gflags.h" #include "mace/core/runtime/cpu/cpu_runtime.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" DEFINE_string(filter, "all", "op benchmark regex filter, eg:.*CONV.*"); diff --git a/mace/ops/activation_benchmark.cc b/test/ccbenchmark/mace/ops/activation_benchmark.cc similarity index 99% rename from mace/ops/activation_benchmark.cc rename to test/ccbenchmark/mace/ops/activation_benchmark.cc index 9f78ee7ec966bd86577d76d8edf0cba9d6e76443..c1e79288ecaa39ae06c11c6815b6558bee3e879a 100644 --- a/mace/ops/activation_benchmark.cc +++ b/test/ccbenchmark/mace/ops/activation_benchmark.cc @@ -14,7 +14,7 @@ #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/addn_benchmark.cc b/test/ccbenchmark/mace/ops/addn_benchmark.cc similarity index 98% rename from mace/ops/addn_benchmark.cc rename to test/ccbenchmark/mace/ops/addn_benchmark.cc index 1933597e626dea0c842e1165024ad255547b44fe..c4d9a1adbd59479038f746cae8868f22ea28dd2f 100644 --- a/mace/ops/addn_benchmark.cc +++ b/test/ccbenchmark/mace/ops/addn_benchmark.cc @@ -14,7 +14,7 @@ #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/batch_norm_benchmark.cc b/test/ccbenchmark/mace/ops/batch_norm_benchmark.cc similarity index 98% rename from mace/ops/batch_norm_benchmark.cc rename to test/ccbenchmark/mace/ops/batch_norm_benchmark.cc index 939cb3cb2428287487576a5a5cfa1e2b83c3409f..068d604bba8b1b956c056da4d8e55d157e293195 100644 --- a/mace/ops/batch_norm_benchmark.cc +++ b/test/ccbenchmark/mace/ops/batch_norm_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/batch_to_space_benchmark.cc b/test/ccbenchmark/mace/ops/batch_to_space_benchmark.cc similarity index 98% rename from mace/ops/batch_to_space_benchmark.cc rename to test/ccbenchmark/mace/ops/batch_to_space_benchmark.cc index c05f4316b8c18cb4599b05260b63565099a1f77e..a438cea243deb30af9f7bb1933a8605198bf37fe 100644 --- a/mace/ops/batch_to_space_benchmark.cc +++ b/test/ccbenchmark/mace/ops/batch_to_space_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/bias_add_benchmark.cc b/test/ccbenchmark/mace/ops/bias_add_benchmark.cc similarity index 98% rename from mace/ops/bias_add_benchmark.cc rename to test/ccbenchmark/mace/ops/bias_add_benchmark.cc index 8c51b70361ea02ecdbc7ae8ba8dc00727ea16dd8..7c3a17e45aaf6e4769a539e9fbfb02db64eb59dc 100644 --- a/mace/ops/bias_add_benchmark.cc +++ b/test/ccbenchmark/mace/ops/bias_add_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/buffer_to_image_benchmark.cc b/test/ccbenchmark/mace/ops/buffer_to_image_benchmark.cc similarity index 98% rename from mace/ops/buffer_to_image_benchmark.cc rename to test/ccbenchmark/mace/ops/buffer_to_image_benchmark.cc index 2a8c42b3a142e723efb8ed6014bab9f486f5e9eb..6e5f7017e822dadb8d8c1044dc8875631fa6a28d 100644 --- a/mace/ops/buffer_to_image_benchmark.cc +++ b/test/ccbenchmark/mace/ops/buffer_to_image_benchmark.cc @@ -15,7 +15,7 @@ #ifdef MACE_ENABLE_OPENCL #include "mace/core/runtime/opencl/opencl_runtime.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/opencl/buffer_transformer.h" #include "mace/ops/ops_test_util.h" diff --git a/mace/ops/channel_shuffle_benchmark.cc b/test/ccbenchmark/mace/ops/channel_shuffle_benchmark.cc similarity index 98% rename from mace/ops/channel_shuffle_benchmark.cc rename to test/ccbenchmark/mace/ops/channel_shuffle_benchmark.cc index 456ea8c3b6389521a90c7fe20f5ca1e7370eb997..b6b0c72132d6a0ab28c438be372c5df556e921ec 100644 --- a/mace/ops/channel_shuffle_benchmark.cc +++ b/test/ccbenchmark/mace/ops/channel_shuffle_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/concat_benchmark.cc b/test/ccbenchmark/mace/ops/concat_benchmark.cc similarity index 98% rename from mace/ops/concat_benchmark.cc rename to test/ccbenchmark/mace/ops/concat_benchmark.cc index e67cfe991f5db9bf2d7bf0cf7f2cdcd08ba0c86d..4443ae762fe885c7b607eb0ed9b2aaa416980642 100644 --- a/mace/ops/concat_benchmark.cc +++ b/test/ccbenchmark/mace/ops/concat_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/conv_2d_benchmark.cc b/test/ccbenchmark/mace/ops/conv_2d_benchmark.cc similarity index 99% rename from mace/ops/conv_2d_benchmark.cc rename to test/ccbenchmark/mace/ops/conv_2d_benchmark.cc index 12bae8912dac006af50ef04245dad61120aa1d3b..3de9a7568f9699132c66f3c07de6b189ba0b4b8b 100644 --- a/mace/ops/conv_2d_benchmark.cc +++ b/test/ccbenchmark/mace/ops/conv_2d_benchmark.cc @@ -14,8 +14,8 @@ #include -#include "mace/benchmark/statistics.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/utils/statistics.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/common/conv_pool_2d_util.h" #include "mace/ops/ops_test_util.h" diff --git a/mace/ops/crop_benchmark.cc b/test/ccbenchmark/mace/ops/crop_benchmark.cc similarity index 98% rename from mace/ops/crop_benchmark.cc rename to test/ccbenchmark/mace/ops/crop_benchmark.cc index e51a555dcf8bde9e0defcdea0c8793ad3658a3ac..59b66949d4c7a057c306a20acc9cc224c45fba5c 100644 --- a/mace/ops/crop_benchmark.cc +++ b/test/ccbenchmark/mace/ops/crop_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/cumsum_benchmark.cc b/test/ccbenchmark/mace/ops/cumsum_benchmark.cc similarity index 98% rename from mace/ops/cumsum_benchmark.cc rename to test/ccbenchmark/mace/ops/cumsum_benchmark.cc index 8ca59fa0501fe92a35fbe0a02141cdd23a7c1198..81c2da218ef45b98921ec1e653a40e0aa97cea55 100644 --- a/mace/ops/cumsum_benchmark.cc +++ b/test/ccbenchmark/mace/ops/cumsum_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/deconv_2d_benchmark.cc b/test/ccbenchmark/mace/ops/deconv_2d_benchmark.cc similarity index 98% rename from mace/ops/deconv_2d_benchmark.cc rename to test/ccbenchmark/mace/ops/deconv_2d_benchmark.cc index 8a16e6918342e6d514ace4d7dbe11f9a77cfebb7..c3ef765227c841e3a8396dae2167f7fa5e9ff54c 100644 --- a/mace/ops/deconv_2d_benchmark.cc +++ b/test/ccbenchmark/mace/ops/deconv_2d_benchmark.cc @@ -14,8 +14,8 @@ #include -#include "mace/benchmark/statistics.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/utils/statistics.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/common/conv_pool_2d_util.h" #include "mace/ops/ops_test_util.h" diff --git a/mace/ops/delay_benchmark.cc b/test/ccbenchmark/mace/ops/delay_benchmark.cc similarity index 97% rename from mace/ops/delay_benchmark.cc rename to test/ccbenchmark/mace/ops/delay_benchmark.cc index 89218a3e80902387a4e1c431b90a5a089e1da0dc..ab5f0cf0001960eac8afff69a91ecf592a94c719 100644 --- a/mace/ops/delay_benchmark.cc +++ b/test/ccbenchmark/mace/ops/delay_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/depth_to_space_benchmark.cc b/test/ccbenchmark/mace/ops/depth_to_space_benchmark.cc similarity index 98% rename from mace/ops/depth_to_space_benchmark.cc rename to test/ccbenchmark/mace/ops/depth_to_space_benchmark.cc index e6f32ff587d61a376c73e6b6a3fe06163a1f9717..825fda2d44f381b3574e84a8462b5d64268615b2 100644 --- a/mace/ops/depth_to_space_benchmark.cc +++ b/test/ccbenchmark/mace/ops/depth_to_space_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/depthwise_conv2d_benchmark.cc b/test/ccbenchmark/mace/ops/depthwise_conv2d_benchmark.cc similarity index 98% rename from mace/ops/depthwise_conv2d_benchmark.cc rename to test/ccbenchmark/mace/ops/depthwise_conv2d_benchmark.cc index d04dfb3a8f50daa0dcb2718909aee7aadbeeeab5..7a72d6e22e7290b18e9160e6112a45c949ae5b54 100644 --- a/mace/ops/depthwise_conv2d_benchmark.cc +++ b/test/ccbenchmark/mace/ops/depthwise_conv2d_benchmark.cc @@ -14,8 +14,8 @@ #include -#include "mace/benchmark/statistics.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/utils/statistics.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/common/conv_pool_2d_util.h" #include "mace/ops/ops_test_util.h" diff --git a/mace/ops/depthwise_deconv2d_benchmark.cc b/test/ccbenchmark/mace/ops/depthwise_deconv2d_benchmark.cc similarity index 98% rename from mace/ops/depthwise_deconv2d_benchmark.cc rename to test/ccbenchmark/mace/ops/depthwise_deconv2d_benchmark.cc index 969c0ecc9ec30ae718eeae8032a56e02672792f4..2ac04e0c0a398e68e1b4cd4bab8b9b78db7a48ae 100644 --- a/mace/ops/depthwise_deconv2d_benchmark.cc +++ b/test/ccbenchmark/mace/ops/depthwise_deconv2d_benchmark.cc @@ -14,9 +14,9 @@ #include -#include "mace/benchmark/statistics.h" +#include "mace/utils/statistics.h" #include "mace/core/operator.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/dynamic_lstm_benchmark.cc b/test/ccbenchmark/mace/ops/dynamic_lstm_benchmark.cc similarity index 98% rename from mace/ops/dynamic_lstm_benchmark.cc rename to test/ccbenchmark/mace/ops/dynamic_lstm_benchmark.cc index 00cd11bfd28fe4108847021dd11a40a237d15125..659ea0e6d232efbf97be228629e89834c8b8c72e 100644 --- a/mace/ops/dynamic_lstm_benchmark.cc +++ b/test/ccbenchmark/mace/ops/dynamic_lstm_benchmark.cc @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/benchmark/statistics.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/utils/statistics.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/lstmcell_test_util.h" #include "mace/ops/ops_test_util.h" diff --git a/mace/ops/eltwise_benchmark.cc b/test/ccbenchmark/mace/ops/eltwise_benchmark.cc similarity index 98% rename from mace/ops/eltwise_benchmark.cc rename to test/ccbenchmark/mace/ops/eltwise_benchmark.cc index 5750132ddb2498b8d0aa08d593cc50d96059efb0..fded8a03aba4f52f1b56adb4f04c07d4ea81ba8a 100644 --- a/mace/ops/eltwise_benchmark.cc +++ b/test/ccbenchmark/mace/ops/eltwise_benchmark.cc @@ -14,7 +14,7 @@ #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/eltwise.h" #include "mace/ops/ops_test_util.h" diff --git a/mace/ops/extract_pooling_benchmark.cc b/test/ccbenchmark/mace/ops/extract_pooling_benchmark.cc similarity index 98% rename from mace/ops/extract_pooling_benchmark.cc rename to test/ccbenchmark/mace/ops/extract_pooling_benchmark.cc index 694777272bc9a004a050313dbc7b51593d9ef0e2..d2f847b6fb057a6bd341a36dbb29a146f34728ca 100644 --- a/mace/ops/extract_pooling_benchmark.cc +++ b/test/ccbenchmark/mace/ops/extract_pooling_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/fully_connected_benchmark.cc b/test/ccbenchmark/mace/ops/fully_connected_benchmark.cc similarity index 98% rename from mace/ops/fully_connected_benchmark.cc rename to test/ccbenchmark/mace/ops/fully_connected_benchmark.cc index 2b5bb07404f2ccbfae597ba09b1807b1ab5b2e89..bdc6105b17a8087c859fc42bf5f97e60fe732560 100644 --- a/mace/ops/fully_connected_benchmark.cc +++ b/test/ccbenchmark/mace/ops/fully_connected_benchmark.cc @@ -14,8 +14,8 @@ #include -#include "mace/benchmark/statistics.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/utils/statistics.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/gather_benchmark.cc b/test/ccbenchmark/mace/ops/gather_benchmark.cc similarity index 98% rename from mace/ops/gather_benchmark.cc rename to test/ccbenchmark/mace/ops/gather_benchmark.cc index a1a95b690280d9504e247dcf06a3ab5c5cf84bae..732038d5ec7e9afe75c6b4c88b9e1406eb853be9 100644 --- a/mace/ops/gather_benchmark.cc +++ b/test/ccbenchmark/mace/ops/gather_benchmark.cc @@ -14,7 +14,7 @@ #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/kaldi_batch_norm_benchmark.cc b/test/ccbenchmark/mace/ops/kaldi_batch_norm_benchmark.cc similarity index 98% rename from mace/ops/kaldi_batch_norm_benchmark.cc rename to test/ccbenchmark/mace/ops/kaldi_batch_norm_benchmark.cc index ac5e117bb92c9b71ed5d82ad760f10d1c7a73435..4a1f66bc5612b54579f19f1dd42dff0af14a1dfa 100644 --- a/mace/ops/kaldi_batch_norm_benchmark.cc +++ b/test/ccbenchmark/mace/ops/kaldi_batch_norm_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/local_response_norm_benchmark.cc b/test/ccbenchmark/mace/ops/local_response_norm_benchmark.cc similarity index 98% rename from mace/ops/local_response_norm_benchmark.cc rename to test/ccbenchmark/mace/ops/local_response_norm_benchmark.cc index a8718c22b2e4b49d1cd4d8807ced45def4227bfc..9d9eac639d23365dda1f92641ed4a5f7ff461180 100644 --- a/mace/ops/local_response_norm_benchmark.cc +++ b/test/ccbenchmark/mace/ops/local_response_norm_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/lstm_nonlinear_benchmark.cc b/test/ccbenchmark/mace/ops/lstm_nonlinear_benchmark.cc similarity index 98% rename from mace/ops/lstm_nonlinear_benchmark.cc rename to test/ccbenchmark/mace/ops/lstm_nonlinear_benchmark.cc index 6ca881c57f4fa768368a6977fbe89ac276dd83c1..b383d86e875e4dd821c1642243960490dd45004c 100644 --- a/mace/ops/lstm_nonlinear_benchmark.cc +++ b/test/ccbenchmark/mace/ops/lstm_nonlinear_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/lstmcell_test_util.h" #include "mace/ops/ops_test_util.h" diff --git a/mace/ops/lstmcell_benchmark.cc b/test/ccbenchmark/mace/ops/lstmcell_benchmark.cc similarity index 98% rename from mace/ops/lstmcell_benchmark.cc rename to test/ccbenchmark/mace/ops/lstmcell_benchmark.cc index 9f16a51b9c8c1630e3d82033e097cd5c2d1ef6cc..56c1e3f753fedd75ec3b1a067d3d559d85a068f4 100644 --- a/mace/ops/lstmcell_benchmark.cc +++ b/test/ccbenchmark/mace/ops/lstmcell_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/lstmcell_test_util.h" #include "mace/ops/ops_test_util.h" diff --git a/mace/ops/matmul_benchmark.cc b/test/ccbenchmark/mace/ops/matmul_benchmark.cc similarity index 99% rename from mace/ops/matmul_benchmark.cc rename to test/ccbenchmark/mace/ops/matmul_benchmark.cc index c0d5af05c172cd108286fa3ec1c0f25ee776531a..a478b6db2c8edf52944c36ff6549628d4fc1096f 100644 --- a/mace/ops/matmul_benchmark.cc +++ b/test/ccbenchmark/mace/ops/matmul_benchmark.cc @@ -19,8 +19,8 @@ #include #include "public/gemmlowp.h" -#include "mace/benchmark/statistics.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/utils/statistics.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace gemmlowp { diff --git a/mace/ops/memory_benchmark.cc b/test/ccbenchmark/mace/ops/memory_benchmark.cc similarity index 98% rename from mace/ops/memory_benchmark.cc rename to test/ccbenchmark/mace/ops/memory_benchmark.cc index c758891b38a11a7c0ffb9cb2bd2f87f0544bea08..1ef878f8df3619a7d3dd1b0369c88b6bf86b1f6c 100644 --- a/mace/ops/memory_benchmark.cc +++ b/test/ccbenchmark/mace/ops/memory_benchmark.cc @@ -16,7 +16,7 @@ #include #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" namespace mace { namespace ops { diff --git a/mace/ops/one_hot_benchmark.cc b/test/ccbenchmark/mace/ops/one_hot_benchmark.cc similarity index 98% rename from mace/ops/one_hot_benchmark.cc rename to test/ccbenchmark/mace/ops/one_hot_benchmark.cc index ecb5ca8a165315c2729dae9af9f6f80d80d4f812..0e85914e78f22d588848df03e01942df1f9bb2af 100644 --- a/mace/ops/one_hot_benchmark.cc +++ b/test/ccbenchmark/mace/ops/one_hot_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/pad_benchmark.cc b/test/ccbenchmark/mace/ops/pad_benchmark.cc similarity index 98% rename from mace/ops/pad_benchmark.cc rename to test/ccbenchmark/mace/ops/pad_benchmark.cc index 0d629c8ece9afa40a5ed68ecae3f5b93a52bf7f0..2d0b4bc42a41a31ce4640b4d8227245084490515 100644 --- a/mace/ops/pad_benchmark.cc +++ b/test/ccbenchmark/mace/ops/pad_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" #include "mace/ops/pad.h" diff --git a/mace/ops/pad_context_benchmark.cc b/test/ccbenchmark/mace/ops/pad_context_benchmark.cc similarity index 98% rename from mace/ops/pad_context_benchmark.cc rename to test/ccbenchmark/mace/ops/pad_context_benchmark.cc index 3384f79d9f7aef9d18785cf89511de64f5ca609d..0f83b87b5d7a3b0ae859613ccac869af668e76ea 100644 --- a/mace/ops/pad_context_benchmark.cc +++ b/test/ccbenchmark/mace/ops/pad_context_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/pnorm_benchmark.cc b/test/ccbenchmark/mace/ops/pnorm_benchmark.cc similarity index 97% rename from mace/ops/pnorm_benchmark.cc rename to test/ccbenchmark/mace/ops/pnorm_benchmark.cc index e1efd0eb4052981188ae703f8044913c54afe671..c44e5df4c5a3a4fe32def0c037105634d6f82fb7 100644 --- a/mace/ops/pnorm_benchmark.cc +++ b/test/ccbenchmark/mace/ops/pnorm_benchmark.cc @@ -14,7 +14,7 @@ #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/pooling_benchmark.cc b/test/ccbenchmark/mace/ops/pooling_benchmark.cc similarity index 98% rename from mace/ops/pooling_benchmark.cc rename to test/ccbenchmark/mace/ops/pooling_benchmark.cc index 6dc0aad21086919ec77225cddcc73910a1cf650b..6b66a9fa7032ca29fc16fe888c9f532997ee37de 100644 --- a/mace/ops/pooling_benchmark.cc +++ b/test/ccbenchmark/mace/ops/pooling_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/common/conv_pool_2d_util.h" #include "mace/ops/pooling.h" #include "mace/ops/ops_test_util.h" diff --git a/mace/ops/prior_box_benchmark.cc b/test/ccbenchmark/mace/ops/prior_box_benchmark.cc similarity index 98% rename from mace/ops/prior_box_benchmark.cc rename to test/ccbenchmark/mace/ops/prior_box_benchmark.cc index f218e8ef9abb890adc07d4d2ccc4809a37ec098c..1ab6e8a124bf6e32b32b832c89e9244ca412b02d 100644 --- a/mace/ops/prior_box_benchmark.cc +++ b/test/ccbenchmark/mace/ops/prior_box_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/quantize_benchmark.cc b/test/ccbenchmark/mace/ops/quantize_benchmark.cc similarity index 98% rename from mace/ops/quantize_benchmark.cc rename to test/ccbenchmark/mace/ops/quantize_benchmark.cc index c42cea360f5b75f5e436fed592b362a526c0be84..0923a29310b4483ee9abcd249194b1782213c37a 100644 --- a/mace/ops/quantize_benchmark.cc +++ b/test/ccbenchmark/mace/ops/quantize_benchmark.cc @@ -15,7 +15,7 @@ #ifdef MACE_ENABLE_QUANTIZE #include "mace/core/operator.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/reduce_benchmark.cc b/test/ccbenchmark/mace/ops/reduce_benchmark.cc similarity index 98% rename from mace/ops/reduce_benchmark.cc rename to test/ccbenchmark/mace/ops/reduce_benchmark.cc index 6555515254302b4fcbdc3b6f2ecd5d50e1522075..22effd701e723a0713934bde9a4d2ff433000654 100644 --- a/mace/ops/reduce_benchmark.cc +++ b/test/ccbenchmark/mace/ops/reduce_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/resize_bicubic_benchmark.cc b/test/ccbenchmark/mace/ops/resize_bicubic_benchmark.cc similarity index 97% rename from mace/ops/resize_bicubic_benchmark.cc rename to test/ccbenchmark/mace/ops/resize_bicubic_benchmark.cc index 5dc377fd79a62d77d8f4dfe218409989db8328f6..7afc2eea258169ac17753599991c5c2cdafc0067 100644 --- a/mace/ops/resize_bicubic_benchmark.cc +++ b/test/ccbenchmark/mace/ops/resize_bicubic_benchmark.cc @@ -14,8 +14,8 @@ #include -#include "mace/benchmark/statistics.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/utils/statistics.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/resize_bilinear_benchmark.cc b/test/ccbenchmark/mace/ops/resize_bilinear_benchmark.cc similarity index 98% rename from mace/ops/resize_bilinear_benchmark.cc rename to test/ccbenchmark/mace/ops/resize_bilinear_benchmark.cc index 64a19f54591c99838ef3fa70f677ba0235e31848..5b472a68eb9423fc00fd5c7e24d69bd02725fbe8 100644 --- a/mace/ops/resize_bilinear_benchmark.cc +++ b/test/ccbenchmark/mace/ops/resize_bilinear_benchmark.cc @@ -14,8 +14,8 @@ #include -#include "mace/benchmark/statistics.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/utils/statistics.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/resize_nearest_neighbor_benchmark.cc b/test/ccbenchmark/mace/ops/resize_nearest_neighbor_benchmark.cc similarity index 98% rename from mace/ops/resize_nearest_neighbor_benchmark.cc rename to test/ccbenchmark/mace/ops/resize_nearest_neighbor_benchmark.cc index 6fbaff5291c45a094dcf6b873aaaef96d7850541..6ab13684b2498582326d94570d063fd5d7f44041 100644 --- a/mace/ops/resize_nearest_neighbor_benchmark.cc +++ b/test/ccbenchmark/mace/ops/resize_nearest_neighbor_benchmark.cc @@ -14,8 +14,8 @@ #include -#include "mace/benchmark/statistics.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/utils/statistics.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/reverse_benchmark.cc b/test/ccbenchmark/mace/ops/reverse_benchmark.cc similarity index 97% rename from mace/ops/reverse_benchmark.cc rename to test/ccbenchmark/mace/ops/reverse_benchmark.cc index e9d225d3a413f891d8e446523bfd4c60628c8ebb..760268a4db46e70940178f739326bd9475e6f795 100644 --- a/mace/ops/reverse_benchmark.cc +++ b/test/ccbenchmark/mace/ops/reverse_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/slice_benchmark.cc b/test/ccbenchmark/mace/ops/slice_benchmark.cc similarity index 98% rename from mace/ops/slice_benchmark.cc rename to test/ccbenchmark/mace/ops/slice_benchmark.cc index fd2a383934964c37d132ec9fc4fe6dd731f490b6..ac88251711f7c84cc10e09ea55af7acf089643e0 100644 --- a/mace/ops/slice_benchmark.cc +++ b/test/ccbenchmark/mace/ops/slice_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/softmax_benchmark.cc b/test/ccbenchmark/mace/ops/softmax_benchmark.cc similarity index 98% rename from mace/ops/softmax_benchmark.cc rename to test/ccbenchmark/mace/ops/softmax_benchmark.cc index ec70e94b1cbc2e31ba8f3fe9d19ac7f8e677929f..a5b06c50c640b79abf6b13e98b7bb16184f4e60d 100644 --- a/mace/ops/softmax_benchmark.cc +++ b/test/ccbenchmark/mace/ops/softmax_benchmark.cc @@ -14,7 +14,7 @@ #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/space_to_batch_benchmark.cc b/test/ccbenchmark/mace/ops/space_to_batch_benchmark.cc similarity index 98% rename from mace/ops/space_to_batch_benchmark.cc rename to test/ccbenchmark/mace/ops/space_to_batch_benchmark.cc index 4a9fa11ed989c45c962cc9346eb2fa28939efe9c..9539e6f0d27488894fc39112aa0991659f5235a4 100644 --- a/mace/ops/space_to_batch_benchmark.cc +++ b/test/ccbenchmark/mace/ops/space_to_batch_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/space_to_depth_benchmark.cc b/test/ccbenchmark/mace/ops/space_to_depth_benchmark.cc similarity index 98% rename from mace/ops/space_to_depth_benchmark.cc rename to test/ccbenchmark/mace/ops/space_to_depth_benchmark.cc index 56d6a0c1ac8e07998d9bdbe2b4f36598bc332e24..e49214e2a5e01292a7944de4ed8a26a40ca73f88 100644 --- a/mace/ops/space_to_depth_benchmark.cc +++ b/test/ccbenchmark/mace/ops/space_to_depth_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/splice_benchmark.cc b/test/ccbenchmark/mace/ops/splice_benchmark.cc similarity index 98% rename from mace/ops/splice_benchmark.cc rename to test/ccbenchmark/mace/ops/splice_benchmark.cc index 2a90493dcf2535e341db49fe848127bf70bd1929..03820f851d0e1a8936b1a0d2f64bf467ae561d95 100644 --- a/mace/ops/splice_benchmark.cc +++ b/test/ccbenchmark/mace/ops/splice_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/split_benchmark.cc b/test/ccbenchmark/mace/ops/split_benchmark.cc similarity index 98% rename from mace/ops/split_benchmark.cc rename to test/ccbenchmark/mace/ops/split_benchmark.cc index 1cce558e80ec5e76a2d84d0049063d5f970f8c81..efbd417c69e726caa39e1ce52d235efca2d8e239 100644 --- a/mace/ops/split_benchmark.cc +++ b/test/ccbenchmark/mace/ops/split_benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/sqrdiff_mean_benchmark.cc b/test/ccbenchmark/mace/ops/sqrdiff_mean_benchmark.cc similarity index 98% rename from mace/ops/sqrdiff_mean_benchmark.cc rename to test/ccbenchmark/mace/ops/sqrdiff_mean_benchmark.cc index 211d8813f54eb01cae52fd6bfddc9b9372406b11..05eaf21d11c3fb5dd36173f73f9ba1d70a892c62 100644 --- a/mace/ops/sqrdiff_mean_benchmark.cc +++ b/test/ccbenchmark/mace/ops/sqrdiff_mean_benchmark.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "mace/core/operator.h" -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/sum_group_benchmark.cc b/test/ccbenchmark/mace/ops/sum_group_benchmark.cc similarity index 97% rename from mace/ops/sum_group_benchmark.cc rename to test/ccbenchmark/mace/ops/sum_group_benchmark.cc index bb3b20e855b23a0babd9d31cee840425cce9545c..91ec56fc7cf5572a9eea826f267e957f48a44cb7 100644 --- a/mace/ops/sum_group_benchmark.cc +++ b/test/ccbenchmark/mace/ops/sum_group_benchmark.cc @@ -14,7 +14,7 @@ #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/target_rms_norm_benchmark.cc b/test/ccbenchmark/mace/ops/target_rms_norm_benchmark.cc similarity index 97% rename from mace/ops/target_rms_norm_benchmark.cc rename to test/ccbenchmark/mace/ops/target_rms_norm_benchmark.cc index d496bb8b101bc8f083e077bc0c8754c1cf932b0f..79dde3ff4ebd0e301a0e7c216bd6ad4a554b353e 100644 --- a/mace/ops/target_rms_norm_benchmark.cc +++ b/test/ccbenchmark/mace/ops/target_rms_norm_benchmark.cc @@ -14,7 +14,7 @@ #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/mace/ops/thread_pool_benchmark.cc b/test/ccbenchmark/mace/ops/thread_pool_benchmark.cc similarity index 98% rename from mace/ops/thread_pool_benchmark.cc rename to test/ccbenchmark/mace/ops/thread_pool_benchmark.cc index f800929809725ac73cd63fb082831e0dd7a38dd5..32eaa32ff12d90e1aba5e077e9f6f4dd9e4e78bb 100644 --- a/mace/ops/thread_pool_benchmark.cc +++ b/test/ccbenchmark/mace/ops/thread_pool_benchmark.cc @@ -18,7 +18,8 @@ #include #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/core/types.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/utils/thread_pool.h" #define MACE_EMPTY_STATEMENT asm volatile("":::"memory"); diff --git a/mace/ops/transpose_benchmark.cc b/test/ccbenchmark/mace/ops/transpose_benchmark.cc similarity index 98% rename from mace/ops/transpose_benchmark.cc rename to test/ccbenchmark/mace/ops/transpose_benchmark.cc index 3c88cbe886bf4916ee7fc92de72a0c99281e4763..a041ba1a3cfe0ae9dcc3b39f4a34df317deaf845 100644 --- a/mace/ops/transpose_benchmark.cc +++ b/test/ccbenchmark/mace/ops/transpose_benchmark.cc @@ -15,7 +15,7 @@ #include #include -#include "mace/core/testing/test_benchmark.h" +#include "mace/benchmark_utils/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { diff --git a/test/ccunit/BUILD.bazel b/test/ccunit/BUILD.bazel new file mode 100644 index 0000000000000000000000000000000000000000..d3039c0067793111783cda70398f8ac7a35f094d --- /dev/null +++ b/test/ccunit/BUILD.bazel @@ -0,0 +1,72 @@ +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", + ], +) diff --git a/test/ccunit/CMakeLists.txt b/test/ccunit/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..21107815e9b604e4a0eb616db4d9c20c80186c6c --- /dev/null +++ b/test/ccunit/CMakeLists.txt @@ -0,0 +1,18 @@ +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) diff --git a/mace/test/BUILD.bazel b/test/ccunit/mace/libmace/BUILD.bazel similarity index 100% rename from mace/test/BUILD.bazel rename to test/ccunit/mace/libmace/BUILD.bazel diff --git a/mace/test/device_capability_api_test.cc b/test/ccunit/mace/libmace/device_capability_api_test.cc similarity index 100% rename from mace/test/device_capability_api_test.cc rename to test/ccunit/mace/libmace/device_capability_api_test.cc diff --git a/mace/test/mace_api_exception_test.cc b/test/ccunit/mace/libmace/mace_api_exception_test.cc similarity index 100% rename from mace/test/mace_api_exception_test.cc rename to test/ccunit/mace/libmace/mace_api_exception_test.cc diff --git a/mace/test/mace_api_mt_test.cc b/test/ccunit/mace/libmace/mace_api_mt_test.cc similarity index 98% rename from mace/test/mace_api_mt_test.cc rename to test/ccunit/mace/libmace/mace_api_mt_test.cc index a06ce49347ea117d501c2d1273291be802b3dd69..77a5977ba6d8568514dbce94e5ab7ec81e96781f 100644 --- a/mace/test/mace_api_mt_test.cc +++ b/test/ccunit/mace/libmace/mace_api_mt_test.cc @@ -16,7 +16,7 @@ #include // NOLINT(build/c++11) -#include "mace/test/mace_api_test.h" +#include "mace/libmace/mace_api_test.h" namespace mace { namespace test { diff --git a/mace/test/mace_api_test.cc b/test/ccunit/mace/libmace/mace_api_test.cc similarity index 99% rename from mace/test/mace_api_test.cc rename to test/ccunit/mace/libmace/mace_api_test.cc index 6cad55b91464937586398f77f7e0694011d6cbda..50e897f0a41d2b6653cb6723fa31ec7c2741aeed 100644 --- a/mace/test/mace_api_test.cc +++ b/test/ccunit/mace/libmace/mace_api_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "mace/test/mace_api_test.h" +#include "mace/libmace/mace_api_test.h" namespace mace { namespace test { diff --git a/mace/test/mace_api_test.h b/test/ccunit/mace/libmace/mace_api_test.h similarity index 98% rename from mace/test/mace_api_test.h rename to test/ccunit/mace/libmace/mace_api_test.h index faaf144347f0020f39e6de3c9d50d7b553b03b17..652a46a7bf92e891c1e4446e62e5fcfd7af9a56d 100644 --- a/mace/test/mace_api_test.h +++ b/test/ccunit/mace/libmace/mace_api_test.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MACE_TEST_MACE_API_TEST_H_ -#define MACE_TEST_MACE_API_TEST_H_ +#ifndef MACE_LIBMACE_MACE_API_TEST_H_ +#define MACE_LIBMACE_MACE_API_TEST_H_ #include #include @@ -187,4 +187,4 @@ void CheckOutputs(const NetDef &net_def, } } // namespace test } // namespace mace -#endif // MACE_TEST_MACE_API_TEST_H_ +#endif // MACE_LIBMACE_MACE_API_TEST_H_ diff --git a/mace/ops/activation_test.cc b/test/ccunit/mace/ops/activation_test.cc similarity index 100% rename from mace/ops/activation_test.cc rename to test/ccunit/mace/ops/activation_test.cc diff --git a/mace/ops/addn_test.cc b/test/ccunit/mace/ops/addn_test.cc similarity index 100% rename from mace/ops/addn_test.cc rename to test/ccunit/mace/ops/addn_test.cc diff --git a/mace/ops/argmax_test.cc b/test/ccunit/mace/ops/argmax_test.cc similarity index 100% rename from mace/ops/argmax_test.cc rename to test/ccunit/mace/ops/argmax_test.cc diff --git a/mace/ops/arm/fp32/gemm_test.cc b/test/ccunit/mace/ops/arm/fp32/gemm_test.cc similarity index 100% rename from mace/ops/arm/fp32/gemm_test.cc rename to test/ccunit/mace/ops/arm/fp32/gemm_test.cc diff --git a/mace/ops/arm/fp32/gemv_test.cc b/test/ccunit/mace/ops/arm/fp32/gemv_test.cc similarity index 100% rename from mace/ops/arm/fp32/gemv_test.cc rename to test/ccunit/mace/ops/arm/fp32/gemv_test.cc diff --git a/mace/ops/arm/q8/gemv_test.cc b/test/ccunit/mace/ops/arm/q8/gemv_test.cc similarity index 100% rename from mace/ops/arm/q8/gemv_test.cc rename to test/ccunit/mace/ops/arm/q8/gemv_test.cc diff --git a/mace/ops/batch_norm_test.cc b/test/ccunit/mace/ops/batch_norm_test.cc similarity index 100% rename from mace/ops/batch_norm_test.cc rename to test/ccunit/mace/ops/batch_norm_test.cc diff --git a/mace/ops/bias_add_test.cc b/test/ccunit/mace/ops/bias_add_test.cc similarity index 100% rename from mace/ops/bias_add_test.cc rename to test/ccunit/mace/ops/bias_add_test.cc diff --git a/mace/ops/buffer_to_image_test.cc b/test/ccunit/mace/ops/buffer_to_image_test.cc similarity index 100% rename from mace/ops/buffer_to_image_test.cc rename to test/ccunit/mace/ops/buffer_to_image_test.cc diff --git a/mace/ops/buffer_transform_test.cc b/test/ccunit/mace/ops/buffer_transform_test.cc similarity index 100% rename from mace/ops/buffer_transform_test.cc rename to test/ccunit/mace/ops/buffer_transform_test.cc diff --git a/mace/ops/cast_test.cc b/test/ccunit/mace/ops/cast_test.cc similarity index 100% rename from mace/ops/cast_test.cc rename to test/ccunit/mace/ops/cast_test.cc diff --git a/mace/ops/channel_shuffle_test.cc b/test/ccunit/mace/ops/channel_shuffle_test.cc similarity index 100% rename from mace/ops/channel_shuffle_test.cc rename to test/ccunit/mace/ops/channel_shuffle_test.cc diff --git a/mace/ops/concat_test.cc b/test/ccunit/mace/ops/concat_test.cc similarity index 100% rename from mace/ops/concat_test.cc rename to test/ccunit/mace/ops/concat_test.cc diff --git a/mace/ops/conv_2d_test.cc b/test/ccunit/mace/ops/conv_2d_test.cc similarity index 100% rename from mace/ops/conv_2d_test.cc rename to test/ccunit/mace/ops/conv_2d_test.cc diff --git a/mace/ops/crop_test.cc b/test/ccunit/mace/ops/crop_test.cc similarity index 100% rename from mace/ops/crop_test.cc rename to test/ccunit/mace/ops/crop_test.cc diff --git a/mace/ops/cumsum_test.cc b/test/ccunit/mace/ops/cumsum_test.cc similarity index 100% rename from mace/ops/cumsum_test.cc rename to test/ccunit/mace/ops/cumsum_test.cc diff --git a/mace/ops/deconv_2d_test.cc b/test/ccunit/mace/ops/deconv_2d_test.cc similarity index 100% rename from mace/ops/deconv_2d_test.cc rename to test/ccunit/mace/ops/deconv_2d_test.cc diff --git a/mace/ops/depth_to_space_test.cc b/test/ccunit/mace/ops/depth_to_space_test.cc similarity index 100% rename from mace/ops/depth_to_space_test.cc rename to test/ccunit/mace/ops/depth_to_space_test.cc diff --git a/mace/ops/depthwise_conv2d_test.cc b/test/ccunit/mace/ops/depthwise_conv2d_test.cc similarity index 100% rename from mace/ops/depthwise_conv2d_test.cc rename to test/ccunit/mace/ops/depthwise_conv2d_test.cc diff --git a/mace/ops/depthwise_deconv2d_test.cc b/test/ccunit/mace/ops/depthwise_deconv2d_test.cc similarity index 100% rename from mace/ops/depthwise_deconv2d_test.cc rename to test/ccunit/mace/ops/depthwise_deconv2d_test.cc diff --git a/mace/ops/eltwise_test.cc b/test/ccunit/mace/ops/eltwise_test.cc similarity index 100% rename from mace/ops/eltwise_test.cc rename to test/ccunit/mace/ops/eltwise_test.cc diff --git a/mace/ops/expand_dims_test.cc b/test/ccunit/mace/ops/expand_dims_test.cc similarity index 100% rename from mace/ops/expand_dims_test.cc rename to test/ccunit/mace/ops/expand_dims_test.cc diff --git a/mace/ops/extract_pooling_test.cc b/test/ccunit/mace/ops/extract_pooling_test.cc similarity index 100% rename from mace/ops/extract_pooling_test.cc rename to test/ccunit/mace/ops/extract_pooling_test.cc diff --git a/mace/ops/fill_test.cc b/test/ccunit/mace/ops/fill_test.cc similarity index 100% rename from mace/ops/fill_test.cc rename to test/ccunit/mace/ops/fill_test.cc diff --git a/mace/ops/fixpoint_test.cc b/test/ccunit/mace/ops/fixpoint_test.cc similarity index 100% rename from mace/ops/fixpoint_test.cc rename to test/ccunit/mace/ops/fixpoint_test.cc diff --git a/mace/ops/folded_batch_norm_test.cc b/test/ccunit/mace/ops/folded_batch_norm_test.cc similarity index 100% rename from mace/ops/folded_batch_norm_test.cc rename to test/ccunit/mace/ops/folded_batch_norm_test.cc diff --git a/mace/ops/fully_connected_test.cc b/test/ccunit/mace/ops/fully_connected_test.cc similarity index 100% rename from mace/ops/fully_connected_test.cc rename to test/ccunit/mace/ops/fully_connected_test.cc diff --git a/mace/ops/gather_test.cc b/test/ccunit/mace/ops/gather_test.cc similarity index 100% rename from mace/ops/gather_test.cc rename to test/ccunit/mace/ops/gather_test.cc diff --git a/mace/ops/identity_test.cc b/test/ccunit/mace/ops/identity_test.cc similarity index 100% rename from mace/ops/identity_test.cc rename to test/ccunit/mace/ops/identity_test.cc diff --git a/mace/ops/infer_conv2d_shape_test.cc b/test/ccunit/mace/ops/infer_conv2d_shape_test.cc similarity index 100% rename from mace/ops/infer_conv2d_shape_test.cc rename to test/ccunit/mace/ops/infer_conv2d_shape_test.cc diff --git a/mace/ops/kaldi_batch_norm_test.cc b/test/ccunit/mace/ops/kaldi_batch_norm_test.cc similarity index 100% rename from mace/ops/kaldi_batch_norm_test.cc rename to test/ccunit/mace/ops/kaldi_batch_norm_test.cc diff --git a/mace/ops/local_response_norm_test.cc b/test/ccunit/mace/ops/local_response_norm_test.cc similarity index 100% rename from mace/ops/local_response_norm_test.cc rename to test/ccunit/mace/ops/local_response_norm_test.cc diff --git a/mace/ops/lstmcell_test.cc b/test/ccunit/mace/ops/lstmcell_test.cc similarity index 100% rename from mace/ops/lstmcell_test.cc rename to test/ccunit/mace/ops/lstmcell_test.cc diff --git a/mace/ops/matmul_test.cc b/test/ccunit/mace/ops/matmul_test.cc similarity index 100% rename from mace/ops/matmul_test.cc rename to test/ccunit/mace/ops/matmul_test.cc diff --git a/mace/ops/one_hot_test.cc b/test/ccunit/mace/ops/one_hot_test.cc similarity index 100% rename from mace/ops/one_hot_test.cc rename to test/ccunit/mace/ops/one_hot_test.cc diff --git a/mace/ops/opencl/out_of_range_check_test.cc b/test/ccunit/mace/ops/opencl/out_of_range_check_test.cc similarity index 100% rename from mace/ops/opencl/out_of_range_check_test.cc rename to test/ccunit/mace/ops/opencl/out_of_range_check_test.cc diff --git a/mace/ops/pad_context_test.cc b/test/ccunit/mace/ops/pad_context_test.cc similarity index 100% rename from mace/ops/pad_context_test.cc rename to test/ccunit/mace/ops/pad_context_test.cc diff --git a/mace/ops/pad_test.cc b/test/ccunit/mace/ops/pad_test.cc similarity index 100% rename from mace/ops/pad_test.cc rename to test/ccunit/mace/ops/pad_test.cc diff --git a/mace/ops/pnorm_test.cc b/test/ccunit/mace/ops/pnorm_test.cc similarity index 100% rename from mace/ops/pnorm_test.cc rename to test/ccunit/mace/ops/pnorm_test.cc diff --git a/mace/ops/pooling_test.cc b/test/ccunit/mace/ops/pooling_test.cc similarity index 100% rename from mace/ops/pooling_test.cc rename to test/ccunit/mace/ops/pooling_test.cc diff --git a/mace/ops/prior_box_test.cc b/test/ccunit/mace/ops/prior_box_test.cc similarity index 100% rename from mace/ops/prior_box_test.cc rename to test/ccunit/mace/ops/prior_box_test.cc diff --git a/mace/ops/quantize_test.cc b/test/ccunit/mace/ops/quantize_test.cc similarity index 100% rename from mace/ops/quantize_test.cc rename to test/ccunit/mace/ops/quantize_test.cc diff --git a/mace/ops/reduce_test.cc b/test/ccunit/mace/ops/reduce_test.cc similarity index 100% rename from mace/ops/reduce_test.cc rename to test/ccunit/mace/ops/reduce_test.cc diff --git a/mace/ops/reshape_test.cc b/test/ccunit/mace/ops/reshape_test.cc similarity index 100% rename from mace/ops/reshape_test.cc rename to test/ccunit/mace/ops/reshape_test.cc diff --git a/mace/ops/resize_bicubic_test.cc b/test/ccunit/mace/ops/resize_bicubic_test.cc similarity index 100% rename from mace/ops/resize_bicubic_test.cc rename to test/ccunit/mace/ops/resize_bicubic_test.cc diff --git a/mace/ops/resize_bilinear_test.cc b/test/ccunit/mace/ops/resize_bilinear_test.cc similarity index 100% rename from mace/ops/resize_bilinear_test.cc rename to test/ccunit/mace/ops/resize_bilinear_test.cc diff --git a/mace/ops/resize_nearest_neighbor_test.cc b/test/ccunit/mace/ops/resize_nearest_neighbor_test.cc similarity index 100% rename from mace/ops/resize_nearest_neighbor_test.cc rename to test/ccunit/mace/ops/resize_nearest_neighbor_test.cc diff --git a/mace/ops/reverse_test.cc b/test/ccunit/mace/ops/reverse_test.cc similarity index 100% rename from mace/ops/reverse_test.cc rename to test/ccunit/mace/ops/reverse_test.cc diff --git a/mace/ops/scalar_math_test.cc b/test/ccunit/mace/ops/scalar_math_test.cc similarity index 100% rename from mace/ops/scalar_math_test.cc rename to test/ccunit/mace/ops/scalar_math_test.cc diff --git a/mace/ops/shape_test.cc b/test/ccunit/mace/ops/shape_test.cc similarity index 100% rename from mace/ops/shape_test.cc rename to test/ccunit/mace/ops/shape_test.cc diff --git a/mace/ops/slice_test.cc b/test/ccunit/mace/ops/slice_test.cc similarity index 100% rename from mace/ops/slice_test.cc rename to test/ccunit/mace/ops/slice_test.cc diff --git a/mace/ops/softmax_test.cc b/test/ccunit/mace/ops/softmax_test.cc similarity index 100% rename from mace/ops/softmax_test.cc rename to test/ccunit/mace/ops/softmax_test.cc diff --git a/mace/ops/space_to_batch_test.cc b/test/ccunit/mace/ops/space_to_batch_test.cc similarity index 100% rename from mace/ops/space_to_batch_test.cc rename to test/ccunit/mace/ops/space_to_batch_test.cc diff --git a/mace/ops/space_to_depth_test.cc b/test/ccunit/mace/ops/space_to_depth_test.cc similarity index 100% rename from mace/ops/space_to_depth_test.cc rename to test/ccunit/mace/ops/space_to_depth_test.cc diff --git a/mace/ops/splice_test.cc b/test/ccunit/mace/ops/splice_test.cc similarity index 100% rename from mace/ops/splice_test.cc rename to test/ccunit/mace/ops/splice_test.cc diff --git a/mace/ops/split_test.cc b/test/ccunit/mace/ops/split_test.cc similarity index 100% rename from mace/ops/split_test.cc rename to test/ccunit/mace/ops/split_test.cc diff --git a/mace/ops/sqrdiff_mean_test.cc b/test/ccunit/mace/ops/sqrdiff_mean_test.cc similarity index 100% rename from mace/ops/sqrdiff_mean_test.cc rename to test/ccunit/mace/ops/sqrdiff_mean_test.cc diff --git a/mace/ops/squeeze_test.cc b/test/ccunit/mace/ops/squeeze_test.cc similarity index 100% rename from mace/ops/squeeze_test.cc rename to test/ccunit/mace/ops/squeeze_test.cc diff --git a/mace/ops/stack_test.cc b/test/ccunit/mace/ops/stack_test.cc similarity index 100% rename from mace/ops/stack_test.cc rename to test/ccunit/mace/ops/stack_test.cc diff --git a/mace/ops/strided_slice_test.cc b/test/ccunit/mace/ops/strided_slice_test.cc similarity index 100% rename from mace/ops/strided_slice_test.cc rename to test/ccunit/mace/ops/strided_slice_test.cc diff --git a/mace/ops/sum_group_test.cc b/test/ccunit/mace/ops/sum_group_test.cc similarity index 100% rename from mace/ops/sum_group_test.cc rename to test/ccunit/mace/ops/sum_group_test.cc diff --git a/mace/ops/target_rms_norm_test.cc b/test/ccunit/mace/ops/target_rms_norm_test.cc similarity index 100% rename from mace/ops/target_rms_norm_test.cc rename to test/ccunit/mace/ops/target_rms_norm_test.cc diff --git a/mace/ops/transpose_test.cc b/test/ccunit/mace/ops/transpose_test.cc similarity index 100% rename from mace/ops/transpose_test.cc rename to test/ccunit/mace/ops/transpose_test.cc diff --git a/mace/ops/unstack_test.cc b/test/ccunit/mace/ops/unstack_test.cc similarity index 100% rename from mace/ops/unstack_test.cc rename to test/ccunit/mace/ops/unstack_test.cc diff --git a/mace/port/env_test.cc b/test/ccunit/mace/port/env_test.cc similarity index 100% rename from mace/port/env_test.cc rename to test/ccunit/mace/port/env_test.cc diff --git a/mace/port/logger_test.cc b/test/ccunit/mace/port/logger_test.cc similarity index 100% rename from mace/port/logger_test.cc rename to test/ccunit/mace/port/logger_test.cc diff --git a/mace/utils/count_down_latch_test.cc b/test/ccunit/mace/utils/count_down_latch_test.cc similarity index 100% rename from mace/utils/count_down_latch_test.cc rename to test/ccunit/mace/utils/count_down_latch_test.cc diff --git a/mace/utils/logging_test.cc b/test/ccunit/mace/utils/logging_test.cc similarity index 100% rename from mace/utils/logging_test.cc rename to test/ccunit/mace/utils/logging_test.cc diff --git a/mace/utils/spinlock_test.cc b/test/ccunit/mace/utils/spinlock_test.cc similarity index 100% rename from mace/utils/spinlock_test.cc rename to test/ccunit/mace/utils/spinlock_test.cc diff --git a/mace/utils/string_util_test.cc b/test/ccunit/mace/utils/string_util_test.cc similarity index 100% rename from mace/utils/string_util_test.cc rename to test/ccunit/mace/utils/string_util_test.cc diff --git a/mace/utils/thread_pool_test.cc b/test/ccunit/mace/utils/thread_pool_test.cc similarity index 100% rename from mace/utils/thread_pool_test.cc rename to test/ccunit/mace/utils/thread_pool_test.cc diff --git a/mace/utils/tuner_test.cc b/test/ccunit/mace/utils/tuner_test.cc similarity index 100% rename from mace/utils/tuner_test.cc rename to test/ccunit/mace/utils/tuner_test.cc diff --git a/test/ccutils/BUILD.bazel b/test/ccutils/BUILD.bazel new file mode 100644 index 0000000000000000000000000000000000000000..bb31fff9ade347d3c248f22227cd99b53a3aa92f --- /dev/null +++ b/test/ccutils/BUILD.bazel @@ -0,0 +1,47 @@ +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", + ], +) diff --git a/test/ccutils/CMakeLists.txt b/test/ccutils/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..48f4e07f26a1302ee0a1aeed03c5c47262d0aec3 --- /dev/null +++ b/test/ccutils/CMakeLists.txt @@ -0,0 +1,10 @@ +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 +) diff --git a/mace/ops/lstmcell_test_util.h b/test/ccutils/mace/ops/lstmcell_test_util.h similarity index 100% rename from mace/ops/lstmcell_test_util.h rename to test/ccutils/mace/ops/lstmcell_test_util.h diff --git a/mace/ops/ops_test_util.cc b/test/ccutils/mace/ops/ops_test_util.cc similarity index 100% rename from mace/ops/ops_test_util.cc rename to test/ccutils/mace/ops/ops_test_util.cc diff --git a/mace/ops/ops_test_util.h b/test/ccutils/mace/ops/ops_test_util.h similarity index 99% rename from mace/ops/ops_test_util.h rename to test/ccutils/mace/ops/ops_test_util.h index cc761699c974991a7c6a90ddda35a8e7f229da3b..a6e2aa8df6c28fa585f6e3e2c93a719251214db2 100644 --- a/mace/ops/ops_test_util.h +++ b/test/ccutils/mace/ops/ops_test_util.h @@ -31,7 +31,7 @@ #include "mace/core/device_context.h" #include "mace/core/tensor.h" #include "mace/core/workspace.h" -#include "mace/ops/ops_registry.h" +#include "mace/ops/registry/ops_registry.h" #include "mace/public/mace.h" #include "mace/utils/memory.h" #include "mace/utils/math.h" diff --git a/mace/ops/testing/test_utils.h b/test/ccutils/mace/ops/testing/test_utils.h similarity index 100% rename from mace/ops/testing/test_utils.h rename to test/ccutils/mace/ops/testing/test_utils.h diff --git a/third_party/eigen3/eigen3.cmake b/third_party/eigen3/eigen3.cmake new file mode 100644 index 0000000000000000000000000000000000000000..34ad8bed32ab568b8da1a5f3408a7104a418cd35 --- /dev/null +++ b/third_party/eigen3/eigen3.cmake @@ -0,0 +1,22 @@ +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 "" +) diff --git a/third_party/gemmlowp/gemmlowp.cmake b/third_party/gemmlowp/gemmlowp.cmake new file mode 100644 index 0000000000000000000000000000000000000000..3ad422a13559f9dba8c27e8432ae96b388c00aa4 --- /dev/null +++ b/third_party/gemmlowp/gemmlowp.cmake @@ -0,0 +1,21 @@ +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 "" +) diff --git a/third_party/gflags/gflags.cmake b/third_party/gflags/gflags.cmake new file mode 100644 index 0000000000000000000000000000000000000000..ded60019268e59a87e8acd612572a606a9562ebd --- /dev/null +++ b/third_party/gflags/gflags.cmake @@ -0,0 +1,48 @@ +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 $==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) diff --git a/third_party/googletest/googletest.cmake b/third_party/googletest/googletest.cmake new file mode 100644 index 0000000000000000000000000000000000000000..6b715c877003429fd65b8608a935e5e1887af43a --- /dev/null +++ b/third_party/googletest/googletest.cmake @@ -0,0 +1,52 @@ +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) diff --git a/third_party/half/half.cmake b/third_party/half/half.cmake new file mode 100644 index 0000000000000000000000000000000000000000..35ced1d422d26fdf858dc71db3b84d68b84f1027 --- /dev/null +++ b/third_party/half/half.cmake @@ -0,0 +1,21 @@ +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 "" +) diff --git a/third_party/hta/hta.cmake b/third_party/hta/hta.cmake new file mode 100644 index 0000000000000000000000000000000000000000..90777623ee5dd0749acf63639f06ee34c6628254 --- /dev/null +++ b/third_party/hta/hta.cmake @@ -0,0 +1,25 @@ +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) diff --git a/third_party/nnlib/nnlib.cmake b/third_party/nnlib/nnlib.cmake new file mode 100644 index 0000000000000000000000000000000000000000..03aa770035b3ac4658bc37c02731d18ddb350a4c --- /dev/null +++ b/third_party/nnlib/nnlib.cmake @@ -0,0 +1,10 @@ +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) diff --git a/third_party/opencl-clhpp/opencl-clhpp.BUILD b/third_party/opencl-clhpp/opencl-clhpp.BUILD index 1b5f0052f30801cd01196567e8416dd7e840d3c1..494006c450725c503950d0e86c8f07f345d704df 100644 --- a/third_party/opencl-clhpp/opencl-clhpp.BUILD +++ b/third_party/opencl-clhpp/opencl-clhpp.BUILD @@ -15,5 +15,6 @@ genrule( cc_library( name = "opencl_clhpp", hdrs = ["include/CL/cl.hpp", "include/CL/cl2.hpp"], + strip_include_prefix = "include", visibility = ["//visibility:public"], ) diff --git a/third_party/opencl-clhpp/opencl-clhpp.cmake b/third_party/opencl-clhpp/opencl-clhpp.cmake new file mode 100644 index 0000000000000000000000000000000000000000..fbc52f2bb9426cdcf000c01df4cee0c5f64ddb46 --- /dev/null +++ b/third_party/opencl-clhpp/opencl-clhpp.cmake @@ -0,0 +1,25 @@ +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) diff --git a/third_party/opencl-headers/opencl-headers.cmake b/third_party/opencl-headers/opencl-headers.cmake new file mode 100644 index 0000000000000000000000000000000000000000..59c2260b7e6dd943037bf6967ebfa24bade043d3 --- /dev/null +++ b/third_party/opencl-headers/opencl-headers.cmake @@ -0,0 +1,22 @@ +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 "" +) diff --git a/third_party/protobuf/LICENSE b/third_party/protobuf/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..19b305b00060a774a9180fb916c14b49edb2008f --- /dev/null +++ b/third_party/protobuf/LICENSE @@ -0,0 +1,32 @@ +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. diff --git a/third_party/protobuf/protobuf.cmake b/third_party/protobuf/protobuf.cmake new file mode 100644 index 0000000000000000000000000000000000000000..4f95317de46f6e420f697d10ac9361c2881b2156 --- /dev/null +++ b/third_party/protobuf/protobuf.cmake @@ -0,0 +1,120 @@ +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 $==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) diff --git a/third_party/tflite/tflite.cmake b/third_party/tflite/tflite.cmake new file mode 100644 index 0000000000000000000000000000000000000000..d1dfbbe452be483cb3c0e5aa31984b00619425a8 --- /dev/null +++ b/third_party/tflite/tflite.cmake @@ -0,0 +1,21 @@ +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 "" +) diff --git a/third_party/third_party.cmake b/third_party/third_party.cmake new file mode 100644 index 0000000000000000000000000000000000000000..b25a168977064ba22813d336e3dfdf9f01f30081 --- /dev/null +++ b/third_party/third_party.cmake @@ -0,0 +1,60 @@ +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) diff --git a/tools/build-standalone-lib.sh b/tools/bazel-build-standalone-lib.sh similarity index 83% rename from tools/build-standalone-lib.sh rename to tools/bazel-build-standalone-lib.sh index 9adf9bb79fed92fce8769fc706a1e420091c8389..2b7116e218d0a27da91cace868bbfc6fe9e1f20f 100755 --- a/tools/build-standalone-lib.sh +++ b/tools/bazel-build-standalone-lib.sh @@ -2,14 +2,14 @@ set -e -LIB_DIR=builds/lib -INCLUDE_DIR=builds/include/mace/public +LIB_DIR=build/lib +INCLUDE_DIR=build/include mkdir -p $LIB_DIR mkdir -p $INCLUDE_DIR # copy include headers -cp mace/public/*.h $INCLUDE_DIR/ +cp -R include/mace $INCLUDE_DIR/ # make directories rm -rf $LIB_DIR/armeabi-v7a @@ -19,7 +19,6 @@ mkdir -p $LIB_DIR/armeabi-v7a/cpu_gpu rm -rf $LIB_DIR/arm64-v8a 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_apu rm -rf $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" 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/ -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" 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/ @@ -66,7 +60,7 @@ cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/aarch64_linux_gnu/cpu_gpu/ if [[ "$OSTYPE" != "darwin"* ]];then 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/ fi @@ -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 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" 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/ @@ -104,7 +93,7 @@ cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/aarch64_linux_gnu/cpu_gpu/ if [[ "$OSTYPE" != "darwin"* ]];then 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/ fi diff --git a/tools/bazel.rc b/tools/bazel.rc index 7081296c9fd2ea9060f6410be42c6392b8bc5b42..5c85f453f0234ebbfe0c88e8abf719cb237fc12a 100644 --- a/tools/bazel.rc +++ b/tools/bazel.rc @@ -3,6 +3,7 @@ # By default, we don't distinct target and host platfroms. build --distinct_host_configuration=false +build -s build --verbose_failures build --copt=-std=c++11 build --copt=-fPIC diff --git a/tools/bazel_adb_run.py b/tools/bazel_adb_run.py index dec4e21f566490c4dc8f4cf218f2999a25e44d3a..447e07afb23030e2c7677ae0b48bcd5aeec98b4f 100644 --- a/tools/bazel_adb_run.py +++ b/tools/bazel_adb_run.py @@ -16,7 +16,7 @@ # python tools/bazel_adb_run.py \ # --target_abis=armeabi-v7a \ # --target_socs=sdm845 -# --target=//mace/ops:ops_test +# --target=//test/ccunit:mace_cc_test # --stdout_processor=stdout_processor import argparse @@ -43,22 +43,6 @@ def ops_benchmark_stdout_processor(stdout, dev, abi): for line in stdout_lines: if "Aborted" in line or "Segmentation fault" in line: 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, diff --git a/tools/cmake-build-aarch64-linux-gnu-full.sh b/tools/cmake-build-aarch64-linux-gnu-full.sh new file mode 100755 index 0000000000000000000000000000000000000000..603d44ee5f456cf4bebe15c0043dcee5034581e4 --- /dev/null +++ b/tools/cmake-build-aarch64-linux-gnu-full.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh + +set -e + +# build for arm linux aarch64 +BUILD_DIR=cmake-build/aarch64-linux-gnu-full +rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} +cmake -DCROSSTOOL_ROOT=${LINARO_AARCH64_LINUX_GNU} \ + -DCMAKE_TOOLCHAIN_FILE=../../cmake/toolchains/aarch64-linux-gnu.cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DMACE_ENABLE_NEON=ON \ + -DMACE_ENABLE_QUANTIZE=ON \ + -DMACE_ENABLE_OPENCL=ON \ + -DMACE_ENABLE_OPT_SIZE=ON \ + -DMACE_ENABLE_OBFUSCATE=ON \ + -DCMAKE_INSTALL_PREFIX=install \ + ../.. +make -j6 VERBOSE=1 && make install +cd ../.. diff --git a/tools/cmake-build-android-arm64-v8a-cpu.sh b/tools/cmake-build-android-arm64-v8a-cpu.sh new file mode 100755 index 0000000000000000000000000000000000000000..dea3fe5d1c7d9798d69277173618ce6368f8c5a3 --- /dev/null +++ b/tools/cmake-build-android-arm64-v8a-cpu.sh @@ -0,0 +1,23 @@ +#!/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 ../.. diff --git a/tools/cmake-build-android-arm64-v8a-full.sh b/tools/cmake-build-android-arm64-v8a-full.sh new file mode 100755 index 0000000000000000000000000000000000000000..b51ec2004ed33b179a87771ccf24a388943a16db --- /dev/null +++ b/tools/cmake-build-android-arm64-v8a-full.sh @@ -0,0 +1,23 @@ +#!/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 ../.. diff --git a/tools/cmake-build-android-armeabi-v7a-cpu.sh b/tools/cmake-build-android-armeabi-v7a-cpu.sh new file mode 100755 index 0000000000000000000000000000000000000000..bbea9d4c8eb0f918844ad62360d25f61446e2d31 --- /dev/null +++ b/tools/cmake-build-android-armeabi-v7a-cpu.sh @@ -0,0 +1,24 @@ +#!/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 ../.. diff --git a/tools/cmake-build-android-armeabi-v7a-full.sh b/tools/cmake-build-android-armeabi-v7a-full.sh new file mode 100755 index 0000000000000000000000000000000000000000..09e5c7f896d709b0e1e794e35f087c85be397ea8 --- /dev/null +++ b/tools/cmake-build-android-armeabi-v7a-full.sh @@ -0,0 +1,24 @@ +#!/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 ../.. diff --git a/tools/cmake-build-arm-linux-gnueabihf-full.sh b/tools/cmake-build-arm-linux-gnueabihf-full.sh new file mode 100755 index 0000000000000000000000000000000000000000..91fd18f7174b89cb66ff137014fcab39a6c08d31 --- /dev/null +++ b/tools/cmake-build-arm-linux-gnueabihf-full.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh + +set -e + +# build for arm linux gnueabihf +BUILD_DIR=cmake-build/arm-linux-gnueabihf-full +rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} +cmake -DCROSSTOOL_ROOT=${LINARO_ARM_LINUX_GNUEABIHF} \ + -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/arm-linux-gnueabihf.cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DMACE_ENABLE_NEON=ON \ + -DMACE_ENABLE_QUANTIZE=ON \ + -DMACE_ENABLE_OPENCL=ON \ + -DMACE_ENABLE_OPT_SIZE=ON \ + -DMACE_ENABLE_OBFUSCATE=ON \ + -DCMAKE_INSTALL_PREFIX=install \ + ../.. +make -j6 VERBOSE=1 && make install +cd ../.. diff --git a/tools/cmake-build-host.sh b/tools/cmake-build-host.sh new file mode 100755 index 0000000000000000000000000000000000000000..4119bc2f9665e847f88358206492ff9a9b9af3d8 --- /dev/null +++ b/tools/cmake-build-host.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +set -e + +# build for host +BUILD_DIR=cmake-build/host +rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} +cmake -DMACE_ENABLE_NEON=OFF \ + -DMACE_ENABLE_QUANTIZE=OFF \ + -DMACE_ENABLE_OPENCL=ON \ + -DCMAKE_INSTALL_PREFIX=install \ + ../.. +make -j6 VERBOSE=1 && make install +cd ../.. diff --git a/tools/cmake-build-standalone-lib.sh b/tools/cmake-build-standalone-lib.sh new file mode 100755 index 0000000000000000000000000000000000000000..ecdf77bdbfd61dff1c8c9f62cc9b121b6671758c --- /dev/null +++ b/tools/cmake-build-standalone-lib.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env sh + +set -e + +# build for local host +sh tools/cmake-build-host.sh + +# Nuild for Android arm64-v8a with NEON +sh tools/cmake-build-android-arm64-v8a-cpu.sh + +# Build for Android arm64-v8a with NEON, Quantize, OpenCL, Hexagon HTA, Hexagon DSP +sh tools/cmake-build-android-arm64-v8a-full.sh + +# Nuild for Android armeabi-v7a with NEON +sh tools/cmake-build-android-armeabi-v7a-cpu.sh + +# Build for Android armeabi-v7a with NEON, Quantize, OpenCL, Hexagon HTA, Hexagon DSP +sh tools/cmake-build-android-armeabi-v7a-full.sh + +# Build for arm-linux-gnueabihf with NEON, Quantize, OpenCL +sh tools/cmake-build-arm-linux-gnueabihf-full.sh + +# Build for aarch64-linux-gnu with NEON, Quantize, OpenCL +sh tools/cmake-build-aarch64-linux-gnu-full.sh diff --git a/tools/common.py b/tools/common.py index 676227c822fb3c234c866207f1de5c56747a6908..5137327bcddc56129de4bda3bcb8d1e647ca2503 100644 --- a/tools/common.py +++ b/tools/common.py @@ -438,15 +438,15 @@ class SystemType: PHONE_DATA_DIR = '/data/local/tmp/mace_run' DEVICE_DATA_DIR = '/tmp/data/mace_run' DEVICE_INTERIOR_DIR = PHONE_DATA_DIR + "/interior" -BUILD_OUTPUT_DIR = 'builds' +BUILD_OUTPUT_DIR = 'build' BUILD_TMP_DIR_NAME = '_tmp' BUILD_DOWNLOADS_DIR = BUILD_OUTPUT_DIR + '/downloads' BUILD_TMP_GENERAL_OUTPUT_DIR_NAME = 'general' MODEL_OUTPUT_DIR_NAME = 'model' EXAMPLE_STATIC_NAME = "example_static" EXAMPLE_DYNAMIC_NAME = "example_dynamic" -EXAMPLE_STATIC_TARGET = "//mace/examples/cli:" + EXAMPLE_STATIC_NAME -EXAMPLE_DYNAMIC_TARGET = "//mace/examples/cli:" + EXAMPLE_DYNAMIC_NAME +EXAMPLE_STATIC_TARGET = "//examples/cli:" + EXAMPLE_STATIC_NAME +EXAMPLE_DYNAMIC_TARGET = "//examples/cli:" + EXAMPLE_DYNAMIC_NAME MACE_RUN_STATIC_NAME = "mace_run_static" MACE_RUN_DYNAMIC_NAME = "mace_run_dynamic" MACE_RUN_STATIC_TARGET = "//mace/tools/validation:" + MACE_RUN_STATIC_NAME @@ -469,12 +469,12 @@ LIBMACE_SO_TARGET = "//mace/libmace:libmace.so" LIBMACE_STATIC_TARGET = "//mace/libmace:libmace_static" LIBMACE_STATIC_PATH = "bazel-genfiles/mace/libmace/libmace.a" 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" BM_MODEL_STATIC_NAME = "benchmark_model_static" BM_MODEL_DYNAMIC_NAME = "benchmark_model_dynamic" -BM_MODEL_STATIC_TARGET = "//mace/benchmark:" + BM_MODEL_STATIC_NAME -BM_MODEL_DYNAMIC_TARGET = "//mace/benchmark:" + BM_MODEL_DYNAMIC_NAME +BM_MODEL_STATIC_TARGET = "//mace/tools/benchmark:" + BM_MODEL_STATIC_NAME +BM_MODEL_DYNAMIC_TARGET = "//mace/tools/benchmark:" + BM_MODEL_DYNAMIC_NAME ################################ diff --git a/tools/converter.py b/tools/converter.py index f16bc434d61ce62e02ce75e24f9b38d1ed8ebb0b..4c1ca1c808f6078a5594923e688e99b8cbae4bac 100644 --- a/tools/converter.py +++ b/tools/converter.py @@ -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, target_abi) 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: example_target = EXAMPLE_DYNAMIC_TARGET @@ -1064,7 +1064,7 @@ def build_benchmark_model(configs, mace_check(os.path.exists(ENGINE_CODEGEN_DIR), ModuleName.BENCHMARK, "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, abi=target_abi, diff --git a/tools/cpplint.sh b/tools/cpplint.sh new file mode 100755 index 0000000000000000000000000000000000000000..ef8e1c3cf62e7c5aa0b26fc2122d041c49de4990 --- /dev/null +++ b/tools/cpplint.sh @@ -0,0 +1,9 @@ +#!/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") diff --git a/tools/falcon_cli.py b/tools/falcon_cli.py deleted file mode 100644 index 5ed027fbdd4d061383ebe12c8b9326a5396e8f36..0000000000000000000000000000000000000000 --- a/tools/falcon_cli.py +++ /dev/null @@ -1,80 +0,0 @@ -# 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 diff --git a/tools/google-format.sh b/tools/google-format.sh deleted file mode 100755 index 4d563e3e29e843f97f2f302d78c6bec68c39557c..0000000000000000000000000000000000000000 --- a/tools/google-format.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -clang-format \ - -style="{BasedOnStyle: google, \ - DerivePointerAlignment: false, \ - PointerAlignment: Right, \ - BinPackParameters: false}" -i $1 diff --git a/tools/sh_commands.py b/tools/sh_commands.py index e67a7b22c95270f4d8d148b4ccc506f856e7cb5d..1380a4921dbd8dff3a968d61f092effc1d153724 100644 --- a/tools/sh_commands.py +++ b/tools/sh_commands.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import falcon_cli import glob import logging import numpy as np @@ -972,31 +971,3 @@ def build_run_throughput_test(abi, _fg=True) six.print_("throughput_test done!\n") - - -################################ -# falcon -################################ -def falcon_tags(tags_dict): - tags = "" - for k, v in tags_dict.iteritems(): - if tags == "": - tags = "%s=%s" % (k, v) - else: - tags = tags + ",%s=%s" % (k, v) - return tags - - -def falcon_push_metrics(server, metrics, endpoint="mace_dev", tags={}): - cli = falcon_cli.FalconCli.connect(server=server, port=8433, debug=False) - ts = int(time.time()) - falcon_metrics = [{ - "endpoint": endpoint, - "metric": key, - "tags": falcon_tags(tags), - "timestamp": ts, - "value": value, - "step": 600, - "counterType": "GAUGE" - } for key, value in metrics.iteritems()] - cli.update(falcon_metrics)