Commit 4ef0d67
Fixes #445 — `winml perf --monitor --device gpu` now shows GPU
utilization instead of silently falling back to NPU.
## Summary
- **Adapter routing.** `PdhPoller` / `HWMonitor` now accept `device=`
(`npu` | `gpu` | `cpu` | `auto`) and `ep_name=`. Per-device queries go
through `build_npu_query` (Compute engine) or `build_gpu_query` (3D
engine).
- **ORT-first LUID resolution.** Added
`resolve_adapter_luid(device_kind, ep_name=None)` in
`sysinfo/pdh_adapters.py`. It walks `ort.get_ep_devices()`, filters by
EP name + device type, reads `OrtHardwareDevice.metadata["LUID"]`, and
converts the decimal LUID to the PDH `0xHHHHHHHH_0xHHHHHHHH` form via
`(v >> 32, v & 0xFFFFFFFF)`. ORT-resolved LUIDs are sanity-checked
against `enumerate_adapters()` — if PDH doesn't enumerate the LUID (some
drivers register the adapter only for autoEP), we skip it and fall
through to the PDH-fingerprint helpers (`discover_npu_luid`,
`discover_gpu_luid`) instead of raising later in `build_adapter_query`.
Same fallback applies when ORT isn't installed, when `get_ep_devices()`
raises, when no matching ep_device exists, when LUID metadata is
missing, or when an individual ep_device entry is malformed (each is
wrapped in `try/except` so one bad entry can't break resolution).
- **Graceful build-query degradation.** `PdhPoller.start()` wraps
`build_npu_query` / `build_gpu_query` in a local `try/except
ValueError`. If a resolved LUID still proves unusable, it clears
`device_kind` / `adapter_luid` and degrades to CPU/RAM-only — CPU/RAM
counters still register and the benchmark continues.
- **`perf.py` plumbing.** `_run_benchmark_monitored` (HF),
`_run_onnx_benchmark` (ONNX direct), and `_perf_modules` (per-module)
all pass the resolved device + normalized EP name into `HWMonitor`.
`--monitor` help text updated to *"Show live hardware utilization chart
for the benchmarked device (NPU, GPU, or CPU)"*.
- **`HWMonitor.to_dict()` schema.** Always emits an `npu` block (zeros
when monitoring GPU — back-compat with existing consumers/tests). When
`device_kind == "gpu"` a parallel `gpu` block is added. New top-level
keys `device_kind` and `adapter_luid`.
- **Live chart labels follow what's actually polled.** Centralised
`adapter_label(device_kind)` helper in `hw_monitor.py`.
`LiveMonitorDisplay` accepts `device_kind=` (threaded through from
`_run_monitored_loop` as `hw.device_kind`); `HWLiveDisplay` derives the
label dynamically from `self._hw.device_kind`. So `auto` resolving to
GPU now labels "GPU", and CPU-only mode no longer falsely says "NPU".
- **CPU-only display drops the adapter row entirely.** When no adapter
is polled (`--device cpu` or `auto` resolving to nothing),
`LiveMonitorDisplay` / `HWLiveDisplay` skip the green plot, drop the
swatch from the chart legend, and collapse the status row to `CPU: ... |
Sys Mem: ...` (no adapter cell, no Device Mem cell). The post-benchmark
`display_console_report` in `perf.py` likewise prints CPU/RAM only — no
zeroed `NPU: 0.0% avg, 0.0% peak`.
## Verification
- Targeted suite: `tests/unit/session/test_ep_monitor.py` (84 passed,
+15 new) plus `test_perf_cli.py` and `test_perf_module.py` (26 passed).
- Full unit suite green: 4665 passed, 73 skipped, 2 xfailed.
- `ruff check` clean on every modified file.
- Smoke-checked on a Snapdragon X laptop after
`winml.register_execution_providers(ort=True)`:
```
GPU (no ep_name) -> 0x00000000_0x000121CF # Adreno X1-85 via DML and QNN
GPU (ep=DML) -> 0x00000000_0x000121CF
GPU (ep=QNN) -> 0x00000000_0x000121CF
NPU (ep=QNN) -> 0x00000000_0x00012C89 # authoritative, not just
fingerprinted
NPU (no ep_name) -> 0x00000000_0x00012C89
```
---------
Co-authored-by: hualxie <hualxie@microsoft.com>
1 parent 8aceb27 commit 4ef0d67
8 files changed
Lines changed: 1150 additions & 143 deletions
File tree
- src/winml/modelkit
- commands
- session/monitor
- sysinfo
- tests
- e2e
- unit/session
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| 43 | + | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
46 | 61 | | |
47 | 62 | | |
48 | 63 | | |
| |||
111 | 126 | | |
112 | 127 | | |
113 | 128 | | |
114 | | - | |
| 129 | + | |
115 | 130 | | |
116 | 131 | | |
117 | 132 | | |
| 133 | + | |
| 134 | + | |
118 | 135 | | |
119 | 136 | | |
120 | 137 | | |
121 | 138 | | |
122 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
123 | 148 | | |
124 | 149 | | |
125 | 150 | | |
126 | 151 | | |
127 | | - | |
128 | | - | |
| 152 | + | |
| 153 | + | |
129 | 154 | | |
130 | 155 | | |
131 | 156 | | |
| |||
134 | 159 | | |
135 | 160 | | |
136 | 161 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
145 | 170 | | |
146 | | - | |
| 171 | + | |
147 | 172 | | |
| 173 | + | |
148 | 174 | | |
149 | 175 | | |
150 | | - | |
151 | 176 | | |
152 | 177 | | |
153 | 178 | | |
| |||
162 | 187 | | |
163 | 188 | | |
164 | 189 | | |
165 | | - | |
166 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
167 | 194 | | |
168 | 195 | | |
169 | 196 | | |
| |||
174 | 201 | | |
175 | 202 | | |
176 | 203 | | |
177 | | - | |
178 | | - | |
| 204 | + | |
| 205 | + | |
179 | 206 | | |
180 | | - | |
| 207 | + | |
| 208 | + | |
181 | 209 | | |
| 210 | + | |
| 211 | + | |
182 | 212 | | |
183 | | - | |
| 213 | + | |
184 | 214 | | |
185 | 215 | | |
186 | 216 | | |
| |||
219 | 249 | | |
220 | 250 | | |
221 | 251 | | |
222 | | - | |
223 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
224 | 255 | | |
225 | 256 | | |
226 | | - | |
227 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
228 | 263 | | |
229 | 264 | | |
230 | 265 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
407 | 419 | | |
408 | 420 | | |
409 | 421 | | |
| |||
428 | 440 | | |
429 | 441 | | |
430 | 442 | | |
431 | | - | |
| 443 | + | |
432 | 444 | | |
433 | 445 | | |
434 | 446 | | |
| |||
624 | 636 | | |
625 | 637 | | |
626 | 638 | | |
| 639 | + | |
627 | 640 | | |
628 | 641 | | |
629 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
630 | 647 | | |
631 | 648 | | |
632 | 649 | | |
| |||
778 | 795 | | |
779 | 796 | | |
780 | 797 | | |
781 | | - | |
782 | 798 | | |
783 | 799 | | |
784 | 800 | | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
795 | 820 | | |
796 | 821 | | |
797 | 822 | | |
| |||
884 | 909 | | |
885 | 910 | | |
886 | 911 | | |
| 912 | + | |
887 | 913 | | |
888 | 914 | | |
889 | 915 | | |
| |||
959 | 985 | | |
960 | 986 | | |
961 | 987 | | |
| 988 | + | |
962 | 989 | | |
963 | 990 | | |
964 | | - | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
965 | 996 | | |
966 | 997 | | |
967 | 998 | | |
| |||
1132 | 1163 | | |
1133 | 1164 | | |
1134 | 1165 | | |
1135 | | - | |
| 1166 | + | |
1136 | 1167 | | |
1137 | 1168 | | |
1138 | 1169 | | |
| |||
0 commit comments