Skip to content

[QNN EP] Enable automatic selection of QNN EP for PREFER_NPU policy - #24629

Merged
Adrian Lizarraga (adrianlizarraga) merged 2 commits into
mainfrom
adrianl/qnn-support-autoep
May 4, 2025
Merged

Adrian Lizarraga (adrianlizarraga) merged 2 commits into
mainfrom
adrianl/qnn-support-autoep

Conversation

@adrianlizarraga

@adrianlizarraga Adrian Lizarraga (adrianlizarraga) commented May 3, 2025 •

Copy link
Copy Markdown
Contributor

Description

  • Enables automatic selection of QNN EP for PREFER_NPU policy
  • Fixes cpuid vendor id for Qualcomm to be 'Q' | ('C' << 8) | ('O' << 16) | ('M' << 24);

Sample code from unit test:

// Tests autoEP feature to automatically select an EP that supports the NPU.
// Currently only works on Windows.
TEST_F(QnnHTPBackendTests, AutoEp_PreferNpu) {
  ASSERT_ORTSTATUS_OK(Ort::GetApi().RegisterExecutionProviderLibrary(*ort_env, kQnnExecutionProvider,
                                                                     ORT_TSTR("onnxruntime_providers_qnn.dll")));

  Ort::SessionOptions so;
  so.SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy_PREFER_NPU);

  const ORTCHAR_T* ort_model_path = ORT_MODEL_FOLDER "nhwc_resize_sizes_opset18.quant.onnx";
  Ort::Session session(*ort_env, ort_model_path, so);
  EXPECT_TRUE(SessionHasEp(session, kQnnExecutionProvider));

  ASSERT_ORTSTATUS_OK(Ort::GetApi().UnregisterExecutionProviderLibrary(*ort_env, kQnnExecutionProvider));
}

Motivation and Context

A recent feature allows ORT to automatically select an EP according to policies set by the user (e.g., prefer npu or prefer gpu). This PR allows QNN EP to be potentially selected when the user sets the PREFER_NPU policy.

Comment thread onnxruntime/core/providers/qnn/qnn_provider_factory.cc
Comment thread onnxruntime/core/providers/qnn/qnn_provider_factory.cc Outdated
@adrianlizarraga
Adrian Lizarraga (adrianlizarraga) deleted the adrianl/qnn-support-autoep branch May 4, 2025 07:57
Adrian Lizarraga (adrianlizarraga) added a commit that referenced this pull request May 4, 2025
…24629)

### Description
- Enables automatic selection of QNN EP for PREFER_NPU policy
- Fixes cpuid vendor id for Qualcomm to be `'Q' | ('C' << 8) | ('O' <<
16) | ('M' << 24);`

Sample code from unit test:
```c++
// Tests autoEP feature to automatically select an EP that supports the NPU.
// Currently only works on Windows.
TEST_F(QnnHTPBackendTests, AutoEp_PreferNpu) {
  ASSERT_ORTSTATUS_OK(Ort::GetApi().RegisterExecutionProviderLibrary(*ort_env, kQnnExecutionProvider,
                                                                     ORT_TSTR("onnxruntime_providers_qnn.dll")));

  Ort::SessionOptions so;
  so.SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy_PREFER_NPU);

  const ORTCHAR_T* ort_model_path = ORT_MODEL_FOLDER "nhwc_resize_sizes_opset18.quant.onnx";
  Ort::Session session(*ort_env, ort_model_path, so);
  EXPECT_TRUE(SessionHasEp(session, kQnnExecutionProvider));

  ASSERT_ORTSTATUS_OK(Ort::GetApi().UnregisterExecutionProviderLibrary(*ort_env, kQnnExecutionProvider));
}
```

### Motivation and Context
A recent feature allows ORT to automatically select an EP according to
policies set by the user (e.g., prefer npu or prefer gpu). This PR
allows QNN EP to be potentially selected when the user sets the
`PREFER_NPU` policy.
George Wu (jywu-mysoft) pushed a commit that referenced this pull request May 4, 2025
### Description
Adds #24629 to the ORT
1.22.0 release branch

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
@snnn

Copy link
Copy Markdown
Contributor

This PR has been cherry-picked into the rel-1.22.0 branch in PR #24630. Removing the release:1.22.0 label.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants