21#ifndef HEDGEHOG_GRAPH_H 
   22#define HEDGEHOG_GRAPH_H 
   27#include "../../behavior/node.h" 
   28#include "../../behavior/copyable.h" 
   29#include "../../behavior/input_output/multi_senders.h" 
   30#include "../../behavior/input_output/multi_receivers.h" 
   32#include "../../core/nodes/core_graph.h" 
   33#include "../printer/options/color_scheme.h" 
   34#include "../printer/options/structure_options.h" 
   35#include "../printer/options/debug_options.h" 
   36#include "../printer/dot_printer.h" 
   37#include "../printer/jet_color.h" 
   43#ifndef DOXYGEN_SHOULD_SKIP_THIS 
   47template<
size_t Separator, 
class ...AllTypes>
 
   48class AbstractExecutionPipeline;
 
  133template<
size_t Separator, 
class ...AllTypes>
 
  136    public tool::BehaviorMultiReceiversTypeDeducer_t<tool::Inputs<Separator, AllTypes...>>,
 
  137    public tool::BehaviorMultiSendersTypeDeducer_t<tool::Outputs<Separator, AllTypes...>> {
 
  139#ifndef DOXYGEN_SHOULD_SKIP_THIS 
  148  std::unique_ptr<std::set<std::shared_ptr<Node>>>
 
  157      std::string 
const &
name = 
"Graph",
 
  158      std::unique_ptr<Scheduler> scheduler = std::make_unique<DefaultScheduler>()) :
 
  159      behavior::
