Skip to content

Commit

Permalink
Update QnnSampleApp.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: quic-zhanweiw <[email protected]>
  • Loading branch information
quic-zhanweiw authored Sep 16, 2024
1 parent 83fc01e commit ffc9798
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/QnnSampleApp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//==============================================================================
//==============================================================================
//
// Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
//
Expand Down Expand Up @@ -817,6 +817,32 @@ sample_app::StatusCode sample_app::QnnSampleApp::executeGraphs() {
return returnStatus;
}

// #define DEBUG_INFERENCE 1
#ifdef DEBUG_INFERENCE

#define BUFSIZE (256)

void bufferToFile(std::vector<uint8_t*>& buffers, std::vector<size_t>& size, std::string& data_name) {
char data_path[BUFSIZE];

QNN_DEBUG("Dump input data, input count = %d", size.size());

for (int i = 0; i < size.size(); i++) {
QNN_DEBUG("Dump input data, size = %d", size[i]);

sprintf_s(data_path, BUFSIZE, data_name.c_str(), i);
std::ofstream os(data_path, std::ofstream::binary);
if (!os) {
QNN_ERR("Failed to open file for writing: %s", data_path);
}
else {
os.write(reinterpret_cast<char*>(&(*(buffers[i]))), size[i]);
}
os.close();
}
}
#endif

sample_app::StatusCode sample_app::QnnSampleApp::executeGraphsBuffers(std::vector<uint8_t*>& inputBuffers,
std::vector<uint8_t*>& outputBuffers, std::vector<size_t>& outputSize,
std::string perfProfile) {
Expand Down Expand Up @@ -863,6 +889,13 @@ sample_app::StatusCode sample_app::QnnSampleApp::executeGraphsBuffers(std::vecto
returnStatus = StatusCode::FAILURE;
}

#ifdef DEBUG_INFERENCE
std::vector<size_t> inputSize;
m_ioTensor.getTensorsSize(&inputs, (*m_graphsInfo)[graphIdx].numInputTensors, (*m_graphsInfo)[graphIdx].inputTensors, inputSize);
std::string data_name = "input_%d.raw";
bufferToFile(inputBuffers, inputSize, data_name);
#endif

if (StatusCode::SUCCESS == returnStatus) {
QNN_DEBUG("Successfully populated input tensors for graphIdx: %d", graphIdx);
Qnn_ErrorHandle_t executeStatus = QNN_GRAPH_NO_ERROR;
Expand Down Expand Up @@ -948,6 +981,11 @@ sample_app::StatusCode sample_app::QnnSampleApp::executeGraphsBuffers(std::vecto
}
}
// QNN_ERROR("output buffer size: %d\n", outputBuffers.size());

#ifdef DEBUG_INFERENCE
std::string data_name = "output_%d.raw";
bufferToFile(outputBuffers, outputSize, data_name);
#endif
}
}
if (StatusCode::SUCCESS != returnStatus) {
Expand Down

0 comments on commit ffc9798

Please sign in to comment.