Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QNN EP HTP shared memory allocator #23136

Merged
merged 61 commits into from
Jan 14, 2025
Merged

Add QNN EP HTP shared memory allocator #23136

merged 61 commits into from
Jan 14, 2025

Conversation

edgchen1
Copy link
Contributor

@edgchen1 edgchen1 commented Dec 18, 2024

Description

Adds QNN EP HTP shared memory allocator.

The HTP shared memory allocator (HtpSharedMemoryAllocator) calls the rpcmem shared library (libcdsprpc.so/dll) to allocate and free memory that can be shared between HTP and CPU.

The allocator can be enabled by setting QNN EP option enable_htp_shared_memory_allocator to 1. QNNExecutionProvider::CreatePreferredAllocators() will then return an instance of HtpSharedMemoryAllocator.

For each QNN context, we also need to register and unregister memory handles in order to use the HTP shared memory. This memory handle management is added to QnnBackendManager, which also manages the QNN context handles.

For more information about using HTP shared memory with QNN, see: https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/htp_shared_buffer_tutorial.html#shared-buffer-tutorial

Limitations:

  • HTP shared memory usage is only supported for graph inputs and outputs. Intermediate values are not supported.
  • An allocation is assigned to a single shared memory buffer. The allocator is not smart enough to have multiple allocations share a single shared memory buffer.

Motivation and Context

Improve performance by using HTP shared memory to avoid overhead from copying data between CPU and NPU.

edgchen1 and others added 30 commits November 5, 2024 15:12
… declarations and definitions for IAllocator::TensorAlloc().
@yuslepukhin
Copy link
Member

Can this be used for Lora support when the model is modified to have optional inputs, and the data can be fed to override default initializers?

Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@edgchen1
Copy link
Contributor Author

Can this be used for Lora support when the model is modified to have optional inputs, and the data can be fed to override default initializers?

I'm not too familiar with the scenario. If that can be done using OrtValues, an input OrtValue can use this new allocator.

@edgchen1 edgchen1 requested a review from yuslepukhin January 13, 2025 23:03
Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@edgchen1
Copy link
Contributor Author

/azp run Windows GPU WebGPU CI Pipeline

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@edgchen1 edgchen1 merged commit 04030f6 into main Jan 14, 2025
98 checks passed
@edgchen1 edgchen1 deleted the edgchen1/qnn_ep_rpcmem branch January 14, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:QNN issues related to QNN exeution provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants