interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / src / ggml-rpc / log.cpp

34 lines · 1039 bytes Raw Blame History
1#include "log.h"
2
3#include <cinttypes>
4#include <cstdio>
5
6std::string rpc_log_format_size(size_t size) {
7 static const char * units[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB" };
8
9 double value = (double) size;
10 size_t unit = 0;
11 while (value >= 1024.0 && unit + 1 < sizeof(units) / sizeof(units[0])) {
12 value /= 1024.0;
13 unit++;
14 }
15
16 char buf[32];
17 if (unit == 0) {
18 snprintf(buf, sizeof(buf), "%zu B", size);
19 } else {
20 snprintf(buf, sizeof(buf), "%.2f %s", value, units[unit]);
21 }
22 return std::string(buf);
23}
24
25std::string rpc_log_format_tensor(const ggml_tensor * tensor) {
26 char shape[64];
27 snprintf(shape, sizeof(shape), "[%" PRId64 ", %" PRId64 ", %" PRId64 ", %" PRId64 "]", tensor->ne[0], tensor->ne[1],
28 tensor->ne[2], tensor->ne[3]);
29
30 char buf[GGML_MAX_NAME + 192];
31 snprintf(buf, sizeof(buf), "%s [%s, %s, %s]", ggml_get_name(tensor), ggml_op_name(tensor->op),
32 ggml_type_name(tensor->type), shape);
33 return std::string(buf);
34}