Games Task Scheduler (GTS)
A multi-processor scheduling framework for games engines
gts::Node Class Reference

A Node represents a task in a generalized task DAG. It contains Workloads that are scheduled onto a ComputeResource by a MacroScheduler. More...

#include <Node.h>

Public Types

enum  { NODE_NAME_MAX = 64 }
 

Public Member Functions

 Node (MacroScheduler *pMyScheduler)
 
WorkloadfindWorkload (WorkloadType::Enum type) const
 
Atomic< uint32_t > const & currPredecessorCount () const
 
uint32_t initPredecessorCount () const
 
GTS_INLINE Vector< Node * > const & predecessors () const
 
GTS_INLINE Vector< Node * > const & successors () const
 
bool isChild (Node *pChild) const
 
GTS_INLINE MacroSchedulermyScheduler ()
 
GTS_INLINE SchedulecurrentSchedule ()
 
GTS_INLINE ComputeResourceId affinity () const
 
GTS_INLINE const char * name () const
 
GTS_INLINE Atomic< uint64_t > const & upRank () const
 
GTS_INLINE Atomic< uint64_t > const & downRank () const
 
GTS_INLINE uint64_t executionCost () const
 
GTS_INLINE Vector< Node * > & predecessors ()
 
GTS_INLINE Vector< Node * > & successors ()
 
template<typename TWorkload , typename... TArgs>
GTS_INLINE TWorkload * addWorkload (TArgs &&... args)
 Allocates a new Workload object of type TWorkload. More...
 
template<typename TLambdaWorkload , typename TFunc , typename... TArgs>
GTS_INLINE TLambdaWorkload * addWorkload (TFunc &&func, TArgs &&... args)
 Allocates a new Workload object of type TLambdaWorkload. More...
 
void removeWorkload (WorkloadType::Enum type)
 Removed a workload by its WorkloadType. More...
 
void reset ()
 Reset the state of this Node for another execution.
 
void addSuccessor (Node *pNode)
 Add the sucessor Node 'pNode'. More...
 
void removeSuccessor (Node *pNode)
 Remove the sucessor Node 'pNode'. More...
 
void setName (const char *format,...)
 Set the name of this Node.
 
GTS_INLINE Atomic< uint64_t > & upRank ()
 
GTS_INLINE Atomic< uint64_t > & downRank ()
 
GTS_INLINE void setAffinity (ComputeResourceId affinity)
 Sets the ID of the ComputeResource that must execute this Node. More...
 
GTS_INLINE bool _removePredecessorRefAndReturnReady ()
 Specifies the ComputeResource that must execute this Workload. More...
 
GTS_INLINE void _markPredecessorComplete ()
 Mark one predecessor as complete. More...
 
GTS_INLINE void _waitUntilComplete () const
 Waits for all predecessors to tally their completion. More...
 
GTS_INLINE void _setCurrentSchedule (Schedule *pSchedule)
 Sets this Node's current Schedule. More...
 
GTS_INLINE void _setExecutionCost (uint64_t exeCost)
 Sets the execution cost of this Node. More...
 

Static Public Member Functions

static void resetGraph (Node *pSource)
 Resets all Nodes in the graph. More...
 

Friends

class CriticiallyAware_Schedule
 

Detailed Description

A Node represents a task in a generalized task DAG. It contains Workloads that are scheduled onto a ComputeResource by a MacroScheduler.

Member Function Documentation

◆ _markPredecessorComplete()

GTS_INLINE void gts::Node::_markPredecessorComplete ( )
inline

Mark one predecessor as complete.

Remarks
Internal use only.
Thread-safe.

◆ _removePredecessorRefAndReturnReady()

GTS_INLINE bool gts::Node::_removePredecessorRefAndReturnReady ( )
inline

Specifies the ComputeResource that must execute this Workload.

Remove a predecessor reference and check if the Node is ready to run.

Returns
True of the Node's predecessor count is zero and ready to run.
Remarks
Internal use only.
Thread-safe.

◆ _setCurrentSchedule()

GTS_INLINE void gts::Node::_setCurrentSchedule ( Schedule pSchedule)
inline

Sets this Node's current Schedule.

Remarks
Internal use only.

◆ _setExecutionCost()

GTS_INLINE void gts::Node::_setExecutionCost ( uint64_t  exeCost)
inline

Sets the execution cost of this Node.

Remarks
Internal use only.
Not thread-safe.

◆ _waitUntilComplete()

GTS_INLINE void gts::Node::_waitUntilComplete ( ) const
inline

Waits for all predecessors to tally their completion.

Remarks
The wait should happen rarely.
Internal use only.
Thread-safe.

◆ addSuccessor()

void gts::Node::addSuccessor ( Node pNode)

