@@ -94,7 +94,7 @@ void ggml_tallocr_alloc(struct ggml_tallocr * talloc, struct ggml_tensor * tenso
94
94
size = GGML_PAD (size , talloc -> alignment );
95
95
96
96
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" ,
98
98
__func__ , tensor -> name , size , ggml_backend_buffer_get_size (talloc -> buffer ) - talloc -> offset );
99
99
GGML_ABORT ("not enough space in the buffer" );
100
100
}
@@ -378,6 +378,7 @@ struct ggml_gallocr {
378
378
};
379
379
380
380
ggml_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);
381
382
ggml_gallocr_t galloc = (ggml_gallocr_t )calloc (1 , sizeof (struct ggml_gallocr ));
382
383
GGML_ASSERT (galloc != NULL );
383
384
@@ -670,7 +671,8 @@ static void ggml_gallocr_alloc_graph_impl(ggml_gallocr_t galloc, struct ggml_cgr
670
671
}
671
672
}
672
673
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__);
674
676
size_t min_hash_size = graph -> n_nodes + graph -> n_leafs ;
675
677
// add 25% margin to avoid hash collisions
676
678
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
771
773
galloc -> buffers [i ] = ggml_backend_buft_alloc_buffer (galloc -> bufts [i ], new_size );
772
774
if (galloc -> buffers [i ] == NULL ) {
773
775
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 ;
775
777
}
776
778
ggml_backend_buffer_set_usage (galloc -> buffers [i ], GGML_BACKEND_BUFFER_USAGE_COMPUTE );
777
779
}
778
780
}
779
781
780
- return true ;
782
+ return GGML_STATUS_SUCCESS ;
781
783
}
782
784
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 ) {
784
786
return ggml_gallocr_reserve_n (galloc , graph , NULL , NULL );
785
787
}
786
788
@@ -865,13 +867,16 @@ static bool ggml_gallocr_needs_realloc(ggml_gallocr_t galloc, struct ggml_cgraph
865
867
return false;
866
868
}
867
869
870
+ // Check with reviewers: any cons to return a ggml_status here?
868
871
bool ggml_gallocr_alloc_graph (ggml_gallocr_t galloc , struct ggml_cgraph * graph ) {
869
872
if (ggml_gallocr_needs_realloc (galloc , graph )) {
870
873
if (galloc -> n_buffers == 1 ) {
871
874
#ifndef NDEBUG
872
875
GGML_LOG_DEBUG ("%s: reallocating buffers automatically\n" , __func__ );
873
876
#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 );
875
880
return false;
876
881
}
877
882
} else {
0 commit comments