1818#include " PAL/FileOp.hpp"
1919#include " PAL/Path.hpp"
2020#include " PAL/StringOp.hpp"
21+ #include " QnnDlcUtils.hpp"
2122#include " QnnSampleApp.hpp"
2223#include " QnnSampleAppUtils.hpp"
2324#include " QnnWrapperUtils.hpp"
@@ -192,7 +193,8 @@ sample_app::QnnSampleApp::QnnSampleApp(QnnFunctionPointers qnnFunctionPointers,
192193 bool dumpOutputs,
193194 std::string cachedBinaryPath,
194195 std::string saveBinaryName,
195- const std::vector<LoraAdapter>& lora_adapters)
196+ const std::vector<LoraAdapter>& lora_adapters,
197+ std::string dlcPath)
196198 : m_qnnFunctionPointers(qnnFunctionPointers),
197199 m_outputPath(outputPath),
198200 m_saveBinaryName(saveBinaryName),
@@ -204,9 +206,17 @@ sample_app::QnnSampleApp::QnnSampleApp(QnnFunctionPointers qnnFunctionPointers,
204206 m_profilingLevel(profilingLevel),
205207 m_dumpOutputs(dumpOutputs),
206208 m_isBackendInitialized(false ),
207- m_isContextCreated(false ) {
209+ m_isContextCreated(false ),
210+ m_dlcPath(dlcPath)
211+ {
212+
208213 split (m_inputListPaths, inputListPaths, ' ,' );
209214 split (m_opPackagePaths, opPackagePaths, ' ,' );
215+ if (!dlcPath.empty ()){
216+ size_t pos = dlcPath.find_last_of (" \\ /" );
217+ m_outputPath = dlcPath.substr (0 , pos);
218+ // printf("m_outputPath=%s\n", m_outputPath.c_str());
219+ }
210220 if (m_outputPath.empty ()) {
211221 m_outputPath = s_defaultOutputPath;
212222 }
@@ -220,6 +230,10 @@ sample_app::QnnSampleApp::QnnSampleApp(QnnFunctionPointers qnnFunctionPointers,
220230}
221231
222232sample_app::QnnSampleApp::~QnnSampleApp () {
233+ // Free DLC resources using utility function
234+ dlc_utils::freeDlcResources (m_qnnFunctionPointers.qnnSystemInterfaceHandle ,
235+ m_dlcHandle,
236+ m_dlcLogHandle);
223237 // Free Profiling object if it was created
224238 if (nullptr != m_profileBackendHandle) {
225239 QNN_DEBUG (" Freeing backend profile object." );
@@ -448,20 +462,30 @@ sample_app::StatusCode sample_app::QnnSampleApp::freeContext() {
448462// are expected to be read by the app.
449463sample_app::StatusCode sample_app::QnnSampleApp::composeGraphs () {
450464 auto returnStatus = StatusCode::SUCCESS;
451- if (qnn_wrapper_api::ModelError_t::MODEL_NO_ERROR !=
452- m_qnnFunctionPointers.composeGraphsFnHandle (
453- m_backendHandle,
454- m_qnnFunctionPointers.qnnInterface ,
455- m_context,
456- (const qnn_wrapper_api::GraphConfigInfo_t**)m_graphConfigsInfo,
457- m_graphConfigsInfoCount,
458- &m_graphsInfo,
459- &m_graphsCount,
460- m_debug,
461- log::getLogCallback (),
462- log::getLogLevel ())) {
463- QNN_ERROR (" Failed in composeGraphs()" );
464- returnStatus = StatusCode::FAILURE;
465+ // If DLC path is provided, use DLC-based composition
466+ if (!m_dlcPath.empty ()) {
467+ printf (" DLC path provided, using DLC-based graph composition\n " );
468+ returnStatus = composeGraphsFromDlc ();
469+ return returnStatus;
470+ } else {
471+ // Default: compose with QNN's model.so
472+ // Default path: use model.so
473+ QNN_INFO (" Using model.so for graph composition" );
474+ if (qnn_wrapper_api::ModelError_t::MODEL_NO_ERROR !=
475+ m_qnnFunctionPointers.composeGraphsFnHandle (
476+ m_backendHandle,
477+ m_qnnFunctionPointers.qnnInterface ,
478+ m_context,
479+ (const qnn_wrapper_api::GraphConfigInfo_t**)m_graphConfigsInfo,
480+ m_graphConfigsInfoCount,
481+ &m_graphsInfo,
482+ &m_graphsCount,
483+ m_debug,
484+ log::getLogCallback (),
485+ log::getLogLevel ())) {
486+ QNN_ERROR (" Failed in composeGraphs()" );
487+ returnStatus = StatusCode::FAILURE;
488+ }
465489 }
466490 return returnStatus;
467491}
@@ -983,6 +1007,38 @@ sample_app::StatusCode sample_app::QnnSampleApp::saveBinary() {
9831007
9841008// C:\Qualcomm\AIStack\QNN\<version>\include\QNN\QnnProfile.h
9851009// C:\Qualcomm\AIStack\QNN\<version>\include\QNN\HTP\QnnHtpProfile.h
1010+ sample_app::StatusCode sample_app::QnnSampleApp::composeGraphsFromDlc () {
1011+ QNN_DEBUG (" Composing graphs from DLC\n " );
1012+ // Create DLC handle using utility function
1013+ auto dlcStatus = dlc_utils::createDlcHandle (m_qnnFunctionPointers.qnnSystemInterfaceHandle ,
1014+ m_dlcPath,
1015+ log::getLogCallback (),
1016+ log::getLogLevel (),
1017+ m_dlcLogHandle,
1018+ m_dlcHandle);
1019+
1020+ if (dlc_utils::StatusCode::SUCCESS != dlcStatus) {
1021+ QNN_ERROR (" Failed to create DLC handle" );
1022+ return StatusCode::FAILURE;
1023+ }
1024+
1025+ // Compose graphs from DLC using utility function
1026+ dlcStatus = dlc_utils::composeGraphsFromDlc (m_qnnFunctionPointers.qnnSystemInterfaceHandle ,
1027+ m_dlcHandle,
1028+ m_backendHandle,
1029+ m_context,
1030+ m_qnnFunctionPointers.qnnInterfaceHandle ,
1031+ m_graphsInfo,
1032+ m_graphsCount);
1033+
1034+ if (dlc_utils::StatusCode::SUCCESS != dlcStatus) {
1035+ QNN_ERROR (" Failed to compose graphs from DLC" );
1036+ return StatusCode::FAILURE;
1037+ }
1038+
1039+ QNN_INFO (" Successfully composed %d graphs from DLC" , m_graphsCount);
1040+ return StatusCode::SUCCESS;
1041+ }
9861042sample_app::StatusCode sample_app::QnnSampleApp::extractBackendProfilingInfo (
9871043 Qnn_ProfileHandle_t profileHandle) {
9881044 if (nullptr == m_profileBackendHandle) {
0 commit comments