@@ -134,7 +134,7 @@ struct ggml_dyn_tallocr {
134134#endif
135135};
136136
137- void ggml_dyn_tallocr_insert_block (struct tallocr_chunk * chunk , size_t offset , size_t size ) {
137+ static void ggml_dyn_tallocr_insert_block (struct tallocr_chunk * chunk , size_t offset , size_t size ) {
138138 GGML_ASSERT (chunk -> n_free_blocks < MAX_FREE_BLOCKS && "out of free blocks" );
139139 // insert the new block in the correct position to keep the array sorted by address (to make merging blocks faster)
140140 int insert_pos = 0 ;
@@ -151,15 +151,15 @@ void ggml_dyn_tallocr_insert_block(struct tallocr_chunk * chunk, size_t offset,
151151 chunk -> n_free_blocks ++ ;
152152}
153153
154- void ggml_dyn_tallocr_remove_block (struct tallocr_chunk * chunk , int idx ) {
154+ static void ggml_dyn_tallocr_remove_block (struct tallocr_chunk * chunk , int idx ) {
155155 // shift all elements after idx by 1 to the left, overwriting the element at idx
156156 for (int i = idx ; i < chunk -> n_free_blocks ; i ++ ) {
157157 chunk -> free_blocks [i ] = chunk -> free_blocks [i + 1 ];
158158 }
159159 chunk -> n_free_blocks -- ;
160160}
161161
162- int ggml_dyn_tallocr_new_chunk (struct ggml_dyn_tallocr * alloc , size_t min_size ) {
162+ static int ggml_dyn_tallocr_new_chunk (struct ggml_dyn_tallocr * alloc , size_t min_size ) {
163163 if (alloc -> n_chunks >= GGML_VBUFFER_MAX_CHUNKS ) {
164164 return -1 ;
165165 }
@@ -210,7 +210,7 @@ static struct buffer_address ggml_dyn_tallocr_alloc(struct ggml_dyn_tallocr * al
210210 int best_fit_block = -1 ;
211211 size_t max_avail = 0 ;
212212
213- // find the best fitting free block in any chunk besides the last block
213+ // find the best fitting free block besides the last block, within any chunk
214214 for (int c = 0 ; c < alloc -> n_chunks ; ++ c ) {
215215 struct tallocr_chunk * chunk = alloc -> chunks [c ];
216216 size_t best_fit_size = SIZE_MAX ;
@@ -246,7 +246,7 @@ static struct buffer_address ggml_dyn_tallocr_alloc(struct ggml_dyn_tallocr * al
246246 best_fit_chunk = ggml_dyn_tallocr_new_chunk (alloc , size );
247247 best_fit_block = 0 ;
248248 }
249- if (best_fit_block == -1 ) {
249+ if (best_fit_chunk == -1 ) {
250250 // since the last chunk always has virtually endless memory, this should never happen
251251 GGML_LOG_ERROR ("%s: not enough space in the buffer to allocate %zu bytes, largest block available %zu bytes\n" ,
252252 __func__ , size , max_avail );
@@ -308,7 +308,7 @@ static void ggml_dyn_tallocr_free_tensor(struct ggml_dyn_tallocr * alloc, struct
308308 size = aligned_offset (NULL , size , alloc -> alignment );
309309
310310 AT_PRINTF ("%s: freeing %s at {chunk=%d, offset=%zu} (%zu bytes) - n_free_blocks = %d\n" ,
311- __func__ , tensor -> name , addr .chunk , addr .offset , size , alloc -> free_blocks_begin [ alloc -> n_chunks ] );
311+ __func__ , tensor -> name , addr .chunk , addr .offset , size , alloc -> chunks [ addr . chunk ] -> n_free_blocks );
312312
313313#ifdef GGML_ALLOCATOR_DEBUG
314314 remove_allocated_tensor (alloc , addr , tensor );
0 commit comments