Skip to content

Commit

Permalink
Merge pull request #30 from JDAI-CV/armv7
Browse files Browse the repository at this point in the history
armv7
  • Loading branch information
daquexian authored May 29, 2019
2 parents 275a855 + 4751fa1 commit e5a35d3
Show file tree
Hide file tree
Showing 21 changed files with 515 additions and 75 deletions.
5 changes: 5 additions & 0 deletions .daq_pm/configs/all_v7
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# It is a configuration file for [project_manager.vim](https://github.com/daquexian/project_manager.vim)
name binary-nn
type cpp
build_dir build_v7
cmake_options -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 -DANDROID_ABI="armeabi-v7a with NEON" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -GNinja
2 changes: 1 addition & 1 deletion .daq_pm/configs/bconv_test_x86
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# It is a configuration file for [project_manager.vim](https://github.com/daquexian/project_manager.vim)
name binary-nn
type cpp
build_dir build_bconv_test_x86
build_dir build_test_x86
target bconv_test
cmake_options -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBNN_BUILD_MAIN_LIB=ON -GNinja
binary tests/bconv_test
4 changes: 2 additions & 2 deletions .daq_pm/configs/bgemm_test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# It is a configuration file for [project_manager.vim](https://github.com/daquexian/project_manager.vim)
name binary-nn
type cpp
build_dir build_bgemm_test
build_dir build_test
target bgemm_test
cmake_options -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-28 -DANDROID_ABI=arm64-v8a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release
cmake_options -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-28 -DANDROID_ABI=arm64-v8a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -GNinja
binary ~/adb_push_and_run.sh tests/bgemm_test
7 changes: 7 additions & 0 deletions .daq_pm/configs/bgemm_test_v7
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# It is a configuration file for [project_manager.vim](https://github.com/daquexian/project_manager.vim)
name binary-nn
type cpp
build_dir build_test_v7
target bgemm_test
cmake_options -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-25 -DANDROID_ABI="armeabi-v7a with NEON" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -GNinja
binary ~/adb_push_and_run.sh tests/bgemm_test
7 changes: 7 additions & 0 deletions .daq_pm/configs/bgemm_test_x86
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# It is a configuration file for [project_manager.vim](https://github.com/daquexian/project_manager.vim)
name binary-nn
type cpp
build_dir build_test_x86
target bgemm_test
cmake_options -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBNN_BUILD_MAIN_LIB=ON -GNinja
binary tests/bgemm_test
4 changes: 2 additions & 2 deletions .daq_pm/configs/bitpack_test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# It is a configuration file for [project_manager.vim](https://github.com/daquexian/project_manager.vim)
name binary-nn
type cpp
build_dir build
build_dir build_test
target bitpack_test
cmake_options -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-28 -DANDROID_ABI=arm64-v8a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release
cmake_options -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-28 -DANDROID_ABI=arm64-v8a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -GNinja
binary ~/adb_push_and_run.sh tests/bitpack_test
2 changes: 1 addition & 1 deletion .daq_pm/configs/net_test
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name binary-nn
type cpp
build_dir build_net_test
target net_test
cmake_options -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-28 -DANDROID_ABI=arm64-v8a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -GNinja
cmake_options -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 -DANDROID_ABI=arm64-v8a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -GNinja
binary ~/adb_push_and_run.sh tests/net_test
7 changes: 7 additions & 0 deletions .daq_pm/configs/net_test_v7
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# It is a configuration file for [project_manager.vim](https://github.com/daquexian/project_manager.vim)
name binary-nn
type cpp
build_dir build_test_v7
target net_test
cmake_options -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 -DANDROID_ABI="armeabi-v7a with NEON" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -GNinja
binary ~/adb_push_and_run.sh tests/net_test
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ option(BNN_USE_MSVC_STATIC_RUNTIME "Link onnx2bnn to msvc static runtime" ON)

message(STATUS "Target architecture: ${CMAKE_SYSTEM_PROCESSOR}")
if (NOT DEFINED BNN_BUILD_MAIN_LIB)
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a")
set(BNN_BUILD_MAIN_LIB ON)
else()
set(BNN_BUILD_MAIN_LIB OFF)
Expand Down
8 changes: 8 additions & 0 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ static void BM_pack_mat_64_small(benchmark::State &state) {
}
}

#ifdef __aarch64__
static void BM_pack_mat_128_small(benchmark::State &state) {
const bnn::Mat a(1, 32, 32, 128, bnn::DataType::Float, 0);
bnn::Mat b(1, 32, 32, 128, bnn::DataType::Bit, 0);
for (auto _ : state) {
pack_mat_128(a, b);
}
}
#endif // __aarch64__

static void BM_pack_mat_64(benchmark::State &state) {
const bnn::Mat a(1, 64, 64, 128, bnn::DataType::Float);
Expand All @@ -37,13 +39,15 @@ static void BM_pack_mat_64(benchmark::State &state) {
}
}

#ifdef __aarch64__
static void BM_pack_mat_128(benchmark::State &state) {
const bnn::Mat a(1, 64, 64, 128, bnn::DataType::Float);
bnn::Mat b(1, 64, 64, 128, bnn::DataType::Bit);
for (auto _ : state) {
pack_mat_128(a, b);
}
}
#endif // __aarch64__

