cui-llama.rn 1.4.0 → 1.4.1

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.
Files changed (73) hide show
  1. package/android/src/main/jni.cpp +9 -9
  2. package/cpp/common.cpp +163 -60
  3. package/cpp/common.h +43 -12
  4. package/cpp/ggml-alloc.c +1042 -1037
  5. package/cpp/ggml-backend-impl.h +255 -256
  6. package/cpp/ggml-backend-reg.cpp +582 -582
  7. package/cpp/ggml-backend.cpp +2002 -2002
  8. package/cpp/ggml-backend.h +354 -352
  9. package/cpp/ggml-common.h +1853 -1853
  10. package/cpp/ggml-cpp.h +39 -39
  11. package/cpp/ggml-cpu-aarch64.cpp +4247 -4247
  12. package/cpp/ggml-cpu-aarch64.h +8 -8
  13. package/cpp/ggml-cpu-impl.h +386 -386
  14. package/cpp/ggml-cpu-quants.c +10920 -10839
  15. package/cpp/ggml-cpu-traits.cpp +36 -36
  16. package/cpp/ggml-cpu-traits.h +38 -38
  17. package/cpp/ggml-cpu.c +329 -60
  18. package/cpp/ggml-cpu.cpp +10 -2
  19. package/cpp/ggml-cpu.h +135 -135
  20. package/cpp/ggml-impl.h +567 -567
  21. package/cpp/ggml-metal-impl.h +17 -17
  22. package/cpp/ggml-metal.m +4884 -4884
  23. package/cpp/ggml-quants.c +5238 -5238
  24. package/cpp/ggml-threading.h +14 -14
  25. package/cpp/ggml.c +6514 -6448
  26. package/cpp/ggml.h +2194 -2163
  27. package/cpp/gguf.cpp +1329 -1325
  28. package/cpp/gguf.h +202 -202
  29. package/cpp/json-schema-to-grammar.cpp +1045 -1045
  30. package/cpp/json-schema-to-grammar.h +8 -8
  31. package/cpp/json.hpp +24766 -24766
  32. package/cpp/llama-adapter.cpp +347 -346
  33. package/cpp/llama-adapter.h +74 -73
  34. package/cpp/llama-arch.cpp +1487 -1434
  35. package/cpp/llama-arch.h +400 -395
  36. package/cpp/llama-batch.cpp +368 -368
  37. package/cpp/llama-batch.h +88 -88
  38. package/cpp/llama-chat.cpp +578 -567
  39. package/cpp/llama-chat.h +52 -51
  40. package/cpp/llama-context.cpp +1775 -1771
  41. package/cpp/llama-context.h +128 -128
  42. package/cpp/llama-cparams.cpp +1 -1
  43. package/cpp/llama-cparams.h +37 -37
  44. package/cpp/llama-cpp.h +30 -30
  45. package/cpp/llama-grammar.cpp +1139 -1139
  46. package/cpp/llama-grammar.h +143 -143
  47. package/cpp/llama-hparams.cpp +71 -71
  48. package/cpp/llama-hparams.h +139 -140
  49. package/cpp/llama-impl.cpp +167 -167
  50. package/cpp/llama-impl.h +61 -61
  51. package/cpp/llama-kv-cache.cpp +718 -718
  52. package/cpp/llama-kv-cache.h +218 -218
  53. package/cpp/llama-mmap.cpp +2 -1
  54. package/cpp/llama-mmap.h +67 -67
  55. package/cpp/llama-model-loader.cpp +1124 -1011
  56. package/cpp/llama-model-loader.h +167 -158
  57. package/cpp/llama-model.cpp +3997 -2202
  58. package/cpp/llama-model.h +370 -391
  59. package/cpp/llama-sampling.cpp +2408 -2406
  60. package/cpp/llama-sampling.h +32 -48
  61. package/cpp/llama-vocab.cpp +3247 -1982
  62. package/cpp/llama-vocab.h +125 -182
  63. package/cpp/llama.cpp +416 -2886
  64. package/cpp/llama.h +1323 -1285
  65. package/cpp/log.cpp +401 -401
  66. package/cpp/log.h +121 -121
  67. package/cpp/rn-llama.hpp +18 -12
  68. package/cpp/sampling.cpp +505 -500
  69. package/cpp/sgemm.cpp +2597 -2597
  70. package/cpp/speculative.cpp +277 -274
  71. package/cpp/speculative.h +28 -28
  72. package/cpp/unicode.cpp +2 -3
  73. package/package.json +1 -1
