Skip to content

Commit 3e24d02

Browse files
Nexesenexikawrakow
andcommitted
Skip barriers of noops
picked from ik_llama.cpp, a llama_cpp fork maintained by Iwan Kawrakow Co-Authored-By: Kawrakow <[email protected]>
1 parent 6ccc073 commit 3e24d02

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ggml/include/ggml.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,12 @@ extern "C" {
734734
GGML_API const char * ggml_op_name (enum ggml_op op);
735735
GGML_API const char * ggml_op_symbol(enum ggml_op op);
736736

737+
738+
GGML_API const char * ggml_unary_op_name(enum ggml_unary_op op);
739+
GGML_API const char * ggml_op_desc(const struct ggml_tensor * t); // unary or op name
740+
741+
GGML_API bool ggml_is_noop(const struct ggml_tensor * tensor);
742+
737743
GGML_API const char * ggml_unary_op_name(enum ggml_unary_op op);
738744
GGML_API const char * ggml_op_desc(const struct ggml_tensor * t); // unary or op name
739745

ggml/src/ggml.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3773,6 +3773,12 @@ bool ggml_is_empty(const struct ggml_tensor * tensor) {
37733773
return false;
37743774
}
37753775

3776+
bool ggml_is_noop(const struct ggml_tensor * tensor) {
3777+
return tensor->op == GGML_OP_NONE || tensor->op == GGML_OP_RESHAPE ||
3778+
tensor->op == GGML_OP_VIEW || tensor->op == GGML_OP_PERMUTE || tensor->op == GGML_OP_TRANSPOSE ||
3779+
ggml_is_empty(tensor) ? true : false;
3780+
}
3781+
37763782
bool ggml_are_same_shape(const struct ggml_tensor * t0, const struct ggml_tensor * t1) {
37773783
static_assert(GGML_MAX_DIMS == 4, "GGML_MAX_DIMS is not 4 - update this function");
37783784

@@ -20035,6 +20041,8 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
2003520041
for (int node_n = 0; node_n < cgraph->n_nodes && !tp->abort; node_n++) {
2003620042
struct ggml_tensor * node = cgraph->nodes[node_n];
2003720043

20044+
if (ggml_is_noop(node)) continue;
20045+
2003820046
ggml_compute_forward(&params, node);
2003920047

2004020048
if (state->ith == 0 && cplan->abort_callback &&

0 commit comments

Comments
 (0)