Skip to main content
Enable hardware acceleration for Edge Impulse models on Android using the Qualcomm AI Engine Direct (QNN) TFLite Delegate. This tutorial demonstrates object detection with real-time performance improvements on Snapdragon devices.
This tutorial builds on the Camera Inference tutorial. You’ll add QNN hardware acceleration to leverage Qualcomm’s Hexagon NPU for significantly faster inference.
Reference code: https://github.com/edgeimpulse/qnn-hardware-acceleration

Where the QNN TFLite delegate fits in the Qualcomm AI Engine Direct stack

What you’ll build

An Android application that:
  • Runs Edge Impulse object detection models with Camera2 API
  • Accelerates inference using Qualcomm’s HTP/DSP via QNN delegate
  • Displays real-time bounding boxes with overlay
  • Logs detailed performance metrics to Logcat

Performance expectations

Results from YOLOv5 small (480×480 quantized) on Qualcomm RB3 Gen 2 (6490): Conservative gains:

Logcat timing without QNN acceleration

  • Inference: 5,748 → 527 µs ≈ 10.9× faster
  • DSP stage: 5,640 → 3,748 µs ≈ 1.5× faster
  • Smoother frame times with dedicated accelerator
  • Lower power consumption
INT8 quantized is required for HTP acceleration.Performance varies by device SoC, model architecture, and quantization. Optimizing your model for available QNN operations increases speedup dramatically.

Prerequisites

  • Edge Impulse account: Sign up
  • Trained object detection model
  • Android Studio: Ladybug 2024.2.2 or later
  • Snapdragon device real or Qualcomm Device Cloud with Hexagon NPU:
    • Snapdragon 8 Gen 1/2/3 (mobile)
    • Snapdragon 6/7 series (mid-range)
    • QRB series (embedded: RB3, RB5, Dragonwing)
  • Qualcomm AI Engine Direct SDK: Download from Qualcomm
  • Tools: Android API 35, NDK 27.0.12077973, CMake 3.22.1

Supported devices

Devices with Qualcomm Hexagon NPU Gen 2 or later: Mobile:

Example Snapdragon reference device used for testing

  • Snapdragon 8 Gen 3/2/1
  • Snapdragon 7+ Gen 2/3
  • Snapdragon 6 Gen 1
Embedded:
  • QRB6490 (Rubik Pi 3)
  • QRB5165 (RB5)
  • Dragonwing platforms
Test on Device Cloud:
Don’t have hardware? Try the Qualcomm Device Cloud with pre-configured Snapdragon devices.

1. Clone the repository

Open in Android Studio and let Gradle/NDK sync.

2. Locate Qualcomm AI Engine Direct SDK

Download and install the Qualcomm AI Engine Direct SDK. Common installation paths:
You’re looking for the folder containing libQnnTFLiteDelegate.so for Android arm64.

Find the delegate directory

macOS/Linux:
Windows: Open File Explorer at C:\qairt\<version>\ and search for libQnnTFLiteDelegate.so. The parent folder of that file is your source directory (it also contains other libQnn*.so runtime libs).

3. Copy QNN libraries

Create the destination directory in your project:
Copy the required libraries from the delegate directory you found: Required libraries:
Optional:
The repository includes a fetch script:
You’ll need to configure the script with your QAIRT SDK path first.

4. Deploy your model

In Edge Impulse Studio:
  1. Go to Deployment
  2. Select Android (C++ library)
  3. Enable Quantized (int8) for best QNN performance
  4. Click Build
  5. Download the .zip
Extract into your project:

5. Configure Android manifest

Update app/src/main/AndroidManifest.xml:
This ensures QNN libraries are extracted and accessible.

6. Build and run

Build in Android Studio

  1. Connect your Snapdragon device via USB
  2. Enable USB debugging in Developer Options
  3. Click Run (green play button)
  4. Select your device

Monitor performance

Open Logcat and filter by MainActivity:
Expected output:

Verify QNN acceleration

Check if QNN libraries are loaded:
If you see QNN library paths, acceleration is active.

How it works

QNN TFLite delegate integration

Environment configuration

The app automatically sets required environment variables on startup:

Project structure

Customization

Adjust HTP performance mode

In native-lib.cpp, modify QNN options:
Modes:
  • burst: Maximum speed, higher power (default)
  • high_performance: Sustained high performance
  • balanced: Balance between speed and power
  • low_power: Minimize power consumption

Enable profiling

Profile output saved to /sdcard/qnn_profile.json.

Optimize model for QNN

In Edge Impulse Studio:
  1. Use quantization: INT8 models leverage HTP better than FP32
  2. Supported operations: Check QNN operator support
  3. Enable EON Compiler: Optimizes for Qualcomm hardware

Change detection threshold

Performance tuning tips

Model optimization

  1. Use INT8 quantization - Essential for HTP acceleration
  2. Reduce input resolution - 320×320 vs 640×640 can be 4× faster
  3. Simplify architecture - Fewer layers = better HTP utilization
  4. Test operator coverage - Check which ops run on HTP vs CPU

Runtime optimization

Frame rate optimization

Benchmark results

Real-world performance on different devices:
Google Tensor processors don’t include Hexagon NPU. QNN acceleration only works on Qualcomm Snapdragon devices.

Next steps

Qualcomm Device Cloud

Test without hardware

Resources