Skip to content

Commit bc43463

Browse files
hex-fusion: move tensor fusion tagging to graph_compute
1 parent 5adb09e commit bc43463

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

ggml/src/ggml-hexagon/ggml-hexagon.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4680,6 +4680,21 @@ static ggml_status ggml_backend_hexagon_graph_compute(ggml_backend_t backend, gg
46804680
if (cache_hit) {
46814681
nodes_ptr = &sess->cached_nodes;
46824682
} else {
4683+
// Tag fusable tensors in graph
4684+
for (int i = 0; i < graph->n_nodes; i++) {
4685+
auto * extra = (ggml_hexagon_tensor_extra *) graph->nodes[i]->extra;
4686+
if (!extra) continue;
4687+
4688+
if (graph->nodes[i]->op == GGML_OP_RMS_NORM && ggml_can_fuse(graph, i, { GGML_OP_RMS_NORM, GGML_OP_MUL })) {
4689+
extra->flags |= GGML_HEXAGON_TENSOR_FUSEABLE;
4690+
} else if (graph->nodes[i]->op == GGML_OP_MUL_MAT) {
4691+
if ((i + 1 < graph->n_nodes && graph->nodes[i + 1]->op == GGML_OP_ADD && ggml_can_fuse(graph, i, { GGML_OP_MUL_MAT, GGML_OP_ADD })) ||
4692+
ggml_node_has_n_uses(graph, i, 1)) {
4693+
extra->flags |= GGML_HEXAGON_TENSOR_FUSEABLE;
4694+
}
4695+
}
4696+
}
4697+
46834698
computed_nodes.reserve(graph->n_nodes);
46844699

46854700
for (int i = 0; i < graph->n_nodes; ++i) {
@@ -4915,21 +4930,6 @@ static void ggml_backend_hexagon_graph_optimize(ggml_backend_t backend, ggml_cgr
49154930
std::vector<htp_opnode> nodes;
49164931
nodes.reserve(gf->n_nodes);
49174932

4918-
// Tag fusable tensors
4919-
for (int i = 0; i < n; i++) {
4920-
auto * extra = (ggml_hexagon_tensor_extra *) gf->nodes[i]->extra;
4921-
if (!extra) continue;
4922-
4923-
if (gf->nodes[i]->op == GGML_OP_RMS_NORM && ggml_can_fuse(gf, i, { GGML_OP_RMS_NORM, GGML_OP_MUL })) {
4924-
extra->flags |= GGML_HEXAGON_TENSOR_FUSEABLE;
4925-
} else if (gf->nodes[i]->op == GGML_OP_MUL_MAT) {
4926-
if ((i + 1 < n && gf->nodes[i + 1]->op == GGML_OP_ADD && ggml_can_fuse(gf, i, { GGML_OP_MUL_MAT, GGML_OP_ADD })) ||
4927-
ggml_node_has_n_uses(gf, i, 1)) {
4928-
extra->flags |= GGML_HEXAGON_TENSOR_FUSEABLE;
4929-
}
4930-
}
4931-
}
4932-
49334933
// Pack nodes for reordering
49344934
for (int i = 0; i < n; i++) {
49354935
htp_opnode node(HTP_OP_INVALID, gf->nodes[i]);

0 commit comments

Comments
 (0)