DPC++ Runtime
Runtime libraries for oneAPI DPC++
sycl::_V1::ext::oneapi::experimental::detail::graph_impl Class Reference

Implementation details of command_graph<modifiable>. More...

#include <detail/graph_impl.hpp>

Collaboration diagram for sycl::_V1::ext::oneapi::experimental::detail::graph_impl:

Public Types

using ReadLock = std::shared_lock< std::shared_mutex >
 
using WriteLock = std::unique_lock< std::shared_mutex >
 

Public Member Functions

 graph_impl (const sycl::context &SyclContext, const sycl::device &SyclDevice, const sycl::property_list &PropList={})
 Constructor. More...
 
 ~graph_impl ()
 
void removeRoot (const std::shared_ptr< node_impl > &Root)
 Remove node from list of root nodes. More...
 
std::shared_ptr< node_impladd (node_type NodeType, std::unique_ptr< sycl::detail::CG > CommandGroup, const std::vector< std::shared_ptr< node_impl >> &Dep={})
 Create a kernel node in the graph. More...
 
std::shared_ptr< node_impladd (const std::shared_ptr< graph_impl > &Impl, std::function< void(handler &)> CGF, const std::vector< sycl::detail::ArgDesc > &Args, const std::vector< std::shared_ptr< node_impl >> &Dep={})
 Create a CGF node in the graph. More...
 
std::shared_ptr< node_impladd (const std::shared_ptr< graph_impl > &Impl, const std::vector< std::shared_ptr< node_impl >> &Dep={})
 Create an empty node in the graph. More...
 
std::shared_ptr< node_impladd (const std::shared_ptr< graph_impl > &Impl, const std::vector< sycl::detail::EventImplPtr > Events)
 Create an empty node in the graph. More...
 
void addQueue (const std::shared_ptr< sycl::detail::queue_impl > &RecordingQueue)
 Add a queue to the set of queues which are currently recording to this graph. More...
 
void removeQueue (const std::shared_ptr< sycl::detail::queue_impl > &RecordingQueue)
 Remove a queue from the set of queues which are currently recording to this graph. More...
 
bool clearQueues ()
 Remove all queues which are recording to this graph, also sets all queues cleared back to the executing state. More...
 
void addEventForNode (std::shared_ptr< graph_impl > GraphImpl, std::shared_ptr< sycl::detail::event_impl > EventImpl, std::shared_ptr< node_impl > NodeImpl)
 Associate a sycl event with a node in the graph. More...
 
std::shared_ptr< sycl::detail::event_impl > getEventForNode (std::shared_ptr< node_impl > NodeImpl) const
 Find the sycl event associated with a node. More...
 
std::shared_ptr< node_implgetNodeForEvent (std::shared_ptr< sycl::detail::event_impl > EventImpl)
 Find the node associated with a SYCL event. More...
 
sycl::context getContext () const
 Query for the context tied to this graph. More...
 
sycl::device getDevice () const
 Query for the device tied to this graph. More...
 
std::shared_ptr< node_implgetLastInorderNode (std::shared_ptr< sycl::detail::queue_impl > Queue)
 Find the last node added to this graph from an in-order queue. More...
 
void setLastInorderNode (std::shared_ptr< sycl::detail::queue_impl > Queue, std::shared_ptr< node_impl > Node)
 Track the last node added to this graph from an in-order queue. More...
 
void printGraphAsDot (const std::string FilePath, bool Verbose) const
 Prints the contents of the graph to a text file in DOT format. More...
 
void makeEdge (std::shared_ptr< node_impl > Src, std::shared_ptr< node_impl > Dest)
 Make an edge between two nodes in the graph. More...
 
void throwIfGraphRecordingQueue (const std::string ExceptionMsg) const
 Throws an invalid exception if this function is called while a queue is recording commands to the graph. More...
 
bool hasSimilarStructure (std::shared_ptr< detail::graph_impl > Graph, bool DebugPrint=false) const
 Checks if the graph_impl of Graph has a similar structure to the graph_impl of the caller. More...
 
size_t getNumberOfNodes () const
 Returns the number of nodes in the Graph. More...
 
std::vector< sycl::detail::EventImplPtr > getExitNodesEvents ()
 Traverse the graph recursively to get the events associated with the output nodes of this graph. More...
 
std::vector< sycl::detail::EventImplPtr > removeBarriersFromExtraDependencies ()
 Removes all Barrier nodes from the list of extra dependencies MExtraDependencies. More...
 

Static Public Member Functions

static bool checkNodeRecursive (const std::shared_ptr< node_impl > &NodeA, const std::shared_ptr< node_impl > &NodeB)
 Recursively check successors of NodeA and NodeB to check they are similar. More...
 

Public Attributes

