@@ -8,6 +8,11 @@ extern "C" {
88
99struct ggml_backend ;
1010struct ggml_backend_buffer ;
11+
12+ //
13+ // Legacy API
14+ //
15+
1116typedef struct ggml_allocr * ggml_allocr_t ;
1217
1318// initialize allocator for use with CPU backend only
@@ -33,12 +38,47 @@ GGML_API size_t ggml_allocr_max_size (ggml_allocr_t alloc);
3338
3439GGML_API size_t ggml_allocr_alloc_graph (ggml_allocr_t alloc , struct ggml_cgraph * graph );
3540
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+
3676// Allocate tensors from the allocators given by the hash table
37- GGML_API void ggml_allocr_alloc_graph_n (
77+ GGML_API void ggml_gallocr_alloc_graph_n (
78+ ggml_gallocr_t galloc ,
3879 struct ggml_cgraph * graph ,
3980 struct ggml_hash_set hash_set ,
40- ggml_allocr_t hash_node_alloct []);
41-
81+ ggml_tallocr_t * hash_node_talloc );
4282
4383#ifdef __cplusplus
4484}
0 commit comments