From: slaren Date: Mon, 13 Nov 2023 15:19:49 +0000 (+0100) Subject: update examples and tests to use ggml_allocr_new_measure_from_backend (#608) X-Git-Tag: upstream/0.0.1642~1196 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=aa1d26e6f3dde28a17f31105cbf1f4e8cebb3425;p=pkg%2Fggml%2Fsources%2Fggml update examples and tests to use ggml_allocr_new_measure_from_backend (#608) * update examples and tests to use ggml_allocr_new_measure_from_backend * update comments --- diff --git a/examples/gpt-2/main-backend.cpp b/examples/gpt-2/main-backend.cpp index ab437260..e986cdee 100644 --- a/examples/gpt-2/main-backend.cpp +++ b/examples/gpt-2/main-backend.cpp @@ -878,9 +878,8 @@ int main(int argc, char ** argv) { struct ggml_allocr * allocr = NULL; // allocate the compute buffer { - // alignment required by the backend - size_t align = ggml_backend_get_alignment(model.backend); - allocr = ggml_allocr_new_measure(align); + // create an allocator to measure the memory usage + allocr = ggml_allocr_new_measure_from_backend(model.backend); // create the worst case graph for memory usage estimation int n_tokens = std::min(model.hparams.n_ctx, params.n_batch); diff --git a/examples/gpt-2/main-batched.cpp b/examples/gpt-2/main-batched.cpp index 99167db9..41d531aa 100644 --- a/examples/gpt-2/main-batched.cpp +++ b/examples/gpt-2/main-batched.cpp @@ -1042,9 +1042,8 @@ int main(int argc, char ** argv) { // prepare required memory and allocate the compute buffer struct ggml_allocr * allocr = NULL; { - // alignment required by the backend - size_t align = ggml_backend_get_alignment(model.backend); - allocr = ggml_allocr_new_measure(align); + // create an allocator to measure the memory usage + allocr = ggml_allocr_new_measure_from_backend(model.backend); batch.n_tokens = n_batch_max; diff --git a/tests/test-conv1d.cpp b/tests/test-conv1d.cpp index a5a418d1..98d45c5d 100644 --- a/tests/test-conv1d.cpp +++ b/tests/test-conv1d.cpp @@ -204,8 +204,7 @@ int main(void) struct ggml_allocr * allocr = NULL; { - size_t align = ggml_backend_get_alignment(model.backend); - allocr = ggml_allocr_new_measure(align); + allocr = ggml_allocr_new_measure_from_backend(model.backend); //create the worst case graph for memory usage estimation struct ggml_cgraph * gf = build_graph(model, allocr); diff --git a/tests/test-conv2d.cpp b/tests/test-conv2d.cpp index df0e2ccd..66e6e32f 100644 --- a/tests/test-conv2d.cpp +++ b/tests/test-conv2d.cpp @@ -208,8 +208,7 @@ int main(void) struct ggml_allocr * allocr = NULL; { - size_t align = ggml_backend_get_alignment(model.backend); - allocr = ggml_allocr_new_measure(align); + allocr = ggml_allocr_new_measure_from_backend(model.backend); //create the worst case graph for memory usage estimation struct ggml_cgraph * gf = build_graph(model, allocr); diff --git a/tests/test-mul-mat.cpp b/tests/test-mul-mat.cpp index 36b7c6bc..d1406d4e 100644 --- a/tests/test-mul-mat.cpp +++ b/tests/test-mul-mat.cpp @@ -314,8 +314,7 @@ int main(void) struct ggml_allocr * allocr = NULL; { - size_t align = ggml_backend_get_alignment(model.backend); - allocr = ggml_allocr_new_measure(align); + allocr = ggml_allocr_new_measure_from_backend(model.backend); //create the worst case graph for memory usage estimation struct ggml_cgraph * gf = build_graph(model, allocr);