Skip to content

Commit d73d06b

Browse files
committed
Qualcomm AI Engine Direct - Support QNN 2.28
Note that if merged, QNN version less than 2.28 will not support it.
1 parent 97e0417 commit d73d06b

File tree

2 files changed

+73
-25
lines changed

2 files changed

+73
-25
lines changed

backends/qualcomm/runtime/backends/QnnBackendCache.cpp

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Error QnnBackendCache::GetQnnGraphInfoFromBinary() {
5151
} else if (binaryinfo->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_2) {
5252
num_graphs = binaryinfo->contextBinaryInfoV2.numGraphs;
5353
graph = binaryinfo->contextBinaryInfoV2.graphs;
54+
} else if (binaryinfo->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_3) {
55+
num_graphs = binaryinfo->contextBinaryInfoV3.numGraphs;
56+
graph = binaryinfo->contextBinaryInfoV3.graphs;
5457
} else {
5558
QNN_EXECUTORCH_LOG_WARN(
5659
"Unknown QNN BinaryInfo version %d.", binaryinfo->version);
@@ -65,28 +68,45 @@ Error QnnBackendCache::GetQnnGraphInfoFromBinary() {
6568
return Error::Internal;
6669
}
6770

68-
// only have version_1 now
69-
if (graph[0].version != QNN_SYSTEM_CONTEXT_GRAPH_INFO_VERSION_1) {
71+
if (graph[0].version == QNN_SYSTEM_CONTEXT_GRAPH_INFO_VERSION_1) {
72+
// get graph name from metadata
73+
graph_name_ = graph->graphInfoV1.graphName;
74+
75+
// get graph inputs from metadata
76+
uint32_t numGraphInputs = graph->graphInfoV1.numGraphInputs;
77+
input_tensor_structs_.reserve(numGraphInputs);
78+
for (std::uint32_t i = 0; i < numGraphInputs; ++i) {
79+
input_tensor_structs_.emplace_back(graph->graphInfoV1.graphInputs[i]);
80+
}
81+
82+
// get graph outputs from metadata
83+
uint32_t numGraphOutputs = graph->graphInfoV1.numGraphOutputs;
84+
output_tensor_structs_.reserve(numGraphOutputs);
85+
for (std::uint32_t i = 0; i < numGraphOutputs; ++i) {
86+
output_tensor_structs_.emplace_back(graph->graphInfoV1.graphOutputs[i]);
87+
}
88+
} else if (graph[0].version == QNN_SYSTEM_CONTEXT_GRAPH_INFO_VERSION_3) {
89+
// get graph name from metadata
90+
graph_name_ = graph->graphInfoV3.graphName;
91+
92+
// get graph inputs from metadata
93+
uint32_t numGraphInputs = graph->graphInfoV3.numGraphInputs;
94+
input_tensor_structs_.reserve(numGraphInputs);
95+
for (std::uint32_t i = 0; i < numGraphInputs; ++i) {
96+
input_tensor_structs_.emplace_back(graph->graphInfoV3.graphInputs[i]);
97+
}
98+
99+
// get graph outputs from metadata
100+
uint32_t numGraphOutputs = graph->graphInfoV3.numGraphOutputs;
101+
output_tensor_structs_.reserve(numGraphOutputs);
102+
for (std::uint32_t i = 0; i < numGraphOutputs; ++i) {
103+
output_tensor_structs_.emplace_back(graph->graphInfoV3.graphOutputs[i]);
104+
}
105+
} else {
70106
QNN_EXECUTORCH_LOG_WARN(
71107
"Unknown QNN GraphInfo version %d.", graph[0].version);
72108
return Error::Internal;
73109
}
74-
// get graph name from metadata
75-
graph_name_ = graph->graphInfoV1.graphName;
76-
77-
// get graph inputs from metadata
78-
uint32_t numGraphInputs = graph->graphInfoV1.numGraphInputs;
79-
input_tensor_structs_.reserve(numGraphInputs);
80-
for (std::uint32_t i = 0; i < numGraphInputs; ++i) {
81-
input_tensor_structs_.emplace_back(graph->graphInfoV1.graphInputs[i]);
82-
}
83-
84-
// get graph outputs from metadata
85-
uint32_t numGraphOutputs = graph->graphInfoV1.numGraphOutputs;
86-
output_tensor_structs_.reserve(numGraphOutputs);
87-
for (std::uint32_t i = 0; i < numGraphOutputs; ++i) {
88-
output_tensor_structs_.emplace_back(graph->graphInfoV1.graphOutputs[i]);
89-
}
90110

91111
return Error::Ok;
92112
}

backends/qualcomm/runtime/backends/htpbackend/HtpBackendCache.cpp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,61 @@ using executorch::runtime::Error;
1717
Error HtpBackendCache::RetrieveBackendBinaryInfo(
1818
const QnnSystemContext_BinaryInfo_t* binaryinfo) {
1919
QnnHtpSystemContext_HwBlobInfo_t* htp_hwblobinfo = nullptr;
20+
QnnHtpSystemContext_GraphBlobInfo_t* htp_graphblobinfo = nullptr;
2021

2122
if (binaryinfo->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_1) {
2223
htp_hwblobinfo = static_cast<QnnHtpSystemContext_HwBlobInfo_t*>(
2324
binaryinfo->contextBinaryInfoV1.hwInfoBlob);
2425
} else if (binaryinfo->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_2) {
2526
htp_hwblobinfo = static_cast<QnnHtpSystemContext_HwBlobInfo_t*>(
2627
binaryinfo->contextBinaryInfoV2.hwInfoBlob);
28+
} else if (binaryinfo->version == QNN_SYSTEM_CONTEXT_BINARY_INFO_VERSION_3) {
29+
if (binaryinfo->contextBinaryInfoV3.numGraphs > 1) {
30+
QNN_EXECUTORCH_LOG_WARN(
31+
"The context binary contains %lu graphs. But now "
32+
"assume that one context binary contains one graph.",
33+
binaryinfo->contextBinaryInfoV3.numGraphs);
34+
return Error::Internal;
35+
}
36+
htp_graphblobinfo = static_cast<QnnHtpSystemContext_GraphBlobInfo_t*>(
37+
binaryinfo->contextBinaryInfoV3.graphs->graphInfoV3.graphBlobInfo);
2738
} else {
2839
QNN_EXECUTORCH_LOG_WARN(
2940
"Unknown QNN BinaryInfo version %d.", binaryinfo->version);
3041
return Error::Internal;
3142
}
3243

33-
if (htp_hwblobinfo == nullptr) {
44+
if (htp_hwblobinfo) {
45+
if (htp_hwblobinfo->version ==
46+
QNN_SYSTEM_CONTEXT_HTP_HW_INFO_BLOB_VERSION_V1) {
47+
spill_fill_buf_ =
48+
(*htp_hwblobinfo).contextBinaryHwInfoBlobV1_t.spillFillBufferSize;
49+
} else {
50+
QNN_EXECUTORCH_LOG_WARN(
51+
"Unknown QNN Htp hw blob info version %d.", htp_hwblobinfo->version);
52+
return Error::Internal;
53+
}
54+
} else {
3455
QNN_EXECUTORCH_LOG_WARN(
3556
"Htp hardware blob information is not found in binary information.");
3657
return Error::Ok;
3758
}
3859

39-
if (htp_hwblobinfo->version ==
40-
QNN_SYSTEM_CONTEXT_HTP_HW_INFO_BLOB_VERSION_V1) {
41-
spill_fill_buf_ =
42-
(*htp_hwblobinfo).contextBinaryHwInfoBlobV1_t.spillFillBufferSize;
60+
if (htp_graphblobinfo) {
61+
if (htp_graphblobinfo->version ==
62+
QNN_SYSTEM_CONTEXT_HTP_GRAPH_INFO_BLOB_VERSION_V1) {
63+
spill_fill_buf_ =
64+
(*htp_graphblobinfo).contextBinaryGraphBlobInfoV1.spillFillBufferSize;
65+
} else {
66+
QNN_EXECUTORCH_LOG_WARN(
67+
"Unknown QNN Htp graph blob info version %d.",
68+
htp_graphblobinfo->version);
69+
return Error::Internal;
70+
}
4371
} else {
4472
QNN_EXECUTORCH_LOG_WARN(
45-
"Unknown QNN Htp hw blob info version %d.", htp_hwblobinfo->version);
46-
return Error::Internal;
73+
"Htp graph blob information is not found in binary information.");
74+
return Error::Ok;
4775
}
4876

4977
return Error::Ok;

0 commit comments

Comments
 (0)