From fe3089c2004ca1644163348cdc6706ccb6d3b961 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sat, 20 Sep 2025 12:08:56 +0300 Subject: [PATCH 1/2] ggml : add ggml_op_is_empty --- ggml/include/ggml.h | 7 ++++--- ggml/src/ggml-metal/ggml-metal-common.cpp | 18 ++---------------- ggml/src/ggml.c | 13 +++++++++++++ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h index 36b23dc6d0d82..c60d70f27c8ff 100644 --- a/ggml/include/ggml.h +++ b/ggml/include/ggml.h @@ -702,9 +702,10 @@ extern "C" { GGML_API double ggml_type_sizef(enum ggml_type type), // ggml_type_size()/ggml_blck_size() as float "use ggml_row_size() instead"); - GGML_API const char * ggml_type_name(enum ggml_type type); - GGML_API const char * ggml_op_name (enum ggml_op op); - GGML_API const char * ggml_op_symbol(enum ggml_op op); + GGML_API const char * ggml_type_name (enum ggml_type type); + GGML_API const char * ggml_op_name (enum ggml_op op); + GGML_API const char * ggml_op_symbol (enum ggml_op op); + GGML_API bool ggml_op_is_empty(enum ggml_op op); GGML_API const char * ggml_unary_op_name(enum ggml_unary_op op); GGML_API const char * ggml_glu_op_name(enum ggml_glu_op op); diff --git a/ggml/src/ggml-metal/ggml-metal-common.cpp b/ggml/src/ggml-metal/ggml-metal-common.cpp index 34d27b6324201..e61a5706d610c 100644 --- a/ggml/src/ggml-metal/ggml-metal-common.cpp +++ b/ggml/src/ggml-metal/ggml-metal-common.cpp @@ -184,20 +184,6 @@ bool ggml_mem_ranges_check(ggml_mem_ranges_t mrs, const ggml_tensor * tensor) { return ggml_mem_ranges_check_dst(mrs, tensor); } -// TODO: move to ggml.h? -static bool is_empty(ggml_op op) { - switch (op) { - case GGML_OP_NONE: - case GGML_OP_RESHAPE: - case GGML_OP_TRANSPOSE: - case GGML_OP_VIEW: - case GGML_OP_PERMUTE: - return true; - default: - return false; - } -} - struct node_info { ggml_tensor * node; @@ -212,7 +198,7 @@ struct node_info { } bool is_empty() const { - return ::is_empty(node->op); + return ggml_op_is_empty(node->op); } void add_fused(ggml_tensor * t) { @@ -289,7 +275,7 @@ static std::vector ggml_metal_graph_optimize_reorder(const std::vector Date: Sat, 20 Sep 2025 16:42:40 +0300 Subject: [PATCH 2/2] ggml : move to ggml-impl.h --- ggml/include/ggml.h | 7 +++---- ggml/src/ggml-impl.h | 15 ++++++++++++++- ggml/src/ggml.c | 13 ------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h index c60d70f27c8ff..36b23dc6d0d82 100644 --- a/ggml/include/ggml.h +++ b/ggml/include/ggml.h @@ -702,10 +702,9 @@ extern "C" { GGML_API double ggml_type_sizef(enum ggml_type type), // ggml_type_size()/ggml_blck_size() as float "use ggml_row_size() instead"); - GGML_API const char * ggml_type_name (enum ggml_type type); - GGML_API const char * ggml_op_name (enum ggml_op op); - GGML_API const char * ggml_op_symbol (enum ggml_op op); - GGML_API bool ggml_op_is_empty(enum ggml_op op); + GGML_API const char * ggml_type_name(enum ggml_type type); + GGML_API const char * ggml_op_name (enum ggml_op op); + GGML_API const char * ggml_op_symbol(enum ggml_op op); GGML_API const char * ggml_unary_op_name(enum ggml_unary_op op); GGML_API const char * ggml_glu_op_name(enum ggml_glu_op op); diff --git a/ggml/src/ggml-impl.h b/ggml/src/ggml-impl.h index 19a7adb2d101b..6e01a42cef675 100644 --- a/ggml/src/ggml-impl.h +++ b/ggml/src/ggml-impl.h @@ -73,7 +73,7 @@ static inline int ggml_up(int n, int m) { return (n + m - 1) & ~(m - 1); } -// TODO: move to ggml.h? +// TODO: move to ggml.h? (won't be able to inline) static bool ggml_are_same_layout(const struct ggml_tensor * a, const struct ggml_tensor * b) { if (a->type != b->type) { return false; @@ -89,6 +89,19 @@ static bool ggml_are_same_layout(const struct ggml_tensor * a, const struct ggml return true; } +static bool ggml_op_is_empty(enum ggml_op op) { + switch (op) { + case GGML_OP_NONE: + case GGML_OP_RESHAPE: + case GGML_OP_TRANSPOSE: + case GGML_OP_VIEW: + case GGML_OP_PERMUTE: + return true; + default: + return false; + } +} + // // logging // diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 7513a73120a4c..3584827dca7fc 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -1258,19 +1258,6 @@ const char * ggml_op_symbol(enum ggml_op op) { return GGML_OP_SYMBOL[op]; } -bool ggml_op_is_empty(enum ggml_op op) { - switch (op) { - case GGML_OP_NONE: - case GGML_OP_RESHAPE: - case GGML_OP_TRANSPOSE: - case GGML_OP_VIEW: - case GGML_OP_PERMUTE: - return true; - default: - return false; - } -} - const char * ggml_unary_op_name(enum ggml_unary_op op) { return GGML_UNARY_OP_NAME[op]; }