Skip to content

Qualcomm AI Engine Direct - Adding QNN LPAI island hint via load-time backend options, persistent-binary query, SW6100 registration - #25852

Open
qti-horodnic wants to merge 1 commit into
pytorch:mainfrom
CodeLinaro:horodnic/island_mode01_enable_island_setup
Open

qti-horodnic wants to merge 1 commit into
pytorch:mainfrom
CodeLinaro:horodnic/island_mode01_enable_island_setup

Conversation

@qti-horodnic

@qti-horodnic qti-horodnic commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds the enablement plumbing for LPAI island mode. It does not make execution run in island. It applies the island context config, but LpaiGraph is unchanged: scratch and persistent memory keep their DDR allocation and memory type, and execute still goes through libQnnLpai.so's graphExecute. The device log shows LPI lib not loaded. Using non-island eaih manager with and without the hint. What island execution still needs is listed under "What is still needed" below.

  • A per-session island hint is added as the ExecuTorch load-time backend option qnn_runtime_lpai_enable_island (bool, default off), passed in LoadBackendOptionsMap to load_method and read in init. A missing key means off; a non-bool value fails the load with InvalidArgument. When set, the LPAI context is created with QNN_LPAI_CONTEXT_SET_CFG_ENABLE_ISLAND for all graphs in the context. Before this change the config was applied only on the FastRPC path, where island cannot happen, and never in Direct Mode. It is now applied on both paths, and only when requested. Existing FastRPC users therefore no longer get it by default, which is harmless.

  • The delegate cache key now includes the load-time runtime specs (QnnRuntimeSpecs), so loads of the same .pte with different specs get separate QNN contexts. The follow-up memory-placement option will be added as another field and becomes part of the key automatically.

  • On Hexagon, QNN_CONTEXT_CONFIG_PERSISTENT_BINARY is now set from the QNN_LPAI_BACKEND_GET_PROP_REQUIRE_PERSISTENT_BINARY backend property instead of being hardcoded. The query needs QNN API 2.37 or newer; if it is unavailable or fails, it falls back to "required".

  • LpaiContext::MakeConfig now reserves its config vector before taking pointers into it; without this, emitting a custom config on Hexagon could leave a dangling pointer.

  • SW6100 is registered as an LPAI v6 target.

  • The Direct Mode harness gains a load_with_options IDL entry point with a LOAD_FLAG_* bitmask and a runner flag --lpai_enable_island. The existing load entry point is kept and is equivalent to load_with_options with flags 0.

What is still needed for execution in island (follow-up PRs, see roadmap):

  • island-resident memory types for scratch and persistent buffers,
  • the island library and an island-safe execute path,
  • a static PD.

Suggested review order:

  1. Option plumbing: QnnExecuTorch.h (key), QnnRuntimeSpecs.h (new), QnnExecuTorchBackend.{h,cpp} (spec read and cache key), QnnBackendFactory.{h,cpp}, QnnManager.{h,cpp}, runtime/backends/CMakeLists.txt.
  2. LPAI: QnnContextCommon.h (protected GetImplementation() / GetBackend() accessors), LpaiContextCustomConfig.h, lpai/target/LpaiContextCustomConfig.cpp, LpaiContext.{h,cpp}, plus the backendGetProperty shim in QnnFunctionInterface.h and QnnSdkCompatibility.h.
  3. Direct Mode harness: qnn_executorch.idl, qnn_executorch_imp.cpp, QnnExecuTorchIdlWrapper.{h,cpp}, qnn_executor_direct_runner.cpp.
  4. SW6100 and tests: qc_schema.py, utils.py, test_lpai_soc.py, QnnExecuTorchBackendTest.cpp.

Roadmap (LPAI island mode)

This PR is one step in a series to let the QNN LPAI backend run inference in island mode in Direct Mode (ExecuTorch running on the aDSP):

  • TCM memory support (in internal review): allow LPAI scratch and persistent buffers to be placed in TCM.
  • Platform enablement (this PR): per-session option plumbing and island context config, persistent-binary capability query, SW6100 registration.
  • Memory placement and allocator: select per-session memory placement through load-time runtime specs (extending QnnRuntimeSpecs), so all buffers used during execution can be island-resident.
  • Island-safe execute path: the island library and execute path, island build flags, removing allocations from the execute path, and an island-safe error record in place of ordinary logging. The Direct Mode load entry points will also be consolidated into load_with_options here.
  • Reference entry point: a reference integration showing how an application loads and runs an island-mode session.

Static PD load validation, which real island entry requires, is tracked separately.

Test plan

