halide / Halide

a language for fast, portable data-parallel computation
https://halide-lang.org
Other
5.9k stars 1.07k forks source link

qurt_hvx_lock failed #3097

Closed autumnqin closed 3 years ago

autumnqin commented 6 years ago

It's OK to run the app/blur as an executable on android arm device. But error in an Android apk.

vendor/qcom/proprietary/adsprpc/src/fastrpc_apps_user.c:1267: /dsp/fastrpc_shell_0 load failed 45, searching... vendor/qcom/proprietary/adsprpc/src/fastrpc_apps_user.c:1375: create user pd with attributes 0 domain 0 vendor/qcom/proprietary/adsprpc/src/fastrpc_apps_user.c:842: Error ffffffff: remote handle invoke failed. domain 0, handle 16503ed0, sc 4060100, pra 0xde599c48 07-03 11:55:28.948 7578 7634 I halide : Error: qurt_hvx_lock failed 07-03 11:55:28.949 7578 7634 I chatty : uid=10164(bcamera) vd_0 identical 3 lines 07-03 11:55:28.949 7578 7634 I halide : Error: qurt_hvx_lock failed 07-03 11:55:28.949 7578 7634 I halide : Error: Hexagon pipeline failed.

ronlieb commented 6 years ago

Hello

what device are you testing on? is it a development device?

could you show the 30-40 lines from logcat immediately before the error text in the post?

thx

autumnqin commented 6 years ago

Hello, Thank you for response! It's a SDM710 device, and it is development device. more og attached.

hvx_lock_error.log

ronlieb commented 6 years ago

looking at your log ... it seems to be trying to use the ADSP rather than the CDSP, so we need to dig a little more ...

Are you using Halide from a Qualcomm Hexagon SDK? if so version of SDK? or are you building Halide yourself from latest upstream sources?

autumnqin commented 6 years ago

I don't know how the set the DSP, the halide used the ADSP as default.

I build Halide from master branch, not from a Qualcom Hexagon SDK. The Hexagon SDK I used is 3.3.3.

What's your suggestion? Should I use the Halide from Qualcomm Hexagon SDK?

ronlieb commented 6 years ago

is this a production SDM 710 ? or a development MTP/Board? if its a development board, i assume you generated a testsig-XXXXXXXX.so file and installed on device?

the next step, would be to ask you to rebuild your app adding "-debug" to the HL_TARGET when you generate code, this will produce more information into the logcat for me to see

autumnqin commented 6 years ago

Yes, I have generated a testsig-XXXXXXXX.so file and installed on device. And run the sample app/blur of Halide on the device successfully. But when I integrate the app/blur into an Android APK, it can not run successfully.

I will try adding "-debug" to the HL_TARGET later

autumnqin commented 6 years ago

More log:

07-04 21:11:59.147 12995 13053 I halide  : Entering Pipeline halide_blur
07-04 21:11:59.147 12995 13053 I halide  :  Input Buffer input: buffer(0, 0x0, 0xd2f80080, 1, uint16, {0, 552, 1}, {0, 640, 552})
07-04 21:11:59.147 12995 13053 I halide  :  Output Buffer blur_y: buffer(0, 0x0, 0xd3080080, 0, uint16, {0, 544, 1}, {0, 638, 544})
07-04 21:11:59.147 12995 13053 I halide  : Hexagon: init_hexagon_runtime (user_context: 0x0)
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_remote_load_library') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd3662fb4
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_remote_get_symbol_v4') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd36630c4
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_remote_run') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd3663fe4
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_remote_release_library') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd3663634
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_host_malloc_init') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd3663aa0
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_host_malloc_deinit') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd3663b0c
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_host_malloc') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd3663b40
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_host_free') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd3663dd0
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_remote_poll_log') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd36636f8
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_remote_poll_profiler_state') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd36637f4
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_remote_power_hvx_on') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd36631cc
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_remote_power_hvx_off') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd3663268
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_remote_set_performance') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd36639a0
07-04 21:11:59.147 12995 13053 I halide  :     halide_get_library_symbol('halide_hexagon_remote_set_performance_mode') -> 
07-04 21:11:59.147 12995 13053 I halide  :         0xd36638dc
07-04 21:11:59.148 12995 13053 I halide  : Hexagon: halide_hexagon_initialize_kernels (user_context: 0x0, state_ptr: 0xd46aba20, *state_ptr: 0x0, code: 0xd401a180, code_size: 16944)
07-04 21:11:59.148 12995 13053 I halide  : , code: 0xd401e3e0, code_size: 82600)
07-04 21:11:59.148 12995 13053 I halide  :     Initializing shared runtime
07-04 21:11:59.148 12995 13053 I halide  :     halide_remote_load_library(libhalide_shared_runtime.so) -> 
07-04 21:11:59.148 12995 13053 V com.mi.ailab.beautycamera: vendor/qcom/proprietary/adsprpc/src/fastrpc_apps_user.c:1267: /dsp/fastrpc_shell_0 load failed 45, searching...
07-04 21:11:59.149 12995 13053 V com.mi.ailab.beautycamera: vendor/qcom/proprietary/adsprpc/src/fastrpc_apps_user.c:1375: create user pd with attributes 0 domain 0
07-04 21:11:59.205 12995 13053 I halide  :         1016114112
07-04 21:11:59.206 12995 13053 I halide  :     allocating module state -> 
07-04 21:11:59.206 12995 13053 I halide  :         0xd47b8ff0
07-04 21:11:59.206 12995 13053 I halide  :     halide_remote_load_library(libhalide_kernels0.so) -> 
07-04 21:11:59.206 12995 13053 I halide  :         1016115248
07-04 21:11:59.206 12995 13053 I halide  :     Time: 5.865932e+01 ms
07-04 21:11:59.207 12995 13053 I halide  : halide_copy_to_device validating input buffer: buffer(0, 0x0, 0xd3080080, 0, uint16, {0, 544, 1}, {0, 638, 544})
07-04 21:11:59.207 12995 13053 I halide  : halide_device_malloc validating input buffer: buffer(0, 0x0, 0xd3080080, 0, uint16, {0, 544, 1}, {0, 638, 544})
07-04 21:11:59.207 12995 13053 I halide  : halide_device_malloc: target device interface 0xd461ab64
07-04 21:11:59.207 12995 13053 I halide  : Hexagon: halide_hexagon_device_malloc (user_context: 0x0, buf: 0xcf982560)
07-04 21:11:59.207 12995 13053 I halide  :     allocating buffer of 694272 bytes
07-04 21:11:59.207 12995 13053 I halide  :     host_malloc len=694272 -> 
07-04 21:11:59.207 12995 13053 I halide  :         0xcef56000
07-04 21:11:59.207 12995 13053 I halide  :     Time: 2.086460e-01 ms
07-04 21:11:59.207 12995 13053 I halide  : halide_copy_to_device validating input buffer: buffer(0, 0x0, 0xd2f80080, 1, uint16, {0, 552, 1}, {0, 640, 552})
07-04 21:11:59.207 12995 13053 I halide  : halide_device_malloc validating input buffer: buffer(0, 0x0, 0xd2f80080, 1, uint16, {0, 552, 1}, {0, 640, 552})
07-04 21:11:59.207 12995 13053 I halide  : halide_device_malloc: target device interface 0xd461ab64
07-04 21:11:59.207 12995 13053 I halide  : Hexagon: halide_hexagon_device_malloc (user_context: 0x0, buf: 0xcf9825d0)
07-04 21:11:59.207 12995 13053 I halide  :     allocating buffer of 706688 bytes
07-04 21:11:59.207 12995 13053 I halide  :     host_malloc len=706688 -> 
07-04 21:11:59.207 12995 13053 I halide  :         0xce5d9000
07-04 21:11:59.207 12995 13053 I halide  :     Time: 1.108340e-01 ms
07-04 21:11:59.207 12995 13053 I halide  : halide_copy_to_device 0xcf9825d0 host is dirty
07-04 21:11:59.207 12995 13053 I halide  : Hexagon: halide_hexagon_device_malloc (user_context: 0x0, buf: 0xcf9825d0)
07-04 21:11:59.207 12995 13053 I halide  : Hexagon: halide_hexagon_copy_to_device (user_context: 0x0, buf: 0xcf9825d0)
07-04 21:11:59.207 12995 13053 I halide  : c.extent[0] = 552
07-04 21:11:59.207 12995 13053 I halide  : c.extent[1] = 640
07-04 21:11:59.208 12995 13053 I halide  :     Time: 5.507810e-01 ms
07-04 21:11:59.208 12995 13053 I halide  : Hexagon: halide_hexagon_run (user_context: 0x0, state_ptr: 0xd47b8ff0 (1016115248), name: offload_rpc.blur_y.s0.__outermost_argv, function: 0xd46aba40 (0))
07-04 21:11:59.208 12995 13053 I halide  :     halide_hexagon_remote_get_symbol offload_rpc.blur_y.s0.__outermost_argv -> 
07-04 21:11:59.209 12995 13053 I halide  :         -530854752
07-04 21:11:59.209 12995 13053 I halide  : 1, 3035205329686528
07-04 21:11:59.209 12995 13053 I halide  : 0, 2981879099396088
07-04 21:11:59.209 12995 13053 I halide  :     halide_hexagon_remote_run -> 
07-04 21:11:59.210 12995 13053 D com.mi.ailab.beautycamera: vendor/qcom/proprietary/adsprpc/src/fastrpc_apps_user.c:842: Error ffffffff: remote handle invoke failed. domain 0, handle 3c903ed0, sc 4050100, pra 0xe91383c0
07-04 21:11:59.210 12995 13053 I halide  : Error: qurt_hvx_lock failed
07-04 21:11:59.211 12995 13053 I chatty  : uid=10164(com.mi.ailab.beautycamera) MiAILab_vd_0 identical 3 lines
07-04 21:11:59.211 12995 13053 I halide  : Error: qurt_hvx_lock failed
07-04 21:11:59.211 12995 13053 I halide  :         -1
07-04 21:11:59.211 12995 13053 I halide  : Error: Hexagon pipeline failed.
ronlieb commented 6 years ago