#define SETUP_BCONV_FLOAT(size_a, size_b, num_output) \
const size_t AHEIGHT = size_a; \
Expand Down Expand Up @@ -73,6 +77,7 @@ static void BM_pack_mat_128(benchmark::State &state) {
\
bnn::Mat c(CHEIGHT, CWIDTH, NUM_OUTPUT, bnn::DataType::Float);

#ifdef __aarch64__
static void BM_bconv_float_3x3_128(benchmark::State &state) {
SETUP_BCONV_FLOAT(30, 3, 128);
for (auto _ : state) {
Expand All @@ -88,6 +93,7 @@ static void BM_bconv_float_1x1_128(benchmark::State &state) {
bnn::bconv_1x1_128(a_binary, b, c);
}
}
#endif // __aarch64__

#undef SETUP_BCONV_FLOAT

Expand Down Expand Up @@ -135,6 +141,7 @@ static void BM_bnn_bconv_1x1_naive_128(benchmark::State &state) {
}
}

#ifdef __aarch64__
static void BM_bnn_bconv_1x1_64(benchmark::State &state) {
SETUP_BCONV(56, 1, 64, 1);
for (auto _ : state) {
Expand Down Expand Up @@ -162,6 +169,7 @@ static void BM_bnn_bconv_1x1_512(benchmark::State &state) {
bnn::bconv_1x1_512(a, b, c);
}
}
#endif // __aarch64__

static void BM_bnn_bconv_3x3_64(benchmark::State &state) {
SETUP_BCONV(58, 3, 64, 1);
Expand Down
11 changes: 11 additions & 0 deletions ci/build_dabnn_v7.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env bash
set -e

echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'ndk-bundle'
nproc=$(ci/get_cores.sh)

mkdir build_dabnn && cd build_dabnn
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 -DANDROID_ABI="armeabi-v7a with NEON" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release ..
cmake --build . -- -j$nproc
cd -

54 changes: 31 additions & 23 deletions ci/dabnn_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,34 @@ pr:
- README.md
- docs/*

pool:
vmImage: 'macOS-10.14'
steps:
- checkout: self
submodules: true
- bash: brew install watch gnu-sed
displayName: Install watch and gnu-sed
- bash: ci/build_dabnn.sh
displayName: Build
- bash: ci/start_android_emulator.sh
displayName: Start Android Emulator
- bash: ci/adb_push_and_run.sh build_dabnn/tests/bconv_test
displayName: Binary Conv Test
- bash: ci/adb_push_and_run.sh build_dabnn/tests/bgemm_test
displayName: Binary Gemm Test
- bash: ci/download_models.sh
displayName: Download Models
- bash: ci/adb_push_and_run.sh build_dabnn/tests/net_test
displayName: Model Test
- bash: ci/build_aar.sh
env:
BINTRAY_KEY: $(bintrayKey)
displayName: Build and Publish AAR package
jobs:
- job: aarch64
pool:
vmImage: 'macOS-10.14'
steps:
- checkout: self
submodules: true
- bash: brew install watch gnu-sed
displayName: Install watch and gnu-sed
- bash: ci/build_dabnn.sh
displayName: Build
- bash: ci/start_android_emulator.sh
displayName: Start Android Emulator
- template: template_dabnn_run_test.yml
- bash: ci/build_aar.sh
env:
BINTRAY_KEY: $(bintrayKey)
displayName: Build and Publish AAR package
- job: armv7a_with_NEON
pool:
vmImage: 'macOS-10.14'
steps:
- checkout: self
submodules: true
- bash: brew install watch gnu-sed
displayName: Install watch and gnu-sed
- bash: ci/build_dabnn_v7.sh
displayName: Build
- bash: ci/start_android_emulator_v7.sh
displayName: Start Android Emulator
- template: template_dabnn_run_test.yml
25 changes: 25 additions & 0 deletions ci/start_android_emulator_v7.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#! /usr/bin/env bash
set -e

export TERM=xterm

echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-25;google_apis;armeabi-v7a'

echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n android_emulator -k 'system-images;android-25;google_apis;armeabi-v7a' --force

echo "Starting emulator"

# Start emulator in background
nohup $ANDROID_HOME/emulator/emulator -avd android_emulator -no-snapshot -no-audio &

# start server in advance, so that the result of watch will only change when device gets online
$ANDROID_HOME/platform-tools/adb start-server

watch -g -n 1 '$ANDROID_HOME/platform-tools/adb devices | grep -c device$'

echo "Emulator is online"

$ANDROID_HOME/platform-tools/adb devices

echo "Emulator started"

9 changes: 9 additions & 0 deletions ci/template_dabnn_run_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
steps:
- bash: ci/adb_push_and_run.sh build_dabnn/tests/bconv_test
displayName: Binary Conv Test
- bash: ci/adb_push_and_run.sh build_dabnn/tests/bgemm_test
displayName: Binary Gemm Test
- bash: ci/download_models.sh
displayName: Download Models
- bash: ci/adb_push_and_run.sh build_dabnn/tests/net_test
displayName: Model Test
4 changes: 4 additions & 0 deletions common/baseline.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
#include <dabnn/mat.h>

inline int bitcount(uint64_t x) {
#ifdef __aarch64__
return __builtin_popcountl(x);
#else
std::bitset<64> bs(x);
return bs.count();
#endif
}

inline void baseline_pack_mat(const bnn::Mat &float_mat, bnn::Mat &binary_mat) {
Expand Down
Loading

0 comments on commit e5a35d3

Please sign in to comment.