Add the sucessor Node 'pNode'.

Remarks
Thread-safe if: (1) The DAG this Node belongs is not executing, OR (2) pNode is being added to this Node during this Node's executing Workload.

◆ addWorkload() [1/2]

template<typename TWorkload , typename... TArgs>
GTS_INLINE TWorkload* gts::Node::addWorkload ( TArgs &&...  args)
inline

Allocates a new Workload object of type TWorkload.

Parameters
argsThe arguments for the TWorkload constructor.
Returns
The allocated TWorkload or nullptr if the allocation failed.
Remarks
Not thread-safe.

◆ addWorkload() [2/2]

template<typename TLambdaWorkload , typename TFunc , typename... TArgs>
GTS_INLINE TLambdaWorkload* gts::Node::addWorkload ( TFunc &&  func,
TArgs &&...  args 
)
inline

Allocates a new Workload object of type TLambdaWorkload.

Parameters
argsThe arguments for the TLambdaWorkload constructor.
Returns
The allocated TLambdaWorkload or nullptr if the allocation failed.
Remarks
Not thread-safe.

◆ affinity()

GTS_INLINE ComputeResourceId gts::Node::affinity ( ) const
inline
Returns
The ID of the ComputeResource that must execute this Node.

◆ currentSchedule()

GTS_INLINE Schedule* gts::Node::currentSchedule ( )
inline
Returns
The Schedule that this Node currently belongs to. nullptr if not scheduled.

◆ currPredecessorCount()

Atomic<uint32_t> const& gts::Node::currPredecessorCount ( ) const
Returns
The number of predecessors Nodes that must complete before this Node can execute.

◆ downRank() [1/2]

GTS_INLINE Atomic<uint64_t>& gts::Node::downRank ( )
inline
Returns
The down-rank of this Node.

◆ downRank() [2/2]

GTS_INLINE Atomic<uint64_t> const& gts::Node::downRank ( ) const
inline
Returns
The down-rank of this Node.

◆ executionCost()

GTS_INLINE uint64_t gts::Node::executionCost ( ) const
inline
Returns
The rank of this Node.

◆ findWorkload()

Workload* gts::Node::findWorkload ( WorkloadType::Enum  type) const
Returns
The Workload associated with 'type' or nullptr is it does not exist.
Remarks
Not thread-safe.

◆ initPredecessorCount()

uint32_t gts::Node::initPredecessorCount ( ) const
Returns
The number of predecessors Nodes this Node starts with.

◆ isChild()

bool gts::Node::isChild ( Node pChild) const
Returns
True if pChild is a child of this Node.

◆ myScheduler()

GTS_INLINE MacroScheduler* gts::Node::myScheduler ( )
inline
Returns
The MacroScheduler that created this Node.

◆ name()

GTS_INLINE const char* gts::Node::name ( ) const
inline
Returns
The rank of this Node.

◆ predecessors() [1/2]

GTS_INLINE Vector<Node*>& gts::Node::predecessors ( )
inline
Returns
The predecessor nodes of this Node.

◆ predecessors() [2/2]

GTS_INLINE Vector<Node*> const& gts::Node::predecessors ( ) const
inline
Returns
The predecessor nodes of this Node.

◆ removeSuccessor()

void gts::Node::removeSuccessor ( Node pNode)

Remove the sucessor Node 'pNode'.

Remarks
Thread-safe if: (1) The DAG this Node belongs is not executing, OR (2) pNode is being removed from this Node during this Node's executing Workload.

◆ removeWorkload()

void gts::Node::removeWorkload ( WorkloadType::Enum  type)

Removed a workload by its WorkloadType.

Remarks
Not thread-safe.

◆ resetGraph()

static void gts::Node::resetGraph ( Node pSource)
static

Resets all Nodes in the graph.

Returns
True if the Node must be executed in isolation.
Remarks
Not thread-safe.

◆ setAffinity()

GTS_INLINE void gts::Node::setAffinity ( ComputeResourceId  affinity)
inline

Sets the ID of the ComputeResource that must execute this Node.

Remarks
Not thread-safe.

◆ successors() [1/2]

GTS_INLINE Vector<Node*>& gts::Node::successors ( )
inline
Returns
The successor nodes of this Node.

◆ successors() [2/2]

GTS_INLINE Vector<Node*> const& gts::Node::successors ( ) const
inline
Returns
The successor nodes of this Node.

◆ upRank() [1/2]

GTS_INLINE Atomic<uint64_t>& gts::Node::upRank ( )
inline
Returns
The up-rank of this Node.

◆ upRank() [2/2]

GTS_INLINE Atomic<uint64_t> const& gts::Node::upRank ( ) const
inline
Returns
The up-rank of this Node.