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

Merge branch 'cmake' into 'master'

Add support for CMake

See merge request !1086
BasedOnStyle: google
MaxEmptyLinesToKeep: 3
DerivePointerAlignment: false
PointerAlignment: Right
BinPackParameters: false
bazel-*
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/
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
# new CUDA support requires 3.8 for Linux/Mac, and 3.9 for Windows
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
message("CMAKE_VERSION: ${CMAKE_VERSION}")
project(mace C CXX)
option(MACE_ENABLE_NEON "whether to enable NEON support" OFF)
option(MACE_ENABLE_QUANTIZE "whether to enable NEON int8 support" OFF)
option(MACE_ENABLE_OPENCL "whether to enable OpenCL support" OFF)
option(MACE_ENABLE_CUDA "whether to enable CUDA support" OFF)
option(MACE_ENABLE_HEXAGON_DSP "whether to enable Hexagon DSP support" OFF)
option(MACE_ENABLE_HEXAGON_HTA "whether to enable Hexagon HTA support" OFF)
option(MACE_ENABLE_TESTS "whether to build c++ unit tests" OFF)
option(MACE_ENABLE_BENCHMARKS "whether to build c++ micro benchmarks" OFF)
option(MACE_ENABLE_EXAMPLES "whether to build examples" OFF)
option(MACE_ENABLE_OPT_SIZE "whether to build with optimized binary size" ON)
option(MACE_ENABLE_OBFUSCATE "whether to build with code obfuscation" ON)
message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
# TODO make these flags well defined and organized
# TODO enable sanitizer
set(MACE_CC_FLAGS "${MACE_CC_FLAGS} -fPIC")
if(MACE_ENABLE_OPT_SIZE)
if(APPLE)
set(MACE_LINKER_FLAGS "${MACE_LINKER_FLAGS} -Wl,-dead_strip -Wl,-dead_strip_dylibs")
else(APPLE)
set(MACE_LINKER_FLAGS "${MACE_LINKER_FLAGS} -Wl,--strip-all -Wl,--gc-sections")
set(MACE_CC_FLAGS "${MACE_CC_FLAGS} -ffunction-sections -fdata-sections")
endif(APPLE)
set(MACE_CC_FLAGS "${MACE_CC_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
set(MACE_CODE_CC_FLAGS "${MACE_CODE_CC_FLAGS} -fno-rtti -fno-exceptions -DGOOGLE_PROTOBUF_NO_RTTI -DPROTOBUF_USE_EXCEPTIONS=0")
endif(MACE_ENABLE_OPT_SIZE)
# flags apply only to mace code (third_party excluded)
set(MACE_CODE_CC_FLAGS "${MACE_CODE_CC_FLAGS} -Wall -Werror")
set(MACE_CODE_CC_FLAGS "${MACE_CODE_CC_FLAGS} -std=c++11 -D_GLIBCXX_USE_C99_MATH_TR1")
if(IOS)
# TODO correct the code
set(MACE_CODE_CC_FLAGS "${MACE_CODE_CC_FLAGS} -Wno-error=shorten-64-to-32")
endif(IOS)
if(MACE_ENABLE_NEON)
add_definitions(-DMACE_ENABLE_NEON)
if(ANDROID_ABI STREQUAL "armeabi-v7a")
# Enable NEON fp16 support
string(REPLACE "-mfpu=neon " "-mfpu=neon-fp16 " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif(ANDROID_ABI STREQUAL "armeabi-v7a")
endif(MACE_ENABLE_NEON)
if(MACE_ENABLE_QUANTIZE)
add_definitions(-DMACE_ENABLE_QUANTIZE)
add_definitions(-DGEMMLOWP_USE_MACE_THREAD_POOL)
add_definitions(-DMACE_DEPTHWISE_U8_USE_MULTI_THREAD)
endif(MACE_ENABLE_QUANTIZE)
if(MACE_ENABLE_OPENCL)
if(IOS)
message(FATAL_ERROR "OpenCL is not supported for iOS")
endif(IOS)
add_definitions(-DMACE_ENABLE_OPENCL)
endif(MACE_ENABLE_OPENCL)
if(MACE_ENABLE_CUDA)
# new CUDA support requires 3.8 for Linux/Mac, and 3.9 for Windows
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
enable_language(CUDA)
endif(MACE_ENABLE_CUDA)
if((MACE_ENABLE_HEXAGON_DSP OR MACE_ENABLE_HEXAGON_HTA))
if(ANDROID_ABI STREQUAL "arm64-v8a")
# Use gold linker to avoid linking check of libcdsprpc.so
set(MACE_LINKER_FLAGS "${MACE_LINKER_FLAGS} -fuse-ld=gold")
endif(ANDROID_ABI STREQUAL "arm64-v8a")
endif(MACE_ENABLE_HEXAGON_DSP OR MACE_ENABLE_HEXAGON_HTA)
if(MACE_ENABLE_HEXAGON_DSP)
if(NOT ANDROID)
message(FATAL_ERROR "Hexagon DSP is only supported on Android")
endif(NOT ANDROID)
# TODO => -DMACE_ENABLE_HEXAGON_DSP
add_definitions(-DMACE_ENABLE_HEXAGON)
endif(MACE_ENABLE_HEXAGON_DSP)
if(MACE_ENABLE_HEXAGON_HTA)
if(NOT ANDROID)
message(FATAL_ERROR "Hexagon HTA is only supported on Android")
endif(NOT ANDROID)
add_definitions(-DMACE_ENABLE_HEXAGON_HTA)
endif(MACE_ENABLE_HEXAGON_HTA)
if(MACE_ENABLE_OBFUSCATE)
add_definitions(-DMACE_OBFUSCATE_LITERALS)
endif(MACE_ENABLE_OBFUSCATE)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MACE_CODE_CC_FLAGS} ${MACE_CC_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${MACE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MACE_LINKER_FLAGS}")
endif(NOT MSVC)
include(${PROJECT_SOURCE_DIR}/third_party/third_party.cmake)
include_directories("${PROJECT_SOURCE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_BINARY_DIR}") # proto
add_subdirectory(include)
add_subdirectory(mace)
if(MACE_ENABLE_EXAMPLES)
add_subdirectory(examples)
endif(MACE_ENABLE_EXAMPLES)
if(MACE_ENABLE_TESTS OR MACE_ENABLE_BENCHMARKS)
add_subdirectory(test)
endif(MACE_ENABLE_TESTS OR MACE_ENABLE_BENCHMARKS)
......@@ -18,7 +18,7 @@
[中文](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
......
......@@ -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专门优化,并且采用
......
......@@ -61,7 +61,6 @@ new_http_archive(
strip_prefix = "half-code-356-trunk",
urls = [
"https://cnbj1.fds.api.xiaomi.com/mace/third-party/half/half-code-356-trunk.zip",
"https://sourceforge.net/code-snapshots/svn/h/ha/half/code/half-code-356-trunk.zip",
],
)
......
# Tested with gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu
# https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER "${CROSSTOOL_ROOT}/bin/aarch64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "${CROSSTOOL_ROOT}/bin/aarch64-linux-gnu-g++")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_CXX_FLAGS "-march=armv8-a ${CMAKE_CXX_FLAGS}")
# Tested with gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabi
# https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabi-gcc")
set(CMAKE_CXX_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabi-g++")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}")
# Tested with gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf
# https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabihf-g++")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}")
此差异已折叠。
......@@ -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
......@@ -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}
......@@ -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
......@@ -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
......
......@@ -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"
```
......@@ -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
......
......@@ -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
......
......@@ -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
......
file(GLOB MACE_EXAMPLE_SRCS
cli/example.cc
)
add_executable(mace_example ${MACE_EXAMPLE_SRCS})
target_link_libraries(mace_example PUBLIC
mace_static
gflags
)
install(TARGETS mace_example RUNTIME DESTINATION bin)
......@@ -20,12 +20,12 @@ fi
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
......
......@@ -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})
......
......@@ -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 <android/log.h>
#include <jni.h>
......@@ -25,9 +25,8 @@
#include <vector>
#include <numeric>
#include "src/main/cpp/include/mace/public/mace.h"
#include "src/main/cpp/include/mace/public/mace_engine_factory.h"
#include "mace/public/mace.h"
#include "mace/public/mace_engine_factory.h"
namespace {
......
......@@ -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",
......
......@@ -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");
......
# Description:
# MACE public API.
#
package(
default_visibility = ["//visibility:public"],
)
......@@ -8,12 +5,12 @@ package(
licenses(["notice"]) # Apache 2.0
cc_library(
name = "public",
hdrs = [
"mace.h",
],
srcs = [
"status.cc",
],
name = "public_headers",
hdrs = glob([
"mace/public/*.h",
"mace/port/*.h",
"mace/utils/*.h",
]),
strip_include_prefix = "",
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"],
)
install(DIRECTORY mace DESTINATION include)
......@@ -16,11 +16,18 @@
#define MACE_PORT_ENV_H_
#include <cstdint>
#include <cstdlib>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#ifdef _WIN32
#include <malloc.h>
#endif
#include <sys/stat.h>
#include "mace/public/mace.h"
namespace mace {
......@@ -38,6 +45,7 @@ class LogWriter;
class Env {
public:
virtual int64_t NowMicros() = 0;
virtual MaceStatus AdviseFree(void *addr, size_t length);
virtual MaceStatus GetCPUMaxFreq(std::vector<float> *max_freqs);
virtual MaceStatus SchedSetAffinity(const std::vector<size_t> &cpu_ids);
virtual FileSystem *GetFileSystem() = 0;
......@@ -58,6 +66,10 @@ inline int64_t NowMicros() {
return port::Env::Default()->NowMicros();
}
inline MaceStatus AdviseFree(void *addr, size_t length) {
return port::Env::Default()->AdviseFree(addr, length);
}
inline MaceStatus GetCPUMaxFreq(std::vector<float> *max_freqs) {
return port::Env::Default()->GetCPUMaxFreq(max_freqs);
}
......@@ -70,6 +82,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_
......@@ -19,6 +19,7 @@
#include <memory>
#include "mace/public/mace.h"
#include "mace/utils/macros.h"
namespace mace {
namespace port {
......@@ -29,6 +30,8 @@ class ReadOnlyMemoryRegion {
virtual ~ReadOnlyMemoryRegion() = default;
virtual const void *data() const = 0;
virtual uint64_t length() const = 0;
private:
MACE_DISABLE_COPY_AND_ASSIGN(ReadOnlyMemoryRegion);
};
class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion {
......@@ -44,12 +47,25 @@ class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion {
uint64_t length_;
};
class WritableFile {
public:
WritableFile() {}
virtual ~WritableFile();
virtual MaceStatus Append(const char *data, size_t length) = 0;
virtual MaceStatus Close() = 0;
virtual MaceStatus Flush() = 0;
private:
MACE_DISABLE_COPY_AND_ASSIGN(WritableFile);
};
class FileSystem {
public:
FileSystem() = default;
virtual ~FileSystem() = default;
virtual MaceStatus NewReadOnlyMemoryRegionFromFile(const char *fname,
std::unique_ptr<ReadOnlyMemoryRegion>* result) = 0;
virtual MaceStatus NewWritableFile(const char *fname,
std::unique_ptr<WritableFile>* result);
};
} // namespace port
......
......@@ -25,8 +25,20 @@
#include <vector>
#ifndef MACE_API
#ifdef _MSC_VER
#define MACE_API
#else
#define MACE_API __attribute__((visibility("default")))
#endif
#endif
#ifndef MACE_DEPRECATED
#ifdef _MSC_VER
#define MACE_DEPRECATED
#else
#define MACE_DEPRECATED __attribute__((deprecated))
#endif
#endif
namespace mace {
......@@ -435,7 +447,8 @@ MACE_API MaceStatus CreateMaceEngineFromProto(
const std::vector<std::string> &input_nodes,
const std::vector<std::string> &output_nodes,
const MaceEngineConfig &config,
std::shared_ptr<MaceEngine> *engine) __attribute__((deprecated));
std::shared_ptr<MaceEngine> *engine) MACE_DEPRECATED;
} // namespace mace
......
......@@ -75,6 +75,15 @@ T &&CheckNotNull(const char *file, int line, const char *exprtext, T &&t) {
#define MACE_NOT_IMPLEMENTED MACE_CHECK(false, "not implemented")
#define MACE_CHECK_SUCCESS(stmt) \
{ \
MaceStatus status = (stmt); \
if (status != MaceStatus::MACE_SUCCESS) { \
LOG(FATAL) << #stmt << " failed with error: " \
<< status.information(); \
} \
}
#define MACE_RETURN_IF_ERROR(stmt) \
{ \
MaceStatus status = (stmt); \
......
add_subdirectory(codegen)
add_subdirectory(core)
add_subdirectory(libmace)
add_subdirectory(ops)
add_subdirectory(port)
add_subdirectory(proto)
add_subdirectory(tools)
add_subdirectory(utils)
......@@ -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"],
)
# 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)
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册