1414
1515//#define GGML_ALLOCATOR_DEBUG
1616
17- //#define AT_PRINTF(...) fprintf(stderr, __VA_ARGS__)
17+ //#define AT_PRINTF(...) GGML_LOG_DEBUG( __VA_ARGS__)
1818#define AT_PRINTF (...)
1919
2020
@@ -89,7 +89,7 @@ void ggml_tallocr_alloc(struct ggml_tallocr * talloc, struct ggml_tensor * tenso
8989 size = GGML_PAD (size , talloc -> alignment );
9090
9191 if (talloc -> offset + size > ggml_backend_buffer_get_size (talloc -> buffer )) {
92- fprintf ( stderr , "%s: not enough space in the buffer to allocate %s (needed %zu, available %zu)\n" ,
92+ GGML_LOG_ERROR ( "%s: not enough space in the buffer to allocate %s (needed %zu, available %zu)\n" ,
9393 __func__ , tensor -> name , size , ggml_backend_buffer_get_size (talloc -> buffer ) - talloc -> offset );
9494 GGML_ABORT ("not enough space in the buffer" );
9595 }
@@ -172,7 +172,7 @@ static size_t ggml_dyn_tallocr_alloc(struct ggml_dyn_tallocr * alloc, size_t siz
172172 best_fit_block = alloc -> n_free_blocks - 1 ;
173173 } else {
174174 // this should never happen
175- fprintf ( stderr , "%s: not enough space in the buffer to allocate %zu bytes, largest block available %zu bytes\n" ,
175+ GGML_LOG_ERROR ( "%s: not enough space in the buffer to allocate %zu bytes, largest block available %zu bytes\n" ,
176176 __func__ , size , max_avail );
177177 GGML_ABORT ("not enough space in the buffer" );
178178 }
@@ -209,16 +209,16 @@ static size_t ggml_dyn_tallocr_alloc(struct ggml_dyn_tallocr * alloc, size_t siz
209209 }
210210 }
211211 }
212- fprintf ( stderr , "max_size = %.2f MB: tensors: " , cur_max / 1024.0 / 1024.0 );
212+ GGML_LOG_DEBUG ( "max_size = %.2f MB: tensors: " , cur_max / 1024.0 / 1024.0 );
213213 for (int i = 0 ; i < 1024 ; i ++ ) {
214214 if (alloc -> allocated_tensors [i ].tensor ) {
215- fprintf ( stderr , "%s [%zx-%zx] (%.2f MB) " , alloc -> allocated_tensors [i ].tensor -> name ,
215+ GGML_LOG_DEBUG ( "%s [%zx-%zx] (%.2f MB) " , alloc -> allocated_tensors [i ].tensor -> name ,
216216 alloc -> allocated_tensors [i ].offset ,
217217 alloc -> allocated_tensors [i ].offset + ggml_nbytes (alloc -> allocated_tensors [i ].tensor ),
218218 ggml_nbytes (alloc -> allocated_tensors [i ].tensor ) / 1024.0 / 1024.0 );
219219 }
220220 }
221- fprintf ( stderr , "\n" );
221+ GGML_LOG_DEBUG ( "\n" );
222222 }
223223#endif
224224
@@ -768,13 +768,13 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c
768768 // even if there are no tensors allocated in this buffer, we still need to allocate it to initialize views
769769 if (new_size > cur_size || galloc -> buffers [i ] == NULL ) {
770770#ifndef NDEBUG
771- fprintf ( stderr , "%s: reallocating %s buffer from size %.02f MiB to %.02f MiB\n" , __func__ , ggml_backend_buft_name (galloc -> bufts [i ]), cur_size / 1024.0 / 1024.0 , new_size / 1024.0 / 1024.0 );
771+ GGML_LOG_DEBUG ( "%s: reallocating %s buffer from size %.02f MiB to %.02f MiB\n" , __func__ , ggml_backend_buft_name (galloc -> bufts [i ]), cur_size / 1024.0 / 1024.0 , new_size / 1024.0 / 1024.0 );
772772#endif
773773
774774 ggml_backend_buffer_free (galloc -> buffers [i ]);
775775 galloc -> buffers [i ] = ggml_backend_buft_alloc_buffer (galloc -> bufts [i ], new_size );
776776 if (galloc -> buffers [i ] == NULL ) {
777- fprintf ( stderr , "%s: failed to allocate %s buffer of size %zu\n" , __func__ , ggml_backend_buft_name (galloc -> bufts [i ]), new_size );
777+ GGML_LOG_ERROR ( "%s: failed to allocate %s buffer of size %zu\n" , __func__ , ggml_backend_buft_name (galloc -> bufts [i ]), new_size );
778778 return false;
779779 }
780780 ggml_backend_buffer_set_usage (galloc -> buffers [i ], GGML_BACKEND_BUFFER_USAGE_COMPUTE );
@@ -825,14 +825,14 @@ static bool ggml_gallocr_node_needs_realloc(ggml_gallocr_t galloc, struct ggml_t
825825static bool ggml_gallocr_needs_realloc (ggml_gallocr_t galloc , struct ggml_cgraph * graph ) {
826826 if (galloc -> n_nodes != graph -> n_nodes ) {
827827#ifndef NDEBUG
828- fprintf ( stderr , "%s: graph has different number of nodes\n" , __func__ );
828+ GGML_LOG_DEBUG ( "%s: graph has different number of nodes\n" , __func__ );
829829#endif
830830 return true;
831831 }
832832
833833 if (galloc -> n_leafs != graph -> n_leafs ) {
834834#ifndef NDEBUG
835- fprintf ( stderr , "%s: graph has different number of leafs\n" , __func__ );
835+ GGML_LOG_DEBUG ( "%s: graph has different number of leafs\n" , __func__ );
836836#endif
837837 return true;
838838 }
@@ -843,7 +843,7 @@ static bool ggml_gallocr_needs_realloc(ggml_gallocr_t galloc, struct ggml_cgraph
843843
844844 if (!ggml_gallocr_node_needs_realloc (galloc , node , & node_alloc -> dst )) {
845845#ifndef NDEBUG
846- fprintf ( stderr , "%s: node %s is not valid\n" , __func__ , node -> name );
846+ GGML_LOG_DEBUG ( "%s: node %s is not valid\n" , __func__ , node -> name );
847847#endif
848848 return true;
849849 }
@@ -855,7 +855,7 @@ static bool ggml_gallocr_needs_realloc(ggml_gallocr_t galloc, struct ggml_cgraph
855855 }
856856 if (!ggml_gallocr_node_needs_realloc (galloc , src , & node_alloc -> src [j ])) {
857857#ifndef NDEBUG
858- fprintf ( stderr , "%s: src %d (%s) of node %s is not valid\n" , __func__ , j , src -> name , node -> name );
858+ GGML_LOG_DEBUG ( "%s: src %d (%s) of node %s is not valid\n" , __func__ , j , src -> name , node -> name );
859859#endif
860860 return true;
861861 }
@@ -869,14 +869,14 @@ bool ggml_gallocr_alloc_graph(ggml_gallocr_t galloc, struct ggml_cgraph * graph)
869869 if (ggml_gallocr_needs_realloc (galloc , graph )) {
870870 if (galloc -> n_buffers == 1 ) {
871871#ifndef NDEBUG
872- fprintf ( stderr , "%s: reallocating buffers automatically\n" , __func__ );
872+ GGML_LOG_DEBUG ( "%s: reallocating buffers automatically\n" , __func__ );
873873#endif
874874 if (!ggml_gallocr_reserve (galloc , graph )) {
875875 return false;
876876 }
877877 } else {
878878#ifndef NDEBUG
879- fprintf ( stderr , "%s: cannot reallocate multi buffer graph automatically, call reserve\n" , __func__ );
879+ GGML_LOG_DEBUG ( "%s: cannot reallocate multi buffer graph automatically, call reserve\n" , __func__ );
880880#endif
881881 return false;
882882 }
@@ -940,7 +940,7 @@ static bool alloc_tensor_range(struct ggml_context * ctx,
940940 ggml_backend_buffer_t buffer = ggml_backend_buft_alloc_buffer (buft , size );
941941 if (buffer == NULL ) {
942942#ifndef NDEBUG
943- fprintf ( stderr , "%s: failed to allocate %s buffer of size %zu\n" , __func__ , ggml_backend_buft_name (buft ), size );
943+ GGML_LOG_DEBUG ( "%s: failed to allocate %s buffer of size %zu\n" , __func__ , ggml_backend_buft_name (buft ), size );
944944#endif
945945 for (size_t i = 0 ; i < * n_buffers ; i ++ ) {
946946 ggml_backend_buffer_free ((* buffers )[i ]);
@@ -990,7 +990,7 @@ ggml_backend_buffer_t ggml_backend_alloc_ctx_tensors_from_buft(struct ggml_conte
990990 }
991991
992992 if (this_size > max_size ) {
993- fprintf ( stderr , "%s: tensor %s is too large to fit in a %s buffer (tensor size: %zu, max buffer size: %zu)\n" ,
993+ GGML_LOG_ERROR ( "%s: tensor %s is too large to fit in a %s buffer (tensor size: %zu, max buffer size: %zu)\n" ,
994994 __func__ , t -> name ,
995995 ggml_backend_buft_name (buft ),
996996 this_size , max_size );
@@ -1022,7 +1022,7 @@ ggml_backend_buffer_t ggml_backend_alloc_ctx_tensors_from_buft(struct ggml_conte
10221022
10231023 if (n_buffers == 0 ) {
10241024#ifndef NDEBUG
1025- fprintf ( stderr , "%s: all tensors in the context are already allocated\n" , __func__ );
1025+ GGML_LOG_DEBUG ( "%s: all tensors in the context are already allocated\n" , __func__ );
10261026#endif
10271027 return NULL ;
10281028 }
0 commit comments