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

Selecting XNNPACK as execution provider for Android following the documentation example results in program termination #23826

Closed
pl121lp opened this issue Feb 26, 2025 · 2 comments
Labels
documentation improvements or additions to documentation; typically submitted using template ep:Xnnpack issues related to XNNPACK EP platform:mobile issues related to ONNX Runtime mobile; typically submitted using template

Comments

@pl121lp
Copy link

pl121lp commented Feb 26, 2025

Describe the documentation issue

I'm using the latest prebuilt onnx runtime package (1.20.0) for Android from here: https://mvnrepository.com/artifact/com.microsoft.onnxruntime/onnxruntime-android/1.20.0

From that package I'm using the "jni/arm64-v8a/libonnxruntime.so" and the C++ header to run inference on an ONNX model.
This works fine using default session options.

But when I try to select XNNPACK execution provider following the instructions from here: https://onnxruntime.ai/docs/execution-providers/Xnnpack-ExecutionProvider.html I run into a program termination (without any error details) when invoking "session_options.AppendExecutionProvider("XNNPACK", {{"intra_op_num_threads", std::to_string(intra_op_num_threads)}});"

Note that Ort::GetAvailableProviders() tells me that the XNNPACK provider is available:
NnapiExecutionProvider
XnnpackExecutionProvider
CPUExecutionProvider

Setting
session_options.AddConfigEntry(kOrtSessionOptionsConfigAllowIntraOpSpinning, "0");
session_options.SetIntraOpNumThreads(1);
or using different "intra_op_num_threads" does not make a difference.

What am I missing?
How do I determine what the default execution provider is. I assume it's "CPUExecutionProvider"?

Page / URL

https://onnxruntime.ai/docs/execution-providers/Xnnpack-ExecutionProvider.html

@pl121lp pl121lp added the documentation improvements or additions to documentation; typically submitted using template label Feb 26, 2025
@github-actions github-actions bot added ep:Xnnpack issues related to XNNPACK EP platform:mobile issues related to ONNX Runtime mobile; typically submitted using template labels Feb 26, 2025
@pl121lp
Copy link
Author

pl121lp commented Feb 26, 2025

It seems the XnnPack backend is sensitive to a specific layer or the layout of the model.
I ran inference using the exact same code but instead using a simple/small mobilenet_v3 model. This works, without crash at call to session_options.AppendExecutionProvider("XNNPACK")
Looking at the logcat log for this workload I can see
GraphTransformer TransposeOptimizer followed by
GraphTransformer Level2_RuleBasedTransformer (which is not seen in the log for the failing case)

This may indicate that the the failure happens in the "GraphTransformer Level2_RuleBasedTransformer" pass

Please find logcat dump below for the failing onnx model inference below
Seems to indicate that XnnPackExecutionProvider is created.
And failure during or right after GraphTransformer actions.

