Backward compatible with old QNN version (#23095)

### Description
Make QNN EP compliable with old QNN version
This commit is contained in:
Hector Li 2024-12-12 17:04:20 -08:00 committed by GitHub
parent 01539ee7ab
commit f43f40facf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 24 deletions

View file

@ -619,6 +619,9 @@ std::unique_ptr<unsigned char[]> QnnBackendManager::GetContextBinaryBuffer(uint6
Status QnnBackendManager::GetMaxSpillFillBufferSize(unsigned char* buffer,
uint64_t buffer_length,
uint64_t& max_spill_fill_buffer_size) {
max_spill_fill_buffer_size = 0;
// spill fill starts from 2.28
#if QNN_API_VERSION_MAJOR == 2 && (QNN_API_VERSION_MINOR >= 21)
bool result = nullptr == qnn_sys_interface_.systemContextCreate ||
nullptr == qnn_sys_interface_.systemContextGetBinaryInfo ||
nullptr == qnn_sys_interface_.systemContextFree;
@ -672,6 +675,10 @@ Status QnnBackendManager::GetMaxSpillFillBufferSize(unsigned char* buffer,
LOGS(*logger_, VERBOSE) << "Unknown context binary graph info version.";
}
}
#else
ORT_UNUSED_PARAMETER(buffer);
ORT_UNUSED_PARAMETER(buffer_length);
#endif
LOGS(*logger_, VERBOSE) << "Get max spill fill buffer size completed.";
return Status::OK();
@ -705,16 +712,23 @@ Status QnnBackendManager::LoadCachedQnnContextFromBuffer(char* buffer, uint64_t
ORT_RETURN_IF(nullptr == binary_info, "Qnn cached binary info is nullptr.");
uint32_t graph_count = 0;
QnnSystemContext_GraphInfo_t* graphs_info = nullptr;
if (binary_info->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_3) {
graph_count = binary_info->contextBinaryInfoV3.numGraphs;
graphs_info = binary_info->contextBinaryInfoV3.graphs;
} else if (binary_info->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_2) {
graph_count = binary_info->contextBinaryInfoV2.numGraphs;
graphs_info = binary_info->contextBinaryInfoV2.graphs;
} else if (binary_info->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_1) {
if (binary_info->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_1) {
graph_count = binary_info->contextBinaryInfoV1.numGraphs;
graphs_info = binary_info->contextBinaryInfoV1.graphs;
} else {
}
#if QNN_API_VERSION_MAJOR == 2 && (QNN_API_VERSION_MINOR >= 15) // starts from 2.22
else if (binary_info->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_2) {
graph_count = binary_info->contextBinaryInfoV2.numGraphs;
graphs_info = binary_info->contextBinaryInfoV2.graphs;
}
#endif
#if QNN_API_VERSION_MAJOR == 2 && (QNN_API_VERSION_MINOR >= 21) // starts from 2.28
else if (binary_info->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_3) {
graph_count = binary_info->contextBinaryInfoV3.numGraphs;
graphs_info = binary_info->contextBinaryInfoV3.graphs;
}
#endif
else {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Unsupported context binary info version.");
}

View file

@ -325,28 +325,35 @@ Status QnnModel::DeserializeGraphInfoFromBinaryInfo(const QnnSystemContext_Graph
Qnn_Tensor_t* output_tensors = nullptr;
uint32_t graph_input_num = 0;
uint32_t graph_output_num = 0;
if (qnn_sys_ctx_graph_info.version == QNN_SYSTEM_CONTEXT_GRAPH_INFO_VERSION_3) {
graph_name.assign(qnn_sys_ctx_graph_info.graphInfoV3.graphName);
graph_input_num = qnn_sys_ctx_graph_info.graphInfoV3.numGraphInputs;
graph_output_num = qnn_sys_ctx_graph_info.graphInfoV3.numGraphOutputs;
input_tensors = qnn_sys_ctx_graph_info.graphInfoV3.graphInputs;
output_tensors = qnn_sys_ctx_graph_info.graphInfoV3.graphOutputs;
} else if (qnn_sys_ctx_graph_info.version == QNN_SYSTEM_CONTEXT_GRAPH_INFO_VERSION_2) {
graph_name.assign(qnn_sys_ctx_graph_info.graphInfoV2.graphName);
graph_input_num = qnn_sys_ctx_graph_info.graphInfoV2.numGraphInputs;
graph_output_num = qnn_sys_ctx_graph_info.graphInfoV2.numGraphOutputs;
input_tensors = qnn_sys_ctx_graph_info.graphInfoV2.graphInputs;
output_tensors = qnn_sys_ctx_graph_info.graphInfoV2.graphOutputs;
} else if (qnn_sys_ctx_graph_info.version == QNN_SYSTEM_CONTEXT_GRAPH_INFO_VERSION_1) {
if (qnn_sys_ctx_graph_info.version == QNN_SYSTEM_CONTEXT_GRAPH_INFO_VERSION_1) {
graph_name.assign(qnn_sys_ctx_graph_info.graphInfoV1.graphName);
graph_input_num = qnn_sys_ctx_graph_info.graphInfoV1.numGraphInputs;
graph_output_num = qnn_sys_ctx_graph_info.graphInfoV1.numGraphOutputs;
input_tensors = qnn_sys_ctx_graph_info.graphInfoV1.graphInputs;
output_tensors = qnn_sys_ctx_graph_info.graphInfoV1.graphOutputs;
} else {
}
#if QNN_API_VERSION_MAJOR == 2 && (QNN_API_VERSION_MINOR >= 18) // start from 2.25
else if (qnn_sys_ctx_graph_info.version == QNN_SYSTEM_CONTEXT_GRAPH_INFO_VERSION_2) {
graph_name.assign(qnn_sys_ctx_graph_info.graphInfoV2.graphName);
graph_input_num = qnn_sys_ctx_graph_info.graphInfoV2.numGraphInputs;
graph_output_num = qnn_sys_ctx_graph_info.graphInfoV2.numGraphOutputs;
input_tensors = qnn_sys_ctx_graph_info.graphInfoV2.graphInputs;
output_tensors = qnn_sys_ctx_graph_info.graphInfoV2.graphOutputs;
}
#endif
#if QNN_API_VERSION_MAJOR == 2 && (QNN_API_VERSION_MINOR >= 21) // start from 2.28
else if (qnn_sys_ctx_graph_info.version == QNN_SYSTEM_CONTEXT_GRAPH_INFO_VERSION_3) {
graph_name.assign(qnn_sys_ctx_graph_info.graphInfoV3.graphName);
graph_input_num = qnn_sys_ctx_graph_info.graphInfoV3.numGraphInputs;
graph_output_num = qnn_sys_ctx_graph_info.graphInfoV3.numGraphOutputs;
input_tensors = qnn_sys_ctx_graph_info.graphInfoV3.graphInputs;
output_tensors = qnn_sys_ctx_graph_info.graphInfoV3.graphOutputs;
}
#endif
else {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Unsupported context graph info version.");
}
ORT_RETURN_IF(nullptr == input_tensors, "Graph from cached context doesn't have any inputs.");