File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
backends/qualcomm/runtime Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1717#include < algorithm>
1818#include < cstdlib>
1919#include < cstring>
20+ #include < filesystem>
2021#include < fstream>
22+ #include < iostream>
2123#include < string>
2224
2325namespace executorch {
@@ -681,6 +683,36 @@ Error QnnManager::Compile(
681683 return Error::Internal;
682684 }
683685
686+ // Write context binary to file for debugging purpose
687+ const char * et_qnn_debug_dir = getenv (" ET_QNN_DEBUG_DIR" );
688+ if (et_qnn_debug_dir != nullptr ) {
689+ namespace fs = std::filesystem;
690+
691+ fs::path debug_dir = et_qnn_debug_dir;
692+ if (!fs::exists (debug_dir) || !fs::is_directory (debug_dir)) {
693+ QNN_EXECUTORCH_LOG_WARN (
694+ " ET_QNN_DEBUG_DIR %s is not a valid directory" , et_qnn_debug_dir);
695+ return Error::Ok;
696+ }
697+
698+ QnnExecuTorchContextBinary qnn_executorch_context_binary{nullptr , 0 };
699+ if (GetContextBinary (qnn_executorch_context_binary) != Error::Ok) {
700+ return Error::Ok;
701+ }
702+
703+ std::string binary_file = std::string (et_qnn_debug_dir) + " /qnn_context_binary.bin" ;
704+ std::ofstream fout (binary_file, std::ios::binary);
705+ fout.write (
706+ reinterpret_cast <const char *>(qnn_executorch_context_binary.buffer ),
707+ qnn_executorch_context_binary.nbytes );
708+
709+ if (!fout) {
710+ QNN_EXECUTORCH_LOG_WARN (
711+ " Failed to write QNN context binary to file %s" , binary_file.c_str ());
712+ }
713+ fout.close ();
714+ }
715+
684716 return Error::Ok;
685717}
686718
You can’t perform that action at this time.
0 commit comments