Skip to content

Commit 40d7e7d

Browse files
hexagon: explicitly check for ops with zero nrows
llm_graph_context::build_inp_out_ids() can generate tensors with zero nrows. Somehow other backends seems to handle this without obvious explicit checks. In the hexagon case we need to check explicitly and skip them.
1 parent ece0f5c commit 40d7e7d

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,26 +3156,28 @@ static inline bool op_reuse_src1(const ggml_tensor * op1, const ggml_tensor * op
31563156
return (op0 && op0->src[1] == op1->src[1]);
31573157
}
31583158

3159+
static inline bool is_compute_op(ggml_tensor *node)
3160+
{
3161+
switch (node->op) {
3162+
case GGML_OP_NONE:
3163+
case GGML_OP_RESHAPE:
3164+
case GGML_OP_VIEW:
3165+
case GGML_OP_PERMUTE:
3166+
case GGML_OP_TRANSPOSE:
3167+
return false;
3168+
default:
3169+
break;
3170+
}
3171+
3172+
return ggml_nrows(node) != 0;
3173+
}
3174+
31593175
// scan the graph and figure out last compute op index
31603176
static inline int last_compute_op(ggml_cgraph * graph) {
3161-
int last;
3177+
int last = 0;
31623178
for (int i = 0; i < graph->n_nodes; ++i) {
3163-
ggml_tensor * node = graph->nodes[i];
3164-
3165-
switch (node->op) {
3166-
case GGML_OP_MUL_MAT:
3167-
case GGML_OP_MUL_MAT_ID:
3168-
case GGML_OP_MUL:
3169-
case GGML_OP_ADD:
3170-
case GGML_OP_SUB:
3171-
case GGML_OP_RMS_NORM:
3172-
case GGML_OP_GLU:
3173-
case GGML_OP_ADD_ID:
3174-
last = i;
3175-
break;
3176-
3177-
default:
3178-
break;
3179+
if (is_compute_op(graph->nodes[i])) {
3180+
last = i;
31793181
}
31803182
}
31813183

@@ -3194,6 +3196,10 @@ static ggml_status ggml_backend_hexagon_graph_compute(ggml_backend_t backend, gg
31943196
for (int i = 0; i < graph->n_nodes; ++i) {
31953197
ggml_tensor * node = graph->nodes[i];
31963198

3199+
if (!is_compute_op(node)) {
3200+
continue;
3201+
}
3202+
31973203
uint32_t flags = 0;
31983204

31993205
// skip quantizer if src1 is reused
@@ -3245,14 +3251,6 @@ static ggml_status ggml_backend_hexagon_graph_compute(ggml_backend_t backend, gg
32453251
ggml_hexagon_rope(node, flags);
32463252
break;
32473253

3248-
// non-compute ops
3249-
case GGML_OP_NONE:
3250-
case GGML_OP_RESHAPE:
3251-
case GGML_OP_VIEW:
3252-
case GGML_OP_PERMUTE:
3253-
case GGML_OP_TRANSPOSE:
3254-
break;
3255-
32563254
default:
32573255
GGML_ABORT("\nggml-hex: graph-compute %s is not supported\n", ggml_op_desc(node));
32583256
}

0 commit comments

Comments
 (0)