From 50bdb3ceb0a7d2eb660796bd96acfb2386d07811 Mon Sep 17 00:00:00 2001 From: Tobias Zehetmair Date: Thu, 20 Feb 2025 11:21:21 +0100 Subject: [PATCH 1/2] extended backend api to enable backend specific allocator --- include/laik/backend.h | 2 ++ src/data.c | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/laik/backend.h b/include/laik/backend.h index b88fd27e..8fda8785 100644 --- a/include/laik/backend.h +++ b/include/laik/backend.h @@ -85,6 +85,8 @@ struct _Laik_Backend { // for elasticity: removal of processes which got started in a previous // resize is finished. They can be marked as dead and resources freed void (*finish_resize)(); + + Laik_Allocator* (*allocator)(); }; diff --git a/src/data.c b/src/data.c index fb077bdc..e380b139 100644 --- a/src/data.c +++ b/src/data.c @@ -156,6 +156,26 @@ void laik_switchstat_free(Laik_SwitchStat* ss, uint64_t bytes) static int data_id = 0; +// get backend specific allocator +// currently lowest backend with custom allocator defines allocator for data container +static Laik_Allocator* allocator(Laik_Instance* inst, Laik_Data* d) +{ + (void)d; + Laik_Allocator* (*create)(); + create = inst->backend->allocator; + //Laik_Inst_Data* idata = NULL; + //for(Laik_Inst_Data* c = inst->inst_data; c->next != NULL; c = c->next) + //{ + //create = c->next_backend->allocator ? c->next_backend->allocator : create; + //idata = c->next; + //} + assert(laik_allocator_def); + + // set backend data of data container to inst data of backend that does allocation + //d->backend_data = idata; + return create ? create() : laik_allocator_def; +} + Laik_Data* laik_new_data(Laik_Space* space, Laik_Type* type) { Laik_Data* d = malloc(sizeof(Laik_Data)); @@ -177,7 +197,8 @@ Laik_Data* laik_new_data(Laik_Space* space, Laik_Type* type) d->activePartitioning = 0; d->activeMappings = 0; assert(laik_allocator_def); - d->allocator = laik_allocator_def; // malloc/free + reuse if possible + d->allocator = allocator(space->inst, d); // malloc/free + reuse if possible + assert(d->allocator); d->layout_factory = laik_new_layout_lex; // by default, use lex layouts d->stat = laik_newSwitchStat(); From 08fe8c3a57f6552f1d0f19499b960d0f7a1f9c81 Mon Sep 17 00:00:00 2001 From: Tobias Zehetmair Date: Tue, 25 Feb 2025 10:16:56 +0100 Subject: [PATCH 2/2] removed comments --- src/data.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/data.c b/src/data.c index e380b139..aa30c09b 100644 --- a/src/data.c +++ b/src/data.c @@ -157,22 +157,14 @@ void laik_switchstat_free(Laik_SwitchStat* ss, uint64_t bytes) static int data_id = 0; // get backend specific allocator -// currently lowest backend with custom allocator defines allocator for data container static Laik_Allocator* allocator(Laik_Instance* inst, Laik_Data* d) { (void)d; Laik_Allocator* (*create)(); create = inst->backend->allocator; - //Laik_Inst_Data* idata = NULL; - //for(Laik_Inst_Data* c = inst->inst_data; c->next != NULL; c = c->next) - //{ - //create = c->next_backend->allocator ? c->next_backend->allocator : create; - //idata = c->next; - //} + assert(laik_allocator_def); - // set backend data of data container to inst data of backend that does allocation - //d->backend_data = idata; return create ? create() : laik_allocator_def; }