diff --git a/backends/qualcomm/export_utils.py b/backends/qualcomm/export_utils.py index 2c7ab2abd02..5973d8a35bf 100644 --- a/backends/qualcomm/export_utils.py +++ b/backends/qualcomm/export_utils.py @@ -306,7 +306,6 @@ def __init__( traditional_general_artifacts = [ f"{self.qnn_sdk}/lib/{self.target}/libQnnSystem.so", f"{self.build_path}/backends/qualcomm/libqnn_executorch_backend.so", - f"{self.qnn_sdk}/lib/{self.target}/libQnnModelDlc.so", ] self.backend_library_paths.update( { @@ -352,9 +351,11 @@ def _adb(self, cmd, output_callback: Optional[Callable[[str], None]] = None): ) output_callback(result) else: - subprocess.run( + result = subprocess.run( cmds, stdout=subprocess.DEVNULL if self.error_only else sys.stdout ) + if result.returncode != 0: + raise RuntimeError(f"adb command failed: {cmds}") def push( # noqa: C901 self, diff --git a/backends/qualcomm/runtime/QnnManager.cpp b/backends/qualcomm/runtime/QnnManager.cpp index b55e3fa15f1..6d5a009ab01 100644 --- a/backends/qualcomm/runtime/QnnManager.cpp +++ b/backends/qualcomm/runtime/QnnManager.cpp @@ -246,6 +246,7 @@ Error QnnManager::InitContext( options_->backend_options()->backend_type()); backend_params_ptr_ = QnnBackendFactory().Create( backend_bundle_ptr_->implementation.get(), + backend_bundle_ptr_->system_implementation.get(), backend_bundle_ptr_->qnn_backend_ptr.get(), backend_bundle_ptr_->qnn_device_ptr.get(), qnn_context_blob_, @@ -279,7 +280,10 @@ Error QnnManager::InitContext( BackendInitializeState::INITIALIZED; } - if (IsOnlinePrepare()) { + if (IsOnlinePrepare() && + backend_params_ptr_->qnn_backend_cache_ptr_->GetCacheState() == + QnnBackendCache::SERIALIZE) { + // The place is used for AOT // Check whether the QNN version supports the DLC format. Qnn_ApiVersion_t qnn_version = {QNN_VERSION_INIT}; backend_bundle_ptr_->implementation->GetQnnInterface() @@ -304,6 +308,7 @@ Error QnnManager::InitContextCache() { options_->backend_options()->backend_type()); backend_params_ptr_ = QnnBackendFactory().Create( backend_bundle_ptr_->implementation.get(), + backend_bundle_ptr_->system_implementation.get(), backend_bundle_ptr_->qnn_backend_ptr.get(), backend_bundle_ptr_->qnn_device_ptr.get(), qnn_context_blob_, @@ -477,9 +482,9 @@ Error QnnManager::ProfileExecuteData( } void QnnManager::Destroy() { + qnn_dlc_manager_->Destroy(); backend_params_ptr_.reset(new BackendConfigParameters()); backend_bundle_ptr_.reset(new QnnBackendBundle()); - qnn_dlc_manager_->Destroy(); } void QnnManager::DestroyContext() { @@ -540,12 +545,17 @@ Error QnnManager::GetContextBinary( Error QnnManager::CompileDlc() { Qnn_ErrorHandle_t error; - auto qnn_dlc_graph_info = qnn_dlc_manager_->GetQnnDlcGraphInfoPtr(); - uint32_t qnn_dlc_graph_info_num = qnn_dlc_manager_->GetQnnDlcGraphInfoNum(); - for (uint32_t i = 0; i < qnn_dlc_graph_info_num; ++i) { - auto& graphInfo = (*qnn_dlc_graph_info)[i]; + auto graphs = qnn_dlc_manager_->GetQnnDlcGraphInfoPtr(); + uint32_t num_graphs = qnn_dlc_manager_->GetQnnDlcGraphInfoNum(); + for (uint32_t i = 0; i < num_graphs; ++i) { + auto& graphInfo = graphs[i].graphInfoV1; + Qnn_GraphHandle_t graphHandle; + backend_bundle_ptr_->implementation->GetQnnInterface().qnn_graph_retrieve( + backend_params_ptr_->qnn_context_ptr_->GetHandle(), + graphInfo.graphName, + &graphHandle); backend_params_ptr_->qnn_graph_ptr_->SetGraphHandle( - graphInfo.graphName, graphInfo.graph); + graphInfo.graphName, graphHandle); error = backend_params_ptr_->qnn_graph_ptr_->GraphFinalize(graphInfo.graphName); if (error != QNN_SUCCESS) { @@ -560,9 +570,9 @@ Error QnnManager::CompileDlc() { // Mapping memory address for the input and output of mutable buffer std::unordered_map mutable_buffer_id_to_memory_map; - for (uint32_t i = 0; i < graphInfo.numInputTensors; ++i) { - auto tw = CreateTensorWrapper(graphInfo.inputTensors[i]); - tw->UpdateQnnTensorMeta(graphInfo.inputTensors[i]); + for (uint32_t i = 0; i < graphInfo.numGraphInputs; ++i) { + auto tw = CreateTensorWrapper(graphInfo.graphInputs[i]); + tw->UpdateQnnTensorMeta(graphInfo.graphInputs[i]); int mutable_buffer_id = ExtractMutableBufferNumber(tw->GetName()); if (mutable_buffer_id != -1) { @@ -573,9 +583,9 @@ Error QnnManager::CompileDlc() { } graph_inputs.push_back(tw); } - for (uint32_t i = 0; i < graphInfo.numOutputTensors; ++i) { - auto tw = CreateTensorWrapper(graphInfo.outputTensors[i]); - tw->UpdateQnnTensorMeta(graphInfo.outputTensors[i]); + for (uint32_t i = 0; i < graphInfo.numGraphOutputs; ++i) { + auto tw = CreateTensorWrapper(graphInfo.graphOutputs[i]); + tw->UpdateQnnTensorMeta(graphInfo.graphOutputs[i]); int mutable_buffer_id = ExtractMutableBufferNumber(tw->GetName()); if (mutable_buffer_id != -1 && mutable_buffer_id_to_memory_map.find(mutable_buffer_id) != diff --git a/backends/qualcomm/runtime/backends/QnnBackendFactory.cpp b/backends/qualcomm/runtime/backends/QnnBackendFactory.cpp index fa2008befd5..9c520db9775 100644 --- a/backends/qualcomm/runtime/backends/QnnBackendFactory.cpp +++ b/backends/qualcomm/runtime/backends/QnnBackendFactory.cpp @@ -17,6 +17,7 @@ using executorch::runtime::Error; std::unique_ptr QnnBackendFactory::Create( QnnImplementation* implementation_ptr, + QnnSystemImplementation* system_implementation_ptr, QnnBackend* qnn_backend_ptr, QnnDevice* qnn_device_ptr, const QnnExecuTorchContextBinary& qnn_context_blob, @@ -67,6 +68,7 @@ std::unique_ptr QnnBackendFactory::Create( backend_params->qnn_context_ptr_ = std::make_unique( implementation_ptr, + system_implementation_ptr, qnn_backend_ptr, qnn_device_ptr, backend_params->qnn_backend_cache_ptr_.get(), @@ -110,6 +112,7 @@ std::unique_ptr QnnBackendFactory::Create( backend_params->qnn_context_ptr_ = std::make_unique( implementation_ptr, + system_implementation_ptr, qnn_backend_ptr, qnn_device_ptr, backend_params->qnn_backend_cache_ptr_.get(), @@ -154,6 +157,7 @@ std::unique_ptr QnnBackendFactory::Create( backend_params->qnn_context_ptr_ = std::make_unique( implementation_ptr, + system_implementation_ptr, qnn_backend_ptr, qnn_device_ptr, backend_params->qnn_backend_cache_ptr_.get(), diff --git a/backends/qualcomm/runtime/backends/QnnBackendFactory.h b/backends/qualcomm/runtime/backends/QnnBackendFactory.h index 753d8cf3007..a5b9af05029 100644 --- a/backends/qualcomm/runtime/backends/QnnBackendFactory.h +++ b/backends/qualcomm/runtime/backends/QnnBackendFactory.h @@ -63,6 +63,7 @@ class QnnBackendFactory { public: std::unique_ptr Create( QnnImplementation* implementation, + QnnSystemImplementation* system_implementation, QnnBackend* qnn_backend_ptr, QnnDevice* qnn_device_ptr, const QnnExecuTorchContextBinary& qnn_context_blob, diff --git a/backends/qualcomm/runtime/backends/QnnBackendUnifiedRegistry.cpp b/backends/qualcomm/runtime/backends/QnnBackendUnifiedRegistry.cpp index cbc28b51f94..7570bdc9ca2 100644 --- a/backends/qualcomm/runtime/backends/QnnBackendUnifiedRegistry.cpp +++ b/backends/qualcomm/runtime/backends/QnnBackendUnifiedRegistry.cpp @@ -152,8 +152,15 @@ Error QnnBackendUnifiedRegistry::GetOrCreateBackendBundle( if (backend->VerifyQNNSDKVersion() != Error::Ok) { return Error::Internal; } + // 5. Create QnnSystemImplementation and load qnn library + std::unique_ptr system_implementation = + std::make_unique("libQnnSystem.so"); + ret = system_implementation->Load(); + ET_CHECK_OR_RETURN_ERROR( + ret == Error::Ok, Internal, "Fail to load Qnn system library"); bundle->implementation = std::move(implementation); + bundle->system_implementation = std::move(system_implementation); bundle->qnn_logger_ptr = std::move(logger); bundle->qnn_backend_ptr = std::move(backend); bundle->qnn_device_ptr = std::move(device); diff --git a/backends/qualcomm/runtime/backends/QnnBackendUnifiedRegistry.h b/backends/qualcomm/runtime/backends/QnnBackendUnifiedRegistry.h index db31404955e..c1330f6be77 100644 --- a/backends/qualcomm/runtime/backends/QnnBackendUnifiedRegistry.h +++ b/backends/qualcomm/runtime/backends/QnnBackendUnifiedRegistry.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -28,19 +29,22 @@ struct QnnBackendBundle { std::unique_ptr qnn_logger_ptr; std::unique_ptr qnn_backend_ptr; std::unique_ptr qnn_device_ptr; + std::unique_ptr system_implementation; // Default ctor QnnBackendBundle() : implementation(nullptr), qnn_logger_ptr(nullptr), qnn_backend_ptr(nullptr), - qnn_device_ptr(nullptr) {} + qnn_device_ptr(nullptr), + system_implementation{nullptr} {} // Default dtor ~QnnBackendBundle() { qnn_device_ptr.reset(); qnn_backend_ptr.reset(); qnn_logger_ptr.reset(); implementation.reset(); + system_implementation.reset(); } }; diff --git a/backends/qualcomm/runtime/backends/QnnContextCommon.cpp b/backends/qualcomm/runtime/backends/QnnContextCommon.cpp index e16a173db6c..49a8faf3b7d 100644 --- a/backends/qualcomm/runtime/backends/QnnContextCommon.cpp +++ b/backends/qualcomm/runtime/backends/QnnContextCommon.cpp @@ -86,9 +86,9 @@ Error QnnContext::Configure() { return Error::Internal; } if (cache_->GetCacheState() == QnnBackendCache::ONLINE_PREPARE) { - // Register graphs from DLC during online prepare for HTP/GPU/DSP backends + // The place is used for runtime return qnn_dlc_manager_->RegisterGraphsFromDLC( - implementation_, backend_, this, cache_); + implementation_, system_implementation_, backend_, this, cache_); } return Error::Ok; } diff --git a/backends/qualcomm/runtime/backends/QnnContextCommon.h b/backends/qualcomm/runtime/backends/QnnContextCommon.h index 7d507a4a50c..11f539eb775 100644 --- a/backends/qualcomm/runtime/backends/QnnContextCommon.h +++ b/backends/qualcomm/runtime/backends/QnnContextCommon.h @@ -25,12 +25,14 @@ class QnnContext { public: explicit QnnContext( QnnImplementation* implementation, + QnnSystemImplementation* system_implementation, QnnBackend* backend, QnnDevice* device, QnnBackendCache* cache, QnnDlcManager* qnn_dlc_manager) : handle_(nullptr), implementation_(implementation), + system_implementation_(system_implementation), backend_(backend), device_(device), cache_(cache), @@ -75,6 +77,7 @@ class QnnContext { private: Qnn_ContextHandle_t handle_; QnnImplementation* implementation_; + QnnSystemImplementation* system_implementation_; QnnBackend* backend_; QnnDevice* device_; QnnBackendCache* cache_; diff --git a/backends/qualcomm/runtime/backends/QnnDlcManager.h b/backends/qualcomm/runtime/backends/QnnDlcManager.h index 4c320fde9ac..8b3f259d7ca 100644 --- a/backends/qualcomm/runtime/backends/QnnDlcManager.h +++ b/backends/qualcomm/runtime/backends/QnnDlcManager.h @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ #pragma once +#include #include #include @@ -26,12 +27,12 @@ class QnnDlcManager { const QnnExecuTorchContextBinary& qnn_context_blob, const QnnExecuTorchOptions* options); - qnn_wrapper_api::GraphInfoPtr_t* GetQnnDlcGraphInfoPtr() { - return qnn_dlc_graph_info_; + QnnSystemContext_GraphInfo_t* GetQnnDlcGraphInfoPtr() { + return graphs_; } uint32_t GetQnnDlcGraphInfoNum() { - return qnn_dlc_graph_info_num_; + return num_graphs_; } std::unique_ptr backend_params_ptr_ = @@ -47,9 +48,60 @@ class QnnDlcManager { Error RegisterGraphsFromDLC( QnnImplementation* implementation, + QnnSystemImplementation* system_implementation, QnnBackend* backend, QnnContext* context, - QnnBackendCache* cache); + QnnBackendCache* cache) { + const QnnSystemInterface& system_interface = + system_implementation->GetQnnSystemInterface(); + + // create dlc_handle + QnnSystemDlc_Handle_t dlc_handle = nullptr; + backend_bundle_ptr_->qnn_logger_ptr = std::make_unique( + implementation, + LoggingCallback, + get_option(options_->log_level(), QNN_RUNTIME_LOG_LEVEL)); + + Qnn_ErrorHandle_t error = + system_interface.qnn_system_dlc_create_from_binary( + /*logger=*/backend_bundle_ptr_->qnn_logger_ptr->GetHandle(), + /*buffer=*/(const uint8_t*)qnn_context_blob_.buffer, + /*bufferSize=*/qnn_context_blob_.nbytes, + /*dlcHandle=*/&dlc_handle); + if (error != QNN_SUCCESS) { + QNN_EXECUTORCH_LOG_ERROR( + "Can't create dlc from binary. Error %d.", QNN_GET_ERROR_CODE(error)); + return Error::Internal; + } + + // compose graphs from dlc + const QnnInterface_t* interface = + implementation->GetQnnInterface().GetInterface(); + // QnnSystemContext_GraphInfo_t* graphs = nullptr; + // uint32_t num_graphs = 0; + error = system_interface.qnn_system_dlc_compose_graphs( + /*dlcHandle=*/dlc_handle, + /*graphConfigs=*/nullptr, + /*numGraphConfigs=*/0, + /*backend=*/backend->GetHandle(), + /*context=*/context->GetHandle(), + /*backendInterface=*/*interface, + /*graphVersion=*/QNN_SYSTEM_CONTEXT_GRAPH_INFO_VERSION_1, + /*graphs=*/&graphs_, + /*numGraphs=*/&num_graphs_); + if (error != QNN_SUCCESS) { + QNN_EXECUTORCH_LOG_ERROR( + "Can't compose graph from dlc. Error %d.", QNN_GET_ERROR_CODE(error)); + return Error::Internal; + } + + for (uint32_t i = 0; i < num_graphs_; ++i) { + auto& graphInfo = graphs_[i].graphInfoV1; + cache->SetGraphNames(graphInfo.graphName); + } + + return Error::Ok; + } private: static constexpr const char* library_name_ = "libQnnIr.so"; @@ -57,9 +109,8 @@ class QnnDlcManager { const QnnExecuTorchContextBinary& qnn_context_blob_; const QnnExecuTorchOptions* options_; - static constexpr const char* dlc_lib_ = "libQnnModelDlc.so"; - qnn_wrapper_api::GraphInfoPtr_t* qnn_dlc_graph_info_ = nullptr; - uint32_t qnn_dlc_graph_info_num_ = 0; + QnnSystemContext_GraphInfo_t* graphs_ = nullptr; + uint32_t num_graphs_ = 0; Error LoadQnnIrLibrary(); diff --git a/backends/qualcomm/runtime/backends/QnnFunctionInterface.h b/backends/qualcomm/runtime/backends/QnnFunctionInterface.h index 598d38f9e33..d098f44e322 100644 --- a/backends/qualcomm/runtime/backends/QnnFunctionInterface.h +++ b/backends/qualcomm/runtime/backends/QnnFunctionInterface.h @@ -106,6 +106,9 @@ class QnnInterface { const QNN_INTERFACE_VER_TYPE& GetInterfaceVer() const { return qnn_interface_->QNN_INTERFACE_VER_NAME; } + const QnnInterface_t* GetInterface() const { + return qnn_interface_; + } void Unload() { qnn_interface_ = nullptr; } diff --git a/backends/qualcomm/runtime/backends/QnnSysFunctionInterface.h b/backends/qualcomm/runtime/backends/QnnSysFunctionInterface.h index b77c7c2903e..ca2d19d78f1 100644 --- a/backends/qualcomm/runtime/backends/QnnSysFunctionInterface.h +++ b/backends/qualcomm/runtime/backends/QnnSysFunctionInterface.h @@ -42,6 +42,12 @@ class QnnSystemInterface { system_context_get_binary_info, systemContextGetBinaryInfo); DEFINE_SHIM_FUNCTION_SYS_INTERFACE(system_context_free, systemContextFree); + DEFINE_SHIM_FUNCTION_SYS_INTERFACE( + system_dlc_compose_graphs, + systemDlcComposeGraphs); + DEFINE_SHIM_FUNCTION_SYS_INTERFACE( + system_dlc_create_from_binary, + systemDlcCreateFromBinary); private: const QnnSystemInterface_t* qnn_sys_interface_{nullptr}; diff --git a/backends/qualcomm/runtime/backends/gpu/GpuContext.cpp b/backends/qualcomm/runtime/backends/gpu/GpuContext.cpp index 07952e77eef..c46db30bf1b 100644 --- a/backends/qualcomm/runtime/backends/gpu/GpuContext.cpp +++ b/backends/qualcomm/runtime/backends/gpu/GpuContext.cpp @@ -16,12 +16,19 @@ using executorch::runtime::Error; GpuContext::GpuContext( QnnImplementation* implementation, + QnnSystemImplementation* system_implementation, QnnBackend* backend, QnnDevice* device, QnnBackendCache* cache, QnnDlcManager* qnn_dlc_manager, const QnnExecuTorchGpuBackendOptions* gpu_options) - : QnnContext(implementation, backend, device, cache, qnn_dlc_manager) { + : QnnContext( + implementation, + system_implementation, + backend, + device, + cache, + qnn_dlc_manager) { gpu_context_custom_config_ = std::make_unique(gpu_options); } diff --git a/backends/qualcomm/runtime/backends/gpu/GpuContext.h b/backends/qualcomm/runtime/backends/gpu/GpuContext.h index 29a36982db9..b7986150fdb 100644 --- a/backends/qualcomm/runtime/backends/gpu/GpuContext.h +++ b/backends/qualcomm/runtime/backends/gpu/GpuContext.h @@ -19,6 +19,7 @@ class GpuContext : public QnnContext { public: GpuContext( QnnImplementation* implementation, + QnnSystemImplementation* system_implementation, QnnBackend* backend, QnnDevice* device, QnnBackendCache* cache, diff --git a/backends/qualcomm/runtime/backends/htp/HtpContext.h b/backends/qualcomm/runtime/backends/htp/HtpContext.h index a0389ea5983..06b56240681 100644 --- a/backends/qualcomm/runtime/backends/htp/HtpContext.h +++ b/backends/qualcomm/runtime/backends/htp/HtpContext.h @@ -21,12 +21,19 @@ class HtpContext : public QnnContext { public: HtpContext( QnnImplementation* implementation, + QnnSystemImplementation* system_implementation, QnnBackend* backend, QnnDevice* device, QnnBackendCache* cache, const QnnExecuTorchHtpBackendOptions* htp_options, QnnDlcManager* qnn_dlc_manager) - : QnnContext(implementation, backend, device, cache, qnn_dlc_manager) { + : QnnContext( + implementation, + system_implementation, + backend, + device, + cache, + qnn_dlc_manager) { htp_context_custom_config_ = std::make_unique(this, htp_options); } diff --git a/backends/qualcomm/runtime/backends/ir/host/QnnDlcManager.cpp b/backends/qualcomm/runtime/backends/ir/host/QnnDlcManager.cpp index 47d583b5c15..d890d949a88 100644 --- a/backends/qualcomm/runtime/backends/ir/host/QnnDlcManager.cpp +++ b/backends/qualcomm/runtime/backends/ir/host/QnnDlcManager.cpp @@ -5,7 +5,6 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -#include #include #include @@ -44,10 +43,11 @@ Error QnnDlcManager::Create() { backend_params_ptr_->qnn_context_ptr_ = std::make_unique( backend_bundle_ptr_->implementation.get(), + backend_bundle_ptr_->system_implementation.get(), backend_bundle_ptr_->qnn_backend_ptr.get(), backend_bundle_ptr_->qnn_device_ptr.get(), backend_params_ptr_->qnn_backend_cache_ptr_.get(), - nullptr); + this); backend_params_ptr_->qnn_graph_ptr_ = std::make_unique( backend_bundle_ptr_->implementation.get(), @@ -120,14 +120,6 @@ Error QnnDlcManager::SetUpDlcEnvironment( return Error::Ok; } -Error QnnDlcManager::RegisterGraphsFromDLC( - QnnImplementation* implementation, - QnnBackend* backend, - QnnContext* context, - QnnBackendCache* cache) { - return Error::Ok; -} - void QnnDlcManager::Destroy() { backend_params_ptr_.reset(new BackendConfigParameters()); backend_bundle_ptr_.reset(new QnnBackendBundle()); diff --git a/backends/qualcomm/runtime/backends/ir/target/QnnDlcManager.cpp b/backends/qualcomm/runtime/backends/ir/target/QnnDlcManager.cpp index 6512b5730b5..356328082a0 100644 --- a/backends/qualcomm/runtime/backends/ir/target/QnnDlcManager.cpp +++ b/backends/qualcomm/runtime/backends/ir/target/QnnDlcManager.cpp @@ -44,95 +44,6 @@ Error QnnDlcManager::SetUpDlcEnvironment( return Error::Ok; } -Error QnnDlcManager::RegisterGraphsFromDLC( - QnnImplementation* implementation, - QnnBackend* backend, - QnnContext* context, - QnnBackendCache* cache) { - void* lib_handle = dlopen(dlc_lib_, RTLD_NOW | RTLD_LOCAL); - if (lib_handle == nullptr) { - QNN_EXECUTORCH_LOG_ERROR( - "Cannot Open lib %s, with error: %s", dlc_lib_, dlerror()); - return Error::Internal; - } - QnnModel_composeGraphsFromDlc composeGraphsFromDlc = - loadQnnFunction( - lib_handle, "QnnModel_composeGraphsFromDlc"); - if (composeGraphsFromDlc == nullptr) { - QNN_EXECUTORCH_LOG_ERROR( - "Cannot load symbol " - "QnnModel_composeGraphsFromDlc : %s", - dlerror()); - return Error::Internal; - } - - // memfd_create on android api level 30 and above - int fd = -1; -#ifdef __ANDROID__ -#if __ANDROID_API__ >= 30 - fd = memfd_create("tmp.dlc", 0); -#endif -#endif - if (fd == -1) { - QNN_EXECUTORCH_LOG_ERROR("memfd_create fail"); - return Error::Internal; - } - - if (ftruncate(fd, qnn_context_blob_.nbytes) == -1) { - QNN_EXECUTORCH_LOG_ERROR("ftruncate fail"); - close(fd); - return Error::Internal; - } - - void* addr = mmap( - NULL, - qnn_context_blob_.nbytes, - PROT_READ | PROT_WRITE, - MAP_SHARED, - fd, - 0); - if (addr == MAP_FAILED) { - QNN_EXECUTORCH_LOG_ERROR("mmap"); - close(fd); - return Error::Internal; - } - - memcpy(addr, qnn_context_blob_.buffer, qnn_context_blob_.nbytes); - - char dlc_path[256]; - snprintf(dlc_path, sizeof(dlc_path), "/proc/self/fd/%d", fd); - - const QNN_INTERFACE_VER_TYPE& interfaceVer = - implementation->GetQnnInterface().GetInterfaceVer(); - - if (composeGraphsFromDlc( - /*backendHandle=*/backend->GetHandle(), - /*interface=*/interfaceVer, - /*contextHandle=*/context->GetHandle(), - /*graphsConfigInfo=*/nullptr, - /*dlcPath=*/dlc_path, - /*numGraphsConfigInfo=*/0, - /*graphsInfo=*/&qnn_dlc_graph_info_, - /*numGraphsInfo=*/&qnn_dlc_graph_info_num_, - /*debug=*/false, - /*logCallback=*/nullptr, - /*maxLogLevel=*/QNN_LOG_LEVEL_VERBOSE) != - qnn_wrapper_api::ModelError_t::MODEL_NO_ERROR) { - QNN_EXECUTORCH_LOG_ERROR("Failed to open Dlc"); - return Error::Internal; - } - munmap(addr, qnn_context_blob_.nbytes); - close(fd); - dlclose(lib_handle); - - for (uint32_t i = 0; i < qnn_dlc_graph_info_num_; ++i) { - auto& graphInfo = (*qnn_dlc_graph_info_)[i]; - cache->SetGraphNames(graphInfo.graphName); - } - - return Error::Ok; -} - void QnnDlcManager::Destroy() {} } // namespace qnn diff --git a/backends/qualcomm/runtime/backends/lpai/LpaiContext.cpp b/backends/qualcomm/runtime/backends/lpai/LpaiContext.cpp index 11f90722f32..21deed0a4e1 100644 --- a/backends/qualcomm/runtime/backends/lpai/LpaiContext.cpp +++ b/backends/qualcomm/runtime/backends/lpai/LpaiContext.cpp @@ -16,11 +16,18 @@ using executorch::runtime::Error; LpaiContext::LpaiContext( QnnImplementation* implementation, + QnnSystemImplementation* system_implementation, QnnBackend* backend, QnnDevice* device, QnnBackendCache* cache, QnnDlcManager* qnn_dlc_manager) - : QnnContext(implementation, backend, device, cache, qnn_dlc_manager) { + : QnnContext( + implementation, + system_implementation, + backend, + device, + cache, + qnn_dlc_manager) { lpai_context_custom_config_ = std::make_unique(); } diff --git a/backends/qualcomm/runtime/backends/lpai/LpaiContext.h b/backends/qualcomm/runtime/backends/lpai/LpaiContext.h index b05dac469bf..dab759678dd 100644 --- a/backends/qualcomm/runtime/backends/lpai/LpaiContext.h +++ b/backends/qualcomm/runtime/backends/lpai/LpaiContext.h @@ -19,6 +19,7 @@ class LpaiContext : public QnnContext { public: LpaiContext( QnnImplementation* implementation, + QnnSystemImplementation* system_implementation, QnnBackend* backend, QnnDevice* device, QnnBackendCache* cache,