From: Georgi Gerganov Date: Sat, 15 Apr 2023 11:25:34 +0000 (+0300) Subject: ggml : add ggml_type_name() X-Git-Tag: upstream/0.0.1642~1542 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=ce67b832e7fbb3089ca8a81a2fb41fd59412ad78;p=pkg%2Fggml%2Fsources%2Fggml ggml : add ggml_type_name() --- diff --git a/include/ggml/ggml.h b/include/ggml/ggml.h index bdff0b4d..617298a9 100644 --- a/include/ggml/ggml.h +++ b/include/ggml/ggml.h @@ -354,6 +354,8 @@ int ggml_blck_size (enum ggml_type type); size_t ggml_type_size (enum ggml_type type); // size in bytes for all elements in a block float ggml_type_sizef(enum ggml_type type); // ggml_type_size()/ggml_blck_size() as float +const char * ggml_type_name(enum ggml_type type); + size_t ggml_element_size(const struct ggml_tensor * tensor); struct ggml_context * ggml_init(struct ggml_init_params params); diff --git a/src/ggml.c b/src/ggml.c index ca3b7b95..cf6a81f4 100644 --- a/src/ggml.c +++ b/src/ggml.c @@ -2680,6 +2680,18 @@ static const size_t GGML_TYPE_SIZE[GGML_TYPE_COUNT] = { }; static_assert(GGML_TYPE_COUNT == 7, "GGML_TYPE_SIZE is outdated"); + +static const char * GGML_TYPE_NAME[GGML_TYPE_COUNT] = { + [GGML_TYPE_F32] = "f32", + [GGML_TYPE_F16] = "f16", + [GGML_TYPE_Q4_0] = "q4_0", + [GGML_TYPE_Q4_1] = "q4_1", + [GGML_TYPE_I8] = "i8", + [GGML_TYPE_I16] = "i16", + [GGML_TYPE_I32] = "i32", +}; +static_assert(GGML_TYPE_COUNT == 7, "GGML_TYPE_NAME is outdated"); + static const char * GGML_OP_LABEL[GGML_OP_COUNT] = { "NONE", @@ -2904,6 +2916,11 @@ float ggml_type_sizef(enum ggml_type type) { return ((float)(GGML_TYPE_SIZE[type]))/GGML_BLCK_SIZE[type]; } +const char * ggml_type_name(enum ggml_type type) { + return GGML_TYPE_NAME[type]; +} + + size_t ggml_element_size(const struct ggml_tensor * tensor) { return GGML_TYPE_SIZE[tensor->type]; }