From aa5a7c6d6d05b13c2e286ff6e037d9d063eac5a8 Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Thu, 24 Jul 2025 19:14:41 -0700 Subject: [PATCH] profiler: output all tensor names --- ggml/src/ggml-profile.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/ggml/src/ggml-profile.cpp b/ggml/src/ggml-profile.cpp index bdafcde1f..c6f3aa09e 100644 --- a/ggml/src/ggml-profile.cpp +++ b/ggml/src/ggml-profile.cpp @@ -111,17 +111,38 @@ static inline void ggml_profile_format_op_types(char *str, struct ggml_tensor *t p += sprintf(p, "%3s", ggml_type_name(t->type)); } +static inline void ggml_profile_format_op_names(char *str, const struct ggml_tensor *t) +{ + char *p = str; + + // append src0 and src1 (if any) + if (t->src[0]) { + p += sprintf(p, "%s", t->src[0]->name); + + for (int i = 1; i < GGML_MAX_SRC && t->src[i]; i++) { + p += sprintf(p, " x "); + p += sprintf(p, "%s", t->src[i]->name); + } + + p += sprintf(p, " -> "); + } + + p += sprintf(p, "%s", t->name); +} + + extern "C" void ggml_graph_profile_finish(struct ggml_cgraph *cg, int n_threads) { if (!cg->prof) { return; } ggml_profile_output *out = cg->prof->output; - fprintf(out->stream, "%s| node idx | op name | proc (nsec) | sync (nsec) | total (nsec) | op dims | op types | tensor name |\n", out->prefix); - fprintf(out->stream, "%s| -------: | :------ | ----------: | ----------: | -----------: | ------: | -------: | ----------: |\n", out->prefix); + fprintf(out->stream, "%s| node idx | op name | proc (nsec) | sync (nsec) | total (nsec) | op dims | op types | tensor names |\n", out->prefix); + fprintf(out->stream, "%s| -------: | :------ | ----------: | ----------: | -----------: | ------: | -------: | -----------: |\n", out->prefix); char dims[64 * GGML_MAX_SRC]; char types[16 * GGML_MAX_SRC]; + char names[128 * GGML_MAX_SRC]; for (int i = 0; i < cg->n_nodes; i++) { uint64_t p_nsec = 0; @@ -143,11 +164,12 @@ extern "C" void ggml_graph_profile_finish(struct ggml_cgraph *cg, int n_threads) ggml_profile_format_op_dims(dims, cg->nodes[i]); ggml_profile_format_op_types(types, cg->nodes[i]); + ggml_profile_format_op_names(names, cg->nodes[i]); fprintf(out->stream, "%s| %04d | %10s | %10lu | %10lu | %10lu | %46s | %22s | %20s |\n", out->prefix, i, ggml_op_name(cg->nodes[i]->op), (unsigned long) p_nsec, (unsigned long) s_nsec, (unsigned long) t_nsec, - dims, types, cg->nodes[i]->name); + dims, types, names); } fprintf(out->stream, "%s \n", out->prefix); // empty line to split tables }