ARM-software / armnn

Arm NN ML Software. The code here is a read-only mirror of https://review.mlplatform.org/admin/repos/ml/armnn
https://developer.arm.com/products/processors/machine-learning/arm-nn
MIT License
1.17k stars 309 forks source link

Crash when support ArmNN AIDL backend based on a shim over the NNAPI Support Library #770

Open khuongtrinh2 opened 4 months ago

khuongtrinh2 commented 4 months ago

Hello team, On v23.02, I was trying to support ArmNN AIDL based on a shim over the NNAPI Support Library. Step:

  1. In device.mk, add:

PRODUCT_PACKAGES += android.hardware.neuralnetworks-shim-service-armnn

  1. In sepolicy:

After complete these above step, I start hal_neuralnetworks_armnn service and get log crash:

--------- beginning of crash 03-20 04:16:01.148 420 420 F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x20 in tid 420 (android.hardwar), pid 420 (android.hardwar) 03-20 04:16:01.865 0 0 I logd : logdr: UID=1000 GID=1000 PID=526 n tail=500 logMask=8 pid=420 start=0ns deadline=0ns 03-20 04:16:01.875 0 0 I logd : logdr: UID=1000 GID=1000 PID=526 n tail=500 logMask=1 pid=420 start=0ns deadline=0ns 03-20 04:16:01.889 526 526 F DEBUG : 03-20 04:16:01.889 526 526 F DEBUG : Revision: '1.0' 03-20 04:16:01.889 526 526 F DEBUG : ABI: 'arm64' 03-20 04:16:01.889 526 526 F DEBUG : Timestamp: 2024-03-20 04:16:01.652114521+0000 03-20 04:16:01.889 526 526 F DEBUG : Process uptime: 6s 03-20 04:16:01.890 526 526 F DEBUG : Cmdline: /vendor/bin/hw/android.hardware.neuralnetworks-shim-service-armnn -c CpuAcc 03-20 04:16:01.890 526 526 F DEBUG : pid: 420, tid: 420, name: android.hardwar >>> /vendor/bin/hw/android.hardware.neuralnetworks-shim-service-armnn <<< 03-20 04:16:01.890 526 526 F DEBUG : uid: 1000 03-20 04:16:01.890 526 526 F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE) 03-20 04:16:01.890 526 526 F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000000020 03-20 04:16:01.890 526 526 F DEBUG : Cause: null pointer dereference 03-20 04:16:01.890 526 526 F DEBUG : x0 b400f6a20c99e1e8 x1 0000f6a2fdc651e0 x2 0000ffffe2b71a80 x3 0000ffffe2b719a8 03-20 04:16:01.890 526 526 F DEBUG : x4 0000000000000060 x5 b400f6a1fc9a9030 x6 3dcccccd00000000 x7 3dcccccd3dcccccd 03-20 04:16:01.890 526 526 F DEBUG : x8 0000000000000000 x9 0000c447fa960940 x10 0000ffffe2b71a88 x11 000000000000000f 03-20 04:16:01.890 526 526 F DEBUG : x12 0000000000006b84 x13 0000000000000001 x14 ffffffffffffffff x15 0000000000000000 03-20 04:16:01.890 526 526 F DEBUG : x16 0000c447faa566d0 x17 0000f6a302880480 x18 0000f6a30877c000 x19 b400f6a20c99e1e8 03-20 04:16:01.890 526 526 F DEBUG : x20 0000ffffe2b71a78 x21 0000f6a30802a000 x22 0000ffffe2b71a78 x23 0000f6a30802a000 03-20 04:16:01.890 526 526 F DEBUG : x24 0000f6a30802a000 x25 0000c447faa500b0 x26 0000c447faa57d78 x27 0000000000000000 03-20 04:16:01.890 526 526 F DEBUG : x28 b400f6a20c99de00 x29 0000ffffe2b719d0 03-20 04:16:01.890 526 526 F DEBUG : lr 0000f6a2fdd42a68 sp 0000ffffe2b719a0 pc 0000f6a2fdc65224 pst 0000000000001000 03-20 04:16:01.890 526 526 F DEBUG : 7 total frames 03-20 04:16:01.890 526 526 F DEBUG : backtrace: 03-20 04:16:01.890 526 526 F DEBUG : #00 pc 0000000001235224 /vendor/lib64/libarmnn_support_library_prebuilt.so (armnn_driver::ArmnnDriver::getNumberOfCacheFilesNeeded() const+68) (BuildId: 7227e80cac6f024da9bd3555a4c61b64) 03-20 04:16:01.890 526 526 F DEBUG : #01 pc 0000000001312a64 /vendor/lib64/libarmnn_support_library_prebuilt.so (SL_ANeuralNetworksDevice_getNumberOfCacheFilesNeeded+72) (BuildId: 7227e80cac6f024da9bd3555a4c61b64) 03-20 04:16:01.890 526 526 F DEBUG : #02 pc 0000000000070028 /vendor/bin/hw/android.hardware.neuralnetworks-shim-service-armnn (aidl::android::hardware::neuralnetworks::ShimDevice::ShimDevice(std::1::shared_ptr, ANeuralNetworksDevice*, std::__1::basic_string<char, std::1::char_traits, std::1::allocator >)+696) (BuildId: 2a5ff4e20e796027757aae11d3a172b5) 03-20 04:16:01.890 526 526 F DEBUG : #03 pc 000000000006e878 /vendor/bin/hw/android.hardware.neuralnetworks-shim-service-armnn (std::1::shared_ptr ndk::SharedRefBase::make<aidl::android::hardware::neuralnetworks::ShimDevice, std::1::shared_ptr&, ANeuralNetworksDevice*&, std::__1::basic_string<char, std::1::char_traits, std::1::allocator > const&>(std::1::shared_ptr&, ANeuralNetworksDevice&, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&)+120) (BuildId: 2a5ff4e20e796027757aae11d3a172b5) 03-20 04:16:01.890 526 526 F DEBUG : #04 pc 000000000006dadc /vendor/bin/hw/android.hardware.neuralnetworks-shim-service-armnn (android::neuralnetworks::shim::registerDevices(NnApiSLDriverImpl, std::1::vector<android::neuralnetworks::shim::ShimDeviceInfo, std::1::allocator > const&, unsigned int, bool, bool)+1596) (BuildId: 2a5ff4e20e796027757aae11d3a172b5) 03-20 04:16:01.891 526 526 F DEBUG : #05 pc 000000000006c0f4 /vendor/bin/hw/android.hardware.neuralnetworks-shim-service-armnn (main+148) (BuildId: 2a5ff4e20e796027757aae11d3a172b5) 03-20 04:16:01.917 526 526 F DEBUG : #06 pc 00000000000546e8 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+104) (BuildId: 19c32900d9d702c303d2b4164fbba76c)