@@ -1,218 +1,218 @@
1
- #pragma once
2
-
3
- #include "llama.h"
4
-
5
- #include "ggml-cpp.h"
6
-
7
- #include <set>
8
- #include <vector>
9
-
10
- struct llama_kv_cell {
11
- llama_pos pos = -1;
12
- llama_pos delta = 0;
13
- int32_t src = -1; // used by recurrent state models to copy states
14
- int32_t tail = -1;
15
-
16
- std::set<llama_seq_id> seq_id;
17
-
18
- bool has_seq_id(const llama_seq_id & id) const {
19
- return seq_id.find(id) != seq_id.end();
20
- }
21
-
22
- bool is_empty() const {
23
- return seq_id.empty();
24
- }
25
-
26
- bool is_same_seq(const llama_kv_cell & other) const {
27
- return seq_id == other.seq_id;
28
- }
29
- };
30
-
31
- // ring-buffer of cached KV data
32
- struct llama_kv_cache {
33
- bool has_shift = false;
34
- bool do_defrag = false;
35
- bool recurrent = false; // with recurrent state models, a cell can hold the state for more than one past token
36
- bool v_trans = true; // the value tensor is transposed
37
- bool can_shift = false;
38
-
39
- // Note: The value of head isn't only used to optimize searching
40
- // for a free KV slot. llama_decode_internal also uses it, so it
41
- // cannot be freely changed after a slot has been allocated.
42
- uint32_t head = 0;
43
- uint32_t size = 0;
44
- uint32_t used = 0; // used cells (i.e. at least one seq_id)
45
-
46
- // computed before each graph build
47
- uint32_t n = 0;
48
-
49
- lm_ggml_type type_k = LM_GGML_TYPE_F16;
50
- lm_ggml_type type_v = LM_GGML_TYPE_F16;
51
-
52
- std::vector<llama_kv_cell> cells;
53
-
54
- std::vector<struct lm_ggml_tensor *> k_l; // per layer
55
- std::vector<struct lm_ggml_tensor *> v_l;
56
-
57
- std::vector<lm_ggml_context_ptr> ctxs;
58
- std::vector<lm_ggml_backend_buffer_ptr> bufs;
59
-
60
- size_t total_size() const {
61
- size_t size = 0;
62
- for (const auto & buf : bufs) {
63
- size += lm_ggml_backend_buffer_get_size(buf.get());
64
- }
65
-
66
- return size;
67
- }
68
-
69
- // TODO: better data structures to reduce the cost of this operation
70
- llama_pos max_pos() const {
71
- llama_pos max_pos = -1;
72
- for (const auto & cell : cells) {
73
- max_pos = std::max(max_pos, cell.pos);
74
- }
75
-
76
- return max_pos;
77
- }
78
- };
79
-
80
- // a structure holds information about the slot found in llama_kv_cache_find_slot
81
- struct llama_kv_cache_slot_info {
82
- std::pair<uint32_t, uint32_t> boundaries; // slot boundaries [begin, end)
83
- bool found = false; // the slot was found
84
-
85
- explicit llama_kv_cache_slot_info(bool found_) : found{found_} {}
86
- llama_kv_cache_slot_info(uint32_t begin, uint32_t end) : boundaries{begin, end}, found{true} {}
87
-
88
- operator bool() const { return found; }
89
- };
90
-
91
- // TODO: maybe not needed
92
- uint32_t llama_kv_cache_get_padding(const struct llama_cparams & cparams);
93
-
94
- bool llama_kv_cache_init(
95
- struct llama_kv_cache & cache,
96
- const llama_model & model,
97
- const llama_cparams & cparams,
98
- lm_ggml_type type_k,
99
- lm_ggml_type type_v,
100
- uint32_t kv_size,
101
- bool offload);
102
-
103
- // find an empty slot of size "n_tokens" in the cache
104
- // updates the cache head
105
- // returns a structure holding information about the slot found
106
- // Note: On success, it's important that cache.head points
107
- // to the first cell of the slot.
108
- struct llama_kv_cache_slot_info llama_kv_cache_find_slot(
109
- struct llama_kv_cache & cache,
110
- const struct llama_ubatch & batch);
111
-
112
- // find how many cells are currently in use
113
- uint32_t llama_kv_cache_cell_max(const struct llama_kv_cache & cache);
114
-
115
- void llama_kv_cache_clear(struct llama_kv_cache & cache);
116
-
117
- bool llama_kv_cache_seq_rm(
118
- struct llama_kv_cache & cache,
119
- llama_seq_id seq_id,
120
- llama_pos p0,
121
- llama_pos p1);
122
-
123
- void llama_kv_cache_seq_cp(
124
- struct llama_kv_cache & cache,
125
- llama_seq_id seq_id_src,
126
- llama_seq_id seq_id_dst,
127
- llama_pos p0,
128
- llama_pos p1);
129
-
130
- void llama_kv_cache_seq_keep(
131
- struct llama_kv_cache & cache,
132
- llama_seq_id seq_id);
133
-
134
- void llama_kv_cache_seq_add(
135
- struct llama_kv_cache & cache,
136
- llama_seq_id seq_id,
137
- llama_pos p0,
138
- llama_pos p1,
139
- llama_pos delta);
140
-
141
- void llama_kv_cache_seq_div(
142
- struct llama_kv_cache & cache,
143
- llama_seq_id seq_id,
144
- llama_pos p0,
145
- llama_pos p1,
146
- int d);
147
-
148
- llama_pos llama_kv_cache_seq_pos_max(
149
- struct llama_kv_cache & cache,
150
- llama_seq_id seq_id);
151
-
152
- void llama_kv_cache_defrag(struct llama_kv_cache & cache);
153
-
154
- int32_t llama_get_kv_cache_token_count(const struct llama_kv_cache & kv);
155
-
156
- int32_t llama_get_kv_cache_used_cells(const struct llama_kv_cache & kv);
157
-
158
- bool llama_kv_cache_can_shift(const struct llama_kv_cache & kv);
159
-
160
- //
161
- // kv cache view
162
- //
163
-
164
- struct llama_kv_cache_view llama_kv_cache_view_init(const struct llama_kv_cache & kv, int32_t n_seq_max);
165
-
166
- void llama_kv_cache_view_update(struct llama_kv_cache_view * view, const struct llama_kv_cache & kv);
167
-
168
- //
169
- // kv cache restore
170
- //
171
-
172
- // saves the kv_cache state for future recovery.
173
- // used to rollback llama_kv_cache_find_slot changes.
174
- struct llama_kv_slot_restorer {
175
- struct llama_kv_cache_state {
176
- uint32_t head = 0;
177
- uint32_t n = 0;
178
- } old_state;
179
-
180
- // for non-recurrent models only
181
- // list of slots to restore
182
- std::vector<std::pair<uint32_t, uint32_t>> slot_boundaries;
183
-
184
- bool do_restore = false;
185
-
186
- explicit llama_kv_slot_restorer(const struct llama_kv_cache & cache) {
187
- old_state.head = cache.head;
188
- old_state.n = cache.n;
189
- }
190
-
191
- // saves a slot information for future restoration
192
- void save(const struct llama_kv_cache_slot_info & slot) {
193
- if (slot) {
194
- do_restore = true;
195
- if (slot.boundaries.first != slot.boundaries.second) {
196
- slot_boundaries.push_back(slot.boundaries);
197
- }
198
- }
199
- }
200
-
201
- // must be explicitly called to restore the kv_cache state
202
- // and rollback changes from all llama_kv_cache_find_slot calls
203
- void restore(struct llama_kv_cache & cache) {
204
- if (do_restore) {
205
- cache.head = old_state.head;
206
- cache.n = old_state.n;
207
-
208
- if (cache.recurrent) { // recurrent models like Mamba or RWKV can't have a state partially erased
209
- llama_kv_cache_seq_rm(cache, -1, -1, -1);
210
- } else {
211
- for (auto & slot : slot_boundaries) {
212
- llama_kv_cache_seq_rm(cache, -1, slot.first, slot.second);
213
- }
214
- }
215
- }
216
- }
217
- };
218
-
1
+ #pragma once
2
+
3
+ #include "llama.h"
4
+
5
+ #include "ggml-cpp.h"
6
+
7
+ #include <set>
8
+ #include <vector>
9
+
10
+ struct llama_kv_cell {
11
+ llama_pos pos = -1;
12
+ llama_pos delta = 0;
13
+ int32_t src = -1; // used by recurrent state models to copy states
14
+ int32_t tail = -1;
15
+
16
+ std::set<llama_seq_id> seq_id;
17
+
18
+ bool has_seq_id(const llama_seq_id & id) const {
19
+ return seq_id.find(id) != seq_id.end();
20
+ }
21
+
22
+ bool is_empty() const {
23
+ return seq_id.empty();
24
+ }
25
+
26
+ bool is_same_seq(const llama_kv_cell & other) const {
27
+ return seq_id == other.seq_id;
28
+ }
29
+ };
30
+
31
+ // ring-buffer of cached KV data
32
+ struct llama_kv_cache {
33
+ bool has_shift = false;
34
+ bool do_defrag = false;
35
+ bool recurrent = false; // with recurrent state models, a cell can hold the state for more than one past token
36
+ bool v_trans = true; // the value tensor is transposed
37
+ bool can_shift = false;
38
+
39
+ // Note: The value of head isn't only used to optimize searching
40
+ // for a free KV slot. llama_decode_internal also uses it, so it
41
+ // cannot be freely changed after a slot has been allocated.
42
+ uint32_t head = 0;
43
+ uint32_t size = 0;
44
+ uint32_t used = 0; // used cells (i.e. at least one seq_id)
45
+
46
+ // computed before each graph build
47
+ uint32_t n = 0;
48
+
49
+ lm_ggml_type type_k = LM_GGML_TYPE_F16;
50
+ lm_ggml_type type_v = LM_GGML_TYPE_F16;
51
+
52
+ std::vector<llama_kv_cell> cells;
53
+
54
+ std::vector<struct lm_ggml_tensor *> k_l; // per layer
55
+ std::vector<struct lm_ggml_tensor *> v_l;
56
+
57
+ std::vector<lm_ggml_context_ptr> ctxs;
58
+ std::vector<lm_ggml_backend_buffer_ptr> bufs;
59
+
60
+ size_t total_size() const {
61
+ size_t size = 0;
62
+ for (const auto & buf : bufs) {
63
+ size += lm_ggml_backend_buffer_get_size(buf.get());
64
+ }
65
+
66
+ return size;
67
+ }
68
+
69
+ // TODO: better data structures to reduce the cost of this operation
70
+ llama_pos max_pos() const {
71
+ llama_pos max_pos = -1;
72
+ for (const auto & cell : cells) {
73
+ max_pos = std::max(max_pos, cell.pos);
74
+ }
75
+
76
+ return max_pos;
77
+ }
78
+ };
79
+
80
+ // a structure holds information about the slot found in llama_kv_cache_find_slot
81
+ struct llama_kv_cache_slot_info {
82
+ std::pair<uint32_t, uint32_t> boundaries; // slot boundaries [begin, end)
83
+ bool found = false; // the slot was found
84
+
85
+ explicit llama_kv_cache_slot_info(bool found_) : found{found_} {}
86
+ llama_kv_cache_slot_info(uint32_t begin, uint32_t end) : boundaries{begin, end}, found{true} {}
87
+
88
+ operator bool() const { return found; }
89
+ };
90
+
91
+ // TODO: maybe not needed
92
+ uint32_t llama_kv_cache_get_padding(const struct llama_cparams & cparams);
93
+
94
+ bool llama_kv_cache_init(
95
+ struct llama_kv_cache & cache,
96
+ const llama_model & model,
97
+ const llama_cparams & cparams,
98
+ lm_ggml_type type_k,
99
+ lm_ggml_type type_v,
100
+ uint32_t kv_size,
101
+ bool offload);
102
+
103
+ // find an empty slot of size "n_tokens" in the cache
104
+ // updates the cache head
105
+ // returns a structure holding information about the slot found
106
+ // Note: On success, it's important that cache.head points
107
+ // to the first cell of the slot.
108
+ struct llama_kv_cache_slot_info llama_kv_cache_find_slot(
109
+ struct llama_kv_cache & cache,
110
+ const struct llama_ubatch & batch);
111
+
112
+ // find how many cells are currently in use
113
+ uint32_t llama_kv_cache_cell_max(const struct llama_kv_cache & cache);
114
+
115
+ void llama_kv_cache_clear(struct llama_kv_cache & cache);
116
+
117
+ bool llama_kv_cache_seq_rm(
118
+ struct llama_kv_cache & cache,
119
+ llama_seq_id seq_id,
120
+ llama_pos p0,
121
+ llama_pos p1);
122
+
123
+ void llama_kv_cache_seq_cp(
124
+ struct llama_kv_cache & cache,
125
+ llama_seq_id seq_id_src,
126
+ llama_seq_id seq_id_dst,
127
+ llama_pos p0,
128
+ llama_pos p1);
129
+
130
+ void llama_kv_cache_seq_keep(
131
+ struct llama_kv_cache & cache,
132
+ llama_seq_id seq_id);
133
+
134
+ void llama_kv_cache_seq_add(
135
+ struct llama_kv_cache & cache,
136
+ llama_seq_id seq_id,
137
+ llama_pos p0,
138
+ llama_pos p1,
139
+ llama_pos delta);
140
+
141
+ void llama_kv_cache_seq_div(
142
+ struct llama_kv_cache & cache,
143
+ llama_seq_id seq_id,
144
+ llama_pos p0,
145
+ llama_pos p1,
146
+ int d);
147
+
148
+ llama_pos llama_kv_cache_seq_pos_max(
149
+ struct llama_kv_cache & cache,
150
+ llama_seq_id seq_id);
151
+
152
+ void llama_kv_cache_defrag(struct llama_kv_cache & cache);
153
+
154
+ int32_t llama_get_kv_cache_token_count(const struct llama_kv_cache & kv);
155
+
156
+ int32_t llama_get_kv_cache_used_cells(const struct llama_kv_cache & kv);
157
+
158
+ bool llama_kv_cache_can_shift(const struct llama_kv_cache & kv);
159
+
160
+ //
161
+ // kv cache view
162
+ //
163
+
164
+ struct llama_kv_cache_view llama_kv_cache_view_init(const struct llama_kv_cache & kv, int32_t n_seq_max);
165
+
166
+ void llama_kv_cache_view_update(struct llama_kv_cache_view * view, const struct llama_kv_cache & kv);
167
+
168
+ //
169
+ // kv cache restore
170
+ //
171
+
172
+ // saves the kv_cache state for future recovery.
173
+ // used to rollback llama_kv_cache_find_slot changes.
174
+ struct llama_kv_slot_restorer {
175
+ struct llama_kv_cache_state {
176
+ uint32_t head = 0;
177
+ uint32_t n = 0;
178
+ } old_state;
179
+
180
+ // for non-recurrent models only
181
+ // list of slots to restore
182
+ std::vector<std::pair<uint32_t, uint32_t>> slot_boundaries;
183
+
184
+ bool do_restore = false;
185
+
186
+ explicit llama_kv_slot_restorer(const struct llama_kv_cache & cache) {
187
+ old_state.head = cache.head;
188
+ old_state.n = cache.n;
189
+ }
190
+
191
+ // saves a slot information for future restoration
192
+ void save(const struct llama_kv_cache_slot_info & slot) {
193
+ if (slot) {
194
+ do_restore = true;
195
+ if (slot.boundaries.first != slot.boundaries.second) {
196
+ slot_boundaries.push_back(slot.boundaries);
197
+ }
198
+ }
199
+ }
200
+
201
+ // must be explicitly called to restore the kv_cache state
202
+ // and rollback changes from all llama_kv_cache_find_slot calls
203
+ void restore(struct llama_kv_cache & cache) {
204
+ if (do_restore) {
205
+ cache.head = old_state.head;
206
+ cache.n = old_state.n;
207
+
208
+ if (cache.recurrent) { // recurrent models like Mamba or RWKV can't have a state partially erased
209
+ llama_kv_cache_seq_rm(cache, -1, -1, -1);
210
+ } else {
211
+ for (auto & slot : slot_boundaries) {
212
+ llama_kv_cache_seq_rm(cache, -1, slot.first, slot.second);
213
+ }
214
+ }
215
+ }
216
+ }
217
+ };
218
+
@@ -7,6 +7,7 @@
7
7
  #include <cstring>
