You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8f50849
Browse filesBrowse the repository at this point in the historyBrowse files
Qualcomm AI Engine Direct - [doc] QNN ExecuTorch on Windows (pytorch#22502)
### Summary
- Add documentation for QNN ExecuTorch on Windows, including build,
test, and inference instructions.
- Add support for the `SC8380XP` SoC model. Refer to the [Supported
Snapdragon
devices](https://docs.qualcomm.com/doc/80-63442-10/topic/QNN_general_overview.html#supported-snapdragon-devices)
for details.
### Test plan
```powershell
python -m examples.qualcomm.scripts.deeplab_v3 --build_folder build-x86_64-windows --soc_model SC8380XP --compile_only --download
```
@@ -36,15 +36,24 @@ Currently, this ExecuTorch Backend can delegate AI computations to Hexagon proce
36
36
37
37
### Host OS
38
38
39
-
The QNN Backend is currently verified on the following Linux host operating systems:
39
+
The QNN Backend is verified on the following host operating systems:
40
40
41
41
-**Ubuntu 22.04 LTS (x64)**
42
42
-**CentOS Stream 9**
43
+
-**Windows 10 / 11 (x64)**
44
+
-**Windows 10 / 11 (ARM64)** with Qualcomm NPU
43
45
-**Windows Subsystem for Linux (WSL)** with Ubuntu 22.04
44
46
45
47
In general, we verify the backend on the same OS versions that the QNN SDK is officially validated against.
46
48
The exact supported versions are documented in the QNN SDK.
47
49
50
+
#### Windows (x64 / ARM64) Setup
51
+
52
+
To build on native Windows platforms, the MSVC toolchain must be installed.
53
+
The required MSVC Build Tools can be installed through **Visual Studio Installer**.
54
+
55
+
For installation instructions, refer to the official [Microsoft Visual Studio Downloads page](https://visualstudio.microsoft.com/downloads/).
56
+
48
57
#### Windows (WSL) Setup
49
58
50
59
To install Ubuntu 22.04 on WSL, run the following command in PowerShell or Windows Terminal:
@@ -55,24 +64,23 @@ wsl --install -d ubuntu 22.04
55
64
56
65
This command will install WSL and set up Ubuntu 22.04 as the default Linux distribution.
57
66
58
-
For more details and troubleshooting, refer to the official Microsoft WSL installation guide:
59
-
👉 [Install WSL | Microsoft Learn](https://learn.microsoft.com/en-us/windows/wsl/install)
67
+
For more details and troubleshooting, refer to the official Microsoft WSL installation guide: [Install WSL | Microsoft Learn](https://learn.microsoft.com/en-us/windows/wsl/install).
60
68
61
69
### Hardware:
62
-
You will need an Android / Linux device with adb-connected running on one of Qualcomm SoCs listed in `QcomChipset`. Please navigate to [qc_schema.py](https://github.com/pytorch/executorch/blob/main/backends/qualcomm/serialization/qc_schema.py).
63
70
64
-
This example is verified with SM8550 and SM8450.
71
+
The QNN backend runs on Qualcomm SoCs (Systems on Chips) across two device families:
72
+
73
+
-**Android / Linux devices** — connected over `adb`. This example is verified with SM8550 and SM8450.
74
+
-**Windows on ARM64 (WoA) devices** — This example is verified with SC8380XP (Qualcomm Snapdragon X Elite).
75
+
76
+
The target SoC must be one of those listed in the `QcomChipset` enum; see [qc_schema.py](https://github.com/pytorch/executorch/blob/main/backends/qualcomm/serialization/qc_schema.py).
65
77
66
78
### Software:
67
79
68
-
- Follow ExecuTorch recommended Python version.
69
-
- A compiler to compile AOT parts, e.g., the GCC compiler comes with Ubuntu LTS. g++ version need to be 13 or higher.
70
-
-[Android NDK](https://developer.android.com/ndk). This example is verified with NDK 26c.
71
-
- (Optional) Target toolchain for linux embedded platform.
72
-
-[Qualcomm AI Engine Direct SDK](https://developer.qualcomm.com/software/qualcomm-ai-engine-direct-sdk)
73
-
- Click the "Get Software" button to download the latest version of the QNN SDK.
74
-
- Although newer versions are available, we have verified and recommend using QNN 2.37.0 for stability.
75
-
- You can download it directly from the following link: [QNN 2.37.0](https://softwarecenter.qualcomm.com/api/download/software/sdks/Qualcomm_AI_Runtime_Community/All/2.37.0.250724/v2.37.0.250724.zip)
80
+
[Qualcomm AI Engine Direct SDK](https://developer.qualcomm.com/software/qualcomm-ai-engine-direct-sdk)
81
+
- Click the "Get Software" button to download the latest version of the QNN SDK.
82
+
- Although newer versions are available, we have verified and recommend using QNN 2.37.0 for stability.
83
+
- You can download it directly from the following link: [QNN 2.37.0](https://softwarecenter.qualcomm.com/api/download/software/sdks/Qualcomm_AI_Runtime_Community/All/2.37.0.250724/v2.37.0.250724.zip)
76
84
77
85
The directory with installed Qualcomm AI Engine Direct SDK looks like:
78
86
```
@@ -94,6 +102,18 @@ The directory with installed Qualcomm AI Engine Direct SDK looks like:
94
102
└── share
95
103
```
96
104
105
+
On Android / Linux devices:
106
+
107
+
- Follow ExecuTorch recommended Python version.
108
+
- A compiler to compile AOT parts, e.g., the GCC compiler comes with Ubuntu LTS. g++ version need to be 13 or higher.
109
+
-[Android NDK](https://developer.android.com/ndk). This example is verified with NDK 26c.
110
+
- (Optional) Target toolchain for linux embedded platform.
111
+
112
+
On Windows on ARM64 (WoA) devices:
113
+
114
+
- Install the **AMD64 version of Python** to run AOT compilation under x64 emulation. This is required because certain Python modules used in the AOT workflow do not currently provide ARM64 prebuilt wheels.
115
+
- MSVC Build Tools.
116
+
97
117
98
118
## Setting up your developer environment
99
119
@@ -106,87 +126,113 @@ i.e., the directory containing `QNN_README.txt`.
106
126
107
127
`$EXECUTORCH_ROOT` refers to the root of executorch git repository.
108
128
109
-
### Setup environment variables
129
+
### Setup QNN SDK paths and environment variables
110
130
111
-
Source the QNN SDK environment setup script to configure paths and environment variables:
131
+
For Linux platform:
112
132
113
133
```bash
114
134
source$QNN_SDK_ROOT/bin/envsetup.sh
115
135
```
116
136
117
137
This sets up `LD_LIBRARY_PATH` and other required variables for the QNN SDK tools and libraries.
118
138
119
-
Additionally, set `PYTHONPATH` for ExecuTorch Python APIs:
An example script for the below building instructions is [here](https://github.com/pytorch/executorch/blob/main/backends/qualcomm/scripts/build.sh).
161
+
**On Linux platform**, an example script for the below building instructions is [`build.sh`](https://github.com/pytorch/executorch/blob/main/backends/qualcomm/scripts/build.sh).
128
162
We recommend to use the script because the ExecuTorch build-command can change from time to time.
129
163
The above script is actively used. It is updated more frequently than this tutorial.
**On Windows platform**, use the PowerShell script [`build.ps1`](https://github.com/pytorch/executorch/blob/main/backends/qualcomm/scripts/build.ps1) for the building instructions. Both Windows x64 and ARM64 architectures are supported.
176
+
Here's the example usage
177
+
```powershell
178
+
cd $env:EXECUTORCH_ROOT
179
+
# Generate both Windows x64 and ARM64 target libraries
> The script supports building both x64 and cross-compiling ARM64 target artifacts on Windows x64 host. After the build completes, the ARM64 libraries and executables can be copied to a Windows on Snapdragon (WoS) device using `scp`.
190
+
> This allows a `.pte` generated on Windows x64 host to be executed on WoS device.
141
191
142
192
## Deploying and running on device
143
193
144
194
### AOT compile a model
145
195
146
196
Refer to [this script](https://github.com/pytorch/executorch/blob/main/examples/qualcomm/scripts/deeplab_v3.py) for the exact flow.
147
-
We use deeplab-v3-resnet101 as an example in this tutorial. Run below commands to compile:
197
+
We use deeplab-v3-resnet101 as an example in this tutorial.
Finish compile_only and save to ./deeplab_v3/dlv3_qnn.pte
213
+
> **Notes**
214
+
>
215
+
> AOT compilation on Windows on ARM64 (WoA) device currently relies on an AMD64 Python environment running under x64 emulation, since some AOT dependencies are not yet distributed as ARM64 prebuilt wheels.
The compiled model is `./deeplab_v3/dlv3_qnn.pte`.
166
229
167
230
Note that the model is compiled for specific backend (e.g., HTP), so you can specify the target backend via `--backend gpu` or `--backend lpai`. If not specified, it will be default to HTP.
168
231
169
232
170
-
### Test model inference on QNN HTP emulator / QNN LPAI emulator
171
-
172
-
We can test model inferences before deploying it to a device by HTP emulator.
I 00:00:00.174364 executorch:qnn_executor_runner.cpp:416] Method loaded.
256
+
E 00:00:00.179250 executorch:method.cpp:1373] Output 0 is memory planned, or is a constant. Cannot override the existing data pointer.
257
+
I 00:00:00.179264 executorch:qnn_executor_runner.cpp:473] ignoring error from set_output_data_ptr(): 0x2
258
+
E 00:00:00.183296 executorch:method.cpp:1373] Output 1 is memory planned, or is a constant. Cannot override the existing data pointer.
259
+
I 00:00:00.183305 executorch:qnn_executor_runner.cpp:473] ignoring error from set_output_data_ptr(): 0x2
260
+
I 00:00:00.183310 executorch:qnn_executor_runner.cpp:479] Inputs prepared.
261
+
I 00:00:00.184008 executorch:qnn_executor_runner.cpp:684] Input list not provided. Inputs prepared with default values set.
262
+
I 00:01:19.663283 executorch:qnn_executor_runner.cpp:695] Model executed successfully.
263
+
I 00:01:19.663299 executorch:qnn_executor_runner.cpp:698] Perform 0 inferences for warming up
264
+
I 00:01:53.881349 executorch:qnn_executor_runner.cpp:715] 1 inferences took 34218.046000 ms, avg 34218.046000 ms
265
+
I 00:01:53.881426 executorch:qnn_executor_runner.cpp:727] Write etdump to etdump.etdp, Size = 576
217
266
[INFO] [Qnn ExecuTorch]: Destroy Qnn context
218
267
[INFO] [Qnn ExecuTorch]: Destroy Qnn device
219
268
[INFO] [Qnn ExecuTorch]: Destroy Qnn backend
220
269
```
221
270
222
-
### Run model inference on an Android smartphone with Qualcomm SoCs
271
+
### Test model inference on Windows x64 host with QNN HTP emulator / QNN LPAI emulator
272
+
273
+
Unlike Linux, which set `LD_LIBRARY_PATH` to access shared libraries, Windows uses the `$env:PATH` environment variable. To enable runtime loading of `qnn_executorch_backend.dll`, ensure that it is discoverable by the Windows DLL loader.
274
+
275
+
This can be achieved by either:
276
+
- Placing `qnn_executorch_backend.dll` in the same directory as `qnn_executor_runner.exe`; or
277
+
- Adding the directory containing `qnn_executorch_backend.dll` to `$env:PATH` environment variable.
@@ -298,6 +372,54 @@ After the above command, pre-processed inputs and outputs are put in `$EXECUTORC
298
372
The command-line arguments are written in [utils.py](https://github.com/pytorch/executorch/blob/main/examples/qualcomm/utils.py#L139).
299
373
The model, inputs, and output location are passed to `qnn_executorch_runner` by `--model_path`, `--input_list_path`, and `--output_folder_path`.
300
374
375
+
### Run model inference on Windows on Snapdragon (WoS) with Qualcomm SoCs
376
+
377
+
Before running inference on Windows on Snapdragon (WoS) with Qualcomm SoCs, ensure that `qnn_executorch_backend.dll` and all required QNN libraries are discoverable by the Windows loader. This can be achieved by either:
378
+
- Copying `qnn_executorch_backend.dll` and the required QNN libraries into the same directory as `qnn_executor_runner.exe`; or
379
+
- Adding the directories containing these libraries to the `$env:PATH` environment variable.
0 commit comments