I run /vendor/bin/hw/android.hardware.neuralnetworks-shim-service-armnn and see that my device doesn't have OpenCL library (No support yet)

Can't load libOpenCL.so: dlopen failed: library "libOpenCL.so" not found Can't load libGLES_mali.so: dlopen failed: library "libGLES_mali.so" not found Can't load libmali.so: dlopen failed: library "libmali.so" not found Can't load libOpenCL-pixel.so: dlopen failed: library "libOpenCL-pixel.so" not found Can't load libOpenCL-car.so: dlopen failed: library "libOpenCL-car.so" not found Couldn't find any OpenCL library.

After, I try disable OpenCL (set opencl =0, embed_kernels=0 in Compute Library and -DARMCOMPUTECL=0 in Arm NN before build) but it still crashes.

Anyone helps me with this issue, Thank you so much.

Colm-in-Arm commented 4 months ago

Hi khuongtrinh2,

This is not a configuration we've ever tried and I'm not too familiar with our shim/support library configuration. Looking at the stack trace the seg fault appears to be happening when that code attempts to address a backendin canonical/ArmnnDriver.hpp. What are you setting for ARMNN_SL_OPTIONS environment variable?

Colm.

khuongtrinh2 commented 4 months ago

Hi Colm-in-Arm Thank you for your support, Can you share some configuration you've ever tried? Thank you so much. I set ARMNN_SL_OPTIONS=-c CpuAcc