i need to look into this a bit more, feels like an Android protection issue. i have a coworker i need to ask a question of, not sure when he will be online , so it may be a day or so...

ronlieb commented 6 years ago

Talked with my co-worker, he recalls the following about getting an APK to run, the hexagon_host.so needs to be made public

1) The library libhalide_hexagon_host.so needs to be copied into /vendor/lib64

2) Then update /vendor/etc/public.libraries.txt by adding libhalide_hexagon_host.so (This makes this library public to be used by app)

3) i suggest rebooting after that to make sure things are activated ...

dsharletg commented 6 years ago

qurt_hvx_lock failing means that we already made it all the way into Hexagon code and were about to execute HVX instructions. That means it got through libhalide_hexagon_host.so, and libhalide_hexagon_remote_skel.so, so we know that these libraries are in the right place and signature verification did not block anything.

If this device has an ADSP (without HVX) and a CDSP (with HVX), my guess is that it's running on the ADSP instead of the CDSP.

ronlieb commented 6 years ago

its this comment "But when I integrate the app/blur into an Android APK, it can not run successfully." that makes me think there is a permissions issue of some kind.

the 710 does have hvx,we run on it all the time, we used to call it our 670, but the name changed recently. Aso, the app/blur is running on autumnnqin's device.

autumnqin commented 6 years ago

I updated /vendor/etc/public.libraries.txt and reboot. It does not work.

I build a debug app/blur exeutable(which run succesfully), the log show it's running on the cdsp

07-05 10:41:55.922  5142  5142 V ./test  : vendor/qcom/proprietary/adsprpc/src/fastrpc_apps_user.c:1267: /dsp/fastrpc_shell_3 load failed 45, searching...
07-05 10:41:55.923  5142  5142 V ./test  : vendor/qcom/proprietary/adsprpc/src/fastrpc_apps_user.c:1375: create user pd with attributes 0 domain 3
07-05 10:41:55.926   819   979 V /vendor/bin/cdsprpcd: vendor/qcom/proprietary/adsprpc/src/sysmon_cdsp_imp.c:45: Got L3 frequency request from CDSP for 556800KHz
07-05 10:41:55.946   819   979 V /vendor/bin/cdsprpcd: vendor/qcom/proprietary/adsprpc/src/sysmon_cdsp_imp.c:45: Got L3 frequency request from CDSP for 0KHz
07-05 10:41:55.951   819   979 V /vendor/bin/cdsprpcd: vendor/qcom/proprietary/adsprpc/src/sysmon_cdsp_imp.c:45: Got L3 frequency request from CDSP for 556800KHz
07-05 10:41:55.985  5142  5142 I halide  :         486583232
07-05 10:41:55.985  5142  5142 I halide  :     allocating module state -> 

Why the same code run on different DSP?

ronlieb commented 6 years ago

I looked through some of my old notes related to running an APK using hexagon. We build a version of libhalide_hexagon_host.so such that it is linked against libcdsprpc.so explicitly, and use that version. I have built an ARM and AARCH64 version of the libhalide_hexagon_host.so file for you t o try. if it works it says there is some issue related to dlopen within an APK that we need to understand.

if you would like to try these libraries, i need to deliver them to you via a Qualcomm service called Me2u which requires me to know your email address.

Please post your email address here, or send it to ronl "@' quicinc.com
thx

autumnqin commented 6 years ago

My email address is: autumnqin@gmail.com

Thank you very much!

ronlieb commented 6 years ago

I delivered the libhalide_hexagon_host.so explicitly linked agains libcdsprpc.so, and this allowed autmnqin to make forward progress.

@dsharletg do you happen to know why we might have issues calling dlopen from libadsprpcshim.cpp when running in an APK ?

dsharletg commented 6 years ago

The only thing I can think of is that libadsprpc.so is on the /vendor/etc/public.libraries.txt whitelist, while libcdsprpc.so is not.