Skip to content

Commit

Permalink
GraphProperty: replace redundant task member with address calculati…
Browse files Browse the repository at this point in the history
…on through offsetof
  • Loading branch information
michaelsippel committed Feb 1, 2024
1 parent 9f4af5f commit 3e0fbb7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
23 changes: 16 additions & 7 deletions redGrapes/task/property/graph.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
/* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <redGrapes/redGrapes.hpp>
#include <redGrapes/resource/resource_user.hpp>
#include <redGrapes/scheduler/event.hpp>
#include <redGrapes/task/property/graph.hpp>
#include <redGrapes/task/task.hpp>
#include <redGrapes/task/task_space.hpp>
#include <redGrapes/util/trace.hpp>

#include <cstddef>
#include <memory>
#include <unordered_set>

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()
Expand All @@ -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())
{
Expand All @@ -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))
Expand All @@ -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()
Expand All @@ -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();

Expand All @@ -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),
Expand Down
16 changes: 8 additions & 8 deletions redGrapes/task/property/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion redGrapes/task/task_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3e0fbb7

Please sign in to comment.