Skip to content

Commit

Permalink
New container graph completed, including unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
massimim committed Sep 17, 2022
1 parent 3ca3d30 commit b9c587b
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 118 deletions.
3 changes: 2 additions & 1 deletion libNeonDomain/include/Neon/domain/tools/TestData.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ auto TestData<G, T, C>::laplace(IODomain& A, NEON_IO IODomain& B)
}

template <typename G, typename T, int C>
auto TestData<G, T, C>::compare(FieldNames name, T tollerance) -> bool
auto TestData<G, T, C>::compare(FieldNames name,
[[maybe_unused]] T tollerance) -> bool
{
bool isTheSame = false;
if constexpr (std::is_integral_v<T>) {
Expand Down
59 changes: 46 additions & 13 deletions libNeonSet/include/Neon/set/container/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@

namespace Neon::set::container {

/**
* Abstraction for a graph of containers.
* Each graph node represents a Neon container,
* directed edges of the graph are dependencies between the containers.
* Dependencies my be data driven or user provided.
*
*
*/
struct Graph
{
using Uid = GraphData::Uid;
Expand Down Expand Up @@ -98,15 +106,24 @@ struct Graph
auto getSubsequentGraphNodes(const GraphNode& graphNode,
const std::vector<GraphDependencyType>& dependencyTypes = {GraphDependencyType::user,
GraphDependencyType::data}) -> std::vector<GraphNode*>;
/**
* Set the stream to run the graph.
* We provide a preset function so that some initialization
* could be only once, before executing the run method.
*/
auto runtimePreSet(int anchorStream)
-> void;

/**
* Execute the scheduling operation associated to the node
* Execute the graph on all devices
*/
auto run(int streamIdx = 0,
Neon::DataView dataView = Neon::DataView::STANDARD)
-> void;

/**
* Run the graph on a target device.
*/
auto run(Neon::SetIdx setIdx,
int streamIdx = 0,
Neon::DataView dataView = Neon::DataView::STANDARD)
Expand All @@ -116,21 +133,34 @@ struct Graph
const std::string& graphName,
bool debug) -> void;

/**
* Returns a reference for the used backend.
*/
auto getBackend() const -> const Neon::Backend&;

/**
* Recursively iterate through the graph nodes
* to expand any graph type of node.
*/
auto expandSubGraphs()
-> void;

auto getNumberOfNodes()
->int;

protected:
/**
* Invalidate all scheduling information that were computed
*/
auto helpInvalidateScheduling() -> void;

/**
* Helper - it checks the initialization of the backend.
*/
auto helpCheckBackendStatus() -> void;

/**
* Remove redundant dependencies
* Helper - it removes redundant dependencies
*/
auto helpRemoveRedundantDependencies() -> void;

Expand Down Expand Up @@ -205,55 +235,58 @@ struct Graph
-> void;

/**
* Execute
* Helper - it executes the graph on all devices
*/
auto helpExecute(int anchorStream)
-> void;

/**
* Helper - it executes the graph on a target device
*/
auto helpExecute(Neon::SetIdx setIdx, int anchorStream)
-> void;
/**
* Resetting node's data related to scheduling
* Helper - It resets node scheduling data
*/
auto helpComputeScheduling_00_resetData()
-> void;

/**
* Resetting node's data related to scheduling
* Helper - it generates a BFS visit structure for the graph
*/
auto helpComputeScheduling_01_generatingBFS(bool filterOutAnchors)
-> Bfs;

/**
* Maps node to streams.
* Helper - it maps node to streams.
* Returns the max stream Id used by the scheduling
*/
auto helpComputeScheduling_02_mappingStreams(Bfs& bfs, bool filterOutAnchors, int anchorStream)
-> int;

/**
* Define events to be waited and fired from each node
* Helper - it defines events to be waited and fired from each node
* Returns the max event Id used by the scheduling.
*/
auto helpComputeScheduling_03_events(Bfs& bfs)
-> int;

/**
* Booking the required resources from the backend.
* Helper - it Books the required resources from the backend.
*/
auto helpComputeScheduling_04_ensureResources(int maxStreamId, int maxEventId)
-> void;


using RawGraph = DiGraph<GraphNode, GraphDependency>;

Uid mUidCounter;
RawGraph mRawGraph;
Uid mUidCounter /**< internal counter to create node uids */;
RawGraph mRawGraph /**< raw graph structure */;
bool mSchedulingStatusIsValid;
int mMaxNumberStreams;
Bfs mBfs;
int mMaxNumberStreams /**< Max number of streams used in the scheduling phase */;
Bfs mBfs /**< Structure for the BFS visit. */;

Backend mBackend;
Backend mBackend /**< Backend used to create streams and events */;
bool mBackendIsSet = false;

bool mFilterOutAnchorsPreSet = false;
Expand Down
4 changes: 3 additions & 1 deletion libNeonSet/include/Neon/set/container/GraphContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ struct GraphContainer : ContainerAPI
* @param streamIdx
* @param dataView
*/
auto run(int streamIdx = 0, Neon::DataView dataView = Neon::DataView::STANDARD) -> void override;
auto run(int streamIdx = 0,
Neon::DataView dataView = Neon::DataView::STANDARD)
-> void override;

auto run(Neon::SetIdx setIdx,
int streamIdx = 0,
Expand Down
4 changes: 2 additions & 2 deletions libNeonSet/include/Neon/set/container/graph/GraphData.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Neon::set::container {
class GraphData
{
public:
using Uid = uint32_t;
using Index = uint32_t;
using Uid = uint64_t;
using Index = uint64_t;

constexpr static Uid notSet = 0;
constexpr static Uid beginUid = 1;
Expand Down
Loading

0 comments on commit b9c587b

Please sign in to comment.