Skip to content

Commit 51f0426

Browse files
committed
[ggml] fixes for cross-platform building successful
1 parent a1610bd commit 51f0426

File tree

7 files changed

+69
-33
lines changed

7 files changed

+69
-33
lines changed

ggml/include/ggml-backend.h

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

49-
enum GGML_PACKED ggml_backend_buffer_usage {
49+
GGML_PACKED_ENUM 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,
5353
};
54+
GGML_PACKED_ENUM_END
5455

5556
GGML_API const char * ggml_backend_buffer_name (ggml_backend_buffer_t buffer);
5657
GGML_API void ggml_backend_buffer_free (ggml_backend_buffer_t buffer);
@@ -127,14 +128,15 @@ extern "C" {
127128
// Backend device
128129
//
129130

130-
enum GGML_PACKED ggml_backend_dev_type {
131+
GGML_PACKED_ENUM ggml_backend_dev_type {
131132
// CPU device using system memory
132133
GGML_BACKEND_DEVICE_TYPE_CPU,
133134
// GPU device using dedicated memory
134135
GGML_BACKEND_DEVICE_TYPE_GPU,
135136
// accelerator devices intended to be used together with the CPU backend (e.g. BLAS or AMX)
136137
GGML_BACKEND_DEVICE_TYPE_ACCEL
137138
};
139+
GGML_PACKED_ENUM_END
138140

139141
// functionality supported by the device
140142
struct ggml_backend_dev_caps {

ggml/include/ggml-cpu.h

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

2424
// numa strategies
25-
enum GGML_PACKED ggml_numa_strategy {
25+
GGML_PACKED_ENUM ggml_numa_strategy {
2626
GGML_NUMA_STRATEGY_DISABLED = 0,
2727
GGML_NUMA_STRATEGY_DISTRIBUTE = 1,
2828
GGML_NUMA_STRATEGY_ISOLATE = 2,
2929
GGML_NUMA_STRATEGY_NUMACTL = 3,
3030
GGML_NUMA_STRATEGY_MIRROR = 4,
3131
GGML_NUMA_STRATEGY_COUNT
3232
};
33+
GGML_PACKED_ENUM_END
3334

3435
GGML_BACKEND_API void ggml_numa_init(enum ggml_numa_strategy numa); // call once for better performance on NUMA systems
3536
GGML_BACKEND_API bool ggml_is_numa(void); // true if init detected that system has >1 NUMA node

ggml/include/ggml.h

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,16 @@
190190
// TODO: support for clang
191191
#ifdef __GNUC__
192192
# define GGML_DEPRECATED(func, hint) func __attribute__((deprecated(hint)))
193-
# define GGML_PACKED __attribute__((__packed__))
193+
# define GGML_PACKED_ENUM enum __attribute__((__packed__))
194+
# define GGML_PACKED_ENUM_END
194195
#elif defined(_MSC_VER)
195196
# define GGML_DEPRECATED(func, hint) __declspec(deprecated(hint)) func
197+
# define GGML_PACKED_ENUM __pragma(pack(push, 1)) enum
198+
# define GGML_PACKED_ENUM_END __pragma(pack(pop))
196199
#else
197200
# define GGML_DEPRECATED(func, hint) func
201+
# define GGML_PACKED_ENUM
202+
# define GGML_PACKED_ENUM_END
198203
#endif
199204

200205
#ifndef __GNUC__
@@ -318,12 +323,13 @@ extern "C" {
318323
GGML_NORETURN GGML_ATTRIBUTE_FORMAT(3, 4)
319324
GGML_API void ggml_abort(const char * file, int line, const char * fmt, ...);
320325

321-
enum GGML_PACKED ggml_status {
326+
GGML_PACKED_ENUM ggml_status {
322327
GGML_STATUS_ALLOC_FAILED = -2,
323328
GGML_STATUS_FAILED = -1,
324329
GGML_STATUS_SUCCESS = 0,
325330
GGML_STATUS_ABORTED = 1,
326331
};
332+
GGML_PACKED_ENUM_END
327333

328334
// get ggml_status name string
329335
GGML_API const char * ggml_status_to_string(enum ggml_status status);
@@ -349,7 +355,7 @@ extern "C" {
349355
struct ggml_cgraph;
350356

351357
// NOTE: always add types at the end of the enum to keep backward compatibility
352-
enum GGML_PACKED ggml_type {
358+
GGML_PACKED_ENUM ggml_type {
353359
GGML_TYPE_F32 = 0,
354360
GGML_TYPE_F16 = 1,
355361
GGML_TYPE_Q4_0 = 2,
@@ -391,15 +397,17 @@ extern "C" {
391397
// GGML_TYPE_IQ4_NL_8_8 = 38,
392398
GGML_TYPE_COUNT = 39,
393399
};
400+
GGML_PACKED_ENUM_END
394401

395402
// precision
396-
enum GGML_PACKED ggml_prec {
403+
GGML_PACKED_ENUM ggml_prec {
397404
GGML_PREC_DEFAULT,
398405
GGML_PREC_F32,
399406
};
407+
GGML_PACKED_ENUM_END
400408

401409
// model file types
402-
enum GGML_PACKED ggml_ftype {
410+
GGML_PACKED_ENUM ggml_ftype {
403411
GGML_FTYPE_UNKNOWN = -1,
404412
GGML_FTYPE_ALL_F32 = 0,
405413
GGML_FTYPE_MOSTLY_F16 = 1, // except 1d tensors
@@ -425,9 +433,10 @@ extern "C" {
425433
GGML_FTYPE_MOSTLY_IQ1_M = 23, // except 1d tensors
426434
GGML_FTYPE_MOSTLY_BF16 = 24, // except 1d tensors
427435
};
436+
GGML_PACKED_ENUM_END
428437

429438
// available tensor operations:
430-
enum GGML_PACKED ggml_op {
439+
GGML_PACKED_ENUM ggml_op {
431440
GGML_OP_NONE = 0,
432441

433442
GGML_OP_DUP,
@@ -520,8 +529,9 @@ extern "C" {
520529

521530
GGML_OP_COUNT,
522531
};
532+
GGML_PACKED_ENUM_END
523533

524-
enum GGML_PACKED ggml_unary_op {
534+
GGML_PACKED_ENUM ggml_unary_op {
525535
GGML_UNARY_OP_ABS,
526536
GGML_UNARY_OP_SGN,
527537
GGML_UNARY_OP_NEG,
@@ -539,29 +549,33 @@ extern "C" {
539549

540550
GGML_UNARY_OP_COUNT,
541551
};
552+
GGML_PACKED_ENUM_END
542553

543-
enum GGML_PACKED ggml_object_type {
554+
GGML_PACKED_ENUM ggml_object_type {
544555
GGML_OBJECT_TYPE_TENSOR,
545556
GGML_OBJECT_TYPE_GRAPH,
546557
GGML_OBJECT_TYPE_WORK_BUFFER
547558
};
559+
GGML_PACKED_ENUM_END
548560

549-
enum GGML_PACKED ggml_log_level {
561+
GGML_PACKED_ENUM ggml_log_level {
550562
GGML_LOG_LEVEL_NONE = 0,
551563
GGML_LOG_LEVEL_DEBUG = 1,
552564
GGML_LOG_LEVEL_INFO = 2,
553565
GGML_LOG_LEVEL_WARN = 3,
554566
GGML_LOG_LEVEL_ERROR = 4,
555567
GGML_LOG_LEVEL_CONT = 5, // continue previous log
556568
};
569+
GGML_PACKED_ENUM_END
557570

558571
// this tensor...
559-
enum GGML_PACKED ggml_tensor_flag {
572+
GGML_PACKED_ENUM ggml_tensor_flag {
560573
GGML_TENSOR_FLAG_INPUT = 1, // ...is an input for the GGML compute graph
561574
GGML_TENSOR_FLAG_OUTPUT = 2, // ...is an output for the GGML compute graph
562575
GGML_TENSOR_FLAG_PARAM = 4, // ...contains trainable parameters
563576
GGML_TENSOR_FLAG_LOSS = 8, // ...defines loss for numerical optimization (multiple loss tensors add up)
564577
};
578+
GGML_PACKED_ENUM_END
565579

566580
struct ggml_init_params {
567581
// memory pool
@@ -1679,11 +1693,12 @@ extern "C" {
16791693
struct ggml_tensor * b,
16801694
int stride);
16811695

1682-
enum GGML_PACKED ggml_op_pool {
1696+
GGML_PACKED_ENUM ggml_op_pool {
16831697
GGML_OP_POOL_MAX,
16841698
GGML_OP_POOL_AVG,
16851699
GGML_OP_POOL_COUNT,
16861700
};
1701+
GGML_PACKED_ENUM_END
16871702

16881703
GGML_API struct ggml_tensor * ggml_pool_1d(
16891704
struct ggml_context * ctx,
@@ -1718,10 +1733,11 @@ extern "C" {
17181733
float p0,
17191734
float p1);
17201735

1721-
enum GGML_PACKED ggml_scale_mode {
1736+
GGML_PACKED_ENUM ggml_scale_mode {
17221737
GGML_SCALE_MODE_NEAREST = 0,
17231738
GGML_SCALE_MODE_BILINEAR = 1,
17241739
};
1740+
GGML_PACKED_ENUM_END
17251741

17261742
// interpolate
17271743
// multiplies ne0 and ne1 by scale factor
@@ -1768,10 +1784,11 @@ extern "C" {
17681784
int max_period);
17691785

17701786
// sort rows
1771-
enum GGML_PACKED ggml_sort_order {
1787+
GGML_PACKED_ENUM ggml_sort_order {
17721788
GGML_SORT_ORDER_ASC,
17731789
GGML_SORT_ORDER_DESC,
17741790
};
1791+
GGML_PACKED_ENUM_END
17751792

17761793
GGML_API struct ggml_tensor * ggml_argsort(
17771794
struct ggml_context * ctx,
@@ -2138,12 +2155,13 @@ extern "C" {
21382155
// the goal should be to create an API that other backends can use move everything to the ggml base
21392156

21402157
// scheduling priorities
2141-
enum GGML_PACKED ggml_sched_priority {
2158+
GGML_PACKED_ENUM ggml_sched_priority {
21422159
GGML_SCHED_PRIO_NORMAL,
21432160
GGML_SCHED_PRIO_MEDIUM,
21442161
GGML_SCHED_PRIO_HIGH,
21452162
GGML_SCHED_PRIO_REALTIME
21462163
};
2164+
GGML_PACKED_ENUM_END
21472165

21482166
// threadpool params
21492167
// Use ggml_threadpool_params_default() or ggml_threadpool_params_init() to populate the defaults

ggml/include/gguf.h

Lines changed: 2 additions & 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 GGML_PACKED gguf_type {
53+
GGML_PACKED_ENUM gguf_type {
5454
GGUF_TYPE_UINT8 = 0,
5555
GGUF_TYPE_INT8 = 1,
5656
GGUF_TYPE_UINT16 = 2,
@@ -66,6 +66,7 @@ extern "C" {
6666
GGUF_TYPE_FLOAT64 = 12,
6767
GGUF_TYPE_COUNT, // marks the end of the enum
6868
};
69+
GGML_PACKED_ENUM_END
6970

7071
struct gguf_context;
7172

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@ typedef atomic_int atomic_flag;
114114

115115
#define ATOMIC_FLAG_INIT 0
116116

117-
typedef enum : uint8_t {
117+
GGML_PACKED_ENUM _MEMORY_ORDER {
118118
memory_order_relaxed,
119119
memory_order_consume,
120120
memory_order_acquire,
121121
memory_order_release,
122122
memory_order_acq_rel,
123123
memory_order_seq_cst
124-
} memory_order;
124+
};
125+
GGML_PACKED_ENUM_END
126+
typedef enum _MEMORY_ORDER memory_order;
125127

126128
static void atomic_store(atomic_int * ptr, LONG val) {
127129
InterlockedExchange(ptr, val);

ggml/src/ggml-impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,12 @@ static size_t ggml_hash_find_or_insert(struct ggml_hash_set * hash_set, struct g
284284

285285
// computation graph
286286

287-
enum GGML_PACKED ggml_cgraph_eval_order {
287+
GGML_PACKED_ENUM ggml_cgraph_eval_order {
288288
GGML_CGRAPH_EVAL_ORDER_LEFT_TO_RIGHT = 0,
289289
GGML_CGRAPH_EVAL_ORDER_RIGHT_TO_LEFT,
290290
GGML_CGRAPH_EVAL_ORDER_COUNT
291291
};
292+
GGML_PACKED_ENUM_END
292293

293294
struct ggml_cgraph {
294295
int size; // maximum number of nodes/leafs/grads/grad_accs

0 commit comments

Comments
 (0)