microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.09k stars 2.84k forks source link

Activate thread pool will cause crash. #21461

Open xiaojingang1777 opened 1 month ago

xiaojingang1777 commented 1 month ago

Describe the issue

My program dlopen libonnxruntime.so, the infence works fine, but when dlclose all the so, the main program crash. If I activate disable thread pool by set _OrtSessionOptions.SetIntraOpNumThreads(1); the main program won't crash, but the infence speed will be very slow.

From the onnxruntime source code comment: ORT_RUNTIME_CLASS(Session); // Don't call ReleaseSession from Dllmain (because session owns a thread pool) Whether my case violation this, and how to use thread pool, and release the thread pool after infence finished.

To reproduce

N/A

Urgency

No response

Platform

Android

OS Version

Android 7.0

ONNX Runtime Installation

Built from Source

Compiler Version (if 'Built from Source')

No response

Package Name (if 'Released Package')

None

ONNX Runtime Version or Commit ID

V1.18

ONNX Runtime API

C++/C

Architecture

ARM64

Execution Provider

Default CPU

Execution Provider Library Version

No response

xiaojingang1777 commented 1 month ago

07-23 13:59:43.248 32076 32076 F DEBUG : pid: 30705, tid: 31908, name: CurProgram >>> com.Xjg.maxi <<< 07-23 13:59:43.248 32076 32076 F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x764b690480 07-23 13:59:43.249 32076 32076 F DEBUG : x0 000000766d3e13c0 x1 0000000000000000 x2 0000007697a00000 x3 0000000000000019 07-23 13:59:43.249 32076 32076 F DEBUG : x4 00000000000001b6 x5 000000007182030d x6 000000767cef2a88 x7 000000766a84e020 07-23 13:59:43.249 32076 32076 F DEBUG : x8 000000764b690480 x9 7ace37599133aaee x10 7fffffffffffffff x11 0000000000000001 07-23 13:59:43.249 32076 32076 F DEBUG : x12 0000000000000000 x13 0000000000000000 x14 0000000000000000 x15 000000766aa5e9e0 07-23 13:59:43.249 32076 32076 F DEBUG : x16 00000076a26e4ec0 x17 00000076a268afb4 x18 00000000717a2468 x19 00000076281f6160 07-23 13:59:43.249 32076 32076 F DEBUG : x20 000000766ecfa450 x21 00000000000077f1 x22 00000076a1c27100 x23 0000007697bb6a00 07-23 13:59:43.249 32076 32076 F DEBUG : x24 000000766ecfa4d0 x25 0000000000105000 x26 7ace37599133aaee x27 000000000000000b 07-23 13:59:43.249 32076 32076 F DEBUG : x28 7ace37599133aaee x29 000000766ecfa3a0 x30 00000076a263ed7c 07-23 13:59:43.249 32076 32076 F DEBUG : sp 000000766ecfa390 pc 000000764b690480 pstate 0000000080000000 07-23 13:59:43.253 32076 32076 F DEBUG : 07-23 13:59:43.253 32076 32076 F DEBUG : backtrace: 07-23 13:59:43.253 32076 32076 F DEBUG : #00 pc 000000764b690480 07-23 13:59:43.253 32076 32076 F DEBUG : https://github.com/UNeedCryDear/yolov8-opencv-onnxruntime-cpp/issues/1 pc 000000000001bd78 /system/lib64/libc.so (cxa_thread_finalize+36) 07-23 13:59:43.253 32076 32076 F DEBUG : https://github.com/UNeedCryDear/yolov8-opencv-onnxruntime-cpp/issues/2 pc 0000000000067fc8 /system/lib64/libc.so (pthread_exit+20) 07-23 13:59:43.253 32076 32076 F DEBUG : https://github.com/UNeedCryDear/yolov8-opencv-onnxruntime-cpp/issues/3 pc 0000000000067ec0 /system/lib64/libc.so (_ZL15pthread_startPv+200) 07-23 13:59:43.253 32076 32076 F DEBUG : https://github.com/UNeedCryDear/yolov8-opencv-onnxruntime-cpp/issues/4 pc 000000000001d940 /system/lib64/libc.so (__start_thread+16)

Android ndk build the code, with onnxruntime h/so, the program works fine, but when my program so is released by dl close, the main program crashed.

Whether this is related to this comment: ORT_RUNTIME_CLASS(Session); // Don't call ReleaseSession from Dllmain (because session owns a thread pool)

xiaojingang1777 commented 1 month ago

默认好像是开启thread pool的,我关闭,设置_OrtSessionOptions.SetIntraOpNumThreads(1);就没问题,但是会慢很多,但是不设置1,就会在释放so的时候,崩溃在thread相关操作,有什么办法能够主动关闭thread pool么,在执行完之后。

github-actions[bot] commented 2 weeks ago

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.