std::shared_mutex MMutex
 Protects all the fields that can be changed by class' methods. More...
 
std::set< std::weak_ptr< node_impl >, std::owner_less< std::weak_ptr< node_impl > > > MRoots
 List of root nodes. More...
 
std::vector< std::shared_ptr< node_impl > > MNodeStorage
 Storage for all nodes contained within a graph. More...
 

Detailed Description

Implementation details of command_graph<modifiable>.

Definition at line 794 of file graph_impl.hpp.

Member Typedef Documentation

◆ ReadLock

using sycl::_V1::ext::oneapi::experimental::detail::graph_impl::ReadLock = std::shared_lock<std::shared_mutex>

Definition at line 796 of file graph_impl.hpp.

◆ WriteLock

using sycl::_V1::ext::oneapi::experimental::detail::graph_impl::WriteLock = std::unique_lock<std::shared_mutex>

Definition at line 797 of file graph_impl.hpp.

Constructor & Destructor Documentation

◆ graph_impl()

sycl::_V1::ext::oneapi::experimental::detail::graph_impl::graph_impl ( const sycl::context SyclContext,
const sycl::device SyclDevice,
const sycl::property_list PropList = {} 
)
inline

Constructor.

Parameters
SyclContextContext to use for graph.
SyclDeviceDevice to create nodes with.
PropListOptional list of properties.

Definition at line 806 of file graph_impl.hpp.

◆ ~graph_impl()

sycl::_V1::ext::oneapi::experimental::detail::graph_impl::~graph_impl ( )

Definition at line 298 of file graph_impl.cpp.

References clearQueues().

Member Function Documentation

◆ add() [1/4]

std::shared_ptr< node_impl > sycl::_V1::ext::oneapi::experimental::detail::graph_impl::add ( const std::shared_ptr< graph_impl > &  Impl,
const std::vector< std::shared_ptr< node_impl >> &  Dep = {} 
)

Create an empty node in the graph.

Parameters
ImplGraph implementation pointer.
DepList of predecessor nodes.
Returns
Created node in the graph.

Definition at line 348 of file graph_impl.cpp.

References addEventForNode(), and MNodeStorage.

◆ add() [2/4]

std::shared_ptr< node_impl > sycl::_V1::ext::oneapi::experimental::detail::graph_impl::add ( const std::shared_ptr< graph_impl > &  Impl,
const std::vector< sycl::detail::EventImplPtr >  Events 
)

Create an empty node in the graph.

Parameters
ImplGraph implementation pointer.
EventsList of events associated to this node.
Returns
Created node in the graph.

Definition at line 413 of file graph_impl.cpp.

References add(), and sycl::_V1::invalid.

◆ add() [3/4]

std::shared_ptr< node_impl > sycl::_V1::ext::oneapi::experimental::detail::graph_impl::add ( const std::shared_ptr< graph_impl > &  Impl,
std::function< void(handler &)>  CGF,
const std::vector< sycl::detail::ArgDesc > &  Args,
const std::vector< std::shared_ptr< node_impl >> &  Dep = {} 
)

Create a CGF node in the graph.

Parameters
ImplGraph implementation pointer to create a handler with.
CGFCommand-group function to create node with.
ArgsNode arguments.
DepDependencies of the created node.
Returns
Created node in the graph.

Definition at line 367 of file graph_impl.cpp.

References add(), addEventForNode(), sycl::_V1::ext::oneapi::experimental::empty, sycl::_V1::ext::oneapi::experimental::detail::getNodeTypeFromCG(), sycl::_V1::invalid, sycl::_V1::ext::oneapi::experimental::kernel, and sycl::_V1::make_error_code().

◆ add() [4/4]

std::shared_ptr< node_impl > sycl::_V1::ext::oneapi::experimental::detail::graph_impl::add ( node_type  NodeType,
std::unique_ptr< sycl::detail::CG >  CommandGroup,
const std::vector< std::shared_ptr< node_impl >> &  Dep = {} 
)

Create a kernel node in the graph.

Parameters
NodeTypeUser facing type of the node.
CommandGroupThe CG which stores all information for this node.
DepDependencies of the created node.
Returns
Created node in the graph.

Definition at line 433 of file graph_impl.cpp.

References sycl::_V1::invalid, sycl::_V1::make_error_code(), and MNodeStorage.

Referenced by add().

◆ addEventForNode()

void sycl::_V1::ext::oneapi::experimental::detail::graph_impl::addEventForNode ( std::shared_ptr< graph_impl GraphImpl,
std::shared_ptr< sycl::detail::event_impl >  EventImpl,
std::shared_ptr< node_impl NodeImpl 
)
inline

Associate a sycl event with a node in the graph.

Parameters
GraphImplshared_ptr to Graph impl associated with this event, aka this.
EventImplEvent to associate with a node in map.
NodeImplNode to associate with event in map.

