cui-llama.rn 1.3.0 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/CMakeLists.txt +6 -1
- package/android/src/main/jni.cpp +6 -6
- package/cpp/amx/amx.cpp +196 -0
- package/cpp/amx/amx.h +20 -0
- package/cpp/amx/common.h +101 -0
- package/cpp/amx/mmq.cpp +2524 -0
- package/cpp/amx/mmq.h +16 -0
- package/cpp/common.cpp +1981 -1682
- package/cpp/common.h +636 -600
- package/cpp/ggml-aarch64.c +129 -129
- package/cpp/ggml-aarch64.h +19 -19
- package/cpp/ggml-alloc.c +1038 -1040
- package/cpp/ggml-alloc.h +76 -76
- package/cpp/ggml-backend-impl.h +238 -216
- package/cpp/ggml-backend-reg.cpp +423 -195
- package/cpp/ggml-backend.cpp +1999 -1997
- package/cpp/ggml-backend.h +351 -328
- package/cpp/ggml-common.h +1859 -1853
- package/cpp/ggml-cpp.h +38 -38
- package/cpp/ggml-cpu-aarch64.c +3823 -3560
- package/cpp/ggml-cpu-aarch64.h +32 -30
- package/cpp/ggml-cpu-impl.h +386 -371
- package/cpp/ggml-cpu-quants.c +10835 -10822
- package/cpp/ggml-cpu-quants.h +63 -63
- package/cpp/ggml-cpu.c +99 -103
- package/cpp/ggml-cpu.cpp +69 -17
- package/cpp/ggml-cpu.h +152 -177
- package/cpp/ggml-impl.h +556 -550
- package/cpp/ggml-metal.h +66 -66
- package/cpp/ggml-metal.m +4426 -4294
- package/cpp/ggml-quants.c +5247 -5247
- package/cpp/ggml-quants.h +100 -100
- package/cpp/ggml-threading.cpp +12 -12
- package/cpp/ggml-threading.h +12 -12
- package/cpp/ggml.c +7618 -8180
- package/cpp/ggml.h +2255 -2411
- package/cpp/json-schema-to-grammar.cpp +1045 -0
- package/cpp/json-schema-to-grammar.h +8 -0
- package/cpp/json.hpp +24766 -0
- package/cpp/llama-grammar.cpp +1138 -1138
- package/cpp/llama-grammar.h +144 -144
- package/cpp/llama-impl.h +181 -181
- package/cpp/llama-sampling.cpp +2348 -2348
- package/cpp/llama-sampling.h +48 -48
- package/cpp/llama-vocab.cpp +1984 -1984
- package/cpp/llama-vocab.h +170 -170
- package/cpp/llama.cpp +22332 -22132
- package/cpp/llama.h +1259 -1253
- package/cpp/log.cpp +401 -401
- package/cpp/log.h +121 -121
- package/cpp/rn-llama.hpp +6 -6
- package/cpp/sampling.cpp +505 -466
- package/cpp/sampling.h +22 -1
- package/cpp/sgemm.cpp +1884 -1884
- package/cpp/speculative.cpp +270 -0
- package/cpp/speculative.h +28 -0
- package/cpp/unicode.cpp +11 -0
- package/ios/RNLlamaContext.mm +13 -0
- package/lib/commonjs/NativeRNLlama.js.map +1 -1
- package/lib/commonjs/grammar.js +4 -2
- package/lib/commonjs/grammar.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeRNLlama.js.map +1 -1
- package/lib/module/grammar.js +2 -1
- package/lib/module/grammar.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/NativeRNLlama.d.ts +94 -4
- package/lib/typescript/NativeRNLlama.d.ts.map +1 -1
- package/lib/typescript/grammar.d.ts +5 -6
- package/lib/typescript/grammar.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/NativeRNLlama.ts +97 -10
- package/src/grammar.ts +10 -8
- package/src/index.ts +22 -1
package/cpp/ggml-cpu.cpp
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
#include "ggml-cpu.h"
|
4
4
|
#include "ggml-cpu-aarch64.h"
|
5
5
|
#include "ggml-impl.h"
|
6
|
+
#include "amx/amx.h"
|
6
7
|
#include <cctype>
|
7
8
|
#include <string>
|
8
9
|
#include <vector>
|
@@ -134,12 +135,16 @@ static lm_ggml_backend_buffer_type_t * lm_ggml_backend_cpu_get_extra_bufts(lm_gg
|
|
134
135
|
static std::vector<lm_ggml_backend_buffer_type_t> bufts = []() {
|
135
136
|
std::vector<lm_ggml_backend_buffer_type_t> bufts;
|
136
137
|
|
137
|
-
#
|
138
|
-
|
138
|
+
#if defined(__AMX_INT8__) && defined(__AVX512VNNI__)
|
139
|
+
if (lm_ggml_backend_amx_buffer_type()) {
|
140
|
+
bufts.push_back(lm_ggml_backend_amx_buffer_type());
|
141
|
+
}
|
139
142
|
#endif
|
140
143
|
|
141
144
|
#ifdef LM_GGML_USE_CPU_AARCH64
|
142
|
-
|
145
|
+
if (lm_ggml_backend_cpu_aarch64_buffer_type()) {
|
146
|
+
bufts.push_back(lm_ggml_backend_cpu_aarch64_buffer_type());
|
147
|
+
}
|
143
148
|
#endif
|
144
149
|
|
145
150
|
bufts.push_back(NULL);
|
@@ -456,12 +461,27 @@ static bool lm_ggml_backend_cpu_device_supports_op(lm_ggml_backend_dev_t dev, co
|
|
456
461
|
const struct lm_ggml_tensor * src0 = op->src[0];
|
457
462
|
const struct lm_ggml_tensor * src1 = op->src[1];
|
458
463
|
|
464
|
+
if (op->op == LM_GGML_OP_NONE || op->op == LM_GGML_OP_RESHAPE || op->op == LM_GGML_OP_VIEW || op->op == LM_GGML_OP_PERMUTE || op->op == LM_GGML_OP_TRANSPOSE) {
|
465
|
+
return true;
|
466
|
+
}
|
467
|
+
|
459
468
|
if (src0 && src0->buffer && lm_ggml_backend_cpu_buft_is_aarch64(src0->buffer->buft)) {
|
460
|
-
if (op->op != LM_GGML_OP_MUL_MAT || src0->type
|
469
|
+
if (op->op != LM_GGML_OP_MUL_MAT || src0->type == lm_ggml_aarch64_get_optimal_repack_type(src0)) {
|
461
470
|
return false;
|
462
471
|
}
|
463
472
|
}
|
464
473
|
|
474
|
+
#if defined(__AMX_INT8__) && defined(__AVX512VNNI__)
|
475
|
+
if (src0 && src0->buffer && lm_ggml_backend_amx_buft_is_amx(src0->buffer->buft)) {
|
476
|
+
return lm_ggml_backend_amx_device_supports_op(op);
|
477
|
+
}
|
478
|
+
for (int i = 1; i < LM_GGML_MAX_SRC; i++) {
|
479
|
+
if (op->src[i] && op->src[i]->buffer && lm_ggml_backend_amx_buft_is_amx(op->src[i]->buffer->buft)) {
|
480
|
+
return false;
|
481
|
+
}
|
482
|
+
}
|
483
|
+
#endif
|
484
|
+
|
465
485
|
for (int i = 1; i < LM_GGML_MAX_SRC; i++) {
|
466
486
|
if (op->src[i] && op->src[i]->buffer && lm_ggml_backend_cpu_buft_is_aarch64(op->src[i]->buffer->buft)) {
|
467
487
|
return false;
|
@@ -491,7 +511,13 @@ static bool lm_ggml_backend_cpu_device_supports_op(lm_ggml_backend_dev_t dev, co
|
|
491
511
|
}
|
492
512
|
|
493
513
|
static bool lm_ggml_backend_cpu_device_supports_buft(lm_ggml_backend_dev_t dev, lm_ggml_backend_buffer_type_t buft) {
|
494
|
-
|
514
|
+
bool supported = lm_ggml_backend_buft_is_host(buft) || lm_ggml_backend_cpu_buft_is_aarch64(buft);
|
515
|
+
|
516
|
+
#if defined(__AMX_INT8__) && defined(__AVX512VNNI__)
|
517
|
+
supported = supported || lm_ggml_backend_amx_buft_is_amx(buft);
|
518
|
+
#endif
|
519
|
+
|
520
|
+
return supported;
|
495
521
|
|
496
522
|
LM_GGML_UNUSED(dev);
|
497
523
|
}
|
@@ -541,16 +567,12 @@ static lm_ggml_backend_dev_t lm_ggml_backend_cpu_reg_get_device(lm_ggml_backend_
|
|
541
567
|
return &lm_ggml_backend_cpu_device;
|
542
568
|
}
|
543
569
|
|
544
|
-
struct lm_ggml_backend_feature {
|
545
|
-
const char * name;
|
546
|
-
const char * value;
|
547
|
-
};
|
548
|
-
|
549
|
-
// Not used yet
|
550
570
|
// This is intended to replace the the lm_ggml_cpu_has_* functions when loading the CPU backend dynamically,
|
551
|
-
// and additionally to allow other backends to expose their own list of features that applications can query using the same API
|
571
|
+
// and additionally to allow other backends to expose their own list of features that applications can query using the same API
|
552
572
|
static lm_ggml_backend_feature * lm_ggml_backend_cpu_get_features(lm_ggml_backend_reg_t reg) {
|
553
573
|
static std::vector<lm_ggml_backend_feature> features = []() {
|
574
|
+
lm_ggml_cpu_init();
|
575
|
+
|
554
576
|
std::vector<lm_ggml_backend_feature> features;
|
555
577
|
if (lm_ggml_cpu_has_sse3()) {
|
556
578
|
features.push_back({ "SSE3", "1" });
|
@@ -561,6 +583,9 @@ static lm_ggml_backend_feature * lm_ggml_backend_cpu_get_features(lm_ggml_backen
|
|
561
583
|
if (lm_ggml_cpu_has_avx()) {
|
562
584
|
features.push_back({ "AVX", "1" });
|
563
585
|
}
|
586
|
+
if (lm_ggml_cpu_has_avx_vnni()) {
|
587
|
+
features.push_back({ "AVX_VNNI", "1" });
|
588
|
+
}
|
564
589
|
if (lm_ggml_cpu_has_avx2()) {
|
565
590
|
features.push_back({ "AVX2", "1" });
|
566
591
|
}
|
@@ -570,9 +595,6 @@ static lm_ggml_backend_feature * lm_ggml_backend_cpu_get_features(lm_ggml_backen
|
|
570
595
|
if (lm_ggml_cpu_has_fma()) {
|
571
596
|
features.push_back({ "FMA", "1" });
|
572
597
|
}
|
573
|
-
if (lm_ggml_cpu_has_avx_vnni()) {
|
574
|
-
features.push_back({ "AVX_VNNI", "1" });
|
575
|
-
}
|
576
598
|
if (lm_ggml_cpu_has_avx512()) {
|
577
599
|
features.push_back({ "AVX512", "1" });
|
578
600
|
}
|
@@ -619,6 +641,10 @@ static lm_ggml_backend_feature * lm_ggml_backend_cpu_get_features(lm_ggml_backen
|
|
619
641
|
if (lm_ggml_cpu_has_llamafile()) {
|
620
642
|
features.push_back({ "LLAMAFILE", "1" });
|
621
643
|
}
|
644
|
+
// TODO: rename this
|
645
|
+
#ifdef LM_GGML_USE_CPU_AARCH64
|
646
|
+
features.push_back({ "AARCH64_REPACK", "1" });
|
647
|
+
#endif
|
622
648
|
|
623
649
|
features.push_back({ nullptr, nullptr });
|
624
650
|
|
@@ -637,6 +663,29 @@ static void * lm_ggml_backend_cpu_get_proc_address(lm_ggml_backend_reg_t reg, co
|
|
637
663
|
if (strcmp(name, "lm_ggml_backend_dev_get_extra_bufts") == 0) {
|
638
664
|
return (void *)lm_ggml_backend_cpu_get_extra_bufts;
|
639
665
|
}
|
666
|
+
if (strcmp(name, "lm_ggml_backend_get_features") == 0) {
|
667
|
+
return (void *)lm_ggml_backend_cpu_get_features;
|
668
|
+
}
|
669
|
+
if (strcmp(name, "lm_ggml_backend_set_abort_callback") == 0) {
|
670
|
+
return (void *)lm_ggml_backend_cpu_set_abort_callback;
|
671
|
+
}
|
672
|
+
if (strcmp(name, "lm_ggml_backend_cpu_numa_init") == 0) {
|
673
|
+
return (void *)lm_ggml_numa_init;
|
674
|
+
}
|
675
|
+
if (strcmp(name, "lm_ggml_backend_cpu_is_numa") == 0) {
|
676
|
+
return (void *)lm_ggml_is_numa;
|
677
|
+
}
|
678
|
+
|
679
|
+
// threadpool - TODO: move to ggml-base
|
680
|
+
if (strcmp(name, "lm_ggml_threadpool_new") == 0) {
|
681
|
+
return (void *)lm_ggml_threadpool_new;
|
682
|
+
}
|
683
|
+
if (strcmp(name, "lm_ggml_threadpool_free") == 0) {
|
684
|
+
return (void *)lm_ggml_threadpool_free;
|
685
|
+
}
|
686
|
+
if (strcmp(name, "lm_ggml_backend_cpu_set_threadpool") == 0) {
|
687
|
+
return (void *)lm_ggml_backend_cpu_set_threadpool;
|
688
|
+
}
|
640
689
|
|
641
690
|
return NULL;
|
642
691
|
|
@@ -655,9 +704,12 @@ lm_ggml_backend_reg_t lm_ggml_backend_cpu_reg(void) {
|
|
655
704
|
lm_ggml_cpu_init();
|
656
705
|
|
657
706
|
static struct lm_ggml_backend_reg lm_ggml_backend_cpu_reg = {
|
658
|
-
/* .
|
659
|
-
/* .
|
707
|
+
/* .api_version = */ LM_GGML_BACKEND_API_VERSION,
|
708
|
+
/* .iface = */ lm_ggml_backend_cpu_reg_i,
|
709
|
+
/* .context = */ NULL,
|
660
710
|
};
|
661
711
|
|
662
712
|
return &lm_ggml_backend_cpu_reg;
|
663
713
|
}
|
714
|
+
|
715
|
+
LM_GGML_BACKEND_DL_IMPL(lm_ggml_backend_cpu_reg)
|
package/cpp/ggml-cpu.h
CHANGED
@@ -1,177 +1,152 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#include "ggml.h"
|
4
|
-
#include "ggml-backend.h"
|
5
|
-
|
6
|
-
#ifdef __cplusplus
|
7
|
-
extern "C" {
|
8
|
-
#endif
|
9
|
-
|
10
|
-
//
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
//
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
LM_GGML_BACKEND_API
|
58
|
-
LM_GGML_BACKEND_API
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
LM_GGML_BACKEND_API struct
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
LM_GGML_BACKEND_API
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
LM_GGML_BACKEND_API
|
79
|
-
LM_GGML_BACKEND_API
|
80
|
-
LM_GGML_BACKEND_API
|
81
|
-
LM_GGML_BACKEND_API
|
82
|
-
LM_GGML_BACKEND_API void
|
83
|
-
LM_GGML_BACKEND_API int
|
84
|
-
LM_GGML_BACKEND_API
|
85
|
-
LM_GGML_BACKEND_API void
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
LM_GGML_BACKEND_API
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
LM_GGML_BACKEND_API
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
LM_GGML_BACKEND_API
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
LM_GGML_BACKEND_API
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
LM_GGML_BACKEND_API void lm_ggml_cpu_init(void);
|
154
|
-
|
155
|
-
//
|
156
|
-
// CPU backend
|
157
|
-
//
|
158
|
-
|
159
|
-
LM_GGML_BACKEND_API lm_ggml_backend_t lm_ggml_backend_cpu_init(void);
|
160
|
-
|
161
|
-
LM_GGML_BACKEND_API bool lm_ggml_backend_is_cpu (lm_ggml_backend_t backend);
|
162
|
-
LM_GGML_BACKEND_API void lm_ggml_backend_cpu_set_n_threads (lm_ggml_backend_t backend_cpu, int n_threads);
|
163
|
-
LM_GGML_BACKEND_API void lm_ggml_backend_cpu_set_threadpool (lm_ggml_backend_t backend_cpu, lm_ggml_threadpool_t threadpool);
|
164
|
-
LM_GGML_BACKEND_API void lm_ggml_backend_cpu_set_abort_callback(lm_ggml_backend_t backend_cpu, lm_ggml_abort_callback abort_callback, void * abort_callback_data);
|
165
|
-
|
166
|
-
LM_GGML_BACKEND_API lm_ggml_backend_reg_t lm_ggml_backend_cpu_reg(void);
|
167
|
-
|
168
|
-
#ifdef LM_GGML_USE_CPU_HBM
|
169
|
-
LM_GGML_BACKEND_API lm_ggml_backend_buffer_type_t lm_ggml_backend_cpu_hbm_buffer_type(void);
|
170
|
-
#endif
|
171
|
-
|
172
|
-
LM_GGML_BACKEND_API lm_ggml_backend_buffer_type_t lm_ggml_backend_cpu_aarch64_buffer_type(void);
|
173
|
-
LM_GGML_BACKEND_API bool lm_ggml_backend_cpu_buft_is_aarch64(lm_ggml_backend_buffer_type_t buft);
|
174
|
-
|
175
|
-
#ifdef __cplusplus
|
176
|
-
}
|
177
|
-
#endif
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "ggml.h"
|
4
|
+
#include "ggml-backend.h"
|
5
|
+
|
6
|
+
#ifdef __cplusplus
|
7
|
+
extern "C" {
|
8
|
+
#endif
|
9
|
+
|
10
|
+
// the compute plan that needs to be prepared for lm_ggml_graph_compute()
|
11
|
+
// since https://github.com/ggerganov/ggml/issues/287
|
12
|
+
struct lm_ggml_cplan {
|
13
|
+
size_t work_size; // size of work buffer, calculated by `lm_ggml_graph_plan()`
|
14
|
+
uint8_t * work_data; // work buffer, to be allocated by caller before calling to `lm_ggml_graph_compute()`
|
15
|
+
|
16
|
+
int n_threads;
|
17
|
+
struct lm_ggml_threadpool * threadpool;
|
18
|
+
|
19
|
+
// abort lm_ggml_graph_compute when true
|
20
|
+
lm_ggml_abort_callback abort_callback;
|
21
|
+
void * abort_callback_data;
|
22
|
+
};
|
23
|
+
|
24
|
+
// numa strategies
|
25
|
+
enum lm_ggml_numa_strategy {
|
26
|
+
LM_GGML_NUMA_STRATEGY_DISABLED = 0,
|
27
|
+
LM_GGML_NUMA_STRATEGY_DISTRIBUTE = 1,
|
28
|
+
LM_GGML_NUMA_STRATEGY_ISOLATE = 2,
|
29
|
+
LM_GGML_NUMA_STRATEGY_NUMACTL = 3,
|
30
|
+
LM_GGML_NUMA_STRATEGY_MIRROR = 4,
|
31
|
+
LM_GGML_NUMA_STRATEGY_COUNT
|
32
|
+
};
|
33
|
+
|
34
|
+
LM_GGML_BACKEND_API void lm_ggml_numa_init(enum lm_ggml_numa_strategy numa); // call once for better performance on NUMA systems
|
35
|
+
LM_GGML_BACKEND_API bool lm_ggml_is_numa(void); // true if init detected that system has >1 NUMA node
|
36
|
+
|
37
|
+
LM_GGML_BACKEND_API struct lm_ggml_tensor * lm_ggml_new_i32(struct lm_ggml_context * ctx, int32_t value);
|
38
|
+
LM_GGML_BACKEND_API struct lm_ggml_tensor * lm_ggml_new_f32(struct lm_ggml_context * ctx, float value);
|
39
|
+
|
40
|
+
LM_GGML_BACKEND_API struct lm_ggml_tensor * lm_ggml_set_i32 (struct lm_ggml_tensor * tensor, int32_t value);
|
41
|
+
LM_GGML_BACKEND_API struct lm_ggml_tensor * lm_ggml_set_f32 (struct lm_ggml_tensor * tensor, float value);
|
42
|
+
|
43
|
+
LM_GGML_BACKEND_API int32_t lm_ggml_get_i32_1d(const struct lm_ggml_tensor * tensor, int i);
|
44
|
+
LM_GGML_BACKEND_API void lm_ggml_set_i32_1d(const struct lm_ggml_tensor * tensor, int i, int32_t value);
|
45
|
+
|
46
|
+
LM_GGML_BACKEND_API int32_t lm_ggml_get_i32_nd(const struct lm_ggml_tensor * tensor, int i0, int i1, int i2, int i3);
|
47
|
+
LM_GGML_BACKEND_API void lm_ggml_set_i32_nd(const struct lm_ggml_tensor * tensor, int i0, int i1, int i2, int i3, int32_t value);
|
48
|
+
|
49
|
+
LM_GGML_BACKEND_API float lm_ggml_get_f32_1d(const struct lm_ggml_tensor * tensor, int i);
|
50
|
+
LM_GGML_BACKEND_API void lm_ggml_set_f32_1d(const struct lm_ggml_tensor * tensor, int i, float value);
|
51
|
+
|
52
|
+
LM_GGML_BACKEND_API float lm_ggml_get_f32_nd(const struct lm_ggml_tensor * tensor, int i0, int i1, int i2, int i3);
|
53
|
+
LM_GGML_BACKEND_API void lm_ggml_set_f32_nd(const struct lm_ggml_tensor * tensor, int i0, int i1, int i2, int i3, float value);
|
54
|
+
|
55
|
+
LM_GGML_BACKEND_API struct lm_ggml_threadpool * lm_ggml_threadpool_new (struct lm_ggml_threadpool_params * params);
|
56
|
+
LM_GGML_BACKEND_API void lm_ggml_threadpool_free (struct lm_ggml_threadpool * threadpool);
|
57
|
+
LM_GGML_BACKEND_API int lm_ggml_threadpool_get_n_threads (struct lm_ggml_threadpool * threadpool);
|
58
|
+
LM_GGML_BACKEND_API void lm_ggml_threadpool_pause (struct lm_ggml_threadpool * threadpool);
|
59
|
+
LM_GGML_BACKEND_API void lm_ggml_threadpool_resume (struct lm_ggml_threadpool * threadpool);
|
60
|
+
|
61
|
+
// lm_ggml_graph_plan() has to be called before lm_ggml_graph_compute()
|
62
|
+
// when plan.work_size > 0, caller must allocate memory for plan.work_data
|
63
|
+
LM_GGML_BACKEND_API struct lm_ggml_cplan lm_ggml_graph_plan(
|
64
|
+
const struct lm_ggml_cgraph * cgraph,
|
65
|
+
int n_threads, /* = LM_GGML_DEFAULT_N_THREADS */
|
66
|
+
struct lm_ggml_threadpool * threadpool /* = NULL */ );
|
67
|
+
LM_GGML_BACKEND_API enum lm_ggml_status lm_ggml_graph_compute(struct lm_ggml_cgraph * cgraph, struct lm_ggml_cplan * cplan);
|
68
|
+
|
69
|
+
// same as lm_ggml_graph_compute() but the work data is allocated as a part of the context
|
70
|
+
// note: the drawback of this API is that you must have ensured that the context has enough memory for the work data
|
71
|
+
LM_GGML_BACKEND_API enum lm_ggml_status lm_ggml_graph_compute_with_ctx(struct lm_ggml_context * ctx, struct lm_ggml_cgraph * cgraph, int n_threads);
|
72
|
+
|
73
|
+
//
|
74
|
+
// system info
|
75
|
+
//
|
76
|
+
|
77
|
+
// x86
|
78
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_sse3 (void);
|
79
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_ssse3 (void);
|
80
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_avx (void);
|
81
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_avx_vnni (void);
|
82
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_avx2 (void);
|
83
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_f16c (void);
|
84
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_fma (void);
|
85
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_avx512 (void);
|
86
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_avx512_vbmi(void);
|
87
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_avx512_vnni(void);
|
88
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_avx512_bf16(void);
|
89
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_amx_int8 (void);
|
90
|
+
// ARM
|
91
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_neon (void);
|
92
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_arm_fma (void);
|
93
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_fp16_va (void);
|
94
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_dotprod (void);
|
95
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_matmul_int8(void);
|
96
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_sve (void);
|
97
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_get_sve_cnt (void); // sve vector length in bytes
|
98
|
+
// other
|
99
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_riscv_v (void);
|
100
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_vsx (void);
|
101
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_wasm_simd (void);
|
102
|
+
LM_GGML_BACKEND_API int lm_ggml_cpu_has_llamafile (void);
|
103
|
+
|
104
|
+
// Internal types and functions exposed for tests and benchmarks
|
105
|
+
|
106
|
+
typedef void (*lm_ggml_from_float_to_mat_t)
|
107
|
+
(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t nr, int64_t k, int64_t bs);
|
108
|
+
typedef void (*lm_ggml_vec_dot_t) (int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT x, size_t bx,
|
109
|
+
const void * LM_GGML_RESTRICT y, size_t by, int nrc);
|
110
|
+
typedef void (*lm_ggml_gemv_t) (int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT x,
|
111
|
+
const void * LM_GGML_RESTRICT y, int nr, int nc);
|
112
|
+
typedef void (*lm_ggml_gemm_t) (int n, float * LM_GGML_RESTRICT s, size_t bs, const void * LM_GGML_RESTRICT x,
|
113
|
+
const void * LM_GGML_RESTRICT y, int nr, int nc);
|
114
|
+
|
115
|
+
struct lm_ggml_type_traits_cpu {
|
116
|
+
lm_ggml_from_float_t from_float;
|
117
|
+
lm_ggml_from_float_to_mat_t from_float_to_mat;
|
118
|
+
lm_ggml_vec_dot_t vec_dot;
|
119
|
+
enum lm_ggml_type vec_dot_type;
|
120
|
+
int64_t nrows; // number of rows to process simultaneously
|
121
|
+
int64_t ncols; // number of columns to process simultaneously
|
122
|
+
lm_ggml_gemv_t gemv;
|
123
|
+
lm_ggml_gemm_t gemm;
|
124
|
+
};
|
125
|
+
|
126
|
+
LM_GGML_BACKEND_API const struct lm_ggml_type_traits_cpu * lm_ggml_get_type_traits_cpu(enum lm_ggml_type type);
|
127
|
+
|
128
|
+
LM_GGML_BACKEND_API void lm_ggml_cpu_init(void);
|
129
|
+
|
130
|
+
//
|
131
|
+
// CPU backend
|
132
|
+
//
|
133
|
+
|
134
|
+
LM_GGML_BACKEND_API lm_ggml_backend_t lm_ggml_backend_cpu_init(void);
|
135
|
+
|
136
|
+
LM_GGML_BACKEND_API bool lm_ggml_backend_is_cpu (lm_ggml_backend_t backend);
|
137
|
+
LM_GGML_BACKEND_API void lm_ggml_backend_cpu_set_n_threads (lm_ggml_backend_t backend_cpu, int n_threads);
|
138
|
+
LM_GGML_BACKEND_API void lm_ggml_backend_cpu_set_threadpool (lm_ggml_backend_t backend_cpu, lm_ggml_threadpool_t threadpool);
|
139
|
+
LM_GGML_BACKEND_API void lm_ggml_backend_cpu_set_abort_callback(lm_ggml_backend_t backend_cpu, lm_ggml_abort_callback abort_callback, void * abort_callback_data);
|
140
|
+
|
141
|
+
LM_GGML_BACKEND_API lm_ggml_backend_reg_t lm_ggml_backend_cpu_reg(void);
|
142
|
+
|
143
|
+
#ifdef LM_GGML_USE_CPU_HBM
|
144
|
+
LM_GGML_BACKEND_API lm_ggml_backend_buffer_type_t lm_ggml_backend_cpu_hbm_buffer_type(void);
|
145
|
+
#endif
|
146
|
+
|
147
|
+
LM_GGML_BACKEND_API lm_ggml_backend_buffer_type_t lm_ggml_backend_cpu_aarch64_buffer_type(void);
|
148
|
+
LM_GGML_BACKEND_API bool lm_ggml_backend_cpu_buft_is_aarch64(lm_ggml_backend_buffer_type_t buft);
|
149
|
+
|
150
|
+
#ifdef __cplusplus
|
151
|
+
}
|
152
|
+
#endif
|