Skip to content

Commit

Permalink
make some QnnBackendManager member functions private, update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
edgchen1 committed Jan 6, 2025
1 parent 5e6e103 commit 78e86cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 37 deletions.
17 changes: 12 additions & 5 deletions onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ static Qnn_Version_t GetQnnInterfaceApiVersion(const QnnSystemInterface_t* qnn_i
return qnn_interface->systemApiVersion;
}

static char* DlError() {
#ifdef _WIN32
return "";
#else
return ::dlerror();
#endif
}

template <typename F, class T>
Status QnnBackendManager::GetQnnInterfaceProvider(const char* lib_path,
const char* interface_provider_name,
Expand Down Expand Up @@ -1693,7 +1701,10 @@ Status QnnBackendManager::GetOrRegisterContextMemHandle(Qnn_ContextHandle_t cont
weak_backend_manager = weak_from_this(),
weak_context_mem_handle_manager = std::weak_ptr{context_mem_handle_manager}](
void* shared_memory_address) {
// get QnnBackendManager shared_ptr to ensure that qnn_interface is still valid
// Get QnnBackendManager shared_ptr to ensure that:
// - QNN interface is still valid.
// - QNN context handle is still valid. This should be true as long as QNN contexts are not freed from
// anywhere other than the destructor.
auto backend_manager = weak_backend_manager.lock();
if (!backend_manager) {
return;
Expand All @@ -1704,10 +1715,6 @@ Status QnnBackendManager::GetOrRegisterContextMemHandle(Qnn_ContextHandle_t cont
return;
}

// TODO should also ensure that the QNN context handle is still valid.
// This *should* be true as long as the QNN contexts are not freed from anywhere other than
// ~QnnBackendManager(). If we are able to lock weak_backend_manager, we haven't gotten to the dtor yet.

auto unregister_status = context_mem_handle_manager->Unregister(shared_memory_address);
if (!unregister_status.IsOK()) {
LOGS(logger, ERROR) << "Failed to unregister shared memory mem handle for address: "
Expand Down
50 changes: 18 additions & 32 deletions onnxruntime/core/providers/qnn/builder/qnn_backend_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,41 +70,9 @@ class QnnBackendManager : public std::enable_shared_from_this<QnnBackendManager>
enable_htp_weight_sharing_(config.enable_htp_weight_sharing) {
}

public:
ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE(QnnBackendManager);

~QnnBackendManager();
char* DlError() {
#ifdef _WIN32
return "";
#else
return ::dlerror();
#endif
}

Status LoadBackend();

Status InitializeBackend();

Status CreateDevice();

Status ReleaseDevice();

Status ShutdownBackend();

Status InitializeProfiling();

Status ReleaseProfilehandle();

Status CreateContext();

Status ReleaseContext();

Status ResetContext() {
ORT_RETURN_IF_ERROR(ReleaseContext());

return CreateContext();
}

std::unique_ptr<unsigned char[]> GetContextBinaryBuffer(uint64_t& written_buffer_size);

Expand Down Expand Up @@ -170,6 +138,24 @@ class QnnBackendManager : public std::enable_shared_from_this<QnnBackendManager>
Qnn_MemHandle_t& mem_handle);

private:
Status LoadBackend();

Status InitializeBackend();

Status CreateDevice();

Status ReleaseDevice();

Status ShutdownBackend();

Status InitializeProfiling();

Status ReleaseProfilehandle();

Status CreateContext();

Status ReleaseContext();

// Sets the ORT logger and creates a corresponding QNN logger with the same log level.
// NOTE: caller must lock the `logger_mutex_` before calling this function.
Status InitializeQnnLog(const logging::Logger& logger);
Expand Down

0 comments on commit 78e86cc

Please sign in to comment.