Skip to content

Commit

Permalink
Merge branch 'master' into doc
Browse files Browse the repository at this point in the history
  • Loading branch information
daquexian committed Jun 3, 2019
2 parents 686b8ca + 1a73802 commit 98f0ad4
Show file tree
Hide file tree
Showing 32 changed files with 596 additions and 78 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
7 changes: 7 additions & 0 deletions .daq_pm/configs/bconv_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 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
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
7 changes: 7 additions & 0 deletions .daq_pm/configs/net_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_net_test_x86
target net_test
cmake_options -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -DBNN_BUILD_MAIN_LIB=ON -GNinja
binary tests/net_test
16 changes: 10 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ option(BNN_SYSTEM_PROTOBUF "Use system protobuf to build onnx2bnn" ON)
option(BNN_BUILD_PYTHON "Build onnx2bnn python interface" OFF)
option(BNN_USE_MSVC_STATIC_RUNTIME "Link onnx2bnn to msvc static runtime" ON)

if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
set(BNN_BUILD_ANDROID ON)
else()
set(BNN_BUILD_ANDROID OFF)
message(STATUS "Target architecture: ${CMAKE_SYSTEM_PROCESSOR}")
if (NOT DEFINED BNN_BUILD_MAIN_LIB)
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)
endif()
endif()
message(STATUS "BNN_BUILD_MAIN_LIB: ${BNN_BUILD_MAIN_LIB}")

include(cmake/utils.cmake)
bnn_add_msvc_runtime_flag()
Expand All @@ -42,7 +47,7 @@ if (${BNN_NET_BENCHMARK})
add_compile_options("-DBNN_BENCHMARK")
endif()

if (${BNN_BUILD_ANDROID})
if (BNN_BUILD_MAIN_LIB)
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
Expand All @@ -64,7 +69,6 @@ if (${BNN_BUILD_ANDROID})
configure_benchmark()
add_subdirectory(benchmark)
endif()

