Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android使用armeabi-v7a-hard with NEON模式编译,应用闪退 #171

Closed
airx opened this issue Oct 27, 2017 · 6 comments
Closed

android使用armeabi-v7a-hard with NEON模式编译,应用闪退 #171

airx opened this issue Oct 27, 2017 · 6 comments

Comments

@airx
Copy link

airx commented Oct 27, 2017

android编译,使用armeabi-v7a-hard with NEON模式运行报错:
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xfffffff8 in tid 16523。
armeabi-v7a with NEON模式编译运行正常。

在树莓派3B+,Linux上编译,加上-march=armv7-a -mfloat-abi=hard -mhard-float -mfpu=neon优化,性能280ms左右;
可是在nubia z11手机上(这处理器应该比树莓派强太多了吧),用armeabi-v7a with NEON编译运行,结果还是270ms左右。
而使用armeabi-v7a-hard with NEON模式又运行报错。
CPU性能优势因为换成android系统,完全没有体现出来,好忧伤!

@airx
Copy link
Author

airx commented Oct 28, 2017

硬件:树莓派3B+;
代码:同样模型和C代码。
系统对比:
1、原生Linux系统,修改src/CMakeList.txt将其判断为arm。
主CMakeList.txt加入add_definitions(-march=armv7-a -mfloat-abi=hard -mhard-float -mfpu=neon),编译运行,运行时间280ms左右
主CMakeList.txt不加add_definitions(-march=armv7-a -mfloat-abi=hard -mhard-float -mfpu=neon),运行时间700ms左右
2、刷入Android 6.0系统,编译:
cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake
-DANDROID_ABI="armeabi-v7a with NEON"
-DANDROID_NATIVE_API_LEVEL=android-9
-DANDROID_FORCE_ARM_BUILD=OFF
-DANDROID_STL_FORCE_FEATURES=OFF ..,
运行时间:920ms。
这个差距太大了吧,同样硬件啊!

@BUG1989
Copy link
Contributor

BUG1989 commented Oct 28, 2017

  1. Disable neon,it always running the normal codes,for example,when do convolution,it use convolution.cpp not use convolution_arm.cpp.
  2. On the android platform,it enable the power management,please make sure that cpu is working on the performance model:
    $ adb shell "echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    Try it again : )

@airx
Copy link
Author

airx commented Oct 28, 2017

1、如果用-DANDROID_ABI="armeabi-v7a"编译,运行速度更慢呀。
2、电源管理可能是个问题,但估计差别没那么大,还没测试

@airx
Copy link
Author

airx commented Oct 28, 2017

@BUG1989 编译参数差别不在于neon,而在于arm linux下使用的是-mfloat-abi=hard -mhard-float,而android下使用的是-mfloat-abi=softfp。也就是armeabi-v7a with NEON和armeabi-v7a-hard with NEON模式编译参数的差别,但是armeabi-v7a-hard with NEON编译了运行不起。

@Dawson-huang
Copy link

遇到了同样的问题:
02-03 10:58:53.576 11277-11277/? A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xbd252952 in tid 11277
02-03 10:58:53.577 11277-11277/? A/libc: Unable to open connection to debuggerd: Connection refused
在AS运行,包名都直接变成了问号,难道是找不到包名而崩溃吗,程序直接闪退

@Dawson-huang
Copy link

我已经解决这个问题,这个问题主要的原因是jni接口没有释放数组内存。
带New到方法(如:NewByteArray)需要手动调用DeleteLocalRef()来释放(返回值除外)。GetByteArrayELement必须要调用ReleaseByteArrayElements进行释放。
返回值释放的方法:
JNIEXPORT jintArray JNICALL Java_com_test_git_jnidemo_JniUtil_JniDemo_createArrayMethod
(JNIEnv *env, jobject jobj, jint len){
//1.新建长度len数组
jintArray jarr = env->NewIntArray(len);
//2.获取数组指针
jint *arr = env->GetIntArrayElements(jarr, NULL);
//3.赋值
int i = 0;
for(; i < len; i++){
arr[i] = i;
}
//4.释放资源
env->ReleaseIntArrayElements(jarr, arr, 0);
//5.返回数组
return jarr;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants