Enabling On-host profiling estimation for Executorch QNN HTP - #22143
Enabling On-host profiling estimation for Executorch QNN HTP#22143quic-boyuc wants to merge 8 commits into
Conversation
QNN HTP profiling APIs and artifacts
- Add public HTP profiling helpers for two workflows:
- `generate_htp_profile_result()` for on-device OpTrace profiling.
- `estimate_htp_profile_result()` for host-only Hextimate estimation.
- Return `QnnHtpProfileArtifacts` for each compiled binary in a `.pte`, including QHAS HTML/JSON, Chrome trace JSON, HTP graph JSONs, binary path,
profile mode, and prepare mode.
- Validate Hextimate constraints before running QNN tools:
- requires `online_prepare=True`
- requires supported SoCs: SA8540, SA8255, QCS9100, SA8797
- requires QNN SDK support for Hextimate.
- Validate offline OpTrace `.pte` inputs so missing `profile_level=3` fails early instead of producing unusable profiling output.
Schematic packaging and profile-level support
- Package schematic binaries into the serialized QNN context payload when `profile_level=3` is used.
- Make offline-prepare OpTrace self-contained by carrying the schematic data needed by `qnn-profile-viewer`.
- Preserve online-prepare behavior where QNN tools generate the profiled context and schematic from the `.dlc`.
Example workflows
- Add explicit example scripts for each supported HTP profiling route:
- `htp_profiling_on_device_op_trace_online.py`: on-device OpTrace with `online_prepare=True`.
- `htp_profiling_on_device_op_trace_offline.py`: on-device OpTrace with `online_prepare=False` and `profile_level=3`.
- `htp_profiling_on_host_hextimate.py`: host-only Hextimate with `online_prepare=True`.
- Keep `qairt-visualizer` optional in example scripts:
- open reports automatically when installed
- print `qhas_html` paths when not installed.
Documentation
- Rewrite the HTP profiling README around supported user workflows:
- select `.pte` prepare mode
- run on-device OpTrace generation
- run host-only Hextimate estimation
- inspect `QnnHtpProfileArtifacts`
- view QHAS reports with QAIRT Visualizer.
- Link README quick starts to the renamed example scripts.
- Document Hextimate limitations and supported SoCs.
- Add util script README entries for the three profiling examples.
Tests and verification
- Add a public API test covering unsupported-SoC rejection for Hextimate before reading `.pte` inputs.
- Verify script syntax with:
- `python -m py_compile examples/qualcomm/util_scripts/htp_profiling_on_device_op_trace_online.py
examples/qualcomm/util_scripts/htp_profiling_on_device_op_trace_offline.py examples/qualcomm/util_scripts/htp_profiling_on_host_hextimate.py`
- Verify example scripts with options:
- `python -m examples.qualcomm.util_scripts.htp_profiling_on_device_op_trace_online --host <HOST> --device <DEVICE_SERIAL> --soc_model <SOC_MODEL>
--build_folder build-android --online_prepare -a <ARTIFACT_DIR>`
- `python -m examples.qualcomm.util_scripts.htp_profiling_on_device_op_trace_offline --host <HOST> --device <DEVICE_SERIAL> --soc_model <SOC_MODEL>
--build_folder build-android --profile_level 3 -a <ARTIFACT_DIR>`
- `python -m examples.qualcomm.util_scripts.htp_profiling_on_host_hextimate --soc_model SA8797 --build_folder build-x86 --enable_x86_64
--online_prepare -a <ARTIFACT_DIR>`
- Preserve targeted profiling test commands:
- `python -m backends.qualcomm.tests.test_qnn_delegate TestQNNQuantizedUtils.test_qnn_backend_generate_optrace --host <HOST> --device <DEVICE_SERIAL>
--soc_model <SOC_MODEL> --build_folder build-android`
- `python -m backends.qualcomm.tests.test_qnn_delegate TestQNNFloatingPointUtils.test_qnn_backend_generate_optrace --host <HOST> --device
<DEVICE_SERIAL> --soc_model <SOC_MODEL> --build_folder build-android`
- `python -m backends.qualcomm.tests.test_qnn_delegate TestQNNQuantizedUtils.test_qnn_backend_generate_hextimate --soc_model SA8797 --build_folder
build-x86 --enable_x86_64`
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22143
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@pytorchbot label "release notes: add support for on-host QNN HTP profiling estimation" |
|
Didn't find following labels among repository labels: release notes: add support for on-host QNN HTP profiling estimation |
|
@claude review HTP profiling workflows |
|
Claude finished @psiddh's task in 6m 31s —— View job Review: HTP profiling workflows
Overall this is a solid refactor — two clearly-named entry points, a frozen 🔴 Blocking: three
|
|
@quic-boyuc can you fix the lint errors pls ? |
User description
Summary
Introduce two officially supported HTP profiling workflows — on-device OpTrace and host-only Hextimate — behind a small public Python API returning
QnnHtpProfileArtifacts. Split the demo into three workflow-named example scripts and rewrite the README around the three routes.Motivation
Profiling QNN-delegated
.ptes used to be a single demo with a hidden--online_prepareswitch that silently picked between.dlcvs.bin, host-side vs on-device tools, and set (or didn't set)profile_level=3behind the user's back. This PR replaces that with three named routes, one public API, and a self-contained.pte.What each topic changes
Public HTP profiling API (
backends/qualcomm/debugger/utils.py)Two workflow-specific entry points instead of one mode-flag function. Each returns a
QnnHtpProfileArtifactsper compiled binary in the.pte, carryingbinary_path,profile_mode,prepare_mode,qhas_html,qhas_json,chrometrace_json, and HTP graph JSONs.generate_htp_profile_result()— on-device OpTrace (both prepare modes)..pte's compile spec and rejecting anything withoutprofile_level=3at the Python boundary, rather than producing an unusable output later.profile_levelis required — the QNN CLI attaches instrumentation at host-side context-binary-generation time.estimate_htp_profile_result()— host-only Hextimate.online_prepare=True(Hextimate requires a.dlc, not a.bin).SA8540,SA8255,QCS9100,SA8797) before touching QNN tools, so misuse fails fast with a legible error.Compile-spec plumbing (
backends/qualcomm/serialization/qc_compiler_spec.fbs,qc_schema.py,utils/utils.py)SA8540 = 62toQcomChipsetand the host-sideget_soc_to_chipset_map(). The other three Hextimate-supported SoCs (SA8255,QCS9100,SA8797) already existed.62matches the QNN SDK's internal SoC ID for SA8540 — the enum wire values are load-bearing, so the addition is at a specific numeric slot, not the tail of the enum.Example scripts (
examples/qualcomm/util_scripts/)One script per route, with the route encoded in the filename so a reader picks the right file without reading code:
htp_profiling_on_device_op_trace_online.py— on-device OpTrace,online_prepare=True,.dlcpath.qnn_config.online_prepareat entry.profile_levelhandling — QNN CLI attaches instrumentation host-side.htp_profiling_on_device_op_trace_offline.py— on-device OpTrace,online_prepare=False+profile_level=3,.binpath.qnn_config.profile_level == 3 and not qnn_config.online_prepareat entry.htp_profiling_on_host_hextimate.py— host-only Hextimate (renamed from the old merged demo, not net-new).--enable_x86_64; no adb involved.qairt-visualizeris optional in all three scripts:qhas_htmlpaths are printed to stdout so users can view them however they want.Design rationale: three short files (~90 lines each) beat one file with
if args.mode == "..."branches. The old merged demo had a bug where--profile_level 3was passed under--online_prepareeven though online-prepare doesn't need it — the kind of bug you get when one file quietly handles multiple pipelines. Naming a file after its pipeline eliminates the class.Documentation (
backends/qualcomm/debugger/README.md+examples/qualcomm/util_scripts/README.md).pteprepare mode (decision table: online-prepare needs Hextimate/graph view; offline-prepare when you already have aprofile_level=3.pte).QnnHtpProfileArtifacts.examples/qualcomm/util_scripts/README.mdindexes each of the three profiling example scripts by filename.Tests (
backends/qualcomm/tests/test_qnn_delegate.py).pteinputs — this is a defensive-order check (validate first, then touch inputs), not just an error-message check. Catches regressions where validation gets reordered behind expensive.pteparsing.test_qnn_backend_generate_optracerefactored in bothTestQNNFloatingPointUtilsandTestQNNQuantizedUtils:profile_level=3).QnnHtpProfileArtifactsreturn shape (.qhas_json,.chrometrace_json).enable_x86_64(OpTrace requires on-device execution) or LPAI backend (unsupported).test_qnn_backend_generate_hextimaterefactored inTestQNNQuantizedUtils:not enable_x86_64(Hextimate is host-only; needs--enable_x86_64).qhas_json is None— Hextimate QHAS JSON is truncated by an upstream SDK bug (division by zero ontime_us=0); we surface this by returningNonefrom the API rather than papering over it. The HTML report and chrometrace remain usable.enable_x86_64skips), Hextimate ⇒ host-only (not enable_x86_64skips). Users run them in two separate test invocations with different--build_folder/--enable_x86_64combinations.Verification
Script syntax
End-to-end example scripts (three routes, matched flags)
Targeted profiling tests (existing framework, no CLI shape change)