Definition at line 899 of file graph_impl.hpp.

Referenced by add().

◆ addQueue()

void sycl::_V1::ext::oneapi::experimental::detail::graph_impl::addQueue ( const std::shared_ptr< sycl::detail::queue_impl > &  RecordingQueue)
inline

Add a queue to the set of queues which are currently recording to this graph.

Parameters
RecordingQueueQueue to add to set.

Definition at line 876 of file graph_impl.hpp.

◆ checkNodeRecursive()

static bool sycl::_V1::ext::oneapi::experimental::detail::graph_impl::checkNodeRecursive ( const std::shared_ptr< node_impl > &  NodeA,
const std::shared_ptr< node_impl > &  NodeB 
)
inlinestatic

Recursively check successors of NodeA and NodeB to check they are similar.

Parameters
NodeApointer to the first node for comparison
NodeBpointer to the second node for comparison
Returns
true is same structure found, false otherwise

Definition at line 1026 of file graph_impl.hpp.

Referenced by hasSimilarStructure().

◆ clearQueues()

bool sycl::_V1::ext::oneapi::experimental::detail::graph_impl::clearQueues ( )

Remove all queues which are recording to this graph, also sets all queues cleared back to the executing state.

Returns
True if any queues were removed.

Definition at line 506 of file graph_impl.cpp.

Referenced by ~graph_impl().

◆ getContext()

sycl::context sycl::_V1::ext::oneapi::experimental::detail::graph_impl::getContext ( ) const
inline

Query for the context tied to this graph.

Returns
Context associated with graph.

Definition at line 945 of file graph_impl.hpp.

◆ getDevice()

sycl::device sycl::_V1::ext::oneapi::experimental::detail::graph_impl::getDevice ( ) const
inline

Query for the device tied to this graph.

Returns
Device associated with graph.

Definition at line 949 of file graph_impl.hpp.

◆ getEventForNode()

std::shared_ptr<sycl::detail::event_impl> sycl::_V1::ext::oneapi::experimental::detail::graph_impl::getEventForNode ( std::shared_ptr< node_impl NodeImpl) const
inline

Find the sycl event associated with a node.

Parameters
NodeImplNode to find event for.
Returns
Event associated with node.

Definition at line 911 of file graph_impl.hpp.

References sycl::_V1::invalid, and MMutex.

Referenced by getExitNodesEvents(), and removeBarriersFromExtraDependencies().

◆ getExitNodesEvents()

std::vector< sycl::detail::EventImplPtr > sycl::_V1::ext::oneapi::experimental::detail::graph_impl::getExitNodesEvents ( )

Traverse the graph recursively to get the events associated with the output nodes of this graph.

Returns
vector of events associated to exit nodes.

Definition at line 611 of file graph_impl.cpp.

References getEventForNode(), and MNodeStorage.

◆ getLastInorderNode()

std::shared_ptr<node_impl> sycl::_V1::ext::oneapi::experimental::detail::graph_impl::getLastInorderNode ( std::shared_ptr< sycl::detail::queue_impl >  Queue)
inline

Find the last node added to this graph from an in-order queue.

Parameters
QueueIn-order queue to find the last node added to the graph from.
Returns
Last node in this graph added from Queue recording, or empty shared pointer if none.

Definition at line 966 of file graph_impl.hpp.

◆ getNodeForEvent()

std::shared_ptr<node_impl> sycl::_V1::ext::oneapi::experimental::detail::graph_impl::getNodeForEvent ( std::shared_ptr< sycl::detail::event_impl >  EventImpl)
inline

Find the node associated with a SYCL event.

Throws if no node is found for the given event.

Parameters
EventImplEvent to find the node for.
Returns
Node associated with the event.

Definition at line 930 of file graph_impl.hpp.

References sycl::_V1::invalid, and MMutex.

◆ getNumberOfNodes()

size_t sycl::_V1::ext::oneapi::experimental::detail::graph_impl::getNumberOfNodes ( ) const
inline

Returns the number of nodes in the Graph.

Returns
Number of nodes in the Graph

Definition at line 1129 of file graph_impl.hpp.

References MNodeStorage.

◆ hasSimilarStructure()

bool sycl::_V1::ext::oneapi::experimental::detail::graph_impl::hasSimilarStructure ( std::shared_ptr< detail::graph_impl Graph,
bool  DebugPrint = false 
) const
inline

Checks if the graph_impl of Graph has a similar structure to the graph_impl of the caller.

Graphs are considered similar if they have same numbers of nodes of the same type with similar predecessor and successor nodes (number and type). Two nodes are considered similar if they have the same command-group type. For command-groups of type "kernel", the "signature" of the kernel is also compared (i.e. the name of the command-group).