8
8
  #include <climits>
9
9
  #include <stdexcept>
10
+ #include <cerrno>
10
11
 
11
12
  #ifdef __has_include
12
13
  #if __has_include(<unistd.h>)
@@ -35,7 +36,7 @@
35
36
 
36
37
  // TODO: consider moving to llama-impl.h if needed in more places
37
38
  #if defined(_WIN32)
38
- std::string llama_format_win_err(DWORD err) {
39
+ static std::string llama_format_win_err(DWORD err) {
39
40
  LPSTR buf;
40
41
  size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
41
42
  NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&buf, 0, NULL);
package/cpp/llama-mmap.h CHANGED
@@ -1,67 +1,67 @@
1
- #pragma once
2
-
3
- #include <memory>
4
- #include <vector>
5
-
6
- struct llama_file;
7
- struct llama_mmap;
8
- struct llama_mlock;
9
-
10
- using llama_files = std::vector<std::unique_ptr<llama_file>>;
11
- using llama_mmaps = std::vector<std::unique_ptr<llama_mmap>>;
12
- using llama_mlocks = std::vector<std::unique_ptr<llama_mlock>>;
13
-
14
- struct llama_file {
15
- llama_file(const char * fname, const char * mode);
16
- ~llama_file();
17
-
18
- size_t tell() const;
19
- size_t size() const;
20
-
21
- int file_id() const; // fileno overload
22
-
23
- void seek(size_t offset, int whence) const;
24
-
25
- void read_raw(void * ptr, size_t len) const;
26
- uint32_t read_u32() const;
27
-
28
- void write_raw(const void * ptr, size_t len) const;
29
- void write_u32(uint32_t val) const;
30
-
31
- private:
32
- struct impl;
33
- std::unique_ptr<impl> pimpl;
34
- };
35
-
36
- struct llama_mmap {
37
- llama_mmap(const llama_mmap &) = delete;
38
- llama_mmap(struct llama_file * file, size_t prefetch = (size_t) -1, bool numa = false);
39
- ~llama_mmap();
40
-
41
- size_t size() const;
42
- void * addr() const;
43
-
44
- void unmap_fragment(size_t first, size_t last);
45
-
46
- static const bool SUPPORTED;
47
-
48
- private:
49
- struct impl;
50
- std::unique_ptr<impl> pimpl;
51
- };
52
-
53
- struct llama_mlock {
54
- llama_mlock();
55
- ~llama_mlock();
56
-
57
- void init(void * ptr);
58
- void grow_to(size_t target_size);
59
-
60
- static const bool SUPPORTED;
61
-
62
- private:
63
- struct impl;
64
- std::unique_ptr<impl> pimpl;
65
- };
66
-
67
- size_t llama_path_max();
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <vector>
5
+
6
+ struct llama_file;
7
+ struct llama_mmap;
8
+ struct llama_mlock;
9
+
10
+ using llama_files = std::vector<std::unique_ptr<llama_file>>;
11
+ using llama_mmaps = std::vector<std::unique_ptr<llama_mmap>>;
12
+ using llama_mlocks = std::vector<std::unique_ptr<llama_mlock>>;
13
+
14
+ struct llama_file {
15
+ llama_file(const char * fname, const char * mode);
16
+ ~llama_file();
17
+
18
+ size_t tell() const;
19
+ size_t size() const;
20
+
21
+ int file_id() const; // fileno overload
22
+
23
+ void seek(size_t offset, int whence) const;
24
+
25
+ void read_raw(void * ptr, size_t len) const;
26
+ uint32_t read_u32() const;
27
+
28
+ void write_raw(const void * ptr, size_t len) const;
29
+ void write_u32(uint32_t val) const;
30
+
31
+ private:
32
+ struct impl;
33
+ std::unique_ptr<impl> pimpl;
34
+ };
35
+
36
+ struct llama_mmap {
37
+ llama_mmap(const llama_mmap &) = delete;
38
+ llama_mmap(struct llama_file * file, size_t prefetch = (size_t) -1, bool numa = false);
39
+ ~llama_mmap();
40
+
41
+ size_t size() const;
42
+ void * addr() const;
43
+
44
+ void unmap_fragment(size_t first, size_t last);
45
+
46
+ static const bool SUPPORTED;
47
+
48
+ private:
49
+ struct impl;
50
+ std::unique_ptr<impl> pimpl;
51
+ };
52
+
53
+ struct llama_mlock {
54
+ llama_mlock();
55
+ ~llama_mlock();
56
+
57
+ void init(void * ptr);
58
+ void grow_to(size_t target_size);
59
+
60
+ static const bool SUPPORTED;
61
+
62
+ private:
63
+ struct impl;
64
+ std::unique_ptr<impl> pimpl;
65
+ };
66
+
67
+ size_t llama_path_max();