How to run fast inference on the NPU of Qualcomm SoCs using the QNN backend of ailia SDK.
QNN is a backend API provided by Qualcomm, equivalent to NVIDIA's cuDNN. By using the QNN backend of ailia, you can use the NPU on Qualcomm SoCs.
QNN is planned to become available experimentally from ailia SDK 1.7 onwards.
In addition to libailia.so, bundle libailia_qnn.so with your application.
You need to declare the execution permission for libcdsprpc.so in AndroidManifest.xml:
<uses-native-library android:name="libcdsprpc.so" android:required="false"/>
You also need to add the following to build.gradle:
implementation 'com.qualcomm.qti:qnn-runtime:2.47.0'
Once added to build.gradle, QNN is automatically bundled into the apk.
A sample is available in ailia-models-kotlin.
After running pip3 install ailia, download QNN and copy the following files from the zip to site-packages/ailia/windows/arm64, based on the path shown by pip3 show ailia.
qairt\2.47.0.260601\lib\aarch64-windows-msvc (QnnHtp.dll, etc.)qairt\2.47.0.260601\lib\hexagon-v73\unsignedhttps://www.qualcomm.com/developer/software/qualcomm-ai-engine-direct-sdk
hexagon-v* directory must be selected according to the Hexagon architecture of your device. For Snapdragon X Plus, copy hexagon-v73. In addition to the so files, the cat files such as qairt\2.47.0.260601\lib\hexagon-v73\unsigned\libsnpehtpv73.cat must also be copied.
ailia SDK takes ONNX as input, parses the graph, instantiates the layers, and performs inference using QNN in each layer. QNN (Qualcomm AI Engine Direct) offloads processing to the Hexagon NPU via libcdsprpc.so (FastRPC), and computation is executed on the HVX (vector unit) and HMX (matrix unit) inside the NPU. Operators not supported by QNN are executed by ailia_cpu, so the NPU and CPU operate in parallel. Computation is performed in FP16.
The NPU is approximately 5–10x faster than CPU inference. ailia automatically offloads operators not supported by QNN to the CPU.
A demo app for Android can be downloaded from the following link:
https://github.com/ailia-ai/ailia-models-kotlin/wiki/QNN
A demo app for Windows can be downloaded from the following link:
https://github.com/ailia-ai/ailia-models-flutter/wiki/QNN
QNN only supports static graphs. In ailia SDK, if a dynamic graph is provided as input, inference is performed on the CPU.