signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0(Cause: null pointer dereference)

  • Post author:
  • Post category:其他


问题描述:

基于mnn编译的面向安卓平台的模型推理so动态在android studio调用其推理函数时报空指针错误(完整错误输出在最后),且错误行在于mnn推理输出的指针数组元素的判断语句(如下代码),但之前使用其他模型时加入类似语句并未报错,所以猜测问题出在了模型上面

int* output_tensor_array = output_tensor->host<int>();
output_tensor_array[col + 1024 * row] == 2 //此处为addr2line显示的报错点

解决:

经过大量试验,发现在转换pytorch模型至onnx模型时,opset_version=10的模型在后续so调用函数均正常,opset_version=11的均错误,但是目前使用的模型实现中有新的pytorch算子只有在opset_version=11的时候才能转换为onnx格式,最终把该新算子改成简单的算子替代重新训练即可

torch.onnx.export(net,                     # model being run
                x,                         # model input (or a tuple for multiple inputs)
                output_path,               # where to save the model (can be a file or file-like object)
                export_params=True,        # store the trained parameter weights inside the model file
                opset_version=10,          # the ONNX version to export the model to
                do_constant_folding=True,  # whether to execute constant folding for optimization
                input_names = ['input'],   # the model's input names
                output_names = ['output'], # the model's output names
                )

完整错误输出:

2021-07-11 16:07:46.463 29653-29653/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2021-07-11 16:07:46.463 29653-29653/? A/DEBUG: Build fingerprint: 'HUAWEI/MRX-W09/HWMRX:10/HUAWEIMRX-W09/11.0.0.180C00:user/release-keys'
2021-07-11 16:07:46.463 29653-29653/? A/DEBUG: Revision: '0'
2021-07-11 16:07:46.463 29653-29653/? A/DEBUG: ABI: 'arm64'
2021-07-11 16:07:46.463 29653-29653/? A/DEBUG: Timestamp: 2021-07-11 16:07:46+0800
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG: pid: 29047, tid: 29640, name: Thread-3  >>> com.example.demo <<<
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG: uid: 10197
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG: Cause: null pointer dereference
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG:     x0  000000792defda00  x1  0000000000000000  x2  0000000000000000  x3  00000078ef2fff80
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG:     x4  00000078ef300000  x5  0000000000000004  x6  0000000000000000  x7  0000000000400000
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG:     x8  0000000000000000  x9  0000000000000000  x10 0000000000000000  x11 000000792defdb58
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG:     x12 00000078ef000000  x13 0000000000000000  x14 0000000000100000  x15 0000000000000000
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG:     x16 0000007904d1ca68  x17 0000007904976028  x18 0000000000000003  x19 00000079033cf4a8
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG:     x20 000000792defdd10  x21 000000792defd9a0  x22 000000792defdb18  x23 00000079033cf4a0
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG:     x24 000000792defdb98  x25 0000000000000000  x26 0000000001010000  x27 0000000042ff0000
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG:     x28 0000000002010000  x29 000000792defdb08
2021-07-11 16:07:46.464 29653-29653/? A/DEBUG:     sp  000000792defd8d0  lr  00000079049540f8  pc  0000007904954110
2021-07-11 16:07:46.471 3089-3917/? E/NcDftMisc: trigger wifi rate&power event fail
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG: backtrace:
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #00 pc 0000000000090110  /data/app/com.example.demo-QJuPM-AwiY8_boEE_J0T_g==/lib/arm64/libVesselDetection.so (Segmentation::vessel_detection(unsigned char*, int, int, int, int, int)+776) (BuildId: fefa236e6b88b908eb43ea102cc76d74b8e106e4)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #01 pc 000000000000caec  /data/app/com.example.demo-QJuPM-AwiY8_boEE_J0T_g==/lib/arm64/libautovolumeflow.so (Java_com_chison_android_pu_Stub_CInterface_vesseldetection+132) (BuildId: a523c3d821e03b082fe120be62f812d8e1f8f32a)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #02 pc 000000000014d350  /apex/com.android.runtime/lib64/libart.so (art_quick_generic_jni_trampoline+144) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #03 pc 00000000001445b8  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_static_stub+568) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #04 pc 00000000001531c4  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+284) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #05 pc 00000000002eee68  /apex/com.android.runtime/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+384) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #06 pc 00000000002eb1cc  /apex/com.android.runtime/lib64/libart.so (bool art::interpreter::DoCall<true, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+656) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #07 pc 00000000005c5540  /apex/com.android.runtime/lib64/libart.so (MterpInvokeStaticRange+236) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #08 pc 000000000013ec94  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_static_range+20) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #09 pc 000000000001298c  [anon:dalvik-classes2.dex extracted in memory from /data/app/com.example.demo-QJuPM-AwiY8_boEE_J0T_g==/base.apk!classes2.dex] (com.example.demo.AutoVolumeFlow.vesselDetection+276)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #10 pc 00000000005c3240  /apex/com.android.runtime/lib64/libart.so (MterpInvokeVirtualRange+1056) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #11 pc 000000000013eb14  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_virtual_range+20) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #12 pc 000000000001324c  [anon:dalvik-classes2.dex extracted in memory from /data/app/com.example.demo-QJuPM-AwiY8_boEE_J0T_g==/base.apk!classes2.dex] (com.example.demo.MainActivity$2.run+28)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #13 pc 00000000005c1640  /apex/com.android.runtime/lib64/libart.so (MterpInvokeInterface+1752) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #14 pc 000000000013ea14  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_interface+20) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #15 pc 00000000000eabdc  /apex/com.android.runtime/javalib/core-oj.jar (java.lang.Thread.run+8)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #16 pc 00000000002bf988  /apex/com.android.runtime/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEbb.llvm.14699443157220891705+320) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #17 pc 00000000005b0854  /apex/com.android.runtime/lib64/libart.so (artQuickToInterpreterBridge+1012) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #18 pc 000000000014d468  /apex/com.android.runtime/lib64/libart.so (art_quick_to_interpreter_bridge+88) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #19 pc 0000000000144334  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #20 pc 00000000001531a4  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+252) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #21 pc 00000000004cea6c  /apex/com.android.runtime/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #22 pc 00000000004cfb00  /apex/com.android.runtime/lib64/libart.so (art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue const*)+416) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #23 pc 00000000005123ec  /apex/com.android.runtime/lib64/libart.so (art::Thread::CreateCallback(void*)+1176) (BuildId: dea42f6b147b2555970fb4b1a84a9169)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #24 pc 00000000000cf6f0  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: 084953f8f5198acc841653c0a2c76779)
2021-07-11 16:07:46.507 29653-29653/? A/DEBUG:       #25 pc 00000000000720e8  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 084953f8f5198acc841653c0a2c76779)
2021-07-11 16:07:46.702 1032-1032/? E//system/bin/tombstoned: Tombstone written to: /data/tombstones/tombstone_05



版权声明:本文为weixin_42388228原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。