Parameters
Graphif reference to the graph to compare with.
DebugPrintif set to true throw exception with additional debug information about the spotted graph differences.
Returns
true if the two graphs are similar, false otherwise

Definition at line 1056 of file graph_impl.hpp.

References checkNodeRecursive(), sycl::_V1::invalid, and MRoots.

◆ makeEdge()

void sycl::_V1::ext::oneapi::experimental::detail::graph_impl::makeEdge ( std::shared_ptr< node_impl Src,
std::shared_ptr< node_impl Dest 
)

Make an edge between two nodes in the graph.

Performs some mandatory error checks as well as an optional check for cycles introduced by making this edge.

Parameters
SrcThe source of the new edge.
DestThe destination of the new edge.

Definition at line 560 of file graph_impl.cpp.

References sycl::_V1::make_error_code(), MNodeStorage, removeRoot(), and throwIfGraphRecordingQueue().

◆ printGraphAsDot()

void sycl::_V1::ext::oneapi::experimental::detail::graph_impl::printGraphAsDot ( const std::string  FilePath,
bool  Verbose 
) const
inline

Prints the contents of the graph to a text file in DOT format.

Parameters
FilePathPath to the output file.
VerboseIf true, print additional information about the nodes such as kernel args or memory access where applicable.

Vector of nodes visited during the graph printing

Definition at line 987 of file graph_impl.hpp.

References MRoots.

◆ removeBarriersFromExtraDependencies()

std::vector<sycl::detail::EventImplPtr> sycl::_V1::ext::oneapi::experimental::detail::graph_impl::removeBarriersFromExtraDependencies ( )
inline

Removes all Barrier nodes from the list of extra dependencies MExtraDependencies.

Returns
vector of events associated to previous barrier nodes.

Definition at line 1140 of file graph_impl.hpp.

References getEventForNode().

◆ removeQueue()

void sycl::_V1::ext::oneapi::experimental::detail::graph_impl::removeQueue ( const std::shared_ptr< sycl::detail::queue_impl > &  RecordingQueue)
inline

Remove a queue from the set of queues which are currently recording to this graph.

Parameters
RecordingQueueQueue to remove from set.

Definition at line 884 of file graph_impl.hpp.

◆ removeRoot()

void sycl::_V1::ext::oneapi::experimental::detail::graph_impl::removeRoot ( const std::shared_ptr< node_impl > &  Root)

Remove node from list of root nodes.

Parameters
RootNode to remove from list of root nodes.

Definition at line 343 of file graph_impl.cpp.

References MRoots.

Referenced by makeEdge().

◆ setLastInorderNode()

void sycl::_V1::ext::oneapi::experimental::detail::graph_impl::setLastInorderNode ( std::shared_ptr< sycl::detail::queue_impl >  Queue,
std::shared_ptr< node_impl Node 
)
inline

Track the last node added to this graph from an in-order queue.

Parameters
QueueIn-order queue to register Node for.
NodeLast node that was added to this graph from Queue.

Definition at line 977 of file graph_impl.hpp.

◆ throwIfGraphRecordingQueue()

void sycl::_V1::ext::oneapi::experimental::detail::graph_impl::throwIfGraphRecordingQueue ( const std::string  ExceptionMsg) const
inline

Throws an invalid exception if this function is called while a queue is recording commands to the graph.

Parameters
ExceptionMsgMessage to append to the exception message

Definition at line 1013 of file graph_impl.hpp.

References sycl::_V1::make_error_code().

Referenced by makeEdge().

Member Data Documentation

◆ MMutex

std::shared_mutex sycl::_V1::ext::oneapi::experimental::detail::graph_impl::MMutex
mutable

Protects all the fields that can be changed by class' methods.

Definition at line 800 of file graph_impl.hpp.

Referenced by getEventForNode(), and getNodeForEvent().

◆ MNodeStorage

std::vector<std::shared_ptr<node_impl> > sycl::_V1::ext::oneapi::experimental::detail::graph_impl::MNodeStorage

Storage for all nodes contained within a graph.

Nodes are connected to each other via weak_ptrs and so do not extend each other's lifetimes. This storage allows easy iteration over all nodes in the graph, rather than needing an expensive depth first search.

Definition at line 959 of file graph_impl.hpp.

Referenced by add(), getExitNodesEvents(), getNumberOfNodes(), and makeEdge().

◆ MRoots

std::set<std::weak_ptr<node_impl>, std::owner_less<std::weak_ptr<node_impl> > > sycl::_V1::ext::oneapi::experimental::detail::graph_impl::MRoots

List of root nodes.

Definition at line 953 of file graph_impl.hpp.

Referenced by hasSimilarStructure(), printGraphAsDot(), and removeRoot().


The documentation for this class was generated from the following files: