31#ifndef DW_FRAMEWORK_COMPUTEGRAPH_IMPL_HPP_
32#define DW_FRAMEWORK_COMPUTEGRAPH_IMPL_HPP_
34#include <dw/core/base/Types.h>
36#include <dwcgf/Types.hpp>
42#include <dw/core/container/Span.hpp>
43#include <dw/core/container/VectorFixed.hpp>
44#include <dw/core/container/HashContainer.hpp>
56template <
typename Type,
size_t CapacityAtCompileTime_ = 0>
57class StackFixed :
public VectorFixed<Type, CapacityAtCompileTime_>
61 : VectorFixed<Type, CapacityAtCompileTime_>()
66 : VectorFixed<Type, CapacityAtCompileTime_>(size_)
70 bool push(
const Type& value)
72 return this->push_back(value);
96 for (
const auto& each : *
this)
107template <
typename Type,
size_t CapacityAtCompileTime_ = 0>
108class QueueFixed :
public VectorFixed<Type, CapacityAtCompileTime_>
112 : VectorFixed<Type, CapacityAtCompileTime_>()
117 : VectorFixed<Type, CapacityAtCompileTime_>(size_)
123 return this->push_back(value);
128 return this->
size() == 0;
147 return this->at(m_index);
152 return VectorFixed<Type, CapacityAtCompileTime_>::size() - m_index;
157 VectorFixed<Type, CapacityAtCompileTime_>::clear();
163 for (
const auto& each : *
this)
204 static constexpr char LOG_TAG[] =
"ComputeGraphImpl";
222 void getPasses(VectorFixed<Pass*>& passList, uint64_t nodeIndex);
233 static constexpr uint64_t MAX_ADJACENCY_MATRIX_DIM = 1000;
234 static constexpr uint64_t MAX_ADJACENCY_MATRIX_CELL_DIM = 100;
236 void connectNode(
const Connection& connection);
238 bool hasChannels()
const;
239 bool hasNodes()
const;
240 bool hasConnections()
const;
241 bool hasValidInputs()
const;
242 bool connectNodeInputsAreValid(
const Connection& connection)
const;
244 using CellEntry_t =
struct CellEntry_t
246 uint64_t inputNodeId;
250 using AdjacencyMatrixCell_t = VectorFixed<CellEntry_t, MAX_ADJACENCY_MATRIX_CELL_DIM>;
251 using AdjacencyMatrixRow_t = VectorFixed<AdjacencyMatrixCell_t, MAX_ADJACENCY_MATRIX_DIM>;
252 using AdjacenyMatrix_t = VectorFixed<AdjacencyMatrixRow_t, MAX_ADJACENCY_MATRIX_DIM>;
253 using Queue_t = QueueFixed<uint64_t, MAX_ADJACENCY_MATRIX_DIM>;
254 using Stack_t = StackFixed<uint64_t, MAX_ADJACENCY_MATRIX_DIM>;
255 using Vector_t = VectorFixed<uint64_t, MAX_ADJACENCY_MATRIX_DIM>;
256 using VectorB_t = VectorFixed<bool, MAX_ADJACENCY_MATRIX_DIM>;
258 static void labelDisconnectedInputs(AdjacenyMatrix_t& adjacencyMatrix);
260 static bool graphHasImproperChannelUse(Vector_t& usedChannels,
261 const AdjacenyMatrix_t& adjacencyMatrix,
262 uint64_t numChannels);
263 static bool graphIsCyclic(uint64_t rowIndex,
265 VectorB_t& nodesToExplore,
266 const AdjacenyMatrix_t& adjacencyMatrix);
267 static bool graphIsIncorrect(Stack_t& stack,
269 VectorB_t& nodesToExplore,
270 const Queue_t& rootNodes,
271 const AdjacenyMatrix_t& adjacencyMatrix);
273 template <
typename Conta
interType>
274 static void findRootNodes(ContainterType& rootNodes,
275 const AdjacenyMatrix_t& adjacencyMatrix);
277 template <
typename ContainerType,
typename VisitFunction>
278 static void traverse(ContainerType& nodesToVisit,
279 const Queue_t& rootNodes,
280 const AdjacenyMatrix_t& adjacencyMatrix,
281 VisitFunction visit);
283 static void prettyPrint(
const AdjacenyMatrix_t& adjacencyMatrix);
286 span<ChannelObject*> m_channels;
288 span<const Connection> m_connections;
314 AdjacenyMatrix_t m_adjacencyMatrix;
316 Vector_t m_usedChannels;
317 VectorB_t m_nodesToExplore;
318 VectorB_t m_visitedNodes;
323 VectorFixed<Pass*> m_passList;
324 using PassTableString = FixedString<256>;
325 HashMap<PassTableString, Pass*> m_passTable;
bool push(const Type &value)
bool contains(const Type &value) const
bool push(const Type &value)
bool contains(const Type &value) const
void getPasses(VectorFixed< Pass * > &passList, ComputeGraphTraversalOrder order)
void setChannels(span< ChannelObject * > channels)
void getPass(Pass *&pass, const char *key)
void getPasses(VectorFixed< Pass * > &passList, dwProcessorType processorType, dwProcessType processType, ComputeGraphTraversalOrder order)
void run(ComputeGraphTraversalOrder order)
void printAdjacencyMatrix()
void setConnections(span< const Connection > connections)
void setNodes(span< Node * > nodes)
static constexpr char LOG_TAG[]
void getPasses(VectorFixed< Pass * > &passList, uint64_t nodeIndex)
virtual ~ComputeGraphImpl()=default
Pass is a runnable describes the metadata of a pass.
Connection { uint64_t srcNodeId Connection
ComputeGraphTraversalOrder
@ TRAVERSAL_ORDER_DEPTH_FIRST
@ TRAVERSAL_ORDER_BREADTH_FIRST