@@ -94,7 +94,7 @@ enum ggml_status ggml_tallocr_alloc(struct ggml_tallocr * talloc, struct ggml_te
9494 size = GGML_PAD (size , talloc -> alignment );
9595
9696 if (talloc -> offset + size > ggml_backend_buffer_get_size (talloc -> buffer )) {
97- GGML_LOG_ERROR ("%s: not enough space in the buffer to allocate %s (needed %zu, available %zu)\n" ,
97+ GGML_LOG_ERROR ("%s: not enough space in the buffer to allocate tensor '%s' (needed %zu, available %zu)\n" ,
9898 __func__ , tensor -> name , size , ggml_backend_buffer_get_size (talloc -> buffer ) - talloc -> offset );
9999 GGML_ABORT ("not enough space in the buffer" );
100100 }
@@ -378,6 +378,7 @@ struct ggml_gallocr {
378378};
379379
380380ggml_gallocr_t ggml_gallocr_new_n (ggml_backend_buffer_type_t * bufts , int n_bufs ) {
381+ //GGML_LOG_TRACE("%s: nbufs=%d\n", __func__, n_bufs);
381382 ggml_gallocr_t galloc = (ggml_gallocr_t )calloc (1 , sizeof (struct ggml_gallocr ));
382383 GGML_ASSERT (galloc != NULL );
383384
@@ -670,7 +671,8 @@ static void ggml_gallocr_alloc_graph_impl(ggml_gallocr_t galloc, struct ggml_cgr
670671 }
671672}
672673
673- bool ggml_gallocr_reserve_n (ggml_gallocr_t galloc , struct ggml_cgraph * graph , const int * node_buffer_ids , const int * leaf_buffer_ids ) {
674+ enum ggml_status ggml_gallocr_reserve_n (ggml_gallocr_t galloc , struct ggml_cgraph * graph , const int * node_buffer_ids , const int * leaf_buffer_ids ) {
675+ //GGML_LOG_DEBUG("%s: \n", __func__);
674676 size_t min_hash_size = graph -> n_nodes + graph -> n_leafs ;
675677 // add 25% margin to avoid hash collisions
676678 min_hash_size += min_hash_size / 4 ;
@@ -771,16 +773,16 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c
771773 galloc -> buffers [i ] = ggml_backend_buft_alloc_buffer (galloc -> bufts [i ], new_size );
772774 if (galloc -> buffers [i ] == NULL ) {
773775 GGML_LOG_ERROR ("%s: failed to allocate %s buffer of size %zu\n" , __func__ , ggml_backend_buft_name (galloc -> bufts [i ]), new_size );
774- return false ;
776+ return GGML_STATUS_ALLOC_FAILED ;
775777 }
776778 ggml_backend_buffer_set_usage (galloc -> buffers [i ], GGML_BACKEND_BUFFER_USAGE_COMPUTE );
777779 }
778780 }
779781
780- return true ;
782+ return GGML_STATUS_SUCCESS ;
781783}
782784
783- bool ggml_gallocr_reserve (ggml_gallocr_t galloc , struct ggml_cgraph * graph ) {
785+ enum ggml_status ggml_gallocr_reserve (ggml_gallocr_t galloc , struct ggml_cgraph * graph ) {
784786 return ggml_gallocr_reserve_n (galloc , graph , NULL , NULL );
785787}
786788
@@ -865,13 +867,16 @@ static bool ggml_gallocr_needs_realloc(ggml_gallocr_t galloc, struct ggml_cgraph
865867 return false;
866868}
867869
870+ // Check with reviewers: any cons to return a ggml_status here?
868871bool ggml_gallocr_alloc_graph (ggml_gallocr_t galloc , struct ggml_cgraph * graph ) {
869872 if (ggml_gallocr_needs_realloc (galloc , graph )) {
870873 if (galloc -> n_buffers == 1 ) {
871874#ifndef NDEBUG
872875 GGML_LOG_DEBUG ("%s: reallocating buffers automatically\n" , __func__ );
873876#endif
874- if (!ggml_gallocr_reserve (galloc , graph )) {
877+ enum ggml_status s = ggml_gallocr_reserve (galloc , graph );
878+ if (s != GGML_STATUS_SUCCESS ) {
879+ GGML_LOG_INFO ("%s: ggml_gallocr_reserve failed to reserve. status=%d \n" , __func__ , s );
875880 return false;
876881 }
877882 } else {
0 commit comments