Skip to content

Commit b4e22c9

Browse files
authored
Update ggml_extend.hpp
1 parent 854b32b commit b4e22c9

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

ggml_extend.hpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -1045,9 +1045,25 @@ struct GGMLRunner {
10451045
reset_compute_ctx();
10461046
struct ggml_cgraph* gf = get_graph();
10471047
backend_tensor_data_map.clear();
1048-
compute_allocr = ggml_gallocr_new(ggml_backend_get_default_buffer_type(backend));
1048+
1049+
ggml_backend_buffer_type_t bufts[2] = {
1050+
ggml_backend_get_default_buffer_type(backend),
1051+
ggml_backend_get_default_buffer_type(backend)
1052+
};
10491053

1050-
if (!ggml_gallocr_reserve(compute_allocr, gf)) {
1054+
compute_allocr = ggml_gallocr_new_n_multi(bufts, 2);
1055+
1056+
int n_nodes = ggml_graph_n_nodes(gf);
1057+
1058+
int total_n_half = n_nodes / 2;
1059+
1060+
int * node_buffer_ids = (int *)calloc(n_nodes, sizeof(int));
1061+
1062+
for (int i = 0; i < n_nodes; i++) {
1063+
node_buffer_ids[i] = i < total_n_half ? 0 : 1;
1064+
}
1065+
1066+
if (!ggml_gallocr_reserve_n(compute_allocr, gf, node_buffer_ids, NULL)) {
10511067
// failed to allocate the compute buffer
10521068
LOG_ERROR("%s: failed to allocate the compute buffer\n", get_desc().c_str());
10531069
free_compute_buffer();

0 commit comments

Comments
 (0)