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 Dec 14, 2023
1 parent a73584e commit f55860b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
19 changes: 14 additions & 5 deletions redGrapes/task/property/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

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

Expand All @@ -19,6 +20,14 @@
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 @@ scheduler::EventPtr GraphProperty::make_event()
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 = get_task()->unique_resources.rbegin(); r != get_task()->unique_resources.rend(); ++r )
{
if( r->task_entry != r->resource->users.rend() )
{
Expand Down Expand Up @@ -65,7 +74,7 @@ void GraphProperty::init_graph()

if(
preceding_task->space == this->space &&
this->space->is_serial( *preceding_task, *this->task )
this->space->is_serial( *preceding_task, *get_task() )
)
{
add_dependency( *preceding_task );
Expand All @@ -87,7 +96,7 @@ void GraphProperty::init_graph()
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 = get_task()->unique_resources.rbegin(); r != get_task()->unique_resources.rend(); ++r )
{
// TODO: can this lock be avoided?
// corresponding lock to init_graph()
Expand All @@ -105,7 +114,7 @@ void GraphProperty::add_dependency( Task & preceding_task )

// scheduling graph
auto preceding_event =
SingletonContext::get().scheduler->task_dependency_type(preceding_task, *this->task)
SingletonContext::get().scheduler->task_dependency_type(preceding_task, *get_task())
? preceding_task->get_pre_event() : preceding_task->get_post_event();

if( ! preceding_event->is_reached() )
Expand All @@ -122,7 +131,7 @@ void GraphProperty::update_graph( )
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), std::end(follower.task->in_edges), this));
Expand Down
40 changes: 17 additions & 23 deletions redGrapes/task/property/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,54 +48,48 @@ struct TaskSpace;
*/
struct GraphProperty
{
Task & operator*()
{
return *task;
}
Task * operator->()
{
return task;
}

//! task space that contains this task, must not be null
memory::Refcounted< TaskSpace, TaskSpaceDeleter >::Guard space;

//! task space for children, may be null
memory::Refcounted< TaskSpace, TaskSpaceDeleter >::Guard children;


/*
// in edges dont need a mutex because they are initialized
// once by `init_dependencies()` and only read afterwards.
// expired pointers (null) must be ignored
std::vector<Task*> in_edges;
*/

//! events of the scheduling-graph
scheduler::Event pre_event;
scheduler::Event post_event;
scheduler::Event result_set_event;
scheduler::Event result_get_event;

Task * task;

//! number of parents
uint8_t scope_depth;

Task * get_task();

inline Task & operator*()
{
return *get_task();
}

inline Task * operator->()
{
return get_task();
}

inline scheduler::EventPtr get_pre_event()
{
return scheduler::EventPtr { nullptr, this->task, scheduler::T_EVT_PRE };
return scheduler::EventPtr { nullptr, this->get_task(), scheduler::T_EVT_PRE };
}
inline scheduler::EventPtr get_post_event()
{
return scheduler::EventPtr { nullptr, this->task, scheduler::T_EVT_POST };
return scheduler::EventPtr { nullptr, this->get_task(), scheduler::T_EVT_POST };
}
inline scheduler::EventPtr get_result_set_event()
{
return scheduler::EventPtr { nullptr, this->task, scheduler::T_EVT_RES_SET };
return scheduler::EventPtr { nullptr, this->get_task(), scheduler::T_EVT_RES_SET };
}
inline scheduler::EventPtr get_result_get_event()
{
return scheduler::EventPtr { nullptr, this->task, scheduler::T_EVT_RES_GET };
return scheduler::EventPtr { nullptr, this->get_task(), scheduler::T_EVT_RES_GET };
}

inline bool is_ready()
Expand Down
1 change: 0 additions & 1 deletion redGrapes/task/task_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ namespace redGrapes
{
TRACE_EVENT("TaskSpace", "submit()");
task->space.acquire( this );
task->task = task;

++ task_count;

Expand Down

0 comments on commit f55860b

Please sign in to comment.