From 3e0fbb771817ce6759eed8348df327c712dde5e0 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Thu, 7 Dec 2023 03:10:31 +0100 Subject: [PATCH] GraphProperty: replace redundant `task` member with address calculation through offsetof --- redGrapes/task/property/graph.cpp | 23 ++++++++++++++++------- redGrapes/task/property/graph.hpp | 16 ++++++++-------- redGrapes/task/task_space.cpp | 2 +- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/redGrapes/task/property/graph.cpp b/redGrapes/task/property/graph.cpp index 3680c795..4b0e0579 100644 --- a/redGrapes/task/property/graph.cpp +++ b/redGrapes/task/property/graph.cpp @@ -1,4 +1,5 @@ -/* Copyright 2019-2022 Michael Sippel +/* Copyright 2019-2024 The RedGrapes Community + * Authors: Michael Sippel * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -6,19 +7,27 @@ */ #include -#include #include #include #include #include #include +#include #include #include namespace redGrapes { + Task* GraphProperty::get_task() + { + /* NOTE: this offsetof gives works because we know that `space` is + * the first member that is derived from `GraphProperty` + */ + return (Task*) ((uintptr_t) this - offsetof(Task, space)); + } + /*! create a new (external) event which precedes the tasks post-event */ scheduler::EventPtr GraphProperty::make_event() @@ -37,7 +46,7 @@ namespace redGrapes void GraphProperty::init_graph() { TRACE_EVENT("Graph", "init_graph"); - for(auto r = this->task->unique_resources.rbegin(); r != this->task->unique_resources.rend(); ++r) + for(auto r = this->get_task()->unique_resources.rbegin(); r != this->get_task()->unique_resources.rend(); ++r) { if(r->task_entry != r->resource->users.rend()) { @@ -63,7 +72,7 @@ namespace redGrapes if(preceding_task == this->space->parent) break; - if(preceding_task->space == this->space && this->space->is_serial(*preceding_task, *this->task)) + if(preceding_task->space == this->space && this->space->is_serial(*preceding_task, *this->get_task())) { add_dependency(*preceding_task); if(preceding_task->has_sync_access(r->resource)) @@ -84,7 +93,7 @@ namespace redGrapes void GraphProperty::delete_from_resources() { TRACE_EVENT("Graph", "delete_from_resources"); - for(auto r = this->task->unique_resources.rbegin(); r != this->task->unique_resources.rend(); ++r) + for(auto r = this->get_task()->unique_resources.rbegin(); r != this->get_task()->unique_resources.rend(); ++r) { // TODO: can this lock be avoided? // corresponding lock to init_graph() @@ -101,7 +110,7 @@ namespace redGrapes // in_edges.push_back(&preceding_task); // scheduling graph - auto preceding_event = SingletonContext::get().scheduler->task_dependency_type(preceding_task, *this->task) + auto preceding_event = SingletonContext::get().scheduler->task_dependency_type(preceding_task, *this->get_task()) ? preceding_task->get_pre_event() : preceding_task->get_post_event(); @@ -119,7 +128,7 @@ namespace redGrapes scheduler::EventPtr follower = *it; if(follower.task) { - if(!space->is_serial(*this->task, *follower.task)) + if(!space->is_serial(*get_task(), *follower.task)) { // remove dependency // follower.task->in_edges.erase(std::find(std::begin(follower.task->in_edges), diff --git a/redGrapes/task/property/graph.hpp b/redGrapes/task/property/graph.hpp index d7d7cadc..1f92ba34 100644 --- a/redGrapes/task/property/graph.hpp +++ b/redGrapes/task/property/graph.hpp @@ -49,16 +49,14 @@ namespace redGrapes { Task& operator*() { - return *task; + return *get_task(); } Task* operator->() { - return task; + return get_task(); } - Task* task; - //! number of parents uint8_t scope_depth; @@ -80,24 +78,26 @@ namespace redGrapes scheduler::Event result_set_event; scheduler::Event result_get_event; + Task* get_task(); + inline scheduler::EventPtr get_pre_event() { - return scheduler::EventPtr{scheduler::T_EVT_PRE, this->task}; + return scheduler::EventPtr{scheduler::T_EVT_PRE, this->get_task()}; } inline scheduler::EventPtr get_post_event() { - return scheduler::EventPtr{scheduler::T_EVT_POST, this->task}; + return scheduler::EventPtr{scheduler::T_EVT_POST, this->get_task()}; } inline scheduler::EventPtr get_result_set_event() { - return scheduler::EventPtr{scheduler::T_EVT_RES_SET, this->task}; + return scheduler::EventPtr{scheduler::T_EVT_RES_SET, this->get_task()}; } inline scheduler::EventPtr get_result_get_event() { - return scheduler::EventPtr{scheduler::T_EVT_RES_GET, this->task}; + return scheduler::EventPtr{scheduler::T_EVT_RES_GET, this->get_task()}; } inline bool is_ready() diff --git a/redGrapes/task/task_space.cpp b/redGrapes/task/task_space.cpp index c889d539..c2a74a07 100644 --- a/redGrapes/task/task_space.cpp +++ b/redGrapes/task/task_space.cpp @@ -70,8 +70,8 @@ namespace redGrapes void TaskSpace::submit(Task* task) { TRACE_EVENT("TaskSpace", "submit()"); + task->space = shared_from_this(); - task->task = task; ++task_count;