Skip to content

Commit

Permalink
move graph finalize into member function finalize()
Browse files Browse the repository at this point in the history
  • Loading branch information
chraac committed Dec 26, 2024
1 parent ac61c03 commit 0379619
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
48 changes: 24 additions & 24 deletions ggml/src/ggml-qnn/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,7 @@ bool qnn_graph::build_graph(ggml_tensor *op, const ggml_tensor_array_t &tensor_i
_tensor_inputs = operation->get_input_tensors();
_tensor_outputs = operation->get_output_tensors();
_operations.push_back(std::move(operation));
if (!qnn::add_op_to_graph(_graph_handle, _operations)) {
QNN_LOG_ERROR("[%s]add nodes failed", _graph_name.c_str());
return false;
}

auto error = _qnn_interface->qnn_graph_finalize(_graph_handle, nullptr, nullptr);
if (error != QNN_SUCCESS) {
QNN_LOG_ERROR("[%s][%s]qnn_graph_finalize.error: %s", get_backend_name(_device), _graph_name.c_str(),
get_qnn_error_string(error));
if (!finalize()) {
return false;
}

Expand Down Expand Up @@ -209,8 +201,8 @@ bool qnn_graph::build_graph_from_ggml_graph(const ggml_cgraph *cgraph) {

{
qnn_tensor_cache_t tensor_cache;
auto intput_tensors = create_tensors(input_set, ggml_qnn_tensor::INPUT, rank, _device, _graph_handle,
_qnn_instance, tensor_cache);
auto input_tensors = create_tensors(input_set, ggml_qnn_tensor::INPUT, rank, _device, _graph_handle,
_qnn_instance, tensor_cache);
auto output_tensors = create_tensors(output_set, ggml_qnn_tensor::OUTPUT, rank, _device, _graph_handle,
_qnn_instance, tensor_cache);
qnn_op_config_array_t operations;
Expand All @@ -226,21 +218,12 @@ bool qnn_graph::build_graph_from_ggml_graph(const ggml_cgraph *cgraph) {
operations.push_back(operation);
}

_tensor_inputs = std::move(intput_tensors);
_tensor_inputs = std::move(input_tensors);
_tensor_outputs = std::move(output_tensors);
_operations = std::move(operations);
}

if (!qnn::add_op_to_graph(_graph_handle, _operations)) {
QNN_LOG_ERROR("[%s]add nodes failed", _graph_name.c_str());
return false;
}

auto error = _qnn_interface->qnn_graph_finalize(_graph_handle, nullptr, nullptr);
if (error != QNN_SUCCESS) {
QNN_LOG_ERROR("[%s][%s]qnn_graph_finalize.error: %s", get_backend_name(_device), _graph_name.c_str(),
get_qnn_error_string(error));
return false;
if (!finalize()) {
return false;
}
}

QNN_LOG_DEBUG("[%s][%s]build_graph succeed", get_backend_name(_device), _graph_name.c_str());
Expand Down Expand Up @@ -281,4 +264,21 @@ bool qnn_graph::execute(const ggml_tensor_array_t &tensor_inputs, const ggml_ten
return true;
}

bool qnn_graph::finalize() {
if (!qnn::add_op_to_graph(_graph_handle, _operations)) {
QNN_LOG_ERROR("[%s]add nodes failed", _graph_name.c_str());
return false;
}

auto error = _qnn_interface->qnn_graph_finalize(_graph_handle, nullptr, nullptr);
if (error != QNN_SUCCESS) {
QNN_LOG_ERROR("[%s][%s]qnn_graph_finalize.error: %s", get_backend_name(_device), _graph_name.c_str(),
get_qnn_error_string(error));
return false;
}

QNN_LOG_DEBUG("[%s][%s]finalize succeed", get_backend_name(_device), _graph_name.c_str());
return true;
}

} // namespace qnn
2 changes: 2 additions & 0 deletions ggml/src/ggml-qnn/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class qnn_graph {
QNNBackend get_device() const { return _device; }

private:
bool finalize();

const std::string _graph_name;
const QNNBackend _device;
Qnn_GraphHandle_t _graph_handle = nullptr;
Expand Down

0 comments on commit 0379619

Please sign in to comment.