Skip to content

Commit 71e1586

Browse files
author
zhouwg
committed
ggml-qnn: active member variable _device_id in class qnn_instance
1 parent 074ae26 commit 71e1586

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

ggml/src/ggml-qnn/ggml-qnn-impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ class qnn_instance {
498498
return _enable_qnn_rpc;
499499
}
500500

501+
QNNBackend get_device_id() {
502+
return _device_id;
503+
}
504+
501505
public:
502506
std::map<std::string, std::tuple<Qnn_GraphHandle_t, std::vector< Qnn_Tensor_t *>>> _qnn_graph_map;
503507

ggml/src/ggml-qnn/ggml-qnn-ops.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ void ggml_qnn_general_node(ggml_backend_qnn_context * ctx, ggml_tensor * op) {
118118

119119
if (!graph_initialized) {
120120
GGMLQNN_LOG_DEBUG("graph name %s", graph_name.c_str());
121+
GGML_ASSERT(instance->get_device_id() == ctx->device);
121122
error = instance->init_qnn_graph(graph_name, static_cast<QNNBackend>(ctx->device), 8);
122123
if (QNN_SUCCESS != error) {
123124
GGMLQNN_LOG_INFO("can't create qnn graph handle with graph name %s, error = %d\n", graph_name.c_str(), error);

ggml/src/ggml-qnn/ggml-qnn.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,17 @@ int qnn_instance::qnn_init(const QnnSaver_Config_t ** saver_config) {
17041704
}
17051705
}
17061706

1707+
_device_id = QNN_BACKEND_CPU;
1708+
if (_backend_name.find("QnnCpu") != std::string::npos) {
1709+
_device_id = QNN_BACKEND_CPU;
1710+
}
1711+
if (_backend_name.find("QnnGpu") != std::string::npos) {
1712+
_device_id = QNN_BACKEND_GPU;
1713+
}
1714+
if (_backend_name.find("QnnHtp") != std::string::npos) {
1715+
_device_id = QNN_BACKEND_NPU;
1716+
}
1717+
17071718
backend_id = _lib_path_to_backend_id[backend_lib_path];
17081719
if (0 == _loaded_backend.count(backend_id) ||
17091720
0 == _loaded_lib_handle.count(backend_id)) {

0 commit comments

Comments
 (0)