提交 747a9e2a 编写于 作者: L Liangliang He

Optimize activation and fix export lib scripts

上级 dd501eea
...@@ -54,17 +54,20 @@ void DoActivation(const T *input_ptr, ...@@ -54,17 +54,20 @@ void DoActivation(const T *input_ptr,
case NOOP: case NOOP:
break; break;
case RELU: case RELU:
#pragma omp parallel for
for (index_t i = 0; i < size; ++i) { for (index_t i = 0; i < size; ++i) {
output_ptr[i] = std::max(input_ptr[i], static_cast<T>(0)); output_ptr[i] = std::max(input_ptr[i], static_cast<T>(0));
} }
break; break;
case RELUX: case RELUX:
#pragma omp parallel for
for (index_t i = 0; i < size; ++i) { for (index_t i = 0; i < size; ++i) {
output_ptr[i] = std::min(std::max(input_ptr[i], static_cast<T>(0)), output_ptr[i] = std::min(std::max(input_ptr[i], static_cast<T>(0)),
static_cast<T>(relux_max_limit)); static_cast<T>(relux_max_limit));
} }
break; break;
case PRELU: case PRELU:
#pragma omp parallel for
for (index_t i = 0; i < size; ++i) { for (index_t i = 0; i < size; ++i) {
T in = input_ptr[i]; T in = input_ptr[i];
if (in < 0) { if (in < 0) {
...@@ -75,12 +78,14 @@ void DoActivation(const T *input_ptr, ...@@ -75,12 +78,14 @@ void DoActivation(const T *input_ptr,
} }
break; break;
case TANH: case TANH:
#pragma omp parallel for
for (index_t i = 0; i < size; ++i) { for (index_t i = 0; i < size; ++i) {
T in_exp = std::exp(-2 * input_ptr[i]); T in_exp = std::exp(-2 * input_ptr[i]);
output_ptr[i] = (1 - in_exp) / (1 + in_exp); output_ptr[i] = (1 - in_exp) / (1 + in_exp);
} }
break; break;
case SIGMOID: case SIGMOID:
#pragma omp parallel for
for (index_t i = 0; i < size; ++i) { for (index_t i = 0; i < size; ++i) {
output_ptr[i] = 1 / (1 + std::exp(-input_ptr[i])); output_ptr[i] = 1 / (1 + std::exp(-input_ptr[i]));
} }
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
set -e set -e
Usage() { Usage() {
echo "Usage: ./tools/export_lib.sh android_abi[armeabi-v7a/arm64-v8a] runtime[gpu/dsp] export_include_dir export_lib_dir" echo "Usage: ./tools/export_lib.sh target_abi[armeabi-v7a | arm64-v8a | host] runtime[gpu | dsp] export_include_dir export_lib_dir"
echo "eg: ./tools/export_lib.sh armeabi-v7a ../include ../lib/libmace_v7" echo "eg: ./tools/export_lib.sh armeabi-v7a gpu ../include ../lib/libmace_v7"
} }
if [ $# -lt 4 ]; then if [ $# -lt 4 ]; then
...@@ -12,9 +12,7 @@ if [ $# -lt 4 ]; then ...@@ -12,9 +12,7 @@ if [ $# -lt 4 ]; then
exit 1 exit 1
fi fi
# ANDROID_ABI=arm64-v8a TARGET_ABI=$1
# ANDROID_ABI=armeabi-v7a
ANDROID_ABI=$1
RUNTIME=$2 RUNTIME=$2
EXPORT_INCLUDE_DIR=$3 EXPORT_INCLUDE_DIR=$3
EXPORT_LIB_DIR=$4 EXPORT_LIB_DIR=$4
...@@ -63,15 +61,18 @@ build_target() ...@@ -63,15 +61,18 @@ build_target()
bazel build --verbose_failures -c opt --strip always $BAZEL_TARGET \ bazel build --verbose_failures -c opt --strip always $BAZEL_TARGET \
--crosstool_top=//external:android/crosstool \ --crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \ --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=$ANDROID_ABI \ --cpu=$TARGET_ABI \
--copt="-std=c++11" \ --copt="-std=c++11" \
--copt="-D_GLIBCXX_USE_C99_MATH_TR1" \ --copt="-D_GLIBCXX_USE_C99_MATH_TR1" \
--copt="-Werror=return-type" \ --copt="-Werror=return-type" \
--copt="-DMACE_OBFUSCATE_LITERALS" \ --copt="-DMACE_OBFUSCATE_LITERALS" \
--copt="-O3" \
--define neon=true \
--define openmp=true \
$DSP_MODE_BUILD_FLAGS || exit 1 $DSP_MODE_BUILD_FLAGS || exit 1
} }
build_local_target() build_host_target()
{ {
BAZEL_TARGET=$1 BAZEL_TARGET=$1
bazel build --verbose_failures -c opt --strip always $BAZEL_TARGET \ bazel build --verbose_failures -c opt --strip always $BAZEL_TARGET \
...@@ -79,7 +80,8 @@ build_local_target() ...@@ -79,7 +80,8 @@ build_local_target()
--copt="-D_GLIBCXX_USE_C99_MATH_TR1" \ --copt="-D_GLIBCXX_USE_C99_MATH_TR1" \
--copt="-Werror=return-type" \ --copt="-Werror=return-type" \
--copt="-DMACE_OBFUSCATE_LITERALS" \ --copt="-DMACE_OBFUSCATE_LITERALS" \
--define openmp=true || exit -1 --copt="-O3" \
--define openmp=true || exit 1
} }
merge_libs() merge_libs()
...@@ -132,10 +134,10 @@ bash mace/tools/git/gen_version_source.sh ${CODEGEN_DIR}/version/version.cc || e ...@@ -132,10 +134,10 @@ bash mace/tools/git/gen_version_source.sh ${CODEGEN_DIR}/version/version.cc || e
echo "Step 3: Build libmace targets" echo "Step 3: Build libmace targets"
bazel clean bazel clean
if [ x"${RUNTIME}" = x"local" ]; then if [ x"${TARGET_ABI}" = x"host" ] || [ x"${TARGET_ABI}" = x"local" ]; then
for target in ${all_targets[*]} for target in ${all_targets[*]}
do do
build_local_target ${target} build_host_target ${target}
done done
else else
for target in ${all_targets[*]} for target in ${all_targets[*]}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册