|
6 | 6 | extern "C" {
|
7 | 7 | #endif
|
8 | 8 |
|
| 9 | +struct ggml_backend; |
9 | 10 | struct ggml_backend_buffer;
|
10 | 11 |
|
11 |
| -GGML_API struct ggml_allocr * ggml_allocr_new(void * data, size_t size, size_t alignment); |
12 |
| -GGML_API struct ggml_allocr * ggml_allocr_new_measure(size_t alignment); |
13 |
| -GGML_API struct ggml_allocr * ggml_allocr_new_from_buffer(struct ggml_backend_buffer * buffer); |
| 12 | +// |
| 13 | +// Legacy API |
| 14 | +// |
| 15 | + |
| 16 | +typedef struct ggml_allocr * ggml_allocr_t; |
| 17 | + |
| 18 | +// initialize allocator for use with CPU backend only |
| 19 | +GGML_API ggml_allocr_t ggml_allocr_new(void * data, size_t size, size_t alignment); |
| 20 | +GGML_API ggml_allocr_t ggml_allocr_new_measure(size_t alignment); |
| 21 | + |
| 22 | +// initialize allocator for use with ggml-backend |
| 23 | +GGML_API ggml_allocr_t ggml_allocr_new_from_buffer(struct ggml_backend_buffer * buffer); |
| 24 | +GGML_API ggml_allocr_t ggml_allocr_new_from_backend(struct ggml_backend * backend, size_t size); // allocates an owned buffer |
| 25 | +GGML_API ggml_allocr_t ggml_allocr_new_measure_from_backend(struct ggml_backend * backend); |
| 26 | + |
| 27 | +GGML_API struct ggml_backend_buffer * ggml_allocr_get_buffer(ggml_allocr_t alloc); |
14 | 28 |
|
15 | 29 | // tell the allocator to parse nodes following the order described in the list
|
16 | 30 | // you should call this if your graph are optimized to execute out-of-order
|
17 |
| -GGML_API void ggml_allocr_set_parse_seq(struct ggml_allocr * alloc, const int * list, int n); |
18 |
| - |
19 |
| -GGML_API void ggml_allocr_free (struct ggml_allocr * alloc); |
20 |
| -GGML_API bool ggml_allocr_is_measure (struct ggml_allocr * alloc); |
21 |
| -GGML_API void ggml_allocr_reset (struct ggml_allocr * alloc); |
22 |
| -GGML_API void ggml_allocr_alloc (struct ggml_allocr * alloc, struct ggml_tensor * tensor); |
23 |
| -GGML_API size_t ggml_allocr_alloc_graph(struct ggml_allocr * alloc, struct ggml_cgraph * graph); |
24 |
| -GGML_API size_t ggml_allocr_max_size (struct ggml_allocr * alloc); |
25 |
| - |
26 |
| -GGML_API size_t ggml_allocr_alloc_graph_n( |
27 |
| - struct ggml_allocr * alloc, |
28 |
| - struct ggml_cgraph ** graphs, int n_graphs, |
29 |
| - struct ggml_tensor *** inputs, struct ggml_tensor *** outputs); |
| 31 | +GGML_API void ggml_allocr_set_parse_seq(ggml_allocr_t alloc, const int * list, int n); |
| 32 | + |
| 33 | +GGML_API void ggml_allocr_free (ggml_allocr_t alloc); |
| 34 | +GGML_API bool ggml_allocr_is_measure (ggml_allocr_t alloc); |
| 35 | +GGML_API void ggml_allocr_reset (ggml_allocr_t alloc); |
| 36 | +GGML_API void ggml_allocr_alloc (ggml_allocr_t alloc, struct ggml_tensor * tensor); |
| 37 | +GGML_API size_t ggml_allocr_max_size (ggml_allocr_t alloc); |
| 38 | + |
| 39 | +GGML_API size_t ggml_allocr_alloc_graph(ggml_allocr_t alloc, struct ggml_cgraph * graph); |
| 40 | + |
| 41 | +// |
| 42 | +// ggml-backend v2 API |
| 43 | +// |
| 44 | + |
| 45 | +// Seperate tensor and graph allocator objects |
| 46 | +// This is necessary for multi-backend allocation because the graph allocator needs to use multiple tensor allocators |
| 47 | +// The original API is kept as a wrapper around the new API |
| 48 | + |
| 49 | +// Tensor allocator |
| 50 | +typedef struct ggml_tallocr * ggml_tallocr_t; |
| 51 | + |
| 52 | +GGML_API ggml_tallocr_t ggml_tallocr_new(void * data, size_t size, size_t alignment); |
| 53 | +GGML_API ggml_tallocr_t ggml_tallocr_new_measure(size_t alignment); |
| 54 | +GGML_API ggml_tallocr_t ggml_tallocr_new_from_buffer(struct ggml_backend_buffer * buffer); |
| 55 | +GGML_API ggml_tallocr_t ggml_tallocr_new_from_backend(struct ggml_backend * backend, size_t size); // allocates an owned buffer |
| 56 | +GGML_API ggml_tallocr_t ggml_tallocr_new_measure_from_backend(struct ggml_backend * backend); |
| 57 | + |
| 58 | +GGML_API struct ggml_backend_buffer * ggml_tallocr_get_buffer(ggml_tallocr_t talloc); |
| 59 | + |
| 60 | +GGML_API void ggml_tallocr_free (ggml_tallocr_t talloc); |
| 61 | +GGML_API bool ggml_tallocr_is_measure (ggml_tallocr_t talloc); |
| 62 | +GGML_API void ggml_tallocr_reset (ggml_tallocr_t talloc); |
| 63 | +GGML_API void ggml_tallocr_alloc (ggml_tallocr_t talloc, struct ggml_tensor * tensor); |
| 64 | +GGML_API size_t ggml_tallocr_max_size (ggml_tallocr_t talloc); |
| 65 | + |
| 66 | + |
| 67 | +// Graph allocator |
| 68 | +typedef struct ggml_gallocr * ggml_gallocr_t; |
| 69 | + |
| 70 | +GGML_API ggml_gallocr_t ggml_gallocr_new(void); |
| 71 | +GGML_API void ggml_gallocr_free(ggml_gallocr_t galloc); |
| 72 | + |
| 73 | +GGML_API void ggml_gallocr_set_parse_seq(ggml_gallocr_t galloc, const int * list, int n); |
| 74 | +GGML_API size_t ggml_gallocr_alloc_graph(ggml_gallocr_t galloc, ggml_tallocr_t talloc, struct ggml_cgraph * graph); |
| 75 | + |
| 76 | +// Allocate tensors from the allocators given by the hash table |
| 77 | +GGML_API void ggml_gallocr_alloc_graph_n( |
| 78 | + ggml_gallocr_t galloc, |
| 79 | + struct ggml_cgraph * graph, |
| 80 | + struct ggml_hash_set hash_set, |
| 81 | + ggml_tallocr_t * hash_node_talloc); |
30 | 82 |
|
31 | 83 | #ifdef __cplusplus
|
32 | 84 | }
|
|
0 commit comments