Node(std::make_unique<
core::CoreGraph<Separator, AllTypes...>>(
name, std::move(scheduler), this)),
 
  160      coreGraph_(std::dynamic_pointer_cast<
core::CoreGraph<Separator, AllTypes...>>(this->
core())),
 
  161      nodes_(std::make_unique<std::set<std::shared_ptr<
Node>>>()) {
 
  162    if (
coreGraph_ == 
nullptr) { 
throw std::runtime_error(
"The core used by the graph should be a CoreGraph."); }
 
  173  void inputs(std::shared_ptr<InputNode_t> inputNode) {
 
  174    auto node = std::static_pointer_cast<Node>(inputNode);
 
  177    this->
coreGraph_->template setInputForAllCommonTypes<typename InputNode_t::inputs_t>(node->core().get());
 
  188                                        typename core::GIM<Separator, AllTypes...>::inputs_t> InputNode_t>
 
  189  void input(std::shared_ptr<InputNode_t> inputNode) {
 
  190    auto node = std::static_pointer_cast<Node>(inputNode);
 
  193    this->
coreGraph_->template setInputForACommonType<InputDataType,
 
  194                                                      typename InputNode_t::inputs_t>(node->core().get());
 
  202  void outputs(std::shared_ptr<OutputNode_t> outputNode) {
 
  203    auto node = std::static_pointer_cast<Node>(outputNode);
 
  207    this->
coreGraph_->template setOutputForAllCommonTypes<typename OutputNode_t::outputs_t>(node->core().get());
 
  215  template<
class OutputType,
 
  217                                         typename core::GOM<Separator, AllTypes...>::outputs_t> OutputNode_t>
 
  218  void output(std::shared_ptr<OutputNode_t> outputNode) {
 
  219    auto node = std::static_pointer_cast<Node>(outputNode);
 
  222    this->
coreGraph_->template setOutputForACommonType<OutputType,
 
  223                                                       typename OutputNode_t::outputs_t>(node->core().get());
 
  233  template<tool::SenderNode SenderNode_t, tool::ReceiverNode ReceiverNode_t>
 
  234  void edges(std::shared_ptr<SenderNode_t> sender, std::shared_ptr<ReceiverNode_t> receiver) {
 
  238        > != 0, 
"The sender and the receiver nodes should at least share a type." 
  240    auto senderNode = std::static_pointer_cast<Node>(sender);
 
  241    auto receiverNode = std::static_pointer_cast<Node>(receiver);
 
  243    nodes_->insert(senderNode);
 
  244    nodes_->insert(receiverNode);
 
  247        ->template addEdgeForAllCommonTypes<typename SenderNode_t::outputs_t, typename ReceiverNode_t::inputs_t>
 
  248            (senderNode->core().get(), receiverNode->core().get());
 
  257  template<
class CommonType,
 
  259  void edge(std::shared_ptr<SenderNode_t> sender, std::shared_ptr<ReceiverNode_t> receiver) {
 
  260    auto senderNode = std::static_pointer_cast<Node>(sender);
 
  261    auto receiverNode = std::static_pointer_cast<Node>(receiver);
 
  263    nodes_->insert(senderNode);
 
  264    nodes_->insert(receiverNode);
 
  266    this->
coreGraph_->template addEdgeForACommonType<
 
  268        typename SenderNode_t::outputs_t, 
typename ReceiverNode_t::inputs_t>
 
  269        (senderNode->core().get(), receiverNode->core().get());
 
  287  void pushData(std::shared_ptr<CompatibleInputType_t> data) { this->
coreGraph_->broadcastAndNotifyAllInputNodes(data); }
 
  328                     std::unique_ptr<ColorPicker> colorPicker = std::make_unique<JetColor>(),
 
  329                     bool verbose = 
false) {
 
  333        std::filesystem::absolute(dotFilePath), colorScheme, structureOptions, debugOption, 
core,
 
  334        std::move(colorPicker), verbose);
 
  335    core->visit(&printer);
 
StructureOptions
Enum structural options.
@ NONE
No added structural options.
DebugOptions
Enum to enable debug printing.
@ NONE
No added debug options.
ColorScheme
Enum color options.
@ NONE
No added coloration.
typename internals::Intersect< Tuple1, Tuple2 >::type Intersect_t
Helper getting the intersection of types between two type tuples.
typename internals::Splitter< delta, Types... >::Inputs Inputs
Helper getting the input types from a list of template types (variadic)
tool::GraphOutputsManagementAbstractionTypeDeducer_t< tool::Outputs< Separator, AllTypes... > > GOM
Type alias for an GraphOutputsManagementAbstraction from the list of template parameters.
tool::GraphInputsManagementAbstractionTypeDeducer_t< tool::Inputs< Separator, AllTypes... > > GIM
Type alias for an GraphInputsManagementAbstraction from the list of template parameters.
Execution pipeline abstraction.
Hedgehog graph abstraction.
void createDotFile(std::filesystem::path const &dotFilePath, ColorScheme colorScheme=ColorScheme::NONE, StructureOptions structureOptions=StructureOptions::NONE, DebugOptions debugOption=DebugOptions::NONE, std::unique_ptr< ColorPicker > colorPicker=std::make_unique< JetColor >(), bool verbose=false)
Create a dot file representing a snapshot of the state of the graph at the moment of the call,...
~Graph() override=default
Default graph destructor.
void inputs(std::shared_ptr< InputNode_t > inputNode)
Set an input node and connect the node to the graph's inputs for all common types.
void pushData(std::shared_ptr< CompatibleInputType_t > data)
Push data into the graph.
void executeGraph(bool waitForInitialization=false)
Execute the graph.
Graph(std::string const &name="Graph", std::unique_ptr< Scheduler > scheduler=std::make_unique< DefaultScheduler >())
Default graph constructor, construct a graph with the name "Graph" and with a default scheduler.
void output(std::shared_ptr< OutputNode_t > outputNode)
Set an output node and connect the node to the graph's output OutputDataType.
void finishPushingData()
Indicate to the graph that no more input data are pushed to the graph.
void edge(std::shared_ptr< SenderNode_t > sender, std::shared_ptr< ReceiverNode_t > receiver)
Create an edge between two nodes for a specific type.
void waitForTermination()
Wait for the graph to terminate.
auto getBlockingResult()
Get result data from the graph.
void input(std::shared_ptr< InputNode_t > inputNode)
Set an input node and connect the node to the graph's input InputDataType.
void edges(std::shared_ptr< SenderNode_t > sender, std::shared_ptr< ReceiverNode_t > receiver)
Create an edge between two nodes for all common types.
std::shared_ptr< core::CoreGraph< Separator, AllTypes... > > const coreGraph_
Core of the graph.
void outputs(std::shared_ptr< OutputNode_t > outputNode)
Set an output node and connect the node to the graph's outputs for all common types.
void deviceId(int deviceId)
Set the device id (GPU ID) for all the nodes in a graph.
std::unique_ptr< std::set< std::shared_ptr< Node > > > nodes_
Set of nodes given by the end user.
void cleanGraph()
Clean the graph.
Behavior abstraction for the base node.
std::string name() const
Node's name accessor.
Node(std::shared_ptr< hh::core::abstraction::NodeAbstraction > core)
Constructor's node.
std::shared_ptr< hh::core::abstraction::NodeAbstraction > const & core() const
Core accessor.
Base graph node abstraction.
Test if an input type is in the list of input types (tuple)
Test if a node is a sender for a type.
Test if a node is a receiver for a type.
Test if a node can be input of a graph.
Test if a node can be input of a graph for a type.
Test if a node can be output of a graph.
Test if a node can be output of a graph for a type.