On SAR2230P with QAIRT 2.52, in a dynamic signed user PD on the aDSP (--domain_id 0), not a static PD:

  • test_qnn_backend_adaptive_avg_pool2d passes on Direct Mode, FastRPC LPAI and HTP.
  • With --lpai_enable_island, FARF confirms the island config is requested and QNN accepts it at context creation. Execution still uses the non-island path (LPI lib not loaded. Using non-island eaih manager), and output is bit-identical with and without the flag.
  • Latency and memory with and without the flag: On SAR2230P with QAIRT 2.52, in a dynamic signed user PD (Direct Mode, --domain_id 0), 100 iterations ×2 per case: outputs are bit-identical. Mean execute is 3.43 ms in both cases. Scratch (50,304 B) and persistent (2,524 B) stay DDR. DSP heap differs by 28 B at load.
  • The persistent-binary query returns 1.
  • test_lpai_soc.py passes on the host.
  • The new IsolatesIslandHintsWithIdenticalSignatures test is in the Buck target qnn_delegate_cache_test and has not been run locally.

The non-bool rejection path and SW6100 hardware are not tested yet.

This PR was authored with AI assistance.

@pytorch-bot

pytorch-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25852

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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 30, 2026
@qti-horodnic

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: qualcomm"

@pytorch-bot pytorch-bot Bot added the release notes: qualcomm Changes to the Qualcomm backend delegate label Nov 30, 2026
@mohankumarkumar

Copy link
Copy Markdown
Contributor

Thanks, a per-load option read in init (no build flag, non-bool rejected) is the right shape, and the cache-key change and the MakeConfig pointe
r fix look good.

My main concern is that, as written, this runs in DRAM. The context gets QNN_LPAI_CONTEXT_SET_CFG_ENABLE_ISLAND, but execute still goes through l\ ibQnnLpai.so's graphExecute, and scratch/persistent keep their DDR allocation and memory type (LpaiGraph is unchanged).

@mohankumarkumar

Copy link
Copy Markdown
Contributor

Please add on-device evidence of what it changes (outputs, memory, latency with and without --lpai_enable_island), and say which PD the runs were in.

… backend options, persistent-binary query, aspen registration
@qti-horodnic

qti-horodnic commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks, a per-load option read in init (no build flag, non-bool rejected) is the right shape, and the cache-key change and the MakeConfig pointe r fix look good.

My main concern is that, as written, this runs in DRAM. The context gets QNN_LPAI_CONTEXT_SET_CFG_ENABLE_ISLAND, but execute still goes through l\ ibQnnLpai.so's graphExecute, and scratch/persistent keep their DDR allocation and memory type (LpaiGraph is unchanged).

Thanks for the review @mohankumarkumar. You're right that as written this won't execute in island, this PR only sets QNN_LPAI_CONTEXT_SET_CFG_ENABLE_ISLAND when the context is created. LpaiGraph is unchanged, so scratch and persistent memory keep their DDR allocation and memory type and execute still goes through libQnnLpai.so's graphExecute; the island library is never loaded. The device log confirms this: LPI lib not loaded. Using non-island eaih manager appears both with and without the hint.

I've updated the description to more accurately reflect the pr's content. It adds the per-load option and its propagation into the cache key, so the follow-up memory-type option can use the same path. It also adds the persistent-binary capability query, the MakeConfig pointer fix, and SW6100 registration. Running in island needs three more pieces, which are listed in the roadmap section of the description: island-resident memory types for scratch and persistent, the island library and execute path, and a static PD. Those will come in follow-up PRs.

If you'd prefer I not merge the option before it has effect on execution, do let me know.

@qti-horodnic

qti-horodnic commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Please add on-device evidence of what it changes (outputs, memory, latency with and without --lpai_enable_island), and say which PD the runs were in.

On-device evidence: SAR2230P, QAIRT 2.52, adaptive_avg_pool2d test model. All runs were in a dynamic signed user PD on the aDSP (Direct Mode, --domain_id 0). Each case ran 100 iterations ×2, interleaved off/on/off/on.

  • Outputs: all 400 outputs are bit-identical with and without --lpai_enable_island.
  • Latency (method execute): without the flag, mean 3.423/3.430 ms, min 3.249/3.260 ms, max 3.469/3.738 ms. With the flag, mean 3.434/3.422 ms, min 3.258/3.261 ms, max 3.720/3.708 ms. No meaningful difference.
  • Memory: scratch is 50,304 B and persistent is 2,524 B, both QNN_LPAI_MEM_TYPE_DDR, in both cases. On the DSP heap, load uses 99,462 B without the flag and 99,490 B with it. Growth during execute is identical (151,512 B).
  • Both cases log LPI lib not loaded. Using non-island eaih manager.

I've also updated the description with these results, for reference.

@qti-horodnic
qti-horodnic force-pushed the horodnic/island_mode01_enable_island_setup branch from db06197 to 53dddcb Compare December 5, 2026 01:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: qualcomm Changes to the Qualcomm backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants