
Where the QNN TFLite delegate fits in the Qualcomm AI Engine Direct stack
What you’ll build
An Android app that:- Runs an Edge Impulse object detection model on frames from the Camera2 API
- Runs inference on the Hexagon NPU (HTP) through the QNN delegate
- Draws bounding boxes over the camera preview
- Logs timing for each stage to Logcat
Performance
The app logs the DSP and inference time for each frame to Logcat, so you can compare runs with and without the delegate on your own device and model:- Before (CPU only)
- After (QNN delegate)

Logcat timing without QNN acceleration
Prerequisites
- A trained Edge Impulse object detection model
- Android Studio Ladybug 2024.2.2 or later, with Android API 35, NDK 27.0.12077973, and CMake 3.22.1
- The Qualcomm AI Engine Direct SDK
- A Snapdragon device with a Hexagon NPU, or access to one through Qualcomm Device Cloud
Supported devices
QNN acceleration needs a Qualcomm Hexagon NPU Gen 2 or later:
Example Snapdragon reference device used for testing
1. Clone the repository
2. Find the QNN delegate in the SDK
Install the Qualcomm AI Engine Direct SDK. It’s usually installed in one of these locations:libQnnTFLiteDelegate.so. On macOS or Linux:
C:\qairt\<version>\ in File Explorer and search for libQnnTFLiteDelegate.so.
The folder that contains it also holds the other libQnn*.so runtime libraries. You copy from this folder in the next step.
3. Copy the QNN libraries
Create the destination folder:app/src/main/jniLibs/arm64-v8a/:
Automated script (experimental)
Automated script (experimental)
The repository includes a script that copies the libraries. Set your QAIRT SDK path in the script first, then run it:
4. Deploy your model
- In Edge Impulse Studio, go to Deployment.
- Select Android (C++ library).
- Select the Quantized (int8) model.
- Click Build and download the
.zipfile.
5. Configure the Android manifest
Inapp/src/main/AndroidManifest.xml, set extractNativeLibs and declare libcdsprpc.so so the app can load the QNN libraries:
6. Build and run
- Connect your Snapdragon device over USB and enable USB debugging in Developer options.
- In Android Studio, click Run and select your device.
MainActivity to see the timing for each stage:
How it works
Load the QNN delegate
native-lib.cpp sets the library search paths, then loads the QNN TFLite delegate with the HTP backend:
Set the environment
MainActivity.kt points the library paths at the app’s native library folder on startup:
Project structure
Customization
Change the HTP performance mode
Sethtp_performance_mode in the QNN options in native-lib.cpp:
Enable profiling
Setprofiling_level to write a profile to /sdcard/qnn_profile.json:
Change the detection threshold
A higher threshold gives fewer false positives. A lower one gives more detections:Performance tuning
Model
- Use INT8 quantization. HTP acceleration requires it.
- Reduce the input resolution. A 320×320 input has a quarter of the pixels of a 640×640 input.
- Use fewer layers, and check which operations run on the HTP and which fall back to the CPU. See the QNN operator support list.
Runtime
Frame rate
If processing can’t keep up with the camera, lower the camera frame rate:Next steps
- Run your model on Qualcomm Device Cloud without your own hardware
- Build a speech-to-image app with QNN
- Android series overview
