Spaces:
Sleeping
Sleeping
Diego Devesa
commited on
Commit
·
0f447f2
1
Parent(s):
b6bfa42
ggml : move CPU backend to a separate file (llama/10144)
Browse files- ggml/include/ggml-backend.h +1 -18
- ggml/include/ggml-cpu.h +150 -0
- ggml/include/ggml.h +18 -131
- ggml/src/CMakeLists.txt +2 -0
- ggml/src/ggml-aarch64.c +1 -0
- ggml/src/ggml-backend.cpp +0 -0
- ggml/src/ggml-cpu.c +0 -0
- ggml/src/ggml-impl.h +87 -0
- ggml/src/ggml-rpc.cpp +1 -8
- ggml/src/ggml.c +0 -0
ggml/include/ggml-backend.h
CHANGED
|
@@ -305,27 +305,10 @@ extern "C" {
|
|
| 305 |
GGML_API void ggml_backend_tensor_alloc(ggml_backend_buffer_t buffer, struct ggml_tensor * tensor, void * addr);
|
| 306 |
GGML_API void ggml_backend_view_init(struct ggml_tensor * tensor);
|
| 307 |
|
| 308 |
-
//
|
| 309 |
-
// CPU backend
|
| 310 |
-
//
|
| 311 |
-
|
| 312 |
-
GGML_API ggml_backend_t ggml_backend_cpu_init(void);
|
| 313 |
-
|
| 314 |
-
GGML_API bool ggml_backend_is_cpu (ggml_backend_t backend);
|
| 315 |
-
GGML_API void ggml_backend_cpu_set_n_threads (ggml_backend_t backend_cpu, int n_threads);
|
| 316 |
-
GGML_API void ggml_backend_cpu_set_threadpool (ggml_backend_t backend_cpu, ggml_threadpool_t threadpool);
|
| 317 |
-
GGML_API void ggml_backend_cpu_set_abort_callback(ggml_backend_t backend_cpu, ggml_abort_callback abort_callback, void * abort_callback_data);
|
| 318 |
-
|
| 319 |
-
// Create a backend buffer from an existing pointer
|
| 320 |
GGML_API ggml_backend_buffer_t ggml_backend_cpu_buffer_from_ptr(void * ptr, size_t size);
|
| 321 |
GGML_API ggml_backend_buffer_type_t ggml_backend_cpu_buffer_type(void);
|
| 322 |
|
| 323 |
-
GGML_API ggml_backend_reg_t ggml_backend_cpu_reg(void);
|
| 324 |
-
|
| 325 |
-
#ifdef GGML_USE_CPU_HBM
|
| 326 |
-
GGML_API ggml_backend_buffer_type_t ggml_backend_cpu_hbm_buffer_type(void);
|
| 327 |
-
#endif
|
| 328 |
-
|
| 329 |
#ifdef __cplusplus
|
| 330 |
}
|
| 331 |
#endif
|
|
|
|
| 305 |
GGML_API void ggml_backend_tensor_alloc(ggml_backend_buffer_t buffer, struct ggml_tensor * tensor, void * addr);
|
| 306 |
GGML_API void ggml_backend_view_init(struct ggml_tensor * tensor);
|
| 307 |
|
| 308 |
+
// CPU buffer types are always available
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
GGML_API ggml_backend_buffer_t ggml_backend_cpu_buffer_from_ptr(void * ptr, size_t size);
|
| 310 |
GGML_API ggml_backend_buffer_type_t ggml_backend_cpu_buffer_type(void);
|
| 311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
#ifdef __cplusplus
|
| 313 |
}
|
| 314 |
#endif
|
ggml/include/ggml-cpu.h
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include "ggml.h"
|
| 4 |
+
#include "ggml-backend.h"
|
| 5 |
+
|
| 6 |
+
#ifdef __cplusplus
|
| 7 |
+
extern "C" {
|
| 8 |
+
#endif
|
| 9 |
+
|
| 10 |
+
// Scheduling priorities
|
| 11 |
+
enum ggml_sched_priority {
|
| 12 |
+
GGML_SCHED_PRIO_NORMAL,
|
| 13 |
+
GGML_SCHED_PRIO_MEDIUM,
|
| 14 |
+
GGML_SCHED_PRIO_HIGH,
|
| 15 |
+
GGML_SCHED_PRIO_REALTIME
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
// Threadpool params
|
| 19 |
+
// Use ggml_threadpool_params_default() or ggml_threadpool_params_init() to populate the defaults
|
| 20 |
+
struct ggml_threadpool_params {
|
| 21 |
+
bool cpumask[GGML_MAX_N_THREADS]; // mask of cpu cores (all-zeros means use default affinity settings)
|
| 22 |
+
int n_threads; // number of threads
|
| 23 |
+
enum ggml_sched_priority prio; // thread priority
|
| 24 |
+
uint32_t poll; // polling level (0 - no polling, 100 - aggressive polling)
|
| 25 |
+
bool strict_cpu; // strict cpu placement
|
| 26 |
+
bool paused; // start in paused state
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
struct ggml_threadpool; // forward declaration, see ggml.c
|
| 30 |
+
|
| 31 |
+
typedef struct ggml_threadpool * ggml_threadpool_t;
|
| 32 |
+
|
| 33 |
+
// the compute plan that needs to be prepared for ggml_graph_compute()
|
| 34 |
+
// since https://github.com/ggerganov/ggml/issues/287
|
| 35 |
+
struct ggml_cplan {
|
| 36 |
+
size_t work_size; // size of work buffer, calculated by `ggml_graph_plan()`
|
| 37 |
+
uint8_t * work_data; // work buffer, to be allocated by caller before calling to `ggml_graph_compute()`
|
| 38 |
+
|
| 39 |
+
int n_threads;
|
| 40 |
+
struct ggml_threadpool * threadpool;
|
| 41 |
+
|
| 42 |
+
// abort ggml_graph_compute when true
|
| 43 |
+
ggml_abort_callback abort_callback;
|
| 44 |
+
void * abort_callback_data;
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
// numa strategies
|
| 48 |
+
enum ggml_numa_strategy {
|
| 49 |
+
GGML_NUMA_STRATEGY_DISABLED = 0,
|
| 50 |
+
GGML_NUMA_STRATEGY_DISTRIBUTE = 1,
|
| 51 |
+
GGML_NUMA_STRATEGY_ISOLATE = 2,
|
| 52 |
+
GGML_NUMA_STRATEGY_NUMACTL = 3,
|
| 53 |
+
GGML_NUMA_STRATEGY_MIRROR = 4,
|
| 54 |
+
GGML_NUMA_STRATEGY_COUNT
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
GGML_API void ggml_numa_init(enum ggml_numa_strategy numa); // call once for better performance on NUMA systems
|
| 58 |
+
GGML_API bool ggml_is_numa(void); // true if init detected that system has >1 NUMA node
|
| 59 |
+
|
| 60 |
+
GGML_API struct ggml_tensor * ggml_new_i32(struct ggml_context * ctx, int32_t value);
|
| 61 |
+
GGML_API struct ggml_tensor * ggml_new_f32(struct ggml_context * ctx, float value);
|
| 62 |
+
|
| 63 |
+
GGML_API struct ggml_tensor * ggml_set_i32 (struct ggml_tensor * tensor, int32_t value);
|
| 64 |
+
GGML_API struct ggml_tensor * ggml_set_f32 (struct ggml_tensor * tensor, float value);
|
| 65 |
+
|
| 66 |
+
GGML_API int32_t ggml_get_i32_1d(const struct ggml_tensor * tensor, int i);
|
| 67 |
+
GGML_API void ggml_set_i32_1d(const struct ggml_tensor * tensor, int i, int32_t value);
|
| 68 |
+
|
| 69 |
+
GGML_API int32_t ggml_get_i32_nd(const struct ggml_tensor * tensor, int i0, int i1, int i2, int i3);
|
| 70 |
+
GGML_API void ggml_set_i32_nd(const struct ggml_tensor * tensor, int i0, int i1, int i2, int i3, int32_t value);
|
| 71 |
+
|
| 72 |
+
GGML_API float ggml_get_f32_1d(const struct ggml_tensor * tensor, int i);
|
| 73 |
+
GGML_API void ggml_set_f32_1d(const struct ggml_tensor * tensor, int i, float value);
|
| 74 |
+
|
| 75 |
+
GGML_API float ggml_get_f32_nd(const struct ggml_tensor * tensor, int i0, int i1, int i2, int i3);
|
| 76 |
+
GGML_API void ggml_set_f32_nd(const struct ggml_tensor * tensor, int i0, int i1, int i2, int i3, float value);
|
| 77 |
+
|
| 78 |
+
GGML_API struct ggml_threadpool_params ggml_threadpool_params_default(int n_threads);
|
| 79 |
+
GGML_API void ggml_threadpool_params_init (struct ggml_threadpool_params * p, int n_threads);
|
| 80 |
+
GGML_API bool ggml_threadpool_params_match (const struct ggml_threadpool_params * p0, const struct ggml_threadpool_params * p1);
|
| 81 |
+
GGML_API struct ggml_threadpool * ggml_threadpool_new (struct ggml_threadpool_params * params);
|
| 82 |
+
GGML_API void ggml_threadpool_free (struct ggml_threadpool * threadpool);
|
| 83 |
+
GGML_API int ggml_threadpool_get_n_threads(struct ggml_threadpool * threadpool);
|
| 84 |
+
GGML_API void ggml_threadpool_pause (struct ggml_threadpool * threadpool);
|
| 85 |
+
GGML_API void ggml_threadpool_resume (struct ggml_threadpool * threadpool);
|
| 86 |
+
|
| 87 |
+
// ggml_graph_plan() has to be called before ggml_graph_compute()
|
| 88 |
+
// when plan.work_size > 0, caller must allocate memory for plan.work_data
|
| 89 |
+
GGML_API struct ggml_cplan ggml_graph_plan(
|
| 90 |
+
const struct ggml_cgraph * cgraph,
|
| 91 |
+
int n_threads, /* = GGML_DEFAULT_N_THREADS */
|
| 92 |
+
struct ggml_threadpool * threadpool /* = NULL */ );
|
| 93 |
+
GGML_API enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cplan * cplan);
|
| 94 |
+
|
| 95 |
+
// same as ggml_graph_compute() but the work data is allocated as a part of the context
|
| 96 |
+
// note: the drawback of this API is that you must have ensured that the context has enough memory for the work data
|
| 97 |
+
GGML_API enum ggml_status ggml_graph_compute_with_ctx(struct ggml_context * ctx, struct ggml_cgraph * cgraph, int n_threads);
|
| 98 |
+
|
| 99 |
+
// TODO: move to backend interface
|
| 100 |
+
GGML_API int ggml_cpu_has_neon (void);
|
| 101 |
+
GGML_API int ggml_cpu_has_sve (void);
|
| 102 |
+
GGML_API int ggml_cpu_has_matmul_int8(void);
|
| 103 |
+
// get the sve vector length in bytes
|
| 104 |
+
GGML_API int ggml_cpu_get_sve_cnt(void);
|
| 105 |
+
|
| 106 |
+
// Internal types and functions exposed for tests and benchmarks
|
| 107 |
+
|
| 108 |
+
typedef void (*ggml_from_float_to_mat_t)
|
| 109 |
+
(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t nr, int64_t k, int64_t bs);
|
| 110 |
+
typedef void (*ggml_vec_dot_t) (int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT x, size_t bx,
|
| 111 |
+
const void * GGML_RESTRICT y, size_t by, int nrc);
|
| 112 |
+
typedef void (*ggml_gemv_t) (int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT x,
|
| 113 |
+
const void * GGML_RESTRICT y, int nr, int nc);
|
| 114 |
+
typedef void (*ggml_gemm_t) (int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT x,
|
| 115 |
+
const void * GGML_RESTRICT y, int nr, int nc);
|
| 116 |
+
|
| 117 |
+
struct ggml_type_traits_cpu {
|
| 118 |
+
ggml_from_float_to_mat_t from_float_to_mat;
|
| 119 |
+
ggml_vec_dot_t vec_dot;
|
| 120 |
+
enum ggml_type vec_dot_type;
|
| 121 |
+
int64_t nrows; // number of rows to process simultaneously
|
| 122 |
+
int64_t ncols; // number of columns to process simultaneously
|
| 123 |
+
ggml_gemv_t gemv;
|
| 124 |
+
ggml_gemm_t gemm;
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
GGML_API const struct ggml_type_traits_cpu * ggml_get_type_traits_cpu(enum ggml_type type);
|
| 128 |
+
|
| 129 |
+
GGML_API void ggml_cpu_init(void);
|
| 130 |
+
|
| 131 |
+
//
|
| 132 |
+
// CPU backend
|
| 133 |
+
//
|
| 134 |
+
|
| 135 |
+
GGML_API ggml_backend_t ggml_backend_cpu_init(void);
|
| 136 |
+
|
| 137 |
+
GGML_API bool ggml_backend_is_cpu (ggml_backend_t backend);
|
| 138 |
+
GGML_API void ggml_backend_cpu_set_n_threads (ggml_backend_t backend_cpu, int n_threads);
|
| 139 |
+
GGML_API void ggml_backend_cpu_set_threadpool (ggml_backend_t backend_cpu, ggml_threadpool_t threadpool);
|
| 140 |
+
GGML_API void ggml_backend_cpu_set_abort_callback(ggml_backend_t backend_cpu, ggml_abort_callback abort_callback, void * abort_callback_data);
|
| 141 |
+
|
| 142 |
+
GGML_API ggml_backend_reg_t ggml_backend_cpu_reg(void);
|
| 143 |
+
|
| 144 |
+
#ifdef GGML_USE_CPU_HBM
|
| 145 |
+
GGML_API ggml_backend_buffer_type_t ggml_backend_cpu_hbm_buffer_type(void);
|
| 146 |
+
#endif
|
| 147 |
+
|
| 148 |
+
#ifdef __cplusplus
|
| 149 |
+
}
|
| 150 |
+
#endif
|
ggml/include/ggml.h
CHANGED
|
@@ -573,6 +573,13 @@ extern "C" {
|
|
| 573 |
GGML_TENSOR_FLAG_LOSS = 8, // ...defines loss for numerical optimization (multiple loss tensors add up)
|
| 574 |
};
|
| 575 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 576 |
// n-dimensional tensor
|
| 577 |
struct ggml_tensor {
|
| 578 |
enum ggml_type type;
|
|
@@ -618,59 +625,6 @@ extern "C" {
|
|
| 618 |
// If it returns true, the computation is aborted
|
| 619 |
typedef bool (*ggml_abort_callback)(void * data);
|
| 620 |
|
| 621 |
-
// Scheduling priorities
|
| 622 |
-
enum ggml_sched_priority {
|
| 623 |
-
GGML_SCHED_PRIO_NORMAL,
|
| 624 |
-
GGML_SCHED_PRIO_MEDIUM,
|
| 625 |
-
GGML_SCHED_PRIO_HIGH,
|
| 626 |
-
GGML_SCHED_PRIO_REALTIME
|
| 627 |
-
};
|
| 628 |
-
|
| 629 |
-
// Threadpool params
|
| 630 |
-
// Use ggml_threadpool_params_default() or ggml_threadpool_params_init() to populate the defaults
|
| 631 |
-
struct ggml_threadpool_params {
|
| 632 |
-
bool cpumask[GGML_MAX_N_THREADS]; // mask of cpu cores (all-zeros means use default affinity settings)
|
| 633 |
-
int n_threads; // number of threads
|
| 634 |
-
enum ggml_sched_priority prio; // thread priority
|
| 635 |
-
uint32_t poll; // polling level (0 - no polling, 100 - aggressive polling)
|
| 636 |
-
bool strict_cpu; // strict cpu placement
|
| 637 |
-
bool paused; // start in paused state
|
| 638 |
-
};
|
| 639 |
-
|
| 640 |
-
struct ggml_threadpool; // forward declaration, see ggml.c
|
| 641 |
-
|
| 642 |
-
typedef struct ggml_threadpool * ggml_threadpool_t;
|
| 643 |
-
|
| 644 |
-
// the compute plan that needs to be prepared for ggml_graph_compute()
|
| 645 |
-
// since https://github.com/ggerganov/ggml/issues/287
|
| 646 |
-
struct ggml_cplan {
|
| 647 |
-
size_t work_size; // size of work buffer, calculated by `ggml_graph_plan()`
|
| 648 |
-
uint8_t * work_data; // work buffer, to be allocated by caller before calling to `ggml_graph_compute()`
|
| 649 |
-
|
| 650 |
-
int n_threads;
|
| 651 |
-
struct ggml_threadpool * threadpool;
|
| 652 |
-
|
| 653 |
-
// abort ggml_graph_compute when true
|
| 654 |
-
ggml_abort_callback abort_callback;
|
| 655 |
-
void * abort_callback_data;
|
| 656 |
-
};
|
| 657 |
-
|
| 658 |
-
struct ggml_init_params {
|
| 659 |
-
// memory pool
|
| 660 |
-
size_t mem_size; // bytes
|
| 661 |
-
void * mem_buffer; // if NULL, memory will be allocated internally
|
| 662 |
-
bool no_alloc; // don't allocate memory for the tensor data
|
| 663 |
-
};
|
| 664 |
-
|
| 665 |
-
// numa strategies
|
| 666 |
-
enum ggml_numa_strategy {
|
| 667 |
-
GGML_NUMA_STRATEGY_DISABLED = 0,
|
| 668 |
-
GGML_NUMA_STRATEGY_DISTRIBUTE = 1,
|
| 669 |
-
GGML_NUMA_STRATEGY_ISOLATE = 2,
|
| 670 |
-
GGML_NUMA_STRATEGY_NUMACTL = 3,
|
| 671 |
-
GGML_NUMA_STRATEGY_MIRROR = 4,
|
| 672 |
-
GGML_NUMA_STRATEGY_COUNT
|
| 673 |
-
};
|
| 674 |
|
| 675 |
//
|
| 676 |
// GUID
|
|
@@ -693,9 +647,6 @@ extern "C" {
|
|
| 693 |
// accepts a UTF-8 path, even on Windows
|
| 694 |
GGML_API FILE * ggml_fopen(const char * fname, const char * mode);
|
| 695 |
|
| 696 |
-
GGML_API void ggml_numa_init(enum ggml_numa_strategy numa); // call once for better performance on NUMA systems
|
| 697 |
-
GGML_API bool ggml_is_numa(void); // true if init detected that system has >1 NUMA node
|
| 698 |
-
|
| 699 |
GGML_API void ggml_print_object (const struct ggml_object * obj);
|
| 700 |
GGML_API void ggml_print_objects(const struct ggml_context * ctx);
|
| 701 |
|
|
@@ -797,8 +748,7 @@ extern "C" {
|
|
| 797 |
int64_t ne2,
|
| 798 |
int64_t ne3);
|
| 799 |
|
| 800 |
-
GGML_API
|
| 801 |
-
GGML_API struct ggml_tensor * ggml_new_f32(struct ggml_context * ctx, float value);
|
| 802 |
|
| 803 |
GGML_API struct ggml_tensor * ggml_dup_tensor (struct ggml_context * ctx, const struct ggml_tensor * src);
|
| 804 |
GGML_API struct ggml_tensor * ggml_view_tensor(struct ggml_context * ctx, struct ggml_tensor * src);
|
|
@@ -808,35 +758,25 @@ extern "C" {
|
|
| 808 |
GGML_API struct ggml_tensor * ggml_get_next_tensor (const struct ggml_context * ctx, struct ggml_tensor * tensor);
|
| 809 |
GGML_API struct ggml_tensor * ggml_get_tensor(struct ggml_context * ctx, const char * name);
|
| 810 |
|
| 811 |
-
GGML_API struct ggml_tensor * ggml_set_zero(struct ggml_tensor * tensor);
|
| 812 |
-
GGML_API struct ggml_tensor * ggml_set_i32 (struct ggml_tensor * tensor, int32_t value);
|
| 813 |
-
GGML_API struct ggml_tensor * ggml_set_f32 (struct ggml_tensor * tensor, float value);
|
| 814 |
-
|
| 815 |
// Converts a flat index into coordinates
|
| 816 |
-
GGML_API void
|
| 817 |
-
|
| 818 |
-
GGML_API int32_t ggml_get_i32_1d(const struct ggml_tensor * tensor, int i);
|
| 819 |
-
GGML_API void ggml_set_i32_1d(const struct ggml_tensor * tensor, int i, int32_t value);
|
| 820 |
-
|
| 821 |
-
GGML_API int32_t ggml_get_i32_nd(const struct ggml_tensor * tensor, int i0, int i1, int i2, int i3);
|
| 822 |
-
GGML_API void ggml_set_i32_nd(const struct ggml_tensor * tensor, int i0, int i1, int i2, int i3, int32_t value);
|
| 823 |
-
|
| 824 |
-
GGML_API float ggml_get_f32_1d(const struct ggml_tensor * tensor, int i);
|
| 825 |
-
GGML_API void ggml_set_f32_1d(const struct ggml_tensor * tensor, int i, float value);
|
| 826 |
|
| 827 |
-
GGML_API
|
| 828 |
-
GGML_API void ggml_set_f32_nd(const struct ggml_tensor * tensor, int i0, int i1, int i2, int i3, float value);
|
| 829 |
|
| 830 |
GGML_API void * ggml_get_data (const struct ggml_tensor * tensor);
|
| 831 |
GGML_API float * ggml_get_data_f32(const struct ggml_tensor * tensor);
|
| 832 |
|
| 833 |
-
GGML_API enum ggml_unary_op ggml_get_unary_op(const struct ggml_tensor * tensor);
|
| 834 |
-
|
| 835 |
GGML_API const char * ggml_get_name (const struct ggml_tensor * tensor);
|
| 836 |
GGML_API struct ggml_tensor * ggml_set_name ( struct ggml_tensor * tensor, const char * name);
|
| 837 |
GGML_ATTRIBUTE_FORMAT(2, 3)
|
| 838 |
GGML_API struct ggml_tensor * ggml_format_name( struct ggml_tensor * tensor, const char * fmt, ...);
|
| 839 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 840 |
//
|
| 841 |
// operations on tensors with backpropagation
|
| 842 |
//
|
|
@@ -2052,9 +1992,6 @@ extern "C" {
|
|
| 2052 |
// automatic differentiation
|
| 2053 |
//
|
| 2054 |
|
| 2055 |
-
GGML_API void ggml_set_param(struct ggml_context * ctx, struct ggml_tensor * tensor);
|
| 2056 |
-
GGML_API void ggml_set_loss(struct ggml_tensor * tensor);
|
| 2057 |
-
|
| 2058 |
GGML_API void ggml_build_forward_expand (struct ggml_cgraph * cgraph, struct ggml_tensor * tensor);
|
| 2059 |
GGML_API void ggml_build_backward_expand(struct ggml_context * ctx, struct ggml_cgraph * gf, struct ggml_cgraph * gb, bool accumulate);
|
| 2060 |
|
|
@@ -2086,27 +2023,6 @@ extern "C" {
|
|
| 2086 |
GGML_API size_t ggml_graph_overhead(void);
|
| 2087 |
GGML_API size_t ggml_graph_overhead_custom(size_t size, bool grads);
|
| 2088 |
|
| 2089 |
-
GGML_API struct ggml_threadpool_params ggml_threadpool_params_default(int n_threads);
|
| 2090 |
-
GGML_API void ggml_threadpool_params_init (struct ggml_threadpool_params * p, int n_threads);
|
| 2091 |
-
GGML_API bool ggml_threadpool_params_match (const struct ggml_threadpool_params * p0, const struct ggml_threadpool_params * p1);
|
| 2092 |
-
GGML_API struct ggml_threadpool * ggml_threadpool_new (struct ggml_threadpool_params * params);
|
| 2093 |
-
GGML_API void ggml_threadpool_free (struct ggml_threadpool * threadpool);
|
| 2094 |
-
GGML_API int ggml_threadpool_get_n_threads(struct ggml_threadpool * threadpool);
|
| 2095 |
-
GGML_API void ggml_threadpool_pause (struct ggml_threadpool * threadpool);
|
| 2096 |
-
GGML_API void ggml_threadpool_resume (struct ggml_threadpool * threadpool);
|
| 2097 |
-
|
| 2098 |
-
// ggml_graph_plan() has to be called before ggml_graph_compute()
|
| 2099 |
-
// when plan.work_size > 0, caller must allocate memory for plan.work_data
|
| 2100 |
-
GGML_API struct ggml_cplan ggml_graph_plan(
|
| 2101 |
-
const struct ggml_cgraph * cgraph,
|
| 2102 |
-
int n_threads, /* = GGML_DEFAULT_N_THREADS */
|
| 2103 |
-
struct ggml_threadpool * threadpool /* = NULL */ );
|
| 2104 |
-
GGML_API enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cplan * cplan);
|
| 2105 |
-
|
| 2106 |
-
// same as ggml_graph_compute() but the work data is allocated as a part of the context
|
| 2107 |
-
// note: the drawback of this API is that you must have ensured that the context has enough memory for the work data
|
| 2108 |
-
GGML_API enum ggml_status ggml_graph_compute_with_ctx(struct ggml_context * ctx, struct ggml_cgraph * cgraph, int n_threads);
|
| 2109 |
-
|
| 2110 |
GGML_API struct ggml_tensor * ggml_graph_get_tensor(struct ggml_cgraph * cgraph, const char * name);
|
| 2111 |
|
| 2112 |
GGML_API void ggml_graph_export(const struct ggml_cgraph * cgraph, const char * fname);
|
|
@@ -2277,6 +2193,8 @@ extern "C" {
|
|
| 2277 |
} lbfgs;
|
| 2278 |
};
|
| 2279 |
|
|
|
|
|
|
|
| 2280 |
GGML_API struct ggml_opt_params ggml_opt_default_params(enum ggml_opt_type type);
|
| 2281 |
|
| 2282 |
// optimize the function defined by the tensor f
|
|
@@ -2308,12 +2226,6 @@ extern "C" {
|
|
| 2308 |
ggml_opt_callback callback,
|
| 2309 |
void * callback_data);
|
| 2310 |
|
| 2311 |
-
//
|
| 2312 |
-
// tensor flags
|
| 2313 |
-
//
|
| 2314 |
-
GGML_API void ggml_set_input(struct ggml_tensor * tensor);
|
| 2315 |
-
GGML_API void ggml_set_output(struct ggml_tensor * tensor);
|
| 2316 |
-
|
| 2317 |
//
|
| 2318 |
// quantization
|
| 2319 |
//
|
|
@@ -2482,8 +2394,6 @@ extern "C" {
|
|
| 2482 |
GGML_API int ggml_cpu_has_avx512_bf16(void);
|
| 2483 |
GGML_API int ggml_cpu_has_amx_int8 (void);
|
| 2484 |
GGML_API int ggml_cpu_has_fma (void);
|
| 2485 |
-
GGML_API int ggml_cpu_has_neon (void);
|
| 2486 |
-
GGML_API int ggml_cpu_has_sve (void);
|
| 2487 |
GGML_API int ggml_cpu_has_arm_fma (void);
|
| 2488 |
GGML_API int ggml_cpu_has_metal (void);
|
| 2489 |
GGML_API int ggml_cpu_has_f16c (void);
|
|
@@ -2500,17 +2410,9 @@ extern "C" {
|
|
| 2500 |
GGML_API int ggml_cpu_has_sycl (void);
|
| 2501 |
GGML_API int ggml_cpu_has_rpc (void);
|
| 2502 |
GGML_API int ggml_cpu_has_vsx (void);
|
| 2503 |
-
GGML_API int ggml_cpu_has_matmul_int8(void);
|
| 2504 |
GGML_API int ggml_cpu_has_cann (void);
|
| 2505 |
GGML_API int ggml_cpu_has_llamafile (void);
|
| 2506 |
|
| 2507 |
-
// get the sve vector length in bytes
|
| 2508 |
-
GGML_API int ggml_cpu_get_sve_cnt(void);
|
| 2509 |
-
|
| 2510 |
-
//
|
| 2511 |
-
// Internal types and functions exposed for tests and benchmarks
|
| 2512 |
-
//
|
| 2513 |
-
|
| 2514 |
#ifdef __cplusplus
|
| 2515 |
// restrict not standard in C++
|
| 2516 |
#define GGML_RESTRICT
|
|
@@ -2519,14 +2421,6 @@ extern "C" {
|
|
| 2519 |
#endif
|
| 2520 |
typedef void (*ggml_to_float_t) (const void * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
|
| 2521 |
typedef void (*ggml_from_float_t)(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
|
| 2522 |
-
typedef void (*ggml_from_float_to_mat_t)
|
| 2523 |
-
(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t nr, int64_t k, int64_t bs);
|
| 2524 |
-
typedef void (*ggml_vec_dot_t) (int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT x, size_t bx,
|
| 2525 |
-
const void * GGML_RESTRICT y, size_t by, int nrc);
|
| 2526 |
-
typedef void (*ggml_gemv_t) (int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT x,
|
| 2527 |
-
const void * GGML_RESTRICT y, int nr, int nc);
|
| 2528 |
-
typedef void (*ggml_gemm_t) (int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT x,
|
| 2529 |
-
const void * GGML_RESTRICT y, int nr, int nc);
|
| 2530 |
|
| 2531 |
struct ggml_type_traits {
|
| 2532 |
const char * type_name;
|
|
@@ -2537,13 +2431,6 @@ extern "C" {
|
|
| 2537 |
ggml_to_float_t to_float;
|
| 2538 |
ggml_from_float_t from_float;
|
| 2539 |
ggml_from_float_t from_float_ref;
|
| 2540 |
-
ggml_from_float_to_mat_t from_float_to_mat;
|
| 2541 |
-
ggml_vec_dot_t vec_dot;
|
| 2542 |
-
enum ggml_type vec_dot_type;
|
| 2543 |
-
int64_t nrows; // number of rows to process simultaneously
|
| 2544 |
-
int64_t ncols; // number of columns to process simultaneously
|
| 2545 |
-
ggml_gemv_t gemv;
|
| 2546 |
-
ggml_gemm_t gemm;
|
| 2547 |
};
|
| 2548 |
|
| 2549 |
GGML_API const struct ggml_type_traits * ggml_get_type_traits(enum ggml_type type);
|
|
|
|
| 573 |
GGML_TENSOR_FLAG_LOSS = 8, // ...defines loss for numerical optimization (multiple loss tensors add up)
|
| 574 |
};
|
| 575 |
|
| 576 |
+
struct ggml_init_params {
|
| 577 |
+
// memory pool
|
| 578 |
+
size_t mem_size; // bytes
|
| 579 |
+
void * mem_buffer; // if NULL, memory will be allocated internally
|
| 580 |
+
bool no_alloc; // don't allocate memory for the tensor data
|
| 581 |
+
};
|
| 582 |
+
|
| 583 |
// n-dimensional tensor
|
| 584 |
struct ggml_tensor {
|
| 585 |
enum ggml_type type;
|
|
|
|
| 625 |
// If it returns true, the computation is aborted
|
| 626 |
typedef bool (*ggml_abort_callback)(void * data);
|
| 627 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
|
| 629 |
//
|
| 630 |
// GUID
|
|
|
|
| 647 |
// accepts a UTF-8 path, even on Windows
|
| 648 |
GGML_API FILE * ggml_fopen(const char * fname, const char * mode);
|
| 649 |
|
|
|
|
|
|
|
|
|
|
| 650 |
GGML_API void ggml_print_object (const struct ggml_object * obj);
|
| 651 |
GGML_API void ggml_print_objects(const struct ggml_context * ctx);
|
| 652 |
|
|
|
|
| 748 |
int64_t ne2,
|
| 749 |
int64_t ne3);
|
| 750 |
|
| 751 |
+
GGML_API void * ggml_new_buffer(struct ggml_context * ctx, size_t nbytes);
|
|
|
|
| 752 |
|
| 753 |
GGML_API struct ggml_tensor * ggml_dup_tensor (struct ggml_context * ctx, const struct ggml_tensor * src);
|
| 754 |
GGML_API struct ggml_tensor * ggml_view_tensor(struct ggml_context * ctx, struct ggml_tensor * src);
|
|
|
|
| 758 |
GGML_API struct ggml_tensor * ggml_get_next_tensor (const struct ggml_context * ctx, struct ggml_tensor * tensor);
|
| 759 |
GGML_API struct ggml_tensor * ggml_get_tensor(struct ggml_context * ctx, const char * name);
|
| 760 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 761 |
// Converts a flat index into coordinates
|
| 762 |
+
GGML_API void ggml_unravel_index(const struct ggml_tensor * tensor, int64_t i, int64_t * i0, int64_t * i1, int64_t * i2, int64_t * i3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 763 |
|
| 764 |
+
GGML_API enum ggml_unary_op ggml_get_unary_op(const struct ggml_tensor * tensor);
|
|
|
|
| 765 |
|
| 766 |
GGML_API void * ggml_get_data (const struct ggml_tensor * tensor);
|
| 767 |
GGML_API float * ggml_get_data_f32(const struct ggml_tensor * tensor);
|
| 768 |
|
|
|
|
|
|
|
| 769 |
GGML_API const char * ggml_get_name (const struct ggml_tensor * tensor);
|
| 770 |
GGML_API struct ggml_tensor * ggml_set_name ( struct ggml_tensor * tensor, const char * name);
|
| 771 |
GGML_ATTRIBUTE_FORMAT(2, 3)
|
| 772 |
GGML_API struct ggml_tensor * ggml_format_name( struct ggml_tensor * tensor, const char * fmt, ...);
|
| 773 |
|
| 774 |
+
// Tensor flags
|
| 775 |
+
GGML_API void ggml_set_input(struct ggml_tensor * tensor);
|
| 776 |
+
GGML_API void ggml_set_output(struct ggml_tensor * tensor);
|
| 777 |
+
GGML_API void ggml_set_param(struct ggml_context * ctx, struct ggml_tensor * tensor);
|
| 778 |
+
GGML_API void ggml_set_loss(struct ggml_tensor * tensor);
|
| 779 |
+
|
| 780 |
//
|
| 781 |
// operations on tensors with backpropagation
|
| 782 |
//
|
|
|
|
| 1992 |
// automatic differentiation
|
| 1993 |
//
|
| 1994 |
|
|
|
|
|
|
|
|
|
|
| 1995 |
GGML_API void ggml_build_forward_expand (struct ggml_cgraph * cgraph, struct ggml_tensor * tensor);
|
| 1996 |
GGML_API void ggml_build_backward_expand(struct ggml_context * ctx, struct ggml_cgraph * gf, struct ggml_cgraph * gb, bool accumulate);
|
| 1997 |
|
|
|
|
| 2023 |
GGML_API size_t ggml_graph_overhead(void);
|
| 2024 |
GGML_API size_t ggml_graph_overhead_custom(size_t size, bool grads);
|
| 2025 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2026 |
GGML_API struct ggml_tensor * ggml_graph_get_tensor(struct ggml_cgraph * cgraph, const char * name);
|
| 2027 |
|
| 2028 |
GGML_API void ggml_graph_export(const struct ggml_cgraph * cgraph, const char * fname);
|
|
|
|
| 2193 |
} lbfgs;
|
| 2194 |
};
|
| 2195 |
|
| 2196 |
+
GGML_API struct ggml_tensor * ggml_set_zero(struct ggml_tensor * tensor);
|
| 2197 |
+
|
| 2198 |
GGML_API struct ggml_opt_params ggml_opt_default_params(enum ggml_opt_type type);
|
| 2199 |
|
| 2200 |
// optimize the function defined by the tensor f
|
|
|
|
| 2226 |
ggml_opt_callback callback,
|
| 2227 |
void * callback_data);
|
| 2228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2229 |
//
|
| 2230 |
// quantization
|
| 2231 |
//
|
|
|
|
| 2394 |
GGML_API int ggml_cpu_has_avx512_bf16(void);
|
| 2395 |
GGML_API int ggml_cpu_has_amx_int8 (void);
|
| 2396 |
GGML_API int ggml_cpu_has_fma (void);
|
|
|
|
|
|
|
| 2397 |
GGML_API int ggml_cpu_has_arm_fma (void);
|
| 2398 |
GGML_API int ggml_cpu_has_metal (void);
|
| 2399 |
GGML_API int ggml_cpu_has_f16c (void);
|
|
|
|
| 2410 |
GGML_API int ggml_cpu_has_sycl (void);
|
| 2411 |
GGML_API int ggml_cpu_has_rpc (void);
|
| 2412 |
GGML_API int ggml_cpu_has_vsx (void);
|
|
|
|
| 2413 |
GGML_API int ggml_cpu_has_cann (void);
|
| 2414 |
GGML_API int ggml_cpu_has_llamafile (void);
|
| 2415 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2416 |
#ifdef __cplusplus
|
| 2417 |
// restrict not standard in C++
|
| 2418 |
#define GGML_RESTRICT
|
|
|
|
| 2421 |
#endif
|
| 2422 |
typedef void (*ggml_to_float_t) (const void * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
|
| 2423 |
typedef void (*ggml_from_float_t)(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2424 |
|
| 2425 |
struct ggml_type_traits {
|
| 2426 |
const char * type_name;
|
|
|
|
| 2431 |
ggml_to_float_t to_float;
|
| 2432 |
ggml_from_float_t from_float;
|
| 2433 |
ggml_from_float_t from_float_ref;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2434 |
};
|
| 2435 |
|
| 2436 |
GGML_API const struct ggml_type_traits * ggml_get_type_traits(enum ggml_type type);
|
ggml/src/CMakeLists.txt
CHANGED
|
@@ -1366,10 +1366,12 @@ endif()
|
|
| 1366 |
|
| 1367 |
add_library(ggml
|
| 1368 |
../include/ggml.h
|
|
|
|
| 1369 |
../include/ggml-alloc.h
|
| 1370 |
../include/ggml-backend.h
|
| 1371 |
../include/ggml-cpp.h
|
| 1372 |
ggml.c
|
|
|
|
| 1373 |
ggml-alloc.c
|
| 1374 |
ggml-backend.cpp
|
| 1375 |
ggml-quants.c
|
|
|
|
| 1366 |
|
| 1367 |
add_library(ggml
|
| 1368 |
../include/ggml.h
|
| 1369 |
+
../include/ggml-cpu.h
|
| 1370 |
../include/ggml-alloc.h
|
| 1371 |
../include/ggml-backend.h
|
| 1372 |
../include/ggml-cpp.h
|
| 1373 |
ggml.c
|
| 1374 |
+
ggml-cpu.c
|
| 1375 |
ggml-alloc.c
|
| 1376 |
ggml-backend.cpp
|
| 1377 |
ggml-quants.c
|
ggml/src/ggml-aarch64.c
CHANGED
|
@@ -7,6 +7,7 @@
|
|
| 7 |
|
| 8 |
#include "ggml-quants.h"
|
| 9 |
#include "ggml-impl.h"
|
|
|
|
| 10 |
#include "ggml-cpu-impl.h"
|
| 11 |
|
| 12 |
#include <math.h>
|
|
|
|
| 7 |
|
| 8 |
#include "ggml-quants.h"
|
| 9 |
#include "ggml-impl.h"
|
| 10 |
+
#include "ggml-cpu.h"
|
| 11 |
#include "ggml-cpu-impl.h"
|
| 12 |
|
| 13 |
#include <math.h>
|
ggml/src/ggml-backend.cpp
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
ggml/src/ggml-cpu.c
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
ggml/src/ggml-impl.h
CHANGED
|
@@ -8,6 +8,7 @@
|
|
| 8 |
#include <stdlib.h> // load `stdlib.h` before other headers to work around MinGW bug: https://sourceforge.net/p/mingw-w64/bugs/192/
|
| 9 |
#include <stdbool.h>
|
| 10 |
#include <stdint.h>
|
|
|
|
| 11 |
|
| 12 |
#ifdef __cplusplus
|
| 13 |
extern "C" {
|
|
@@ -36,6 +37,20 @@ extern "C" {
|
|
| 36 |
#endif
|
| 37 |
#endif
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
//
|
| 40 |
// logging
|
| 41 |
//
|
|
@@ -51,6 +66,74 @@ void ggml_log_callback_default(enum ggml_log_level level, const char * text, voi
|
|
| 51 |
#define GGML_LOG_DEBUG(...) ggml_log_internal(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__)
|
| 52 |
#define GGML_LOG_CONT(...) ggml_log_internal(GGML_LOG_LEVEL_CONT , __VA_ARGS__)
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
// bitset
|
| 55 |
|
| 56 |
typedef uint32_t ggml_bitset_t;
|
|
@@ -204,6 +287,10 @@ struct ggml_cgraph ggml_graph_view(struct ggml_cgraph * cgraph, int i0, int i1);
|
|
| 204 |
void * ggml_aligned_malloc(size_t size);
|
| 205 |
void ggml_aligned_free(void * ptr, size_t size);
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
#ifdef __cplusplus
|
| 208 |
}
|
| 209 |
#endif
|
|
|
|
| 8 |
#include <stdlib.h> // load `stdlib.h` before other headers to work around MinGW bug: https://sourceforge.net/p/mingw-w64/bugs/192/
|
| 9 |
#include <stdbool.h>
|
| 10 |
#include <stdint.h>
|
| 11 |
+
#include <string.h>
|
| 12 |
|
| 13 |
#ifdef __cplusplus
|
| 14 |
extern "C" {
|
|
|
|
| 37 |
#endif
|
| 38 |
#endif
|
| 39 |
|
| 40 |
+
static inline int ggml_up32(int n) {
|
| 41 |
+
return (n + 31) & ~31;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
//static inline int ggml_up64(int n) {
|
| 45 |
+
// return (n + 63) & ~63;
|
| 46 |
+
//}
|
| 47 |
+
|
| 48 |
+
static inline int ggml_up(int n, int m) {
|
| 49 |
+
// assert m is a power of 2
|
| 50 |
+
GGML_ASSERT((m & (m - 1)) == 0);
|
| 51 |
+
return (n + m - 1) & ~(m - 1);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
//
|
| 55 |
// logging
|
| 56 |
//
|
|
|
|
| 66 |
#define GGML_LOG_DEBUG(...) ggml_log_internal(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__)
|
| 67 |
#define GGML_LOG_CONT(...) ggml_log_internal(GGML_LOG_LEVEL_CONT , __VA_ARGS__)
|
| 68 |
|
| 69 |
+
#define GGML_DEBUG 0
|
| 70 |
+
|
| 71 |
+
#if (GGML_DEBUG >= 1)
|
| 72 |
+
#define GGML_PRINT_DEBUG(...) GGML_LOG_DEBUG(__VA_ARGS__)
|
| 73 |
+
#else
|
| 74 |
+
#define GGML_PRINT_DEBUG(...)
|
| 75 |
+
#endif
|
| 76 |
+
|
| 77 |
+
#if (GGML_DEBUG >= 5)
|
| 78 |
+
#define GGML_PRINT_DEBUG_5(...) GGML_LOG_DEBUG(__VA_ARGS__)
|
| 79 |
+
#else
|
| 80 |
+
#define GGML_PRINT_DEBUG_5(...)
|
| 81 |
+
#endif
|
| 82 |
+
|
| 83 |
+
#if (GGML_DEBUG >= 10)
|
| 84 |
+
#define GGML_PRINT_DEBUG_10(...) GGML_LOG_DEBUG(__VA_ARGS__)
|
| 85 |
+
#else
|
| 86 |
+
#define GGML_PRINT_DEBUG_10(...)
|
| 87 |
+
#endif
|
| 88 |
+
|
| 89 |
+
// tensor params
|
| 90 |
+
|
| 91 |
+
static void ggml_set_op_params(struct ggml_tensor * tensor, const void * params, size_t params_size) {
|
| 92 |
+
GGML_ASSERT(tensor != NULL); // silence -Warray-bounds warnings
|
| 93 |
+
assert(params_size <= GGML_MAX_OP_PARAMS);
|
| 94 |
+
memcpy(tensor->op_params, params, params_size);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
static int32_t ggml_get_op_params_i32(const struct ggml_tensor * tensor, uint32_t i) {
|
| 98 |
+
assert(i < GGML_MAX_OP_PARAMS / sizeof(int32_t));
|
| 99 |
+
return ((const int32_t *)(tensor->op_params))[i];
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
static float ggml_get_op_params_f32(const struct ggml_tensor * tensor, uint32_t i) {
|
| 103 |
+
assert(i < GGML_MAX_OP_PARAMS / sizeof(float));
|
| 104 |
+
return ((const float *)(tensor->op_params))[i];
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
static void ggml_set_op_params_i32(struct ggml_tensor * tensor, uint32_t i, int32_t value) {
|
| 108 |
+
assert(i < GGML_MAX_OP_PARAMS / sizeof(int32_t));
|
| 109 |
+
((int32_t *)(tensor->op_params))[i] = value;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
static void ggml_set_op_params_f32(struct ggml_tensor * tensor, uint32_t i, float value) {
|
| 113 |
+
assert(i < GGML_MAX_OP_PARAMS / sizeof(float));
|
| 114 |
+
((float *)(tensor->op_params))[i] = value;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
struct ggml_map_custom1_op_params {
|
| 118 |
+
ggml_custom1_op_t fun;
|
| 119 |
+
int n_tasks;
|
| 120 |
+
void * userdata;
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
struct ggml_map_custom2_op_params {
|
| 125 |
+
ggml_custom2_op_t fun;
|
| 126 |
+
int n_tasks;
|
| 127 |
+
void * userdata;
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
struct ggml_map_custom3_op_params {
|
| 132 |
+
ggml_custom3_op_t fun;
|
| 133 |
+
int n_tasks;
|
| 134 |
+
void * userdata;
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
// bitset
|
| 138 |
|
| 139 |
typedef uint32_t ggml_bitset_t;
|
|
|
|
| 287 |
void * ggml_aligned_malloc(size_t size);
|
| 288 |
void ggml_aligned_free(void * ptr, size_t size);
|
| 289 |
|
| 290 |
+
// TODO: move to threading file
|
| 291 |
+
void ggml_critical_section_start(void);
|
| 292 |
+
void ggml_critical_section_end(void);
|
| 293 |
+
|
| 294 |
#ifdef __cplusplus
|
| 295 |
}
|
| 296 |
#endif
|
ggml/src/ggml-rpc.cpp
CHANGED
|
@@ -1296,13 +1296,6 @@ static ggml_backend_buffer_type_t ggml_backend_rpc_device_get_buffer_type(ggml_b
|
|
| 1296 |
UNUSED(dev);
|
| 1297 |
}
|
| 1298 |
|
| 1299 |
-
static ggml_backend_buffer_t ggml_backend_rpc_device_buffer_from_ptr(ggml_backend_dev_t dev, void * ptr, size_t size, size_t max_tensor_size) {
|
| 1300 |
-
return ggml_backend_cpu_buffer_from_ptr(ptr, size);
|
| 1301 |
-
|
| 1302 |
-
UNUSED(dev);
|
| 1303 |
-
UNUSED(max_tensor_size);
|
| 1304 |
-
}
|
| 1305 |
-
|
| 1306 |
static bool ggml_backend_rpc_device_supports_op(ggml_backend_dev_t dev, const struct ggml_tensor * op) {
|
| 1307 |
UNUSED(dev);
|
| 1308 |
UNUSED(op);
|
|
@@ -1328,7 +1321,7 @@ static const struct ggml_backend_device_i ggml_backend_rpc_device_i = {
|
|
| 1328 |
/* .init_backend = */ ggml_backend_rpc_device_init,
|
| 1329 |
/* .get_buffer_type = */ ggml_backend_rpc_device_get_buffer_type,
|
| 1330 |
/* .get_host_buffer_type = */ NULL,
|
| 1331 |
-
/* .buffer_from_host_ptr = */
|
| 1332 |
/* .supports_op = */ ggml_backend_rpc_device_supports_op,
|
| 1333 |
/* .supports_buft = */ ggml_backend_rpc_device_supports_buft,
|
| 1334 |
/* .offload_op = */ NULL,
|
|
|
|
| 1296 |
UNUSED(dev);
|
| 1297 |
}
|
| 1298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1299 |
static bool ggml_backend_rpc_device_supports_op(ggml_backend_dev_t dev, const struct ggml_tensor * op) {
|
| 1300 |
UNUSED(dev);
|
| 1301 |
UNUSED(op);
|
|
|
|
| 1321 |
/* .init_backend = */ ggml_backend_rpc_device_init,
|
| 1322 |
/* .get_buffer_type = */ ggml_backend_rpc_device_get_buffer_type,
|
| 1323 |
/* .get_host_buffer_type = */ NULL,
|
| 1324 |
+
/* .buffer_from_host_ptr = */ NULL,
|
| 1325 |
/* .supports_op = */ ggml_backend_rpc_device_supports_op,
|
| 1326 |
/* .supports_buft = */ ggml_backend_rpc_device_supports_buft,
|
| 1327 |
/* .offload_op = */ NULL,
|
ggml/src/ggml.c
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|