else()
set(CMAKE_CXX_STANDARD 11)

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Join chat at [Gitter (English)](https://gitter.im/dabnn/dabnn) or QQ Group (Chin

Binary neural networks (BNNs) have great potential on edge devices since they replace float operations by efficient bit-wise operations. However, to leverage the efficiency of bit-wise operations, the reimplmentation of convolution layer and also other layers is needed.

To our best knowledge, dabnn is the first highly-optimized binary neural networks inference framework for mobile platform. We implemented binary convolutions with armv8 assembly. On Google Pixel 1, our dabnn is as **800%~2400% faster** as [BMXNet](https://github.com/hpi-xnor/BMXNet) (the only one open-sourced BNN inference framework except dabnn to our best knowledge) on a single binary convolution, and as about **700% faster** as it on binarized ResNet-18.
To our best knowledge, dabnn is the first highly-optimized binary neural networks inference framework for mobile platform. We implemented binary convolutions with ARM assembly. On Google Pixel 1, our dabnn is as **800%~2400% faster** as [BMXNet](https://github.com/hpi-xnor/BMXNet) (the only one open-sourced BNN inference framework except dabnn to our best knowledge) on a single binary convolution, and as about **700% faster** as it on binarized ResNet-18.

## Benchmark and Comparison

Expand Down Expand Up @@ -46,11 +46,11 @@ The following is the comparison between our dabnn and [Caffe](http://caffe.berke

## Convert ONNX Model

We provide a conversion tool, named onnx2bnn, to convert an ONNX model to a dabnn model. To get the conversion tool, just build the project using the native toolchain (instead of arm cross-compiling toolchain). For Linux users, we provide pre-built onnx2bnn AppImage. Linux users can download it from [GitHub Releases](https://github.com/JDAI-CV/dabnn/releases). For the usage and other information about AppImage, please check out https://appimage.org .
We provide a conversion tool, named onnx2bnn, to convert an ONNX model to a dabnn model. We provide onnx2bnn pre-built binaries for all platforms in [GitHub Releases](https://github.com/JDAI-CV/dabnn/releases). For Linux users, the onnx2bnn pre-built binary is [AppImage](https://appimage.org) format, see https://appimage.org for details.

Note: Binary convolution is a custom operator, so whether the ONNX model is dabnn-comptabile heavily depends on the implementation of the binary convolution in the training code. We will soon provide an dabnn-comptabile PyTorch implementation of binary convolution.
Note: Binary convolution is a custom operator, so whether the ONNX model is dabnn-comptabile heavily depends on the implementation of the binary convolution in the training code. Please check out [our wiki](https://github.com/JDAI-CV/dabnn/wiki/Train,-export-and-convert-a-dabnn-model) for the further information.

After conversion, the generated dabnn model can be deployed on armv8 devices. For Android developer, we have provided Android AAR package and published it on [jcenter](https://bintray.com/daquexian566/maven/dabnn/_latestVersion), for the usage please check out [example project](https://github.com/JDAI-CV/dabnn-example).
After conversion, the generated dabnn model can be deployed on ARM devices (e.g., mobile phones and embedded devices). For Android developer, we have provided Android AAR package and published it on [jcenter](https://bintray.com/daquexian566/maven/dabnn/_latestVersion), for the usage please check out [example project](https://github.com/JDAI-CV/dabnn-example).

## Pretrained Models

Expand Down
8 changes: 4 additions & 4 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ QQ 群:1021964010, 入群答案: nndab

然而,想发挥出位运算的高效率,就需要用位运算对卷积进行重新实现。一直以来,始终没有人针对二值网络推出一个高度优化的 inference 框架,这让二值网络令人遗憾的失去了可以部署在现有通用设备上这个巨大的优势。

为了填补这个巨大的空白,我们推出了 dabnn,一个用 armv8 汇编重写了卷积,高度优化的二值网络 inference 框架。实验显示 dabnn 相对于现有的二值网络和浮点网络 inference 框架均能带来极大的加速。在运行单个二值卷积时,我们的速度是 [BMXNet](https://github.com/hpi-xnor/BMXNet) (除 dabnn 外唯一一个二值网络 inference 框架) 的 **800%~2400%**,在运行二值化的 ResNet-18 时,我们的速度是 BMXNet 的约 **700%**。我们希望 dabnn 的开源可以成为二值网络部署在终端设备的关键一步,也可以有助于使这一领域的爱好者了解二值网络在真实设备上的表现。
为了填补这个巨大的空白,我们推出了 dabnn,一个用 ARM 汇编重写了卷积,高度优化的二值网络 inference 框架。实验显示 dabnn 相对于现有的二值网络和浮点网络 inference 框架均能带来极大的加速。在运行单个二值卷积时,我们的速度是 [BMXNet](https://github.com/hpi-xnor/BMXNet) (除 dabnn 外唯一一个二值网络 inference 框架) 的 **800%~2400%**,在运行二值化的 ResNet-18 时,我们的速度是 BMXNet 的约 **700%**。我们希望 dabnn 的开源可以成为二值网络部署在终端设备的关键一步,也可以有助于使这一领域的爱好者了解二值网络在真实设备上的表现。

## 速度

Expand Down Expand Up @@ -48,11 +48,11 @@ dabnn_bireal18_imagenet_stem 43279353 ns 41533009 ns 14 <---

## 如何转换 ONNX 模型

我们提供模型转换工具 onnx2bnn 将 ONNX 模型转换为 dabnn 格式的模型。用本地编译工具链(而不是 arm 交叉编译工具链)编译这个项目就可以编译出 onnx2dnn。对 Linux 用户我们提供可以在 Linux 下无需编译直接运行的 AppImage,从 [GitHub Releases](https://github.com/JDAI-CV/dabnn/releases) 下载即可。AppImage 的使用方法和其它相关信息请参考 https://appimage.org/。
我们提供模型转换工具 onnx2bnn 将 ONNX 模型转换为 dabnn 格式的模型。[GitHub Releases](https://github.com/JDAI-CV/dabnn/releases) 里有各个平台的 onnx2bnn 预编译二进制文件,可以直接下载运行。Linux 用户我们提供的是 AppImage 格式的二进制文件,AppImage 的使用方法和其它相关信息请参考 https://appimage.org/。

注意:因为二值卷积是一种自定义操作,所以 ONNX 模型是否与 dabnn 兼容极大程度上依赖于训练代码中二值卷积的实现。我们很快会提供一个与 dabnn 兼容的二值卷积 PyTorch 实现
注意:因为二值卷积是一种自定义操作,所以 ONNX 模型是否与 dabnn 兼容极大程度上依赖于训练代码中二值卷积的实现,在 [wiki](https://github.com/JDAI-CV/dabnn/wiki/Train,-export-and-convert-a-dabnn-model) 中有详细的进一步描述

转换完成后得到的 dabnn 模型就可以在 armv8 设备上使用。对 Android 开发者我们已经把 Android AAR 包上传到了 [jcenter](https://bintray.com/daquexian566/maven/dabnn/_latestVersion),使用方法请看[示例工程](https://github.com/JDAI-CV/dabnn-example)
转换完成后得到的 dabnn 模型就可以在 ARM 设备(例如手机和嵌入式设备)上使用。对 Android 开发者我们已经把 Android AAR 包上传到了 [jcenter](https://bintray.com/daquexian566/maven/dabnn/_latestVersion),使用方法请看[示例工程](https://github.com/JDAI-CV/dabnn-example)

## 预训练模型

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
3 changes: 2 additions & 1 deletion cmake/system.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2019 JD.com Inc. JD AI

if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
if ((NOT CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME) OR
(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR))
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Expand Down
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 98f0ad4

Please sign in to comment.