Skip to content

Commit 6fa33f0

Browse files
committed
Add comment about multi-threading considerations
1 parent e86ff2e commit 6fa33f0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,15 @@ Status QnnBackendManager::GetOrRegisterContextMemHandle(Qnn_ContextHandle_t cont
17241724
void* shared_memory_address,
17251725
const Qnn_Tensor_t& qnn_tensor,
17261726
Qnn_MemHandle_t& mem_handle) {
1727+
// Multi-threading situations to consider:
1728+
// 1) Shared memory allocation is being freed in another thread while we are processing `shared_memory_address`.
1729+
// This implies incorrect usage as the memory is being freed while it is still in use. Let's assume this won't
1730+
// happen.
1731+
// 2) The shared memory allocation clean up function is being run from another thread while the
1732+
// QnnContextHandleRecord or QnnBackendManager objects are being destroyed.
1733+
// Usage of weak_ptrs from the clean up function should ensure that those objects are only accessed while they are
1734+
// in scope.
1735+
17271736
const auto context_handle_record_it = context_map_.find(context_handle);
17281737
ORT_RETURN_IF_NOT(context_handle_record_it != context_map_.end(), "QNN context not found: ", context_handle);
17291738

0 commit comments

Comments
 (0)