Skip to content

Commit 55071fb

Browse files
committed
[cmn/ggml/llama] reduced enum size using scoped enums and packed attribute
1 parent 658987c commit 55071fb

File tree

25 files changed

+66
-64
lines changed

25 files changed

+66
-64
lines changed

common/chat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ struct common_chat_tool {
3535
std::string parameters;
3636
};
3737

38-
enum common_chat_tool_choice {
38+
enum common_chat_tool_choice : uint8_t {
3939
COMMON_CHAT_TOOL_CHOICE_AUTO,
4040
COMMON_CHAT_TOOL_CHOICE_REQUIRED,
4141
COMMON_CHAT_TOOL_CHOICE_NONE,
4242
};
4343

44-
enum common_chat_format {
44+
enum common_chat_format : uint8_t {
4545
COMMON_CHAT_FORMAT_CONTENT_ONLY,
4646
COMMON_CHAT_FORMAT_GENERIC,
4747
COMMON_CHAT_FORMAT_MISTRAL_NEMO,

common/common.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int32_t cpu_get_num_math();
6262
// Common params
6363
//
6464

65-
enum llama_example {
65+
enum llama_example : uint8_t {
6666
LLAMA_EXAMPLE_COMMON,
6767
LLAMA_EXAMPLE_SPECULATIVE,
6868
LLAMA_EXAMPLE_MAIN,
@@ -84,7 +84,7 @@ enum llama_example {
8484
LLAMA_EXAMPLE_COUNT,
8585
};
8686

87-
enum common_sampler_type {
87+
enum common_sampler_type : uint8_t {
8888
COMMON_SAMPLER_TYPE_NONE = 0,
8989
COMMON_SAMPLER_TYPE_DRY = 1,
9090
COMMON_SAMPLER_TYPE_TOP_K = 2,
@@ -99,18 +99,18 @@ enum common_sampler_type {
9999
};
100100

101101
// dimensionality reduction methods, used by cvector-generator
102-
enum dimre_method {
102+
enum dimre_method : uint8_t {
103103
DIMRE_METHOD_PCA,
104104
DIMRE_METHOD_MEAN,
105105
};
106106

107-
enum common_conversation_mode {
107+
enum common_conversation_mode : uint8_t {
108108
COMMON_CONVERSATION_MODE_DISABLED = 0,
109109
COMMON_CONVERSATION_MODE_ENABLED = 1,
110110
COMMON_CONVERSATION_MODE_AUTO = 2,
111111
};
112112

113-
enum common_grammar_trigger_type {
113+
enum common_grammar_trigger_type : uint8_t {
114114
COMMON_GRAMMAR_TRIGGER_TYPE_TOKEN,
115115
COMMON_GRAMMAR_TRIGGER_TYPE_WORD,
116116
COMMON_GRAMMAR_TRIGGER_TYPE_PATTERN,
@@ -211,7 +211,7 @@ struct common_params_vocoder {
211211
bool use_guide_tokens = false; // enable guide tokens to improve TTS accuracy // NOLINT
212212
};
213213

214-
enum common_reasoning_format {
214+
enum common_reasoning_format : uint8_t {
215215
COMMON_REASONING_FORMAT_NONE,
216216
COMMON_REASONING_FORMAT_DEEPSEEK, // Extract thinking tag contents and return as `message.reasoning_content`
217217
};

common/console.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#pragma once
44

55
#include <string>
6+
#include <cstdint>
67

78
namespace console {
8-
enum display_t {
9+
enum display_t : uint8_t {
910
reset = 0,
1011
prompt,
1112
user_input,

common/log.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static int64_t t_us() {
2020
}
2121

2222
// colors
23-
enum common_log_col : int {
23+
enum common_log_col : uint8_t {
2424
COMMON_LOG_COL_DEFAULT = 0,
2525
COMMON_LOG_COL_BOLD,
2626
COMMON_LOG_COL_RED,

ggml/include/ggml-backend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern "C" {
4646
// Backend buffer
4747
//
4848

49-
enum ggml_backend_buffer_usage {
49+
enum GGML_PACKED ggml_backend_buffer_usage {
5050
GGML_BACKEND_BUFFER_USAGE_ANY = 0,
5151
GGML_BACKEND_BUFFER_USAGE_WEIGHTS = 1,
5252
GGML_BACKEND_BUFFER_USAGE_COMPUTE = 2,
@@ -127,7 +127,7 @@ extern "C" {
127127
// Backend device
128128
//
129129

130-
enum ggml_backend_dev_type {
130+
enum GGML_PACKED ggml_backend_dev_type {
131131
// CPU device using system memory
132132
GGML_BACKEND_DEVICE_TYPE_CPU,
133133
// GPU device using dedicated memory

ggml/include/ggml-cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern "C" {
2222
};
2323

2424
// numa strategies
25-
enum ggml_numa_strategy {
25+
enum GGML_PACKED ggml_numa_strategy {
2626
GGML_NUMA_STRATEGY_DISABLED = 0,
2727
GGML_NUMA_STRATEGY_DISTRIBUTE = 1,
2828
GGML_NUMA_STRATEGY_ISOLATE = 2,

ggml/include/ggml-opt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727

2828
// built-in loss types, i.e. the built-in quantities minimized by the optimizer
2929
// custom loss types can be defined via mean or sum which simply reduce the outputs for all datapoints to a single value
30-
enum ggml_opt_loss_type {
30+
enum ggml_opt_loss_type : uint8_t {
3131
GGML_OPT_LOSS_TYPE_MEAN,
3232
GGML_OPT_LOSS_TYPE_SUM,
3333
GGML_OPT_LOSS_TYPE_CROSS_ENTROPY,
@@ -59,7 +59,7 @@ extern "C" {
5959

6060
// ====== Model / Context ======
6161

62-
enum ggml_opt_build_type {
62+
enum ggml_opt_build_type : uint8_t {
6363
GGML_OPT_BUILD_TYPE_FORWARD,
6464
GGML_OPT_BUILD_TYPE_GRAD,
6565
GGML_OPT_BUILD_TYPE_OPT,

ggml/include/ggml.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
// TODO: support for clang
191191
#ifdef __GNUC__
192192
# define GGML_DEPRECATED(func, hint) func __attribute__((deprecated(hint)))
193+
# define GGML_PACKED __attribute__((__packed__))
193194
#elif defined(_MSC_VER)
194195
# define GGML_DEPRECATED(func, hint) __declspec(deprecated(hint)) func
195196
#else
@@ -317,7 +318,7 @@ extern "C" {
317318
GGML_NORETURN GGML_ATTRIBUTE_FORMAT(3, 4)
318319
GGML_API void ggml_abort(const char * file, int line, const char * fmt, ...);
319320

320-
enum ggml_status {
321+
enum GGML_PACKED ggml_status {
321322
GGML_STATUS_ALLOC_FAILED = -2,
322323
GGML_STATUS_FAILED = -1,
323324
GGML_STATUS_SUCCESS = 0,
@@ -348,7 +349,7 @@ extern "C" {
348349
struct ggml_cgraph;
349350

350351
// NOTE: always add types at the end of the enum to keep backward compatibility
351-
enum ggml_type {
352+
enum GGML_PACKED ggml_type {
352353
GGML_TYPE_F32 = 0,
353354
GGML_TYPE_F16 = 1,
354355
GGML_TYPE_Q4_0 = 2,
@@ -392,13 +393,13 @@ extern "C" {
392393
};
393394

394395
// precision
395-
enum ggml_prec {
396+
enum GGML_PACKED ggml_prec {
396397
GGML_PREC_DEFAULT,
397398
GGML_PREC_F32,
398399
};
399400

400401
// model file types
401-
enum ggml_ftype {
402+
enum GGML_PACKED ggml_ftype {
402403
GGML_FTYPE_UNKNOWN = -1,
403404
GGML_FTYPE_ALL_F32 = 0,
404405
GGML_FTYPE_MOSTLY_F16 = 1, // except 1d tensors
@@ -426,7 +427,7 @@ extern "C" {
426427
};
427428

428429
// available tensor operations:
429-
enum ggml_op {
430+
enum GGML_PACKED ggml_op {
430431
GGML_OP_NONE = 0,
431432

432433
GGML_OP_DUP,
@@ -520,7 +521,7 @@ extern "C" {
520521
GGML_OP_COUNT,
521522
};
522523

523-
enum ggml_unary_op {
524+
enum GGML_PACKED ggml_unary_op {
524525
GGML_UNARY_OP_ABS,
525526
GGML_UNARY_OP_SGN,
526527
GGML_UNARY_OP_NEG,
@@ -539,13 +540,13 @@ extern "C" {
539540
GGML_UNARY_OP_COUNT,
540541
};
541542

542-
enum ggml_object_type {
543+
enum GGML_PACKED ggml_object_type {
543544
GGML_OBJECT_TYPE_TENSOR,
544545
GGML_OBJECT_TYPE_GRAPH,
545546
GGML_OBJECT_TYPE_WORK_BUFFER
546547
};
547548

548-
enum ggml_log_level {
549+
enum GGML_PACKED ggml_log_level {
549550
GGML_LOG_LEVEL_NONE = 0,
550551
GGML_LOG_LEVEL_DEBUG = 1,
551552
GGML_LOG_LEVEL_INFO = 2,
@@ -555,7 +556,7 @@ extern "C" {
555556
};
556557

557558
// this tensor...
558-
enum ggml_tensor_flag {
559+
enum GGML_PACKED ggml_tensor_flag {
559560
GGML_TENSOR_FLAG_INPUT = 1, // ...is an input for the GGML compute graph
560561
GGML_TENSOR_FLAG_OUTPUT = 2, // ...is an output for the GGML compute graph
561562
GGML_TENSOR_FLAG_PARAM = 4, // ...contains trainable parameters
@@ -1678,7 +1679,7 @@ extern "C" {
16781679
struct ggml_tensor * b,
16791680
int stride);
16801681

1681-
enum ggml_op_pool {
1682+
enum GGML_PACKED ggml_op_pool {
16821683
GGML_OP_POOL_MAX,
16831684
GGML_OP_POOL_AVG,
16841685
GGML_OP_POOL_COUNT,
@@ -1717,7 +1718,7 @@ extern "C" {
17171718
float p0,
17181719
float p1);
17191720

1720-
enum ggml_scale_mode {
1721+
enum GGML_PACKED ggml_scale_mode {
17211722
GGML_SCALE_MODE_NEAREST = 0,
17221723
GGML_SCALE_MODE_BILINEAR = 1,
17231724
};
@@ -1767,7 +1768,7 @@ extern "C" {
17671768
int max_period);
17681769

17691770
// sort rows
1770-
enum ggml_sort_order {
1771+
enum GGML_PACKED ggml_sort_order {
17711772
GGML_SORT_ORDER_ASC,
17721773
GGML_SORT_ORDER_DESC,
17731774
};
@@ -2137,7 +2138,7 @@ extern "C" {
21372138
// the goal should be to create an API that other backends can use move everything to the ggml base
21382139

21392140
// scheduling priorities
2140-
enum ggml_sched_priority {
2141+
enum GGML_PACKED ggml_sched_priority {
21412142
GGML_SCHED_PRIO_NORMAL,
21422143
GGML_SCHED_PRIO_MEDIUM,
21432144
GGML_SCHED_PRIO_HIGH,

ggml/include/gguf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extern "C" {
5050
#endif
5151

5252
// types that can be stored as GGUF KV data
53-
enum gguf_type {
53+
enum GGML_PACKED gguf_type {
5454
GGUF_TYPE_UINT8 = 0,
5555
GGUF_TYPE_INT8 = 1,
5656
GGUF_TYPE_UINT16 = 2,

ggml/src/ggml-cpu/ggml-cpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ typedef atomic_int atomic_flag;
114114

115115
#define ATOMIC_FLAG_INIT 0
116116

117-
typedef enum {
117+
typedef enum : uint8_t {
118118
memory_order_relaxed,
119119
memory_order_consume,
120120
memory_order_acquire,

0 commit comments

Comments
 (0)