02-26 15:12:55.442 21887 21887 I servicemanager: Caller(pid=19930,uid=1068,sid=u:r:secure_element:s0:c44,c260,c512,c768) Tried to start aidl service android.hardware.secure_element.ISecureElement/eSE1 as a lazy service, but was unable to. Usually this happens when a service is not installed, but if the service is intended to be used as a lazy service, then it may be configured incorrectly.
02-26 15:12:55.815 21890 21890 I onnxruntime: [I:onnxruntime:, inference_session.cc:583 TraceSessionOptions] Session Options { execution_mode:0 execution_order:DEFAULT enable_profiling:0 optimized_model_filepath:"" enable_mem_pattern:1 enable_mem_reuse:1 enable_cpu_mem_arena:1 profile_file_prefix:onnxruntime_profile_ session_logid: session_log_severity_level:-1 session_log_verbosity_level:0 max_num_graph_transformation_steps:10 graph_optimization_level:3 intra_op_param:OrtThreadPoolParams { thread_pool_size: 1 auto_set_affinity: 0 allow_spinning: 1 dynamic_block_base_: 0 stack_size: 0 affinity_str: set_denormal_as_zero: 0 } inter_op_param:OrtThreadPoolParams { thread_pool_size: 0 auto_set_affinity: 0 allow_spinning: 1 dynamic_block_base_: 0 stack_size: 0 affinity_str: set_denormal_as_zero: 0 } use_per_session_threads:1 thread_pool_allow_spinning:1 use_deterministic_compute:0 config_options: { session.intra_op.allow_spinning: 0 XNNPACK:intra_op_num_threads: 4 } }
02-26 15:12:55.815 21890 21890 I onnxruntime: [I:onnxruntime:, inference_session.cc:483 operator()] Flush-to-zero and denormal-as-zero are off
02-26 15:12:55.815 21890 21890 I onnxruntime: [I:onnxruntime:, inference_session.cc:491 ConstructorCommon] Creating and using per session threadpools since use_per_session_threads_ is true
02-26 15:12:55.815 21890 21890 I onnxruntime: [I:onnxruntime:, inference_session.cc:509 ConstructorCommon] Dynamic block base set to 0
02-26 15:12:55.979 21890 21890 I onnxruntime: [I:onnxruntime:, inference_session.cc:1669 Initialize] Initializing session.
02-26 15:12:55.979 21890 21890 I onnxruntime: [I:onnxruntime:, inference_session.cc:1706 Initialize] Adding default CPU execution provider.
02-26 15:12:55.979 21890 21890 I onnxruntime: [I:onnxruntime:Verbose, bfc_arena.cc:29 BFCArena] Creating BFCArena for XnnpackExecutionProvider with following configs: initial_chunk_size_bytes: 1048576 max_dead_bytes_per_chunk: 134217728 initial_growth_chunk_size_bytes: 2097152 max_power_of_two_extend_bytes: 1073741824 memory limit: 18446744073709551615 arena_extend_strategy: 0
02-26 15:12:55.979 21890 21890 V onnxruntime: [V:onnxruntime:Verbose, bfc_arena.cc:66 BFCArena] Creating 21 bins of max chunk size 256 to 268435456
02-26 15:12:55.980 21890 21890 I onnxruntime: [I:onnxruntime:Verbose, bfc_arena.cc:29 BFCArena] Creating BFCArena for Cpu with following configs: initial_chunk_size_bytes: 1048576 max_dead_bytes_per_chunk: 134217728 initial_growth_chunk_size_bytes: 2097152 max_power_of_two_extend_bytes: 1073741824 memory limit: 18446744073709551615 arena_extend_strategy: 0
02-26 15:12:55.980 21890 21890 V onnxruntime: [V:onnxruntime:Verbose, bfc_arena.cc:66 BFCArena] Creating 21 bins of max chunk size 256 to 268435456
02-26 15:12:55.982 21890 21890 I onnxruntime: [I:onnxruntime:, graph_partitioner.cc:898 InlineFunctionsAOT] This model does not have any local functions defined. AOT Inlining is not performed
02-26 15:12:55.982 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer EnsureUniqueDQForNodeUnit modified: 0 with status: OK
02-26 15:12:55.982 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer Level1_RuleBasedTransformer modified: 0 with status: OK
02-26 15:12:55.983 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer DoubleQDQPairsRemover modified: 0 with status: OK
02-26 15:12:55.983 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer ConstantSharing modified: 0 with status: OK
02-26 15:12:55.983 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer CommonSubexpressionElimination modified: 0 with status: OK
02-26 15:12:55.983 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer ConstantFolding modified: 0 with status: OK
02-26 15:12:55.983 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer MatMulAddFusion modified: 0 with status: OK
02-26 15:12:55.984 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer ReshapeFusion modified: 0 with status: OK
02-26 15:12:55.984 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer FreeDimensionOverrideTransformer modified: 0 with status: OK
02-26 15:12:55.984 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer GeluFusionL1 modified: 0 with status: OK
02-26 15:12:55.984 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer LayerNormFusionL1 modified: 0 with status: OK
02-26 15:12:55.984 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer QDQPropagationTransformer modified: 0 with status: OK
02-26 15:12:55.984 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer EnsureUniqueDQForNodeUnit modified: 0 with status: OK
02-26 15:12:55.984 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer RocmBlasAltImpl modified: 0 with status: OK
02-26 15:12:55.985 21890 21890 I onnxruntime: [I:onnxruntime:, graph_transformer.cc:15 Apply] GraphTransformer TransposeOptimizer modified: 0 with status: OK
02-26 15:12:55.985 21890 21890 E libc++abi: terminating
--------- beginning of crash
02-26 15:12:55.985 21890 21890 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 21890 (main), pid 21890 (main)
02-26 15:12:56.029 21896 21896 E crash_dump64: failed to get the guest state header for thread 21890: Bad address
02-26 15:12:56.030 21896 21896 E crash_dump64: failed to get the guest state header for thread 21891: Bad address
02-26 15:12:56.030 21896 21896 E crash_dump64: failed to get the guest state header for thread 21892: Bad address
02-26 15:12:56.031 21896 21896 E crash_dump64: failed to get the guest state header for thread 21893: Bad address
02-26 15:12:56.065 21896 21896 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstoneProto
02-26 15:12:56.065 1205 1205 I tombstoned: received crash request for pid 21890
02-26 15:12:56.065 21896 21896 I crash_dump64: performing dump of process 21890 (target tid = 21890)
02-26 15:12:56.131 874 874 I logd : logdr: UID=0 GID=0 PID=21896 n tail=500 logMask=8 pid=21890 start=0ns deadline=0ns
02-26 15:12:56.133 874 874 I logd : logdr: UID=0 GID=0 PID=21896 n tail=500 logMask=1 pid=21890 start=0ns deadline=0ns
02-26 15:12:56.109 21896 21896 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-26 15:12:56.109 21896 21896 F DEBUG : Build fingerprint: 'qti/sun/sun:15/AQ3A.240912.001/eng.lnxbui.00000000.000000:userdebug/test-keys'
02-26 15:12:56.109 21896 21896 F DEBUG : Revision: '0'
02-26 15:12:56.109 21896 21896 F DEBUG : ABI: 'arm64'
02-26 15:12:56.109 21896 21896 F DEBUG : Timestamp: 2025-02-26 15:12:56.067139511-0600
02-26 15:12:56.109 21896 21896 F DEBUG : Process uptime: 1s
02-26 15:12:56.109 21896 21896 F DEBUG : Cmdline: ./main
02-26 15:12:56.109 21896 21896 F DEBUG : pid: 21890, tid: 21890, name: main >>> ./main <<<
02-26 15:12:56.109 21896 21896 F DEBUG : uid: 0
02-26 15:12:56.109 21896 21896 F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
02-26 15:12:56.109 21896 21896 F DEBUG : pac_enabled_keys: 000000000000000f (PR_PAC_APIAKEY, PR_PAC_APIBKEY, PR_PAC_APDAKEY, PR_PAC_APDBKEY)
02-26 15:12:56.109 21896 21896 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
02-26 15:12:56.109 21896 21896 F DEBUG : Abort message: 'terminating'
02-26 15:12:56.109 21896 21896 F DEBUG : x0 0000000000000000 x1 0000000000005582 x2 0000000000000006 x3 0000007fca512c30
02-26 15:12:56.109 21896 21896 F DEBUG : x4 fefefefeff666d68 x5 fefefefeff666d68 x6 fefefefeff666d68 x7 7f7f7f7f7f7f7f7f
02-26 15:12:56.109 21896 21896 F DEBUG : x8 00000000000000f0 x9 0000007cca8ce468 x10 ffffff80ffffffdf x11 0000000000000000
02-26 15:12:56.109 21896 21896 F DEBUG : x12 0000000067bf83d7 x13 000000007fffffff x14 0000000000085aa2 x15 000000231c090531
02-26 15:12:56.110 21896 21896 F DEBUG : x16 0000007cca985ff8 x17 0000007cca96fe40 x18 0000007cd2030000 x19 0000000000005582
02-26 15:12:56.110 21896 21896 F DEBUG : x20 0000000000005582 x21 00000000ffffffff x22 0000007fca512d60 x23 0000007fca512da0
02-26 15:12:56.110 21896 21896 F DEBUG : x24 0000007fca512e50 x25 0000000000000001 x26 000000000000000b x27 b400007c0755ec61
02-26 15:12:56.110 21896 21896 F DEBUG : x28 b400007c174fd1d0 x29 0000007fca512cb0
02-26 15:12:56.110 21896 21896 F DEBUG : lr 0000007cca90b128 sp 0000007fca512c10 pc 0000007cca90b158 pst 0000000000001000
02-26 15:12:56.110 21896 21896 F DEBUG : 19 total frames
02-26 15:12:56.110 21896 21896 F DEBUG : backtrace:
02-26 15:12:56.110 21896 21896 F DEBUG : #00 pc 0000000000060158 /apex/com.android.runtime/lib64/bionic/libc.so (abort+172) (BuildId: f98650a65aa2ec2d87236752af90aa7e)
02-26 15:12:56.110 21896 21896 F DEBUG : #1 pc 000000000048ac04 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #2 pc 000000000048a638 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #3 pc 000000000048a5d4 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #4 pc 000000000048a598 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #5 pc 00000000004bd7f8 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #6 pc 00000000005d76f0 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #7 pc 00000000005e828c /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #8 pc 00000000005becb4 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #9 pc 0000000000c87b7c /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #10 pc 0000000000c89e50 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #11 pc 0000000000c880f8 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #12 pc 0000000000c85ec4 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #13 pc 00000000004daa18 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #14 pc 00000000004de4f0 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #15 pc 00000000004b1464 /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #16 pc 00000000004b046c /data/local/tmp/onnxrttest/libonnxruntime.so (BuildId: 28434ccc8a36215992c1802c13ec10a92b66f08e)
02-26 15:12:56.110 21896 21896 F DEBUG : #17 pc 0000000000005fd8 /data/local/tmp/onnxrttest/main (main+1040)
02-26 15:12:56.110 21896 21896 F DEBUG : #18 pc 0000000000059ac0 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+120) (BuildId: f98650a65aa2ec2d87236752af90aa7e)

@pl121lp
Copy link
Author

pl121lp commented Feb 28, 2025

turns out the issue is that Xnnpack backend cannot handle this specific onnx model parameters for the Resize operation.
Empty tensor for the scales parameter results in crash. Hacked onnxrt xnnpack wrapper code code to resolve the issue,

@pl121lp pl121lp closed this as completed Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation improvements or additions to documentation; typically submitted using template ep:Xnnpack issues related to XNNPACK EP platform:mobile issues related to ONNX Runtime mobile; typically submitted using template
Projects
None yet
Development

No branches or pull requests

1 participant