Repository navigation
Qualcomm AI Engine Direct - Refactor QNN context config construction. - #11546
graham0824 wants to merge 1 commit into
Conversation
52c194e to
c32b6cb
Compare
| static ::qnn::ContextConfigBuilder BuildCompileContextConfigs( | ||
| const ::qnn::Options& options, bool enable_effective_weight_sharing); | ||
| static ::qnn::ContextConfigBuilder BuildDispatchContextConfigs( | ||
| const ::qnn::Options& options); |
There was a problem hiding this comment.
I think these should be handle by builder, or have util functions provide by builder.
And it is strange to have compile / dispatch difference in QnnManager.
There was a problem hiding this comment.
Agreed, I moved the compile/dispatch config construction out of QnnManager into context-config builder utilities. QnnManager now only consumes the finalized configs when creating a QNN context.
| } | ||
|
|
||
| private: | ||
| std::vector<std::unique_ptr<void, void (*)(void*)>> custom_config_storage_; |
There was a problem hiding this comment.
I have some concerns about this:
- it is not good practice to store void pointer. (miss type information and also need to store a deleter).
- User may pass type which are not QNN custom config types.
- If type
Tis QNN structure and it has raw pointer point to a dynamic resource, it may not be release properly.
We can offline discuss about how to address these issue.
There was a problem hiding this comment.
Agreed, I removed the void* storage and the generic AddCustomConfig() API. Custom configs are now represented by typed backend-specific wrappers in a std::variant, so only supported QNN config types can be added.
The built config container owns these wrappers, allowing each wrapper to own and manage any nested dynamic resources when needed.
| context_configs_.push_back(config); | ||
| } | ||
|
|
||
| std::vector<const QnnContext_Config_t*> GetNullTerminatedConfigs() const { |
There was a problem hiding this comment.
After someone call GetNullTerminatedConfigs(), AddCustomConfig and AddContextConfig should not be called. I think we can use c++ "builder" pattern to prevent this.
There was a problem hiding this comment.
Agreed, I replaced GetNullTerminatedConfigs() with a consuming Build() API. Configs can now only be added to the mutable builder.
std::move(builder).Build() returns an immutable config container that owns the payloads and exposes the null-terminated Data() list.
| QnnContext_Config_t custom_config = QNN_CONTEXT_CONFIG_INIT; | ||
| custom_config.option = QNN_CONTEXT_CONFIG_OPTION_PRIORITY; | ||
| custom_config.priority = QNN_PRIORITY_HIGH; | ||
| config_builder.AddCustomConfig(custom_config); |
There was a problem hiding this comment.
QnnContext_Config_t is not a custom config type.
There was a problem hiding this comment.
Good catch. I separated QnnContext_Config_t from custom config payloads, priority now uses AddContextConfig(), while custom configs use typed HTP/GPU wrappers.
The old test was corrected, and passing QnnContext_Config_t as a custom config now fails at compile time.
43c051d to
7a5b520
Compare
ab6ecf1 to
29ab57a
Compare
f97aba9 to
1ee54f7
Compare
afe91dc to
cb80f3e
Compare
Summary: - Add context config builder. - Refactor qnn_manager to use context config. - Refactor how we enable context config via compiler plugin.
cb80f3e to
ffc81d6
Compare
What
Verification
Test