Skip to content

Commit e46f2d1

Browse files
[QNN EP Docs] Update docs for building QNN EP as shared or static library (#23873)
### Description Updates the QNN EP documentation to include instructions for building the QNN EP as a shared or static library. Can view a preview of changes here: - https://adrianlizarraga.github.io/onnxruntime/docs/build/eps.html#qnn - https://adrianlizarraga.github.io/onnxruntime/docs/build/android.html#build-instructions-1 ### Motivation and Context The following PR made QNN EP a shared library by default: #23120. We need to update documentation to include instructions for building QNN EP as a shared or static library.
1 parent 8519974 commit e46f2d1

File tree

2 files changed

+67
-13
lines changed

2 files changed

+67
-13
lines changed

docs/build/android.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ If your device has a supported Qualcomm Snapdragon SOC, and you want to use QNN
146146
### Build Instructions
147147
148148
Download and install [Qualcomm AI Engine Direct SDK](https://qpm.qualcomm.com/main/tools/details/qualcomm_ai_engine_direct)
149-
QNN Execution Provider can be built using building commands in [Android Build instructions](#android-build-instructions) with `--use_qnn --qnn_home [QNN_SDK path]`
149+
QNN Execution Provider can be built using building commands in [Android Build instructions](#android-build-instructions) with `--use_qnn static_lib --qnn_home [QNN_SDK path]`
150150
151151
## Test Android changes using emulator (not applicable for QNN Execution Provider)
152152

docs/build/eps.md

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ redirect_from: /docs/how-to/build/eps
1717

1818
## Execution Provider Shared Libraries
1919

20-
The oneDNN, TensorRT, OpenVINO™, and CANN providers are built as shared libraries vs being statically linked into the main onnxruntime. This enables them to be loaded only when needed, and if the dependent libraries of the provider are not installed onnxruntime will still run fine, it just will not be able to use that provider. For non shared library providers, all dependencies of the provider must exist to load onnxruntime.
20+
The oneDNN, TensorRT, OpenVINO™, CANN, and QNN providers are built as shared libraries vs being statically linked into the main onnxruntime. This enables them to be loaded only when needed, and if the dependent libraries of the provider are not installed onnxruntime will still run fine, it just will not be able to use that provider. For non shared library providers, all dependencies of the provider must exist to load onnxruntime.
2121

2222
### Built files
2323
{: .no_toc }
@@ -356,34 +356,88 @@ See more information on the QNN execution provider [here](../execution-providers
356356
357357
### Prerequisites
358358
{: .no_toc }
359-
* Qualcomm AI Engine Direct SDK (Qualcomm Neural Network SDK) [Linux/Android/Windows](https://qpm.qualcomm.com/main/tools/details/qualcomm_ai_engine_direct)
359+
* Install the Qualcomm AI Engine Direct SDK (Qualcomm Neural Network SDK) [Linux/Android/Windows](https://qpm.qualcomm.com/main/tools/details/qualcomm_ai_engine_direct)
360+
361+
* Install [cmake-3.28](https://cmake.org/download/) or higher.
362+
363+
* Install Python 3.10 or higher.
364+
* [Python 3.12 for Windows Arm64](https://www.python.org/ftp/python/3.12.9/python-3.12.9-arm64.exe)
365+
* [Python 3.12 for Windows x86-64](https://www.python.org/ftp/python/3.12.9/python-3.12.9-amd64.exe)
366+
* Note: Windows on Arm supports a x86-64 Python environment via emulation. Ensure that the Arm64 Python environment is actived for a native Arm64 ONNX Runtime build.
367+
368+
* Checkout the source tree:
369+
370+
```bash
371+
git clone --recursive https://github.com/Microsoft/onnxruntime.git
372+
cd onnxruntime
373+
```
374+
375+
* Install ONNX Runtime Python dependencies.
376+
```bash
377+
pip install -r requirements.txt
378+
```
379+
380+
### Build Options
381+
{: .no_toc }
382+
383+
* `--use_qnn [QNN_LIBRARY_KIND]`: Builds the QNN Execution provider. `QNN_LIBRARY_KIND` is optional and specifies whether to build the QNN Execution Provider as a shared library (default) or static library.
384+
* `--use_qnn` or `--use_qnn shared_lib`: Builds the QNN Execution Provider as a shared library.
385+
* `--use_qnn static_lib`: Builds QNN Execution Provider as a static library linked into ONNX Runtime. This is required for Android builds.
386+
* `--qnn_home QNN_SDK_PATH`: The path to the Qualcomm AI Engine Direct SDK.
387+
* Example on Windows: `--qnn_home 'C:\Qualcomm\AIStack\QAIRT\2.31.0.250130'`
388+
* Example on Linux: `--qnn_home /opt/qcom/aistack/qairt/2.31.0.250130`
389+
* `--build_wheel`: Enables Python bindings and builds Python wheel.
390+
* `--arm64`: Cross-compile for Arm64.
391+
* `--arm64ec`: Cross-compile for Arm64EC. Arm64EC code runs with native performance and is interoperable with x64 code running under emulation within the same process on a Windows on Arm device. Refer to the [Arm64EC Overview](https://learn.microsoft.com/en-us/windows/arm/arm64ec).
392+
393+
Run `python tools/ci_build/build.py --help` for a description of all available build options.
360394
361395
### Build Instructions
362396
{: .no_toc }
363397
364-
#### Windows (arm64 native build)
398+
#### Windows (native x86-64 or native Arm64)
399+
```
400+
.\build.bat --use_qnn --qnn_home [QNN_SDK_PATH] --build_shared_lib --build_wheel --cmake_generator "Visual Studio 17 2022" --config Release --parallel --skip_tests --build_dir build\Windows
401+
```
402+
403+
Notes:
404+
* Not all Qualcomm backends (e.g., HTP) are supported for model execution on a native x86-64 build. Refer to the [Qualcomm SDK backend documentation](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/backend.html) for more information.
405+
* Even if a Qualcomm backend does not support execution on x86-64, the QNN Execution provider may be able to [generate compiled models](../execution-providers/QNN-ExecutionProvider.md#qnn-context-binary-cache-feature) for the Qualcomm backend.
406+
407+
#### Windows (Arm64 cross-compile target)
408+
```
409+
.\build.bat --arm64 --use_qnn --qnn_home [QNN_SDK_PATH] --build_shared_lib --build_wheel --cmake_generator "Visual Studio 17 2022" --config Release --parallel --build_dir build\Windows
410+
```
411+
412+
#### Windows (Arm64EC cross-compile target)
365413
```
366-
build.bat --arm64 --use_qnn --qnn_home=[QNN_SDK path] --build_shared_lib --cmake_generator "Visual Studio 17 2022" --skip_submodule_sync --config Release --build_dir \build\Windows
414+
.\build.bat --arm64ec --use_qnn --qnn_home [QNN_SDK_PATH] --build_shared_lib --build_wheel --cmake_generator "Visual Studio 17 2022" --config Release --parallel --build_dir build\Windows
367415
```
368416
369-
build python bindings
417+
#### Windows (Arm64X cross-compile target)
418+
Use the `build_arm64x.bat` script to build Arm64X binaries. Arm64X binaries bundle both Arm64 and Arm64EC code, making Arm64X compatible with both Arm64 and Arm64EC processes on a Windows on Arm device. Refer to the [Arm64X PE files overview](https://learn.microsoft.com/en-us/windows/arm/arm64x-pe).
419+
370420
```
371-
build.bat --arm64 --use_qnn --qnn_home=[QNN_SDK path] --build_wheel --cmake_generator "Visual Studio 17 2022" --skip_submodule_sync --config Release --build_dir \build\Windows
421+
.\build_arm64x.bat --use_qnn --qnn_home [QNN_SDK_PATH] --build_shared_lib --cmake_generator "Visual Studio 17 2022" --config Release --parallel
372422
```
373-
#### Linux (x64)
423+
Notes:
424+
* Do not specify a `--build_dir` option because `build_arm64x.bat` sets specific build directories.
425+
* The above command places Arm64X binaries in the `.\build\arm64ec-x\Release\Release\` directory.
426+
427+
#### Linux (x86_64)
374428
```
375-
build.py --use_qnn --qnn_home=[QNN_SDK path] --build_shared_lib --skip_submodule_sync --config Release
429+
./build.sh --use_qnn --qnn_home [QNN_SDK_PATH] --build_shared_lib --build_wheel --config Release --parallel --skip_tests --build_dir build/Linux
376430
```
377-
#### Android (Cross-Compile):
431+
432+
#### Android (cross-compile):
378433
379434
Please reference [Build OnnxRuntime For Android](android.md)
380435
```
381436
# on Windows
382-
build.bat --build_shared_lib --skip_submodule_sync --android --config Release --use_qnn --qnn_home [QNN_SDK path] --android_sdk_path [android_SDK path] --android_ndk_path [android_NDK path] --android_abi arm64-v8a --android_api [api-version] --cmake_generator Ninja --build_dir build\Android
437+
.\build.bat --build_shared_lib --android --config Release --parallel --use_qnn static_lib --qnn_home [QNN_SDK_PATH] --android_sdk_path [android_SDK path] --android_ndk_path [android_NDK path] --android_abi arm64-v8a --android_api [api-version] --cmake_generator Ninja --build_dir build\Android
383438
384439
# on Linux
385-
build.sh --build_shared_lib --skip_submodule_sync --android --config Release --use_qnn --qnn_home [QNN_SDK path] --android_sdk_path [android_SDK path] --android_ndk_path [android_NDK path] --android_abi arm64-v8a --android_api [api-version] --cmake_generator Ninja --build_dir build/Android
386-
440+
./build.sh --build_shared_lib --android --config Release --parallel --use_qnn static_lib --qnn_home [QNN_SDK_PATH] --android_sdk_path [android_SDK path] --android_ndk_path [android_NDK path] --android_abi arm64-v8a --android_api [api-version] --cmake_generator Ninja --build_dir build/Android
387441
```
388442
389443
---

0 commit comments

Comments
 (0)