Skip to content

Commit 8468fa7

Browse files
committed
rebase QNN IR PR
1 parent 3624778 commit 8468fa7

File tree

8 files changed

+17
-144
lines changed

8 files changed

+17
-144
lines changed

backends/qualcomm/CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ target_link_libraries(qnn_executorch_logging PRIVATE qnn_schema)
153153
target_link_libraries(qnn_profiler PRIVATE qnn_executorch_logging)
154154
target_link_libraries(qnn_logger PRIVATE qnn_implementation ${android_log})
155155
target_link_libraries(qnn_backend PRIVATE qnn_implementation qnn_logger)
156-
target_link_libraries(qnn_custom_protocol PRIVATE qcir_utils)
156+
target_link_libraries(qnn_custom_protocol PRIVATE qnn_logger)
157157
target_link_libraries(
158158
qnn_device PRIVATE qnn_executorch_logging qnn_implementation qnn_logger
159159
)
160160
target_link_libraries(
161-
qnn_backend_cache PRIVATE qnn_sys_implementation qcir_utils
161+
qnn_backend_cache PRIVATE qnn_sys_implementation
162162
)
163163
target_link_libraries(
164164
qnn_context PRIVATE qnn_implementation qnn_logger qnn_backend qnn_device
@@ -184,7 +184,7 @@ target_link_libraries(
184184
)
185185
target_link_libraries(
186186
qnn_executorch_backend PRIVATE qnn_executorch_header qnn_schema qnn_manager
187-
executorch_core qcir_utils extension_tensor
187+
executorch_core extension_tensor
188188
)
189189
set_target_properties(
190190
qnn_executorch_backend PROPERTIES LINK_FLAGS "-Wl,-rpath='$ORIGIN'"
@@ -243,7 +243,6 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
243243
qnn_manager
244244
qnn_executorch_header
245245
executorch
246-
qcir_utils
247246
extension_tensor
248247
)
249248
target_link_libraries(

backends/qualcomm/aot/python/PyQnnManagerAdaptor.h

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88
#pragma once
9-
#include <executorch/backends/qualcomm/aot/ir/qcir_utils.h>
109
#include <executorch/backends/qualcomm/aot/python/PyQnnWrapperAdaptor.h>
1110
#include <executorch/backends/qualcomm/qc_compiler_spec_generated.h>
1211
#include <executorch/backends/qualcomm/runtime/Logging.h>

backends/qualcomm/runtime/QnnManager.cpp

-121
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <executorch/backends/qualcomm/aot/ir/qcir_utils.h>
109
#include <executorch/backends/qualcomm/runtime/QnnManager.h>
1110
#include <executorch/backends/qualcomm/runtime/SharedBuffer.h>
1211
#include <executorch/backends/qualcomm/runtime/Utils.h>
@@ -572,126 +571,6 @@ Error QnnManager::CompileDlc() {
572571
return Error::Ok;
573572
}
574573

575-
Error QnnManager::CompileQcir() {
576-
QnnQcirCustomProtocol qnn_qcir_custom_protocol;
577-
auto [status, qcir_fbs_size, tensor_size, qcir_fbs_ptr, tensor_ptr] =
578-
qnn_qcir_custom_protocol.DeserializeQcirCustomBuffer(
579-
qnn_context_blob_.buffer);
580-
581-
if (status != Error::Ok) {
582-
QNN_EXECUTORCH_LOG_ERROR("Failed to verify QnnQcirCustomProtocol");
583-
return Error::Internal;
584-
}
585-
586-
auto context = qcir::GetContext(qcir_fbs_ptr);
587-
for (const auto& graph : *context->graphs()) {
588-
// qcir tensors to TensorWrapper
589-
std::vector<std::shared_ptr<TensorWrapper>> graph_inputs, graph_outputs,
590-
tensors;
591-
for (const auto& tensor : *graph->tensors()) {
592-
tensors.emplace_back(CreateTensorWrapper(ToTensor(
593-
tensor, static_cast<uint8_t*>(tensor_ptr) + tensor->offset())));
594-
if (tensor->type() == qcir::TensorType::WRITE) {
595-
graph_inputs.push_back(tensors.back());
596-
} else if (tensor->type() == qcir::TensorType::READ) {
597-
graph_outputs.push_back(tensors.back());
598-
}
599-
}
600-
std::vector<std::shared_ptr<OpWrapper>> op_wrappers;
601-
// qcir graph node to OpWrapper
602-
for (const auto& node : *graph->nodes()) {
603-
std::shared_ptr<OpWrapper> op = std::make_shared<OpWrapper>(
604-
node->name()->str(),
605-
node->package_name()->str(),
606-
node->type_name()->str());
607-
608-
// qcir input tensors to OpWrapper input tensors
609-
std::vector<std::shared_ptr<TensorWrapper>> inputs;
610-
for (uint32_t index : *node->inputs()) {
611-
inputs.push_back(tensors[index]);
612-
}
613-
op->AddInputTensors(inputs);
614-
615-
// qcir output tensors to OpWrapper output tensors
616-
std::vector<std::shared_ptr<TensorWrapper>> outputs;
617-
for (uint32_t index : *node->outputs()) {
618-
outputs.push_back(tensors[index]);
619-
}
620-
op->AddOutputTensors(outputs);
621-
622-
// qcir operator param to OpWrapper param
623-
for (uint32_t index : *node->params()) {
624-
const auto& tensor = graph->tensors()->Get(index);
625-
std::string name = tensor->name()->str();
626-
Qnn_DataType_t dtype = ToDataType(tensor->dtype());
627-
const uint8_t* data_ptr =
628-
static_cast<uint8_t*>(tensor_ptr) + tensor->offset();
629-
if (tensor->shape()->size() != 0) {
630-
// add tensor param
631-
op->AddTensorParam(
632-
name,
633-
dtype,
634-
tensor->shape()->size(),
635-
tensor->shape()->data(),
636-
data_ptr);
637-
} else {
638-
// add scalar param
639-
switch (dtype) {
640-
case Qnn_DataType_t::QNN_DATATYPE_INT_32:
641-
op->AddScalarParam(
642-
name, dtype, *reinterpret_cast<const int32_t*>(data_ptr));
643-
break;
644-
case Qnn_DataType_t::QNN_DATATYPE_INT_16:
645-
op->AddScalarParam(
646-
name, dtype, *reinterpret_cast<const int16_t*>(data_ptr));
647-
break;
648-
case Qnn_DataType_t::QNN_DATATYPE_INT_8:
649-
op->AddScalarParam(name, dtype, static_cast<int8_t>(*data_ptr));
650-
break;
651-
case Qnn_DataType_t::QNN_DATATYPE_UINT_32:
652-
op->AddScalarParam(
653-
name, dtype, *reinterpret_cast<const uint32_t*>(data_ptr));
654-
break;
655-
case Qnn_DataType_t::QNN_DATATYPE_UINT_16:
656-
op->AddScalarParam(
657-
name, dtype, *reinterpret_cast<const uint16_t*>(data_ptr));
658-
break;
659-
case Qnn_DataType_t::QNN_DATATYPE_UINT_8:
660-
op->AddScalarParam(name, dtype, *data_ptr);
661-
break;
662-
case Qnn_DataType_t::QNN_DATATYPE_FLOAT_32:
663-
case Qnn_DataType_t::QNN_DATATYPE_FLOAT_16:
664-
op->AddScalarParam(
665-
name, dtype, *reinterpret_cast<const float*>(data_ptr));
666-
break;
667-
case Qnn_DataType_t::QNN_DATATYPE_BOOL_8:
668-
op->AddScalarParam(name, dtype, *data_ptr);
669-
break;
670-
default:
671-
QNN_EXECUTORCH_LOG_ERROR(
672-
"Invalid scalar type: %s", tensor->name()->c_str());
673-
break;
674-
}
675-
}
676-
}
677-
op_wrappers.emplace_back(std::move(op));
678-
}
679-
ET_CHECK_OR_RETURN_ERROR(
680-
Compile(graph->name()->str(), op_wrappers) == Error::Ok,
681-
Internal,
682-
"Fail to compile graph from qcir with graph_name: %s",
683-
graph->name()->str().c_str());
684-
ET_CHECK_OR_RETURN_ERROR(
685-
AllocateTensor(graph->name()->str(), graph_inputs, graph_outputs) ==
686-
Error::Ok,
687-
Internal,
688-
"Fail to allocate tensor for qcir with graph_name: %s",
689-
graph->name()->str().c_str());
690-
}
691-
692-
return Error::Ok;
693-
}
694-
695574
Error QnnManager::Compile(
696575
const std::string& graph_name,
697576
std::vector<std::shared_ptr<OpWrapper>>& op_wrappers) {

backends/qualcomm/runtime/QnnManager.h

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class QnnManager {
6767
executorch::runtime::Error GetContextBinary(
6868
QnnExecuTorchContextBinary& qnn_executorch_context_binary);
6969

70-
executorch::runtime::Error CompileQcir();
7170
executorch::runtime::Error CompileDlc();
7271
executorch::runtime::Error Compile(
7372
const std::string& graph_name,

backends/qualcomm/runtime/backends/QnnBackendCache.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <executorch/backends/qualcomm/aot/ir/qcir_utils.h>
109
#include <executorch/backends/qualcomm/runtime/backends/QnnBackendCache.h>
1110
#include <executorch/backends/qualcomm/runtime/backends/QnnCustomProtocol.h>
1211
namespace executorch {
@@ -129,18 +128,6 @@ Error QnnBackendCache::Configure(const std::vector<std::string>& graph_names) {
129128
qnn_context_blob_.nbytes);
130129

131130
if (status == Error::Internal) {
132-
auto [status, qcir_fbs_size, _, qcir_fbs_ptr, __] =
133-
QnnQcirCustomProtocol().DeserializeQcirCustomBuffer(
134-
qnn_context_blob_.buffer);
135-
if (status == Error::Ok) {
136-
// first stage of multi graph
137-
state_ = MULTI_GRAPH;
138-
auto context = qcir::GetContext(qcir_fbs_ptr);
139-
for (const auto& graph : *context->graphs()) {
140-
graph_names_.emplace_back(graph->name()->str());
141-
}
142-
return Error::Ok;
143-
}
144131
// online prepare
145132
state_ = ONLINE_PREPARE;
146133
}

backends/qualcomm/runtime/backends/QnnCustomProtocol.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <executorch/backends/qualcomm/aot/ir/qcir_utils.h>
109
#include <executorch/backends/qualcomm/runtime/backends/QnnCustomProtocol.h>
1110

1211
namespace executorch {
1312
namespace backends {
1413
namespace qnn {
1514

15+
// we still need this for on-device op validation of other backends
1616
void QnnQcirCustomProtocol::BuildQcirCustomBuffer(
1717
const QnnExecuTorchContextBinary& qcir_binary,
1818
const std::vector<uint8_t>& tensor_data) {

backends/qualcomm/runtime/backends/irbackend/x86_64/QnnDlcManager.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ Error QnnDlcManager::Create() {
4141
std::make_unique<QnnDevice>(qnn_loaded_backend_, logger_.get());
4242

4343
backend_params_ptr_->qnn_backend_cache_ptr_ =
44-
std::make_unique<QnnBackendCache>(
45-
qnn_context_blob_, options_->graph_name()->str());
44+
std::make_unique<QnnBackendCache>(qnn_context_blob_);
4645

4746
backend_params_ptr_->qnn_context_ptr_ = std::make_unique<IrContext>(
4847
qnn_loaded_backend_,
@@ -64,8 +63,13 @@ Error QnnDlcManager::Create() {
6463
Error QnnDlcManager::Configure() {
6564
ET_CHECK_OR_RETURN_ERROR(
6665
backend_params_ptr_ != nullptr, Internal, "Failed to load Qnn backend.");
66+
std::vector<std::string> graph_names;
67+
for (auto name : *options_->graph_name()) {
68+
graph_names.emplace_back(name->str());
69+
}
6770
ET_CHECK_OR_RETURN_ERROR(
68-
backend_params_ptr_->qnn_backend_cache_ptr_->Configure() == Error::Ok,
71+
backend_params_ptr_->qnn_backend_cache_ptr_->Configure(graph_names) ==
72+
Error::Ok,
6973
Internal,
7074
"Fail to configure Qnn backend cache");
7175
ET_CHECK_OR_RETURN_ERROR(

backends/qualcomm/tests/test_qnn_delegate.py

+6
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,9 @@ def test_qnn_backend_shared_buffer(self):
25352535
)
25362536

25372537
def test_qnn_backend_online_prepare(self):
2538+
if self.enable_x86_64:
2539+
self.skipTest("TODO: add online_prepare support on host platform")
2540+
25382541
backend_options = generate_htp_compiler_spec(use_fp16=True)
25392542
TestQNN.compiler_specs = generate_qnn_executorch_compiler_spec(
25402543
soc_model=self.chipset_table[TestQNN.model],
@@ -3187,6 +3190,9 @@ def test_qnn_backend_shared_buffer(self):
31873190
)
31883191

31893192
def test_qnn_backend_online_prepare(self):
3193+
if self.enable_x86_64:
3194+
self.skipTest("TODO: add online_prepare support on host platform")
3195+
31903196
backend_options = generate_htp_compiler_spec(use_fp16=False)
31913197
TestQNN.compiler_specs = generate_qnn_executorch_compiler_spec(
31923198
soc_model=self.chipset_table[TestQNN.model],

0 commit comments

Comments
 (0)