onnxruntime icon indicating copy to clipboard operation
onnxruntime copied to clipboard

[Mobile] QNN HTP Backend Setup on Android Device

Open DakeQQ opened this issue 1 year ago • 0 comments

Describe the issue

I am trying to run the QNN HTP backend on my Android device, but I repeatedly encounter the following error: [E:onnxruntime:, qnn_execution_provider.cc: 513 GetCapability] QNN SetupBackend failed Failed to create device. Error: 14001 123 Strangely, it works for the QNN CPU backend without any errors. Could someone please provide any advice or suggestions to resolve this issue?

To reproduce

Here is what I have done so far:

  • ONNX Runtime version: 1.18.0

  • QNN SDK: 2.22

  • Android 13

  • Qualcomm 8Gen2, HTP v73

  • Official models:

    • mobilenetv2-12_quant_shape.onnx
    • mobilenetv2-12_net_qnn_ctx.onnx
    • mobilenetv2-12_shape_fp16.onnx
    • mobilenetv2-12_shape.onnx

I pushed the following libraries into the cache folder and also into libs/arm64-v8a:

libQnnHtp.so
libQnnHtpV73Stub.so
libQnnHtpV73Skel.so
libQnnHtpPrepare.so
libqnnhtpv73.cat
libQnnCpu.so
libQnnSystem.so

After pushed, I set the C/C++ code as follows:

option_keys.push_back("backend_path");
option_values.push_back("/data/user/0/com.example.myapplication/cache/libQnnHtp.so");
setenv("LD_LIBRARY_PATH", "/data/user/0/com.example.myapplication/cache", 1);

I also used Java code to load the libraries and set the link path in CMakeLists.txt:

static {
    System.loadLibrary("QnnHtp");
    System.loadLibrary("QnnSystem");
}
add_library(QnnHtp SHARED IMPORTED)
set_target_properties(QnnHtp PROPERTIES IMPORTED_LOCATON ${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/libQnnHtp.so)

add_library(QnnSystem SHARED IMPORTED)
set_target_properties(QnnSystem PROPERTIES IMPORTED_LOCATON ${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/libQnnSystem.so)

Urgency

Looking forward to someone guiding me.

Platform

Android

OS Version

13

ONNX Runtime Installation

Built from Source

Compiler Version (if 'Built from Source')

NDK r26b

Package Name (if 'Released Package')

onnxruntime-android

ONNX Runtime Version or Commit ID

1.18.0 --use_qnn

ONNX Runtime API

C++/C

Architecture

ARM64

Execution Provider

SNPE

Execution Provider Library Version

QNN 2.22

DakeQQ avatar Jun 30 '24 04:06 DakeQQ