Skip to content

Commit 162b2ea

Browse files
committed
feat: support use libs from local SDK
1 parent 88522ff commit 162b2ea

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,27 @@ Qualcomm lib Genie binding for React Native
88
npm install react-native-qnn-llm
99
```
1010

11-
### Add proguard
11+
### Android Setup
12+
13+
#### Download and setup env
14+
15+
1. Download SDK from [here](https://www.qualcomm.com/developer/software/qualcomm-ai-engine-direct-sdk)
16+
2. Setup env `source path/to/QNN/SDK/bin/envsetup.sh`
17+
18+
#### QNN libs
19+
20+
Add QNN libs dependency into `android/app/build.gradle`
21+
22+
```diff
23+
dependencies {
24+
+ implementation "com.qualcomm.qti:qnn-runtime:latest.integration@aar"
25+
```
26+
27+
Or set `useQnnSdkLib=true` in `android/gradle.properties`
28+
29+
Notes: If you use dependency, the version should match QNN SDK version
30+
31+
#### Proguard
1232

1333
```diff
1434
+ -keep class com.qnnllm.** { *; }

android/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ if (DEFINED ENV{QNN_SDK_ROOT} AND NOT QNN_SDK_ROOT)
88
set(QNN_SDK_ROOT $ENV{QNN_SDK_ROOT})
99
endif()
1010

11+
option(USE_QNN_SDK_LIB "Use QNN SDK Lib" OFF)
12+
1113
include_directories(
1214
${QNN_SDK_ROOT}/include/Genie
1315
${QNN_SDK_ROOT}/include/QNN
@@ -61,6 +63,26 @@ if (CMAKE_ANDROID_ARCH_ABI STREQUAL "arm64-v8a" AND QNN_SDK_ROOT)
6163
${QNN_PLAT_LIB_DIR}/libQnnHtpNetRunExtensions.so
6264
)
6365

66+
if (USE_QNN_SDK_LIB)
67+
file(GLOB QNN_HTP_LIBS
68+
${QNN_PLAT_LIB_DIR}/libQnnSystem.so
69+
${QNN_PLAT_LIB_DIR}/libQnnGpu.so
70+
${QNN_PLAT_LIB_DIR}/libQnnHtp.so
71+
${QNN_PLAT_LIB_DIR}/libQnnHtpPrepare.so
72+
${QNN_PLAT_LIB_DIR}/libQnnHtpV68Stub.so
73+
${QNN_PLAT_LIB_DIR}/libQnnHtpV69Stub.so
74+
${QNN_PLAT_LIB_DIR}/libQnnHtpV73Stub.so
75+
${QNN_PLAT_LIB_DIR}/libQnnHtpV75Stub.so
76+
${QNN_PLAT_LIB_DIR}/libQnnHtpV79Stub.so
77+
${QNN_LIB_DIR}/hexagon-v68/unsigned/libQnnHtpV68Skel.so
78+
${QNN_LIB_DIR}/hexagon-v69/unsigned/libQnnHtpV69Skel.so
79+
${QNN_LIB_DIR}/hexagon-v73/unsigned/libQnnHtpV73Skel.so
80+
${QNN_LIB_DIR}/hexagon-v75/unsigned/libQnnHtpV75Skel.so
81+
${QNN_LIB_DIR}/hexagon-v79/unsigned/libQnnHtpV79Skel.so
82+
)
83+
list(APPEND QNN_LIBS ${QNN_HTP_LIBS})
84+
endif()
85+
6486
# concatenate two lists
6587
list(APPEND QNN_LIBS ${QNN_PLAT_LIBS})
6688

android/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def isNewArchitectureEnabled() {
2323
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
2424
}
2525

26+
def isQnnSdkLibEnabled() {
27+
return rootProject.hasProperty("useQnnSdkLib") && rootProject.getProperty("useQnnSdkLib") == "true"
28+
}
29+
2630
apply plugin: "com.android.library"
2731
apply plugin: "kotlin-android"
2832

@@ -68,6 +72,9 @@ android {
6872
externalNativeBuild {
6973
cmake {
7074
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
75+
if (isQnnSdkLibEnabled()) {
76+
arguments "-DUSE_QNN_SDK_LIB=ON"
77+
}
7178
abiFilters (*reactNativeArchitectures())
7279
}
7380
}

example/android/gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ newArchEnabled=true
3737
# Use this property to enable or disable the Hermes JS engine.
3838
# If set to false, you will be using JSC instead.
3939
hermesEnabled=true
40+
41+
useQnnSdkLib=true

0 commit comments

Comments
 (0)