Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
abstract_execution_pipeline.h
1 // NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2 // software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3 // derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4 // or works. Modified works should carry a notice stating that you changed the software and should note the date and
5 // nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6 // source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7 // EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9 // WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10 // CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11 // THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12 // are solely responsible for determining the appropriateness of using and distributing the software and you assume
13 // all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14 // with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15 // operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16 // damage to property. The software developed by NIST employees is not subject to copyright protection within the
17 // United States.
18 
19 
20 #ifndef HEDGEHOG_ABSTRACT_EXECUTION_PIPELINE_H
21 #define HEDGEHOG_ABSTRACT_EXECUTION_PIPELINE_H
22 
23 #include <numeric>
24 #include "graph.h"
25 #include "../core/defaults/core_default_execution_pipeline.h"
26 
28 namespace hh {
29 
96 template<class GraphOutput, class ...GraphInputs>
98  : public behavior::MultiReceivers<GraphInputs...>,
99  public behavior::Sender<GraphOutput>,
100  public behavior::SwitchRule<GraphInputs> ... {
101  static_assert(traits::isUnique<GraphInputs...>, "A node can't accept multiple inputs with the same type.");
102  static_assert(sizeof... (GraphInputs) >= 1, "A node need to have one output type and at least one output type.");
103  private:
104  std::shared_ptr<Graph<GraphOutput, GraphInputs...>>
105  graph_ = nullptr;
106 
107  std::shared_ptr<core::CoreDefaultExecutionPipeline<GraphOutput, GraphInputs...>>
109 
110  public:
111 
113  AbstractExecutionPipeline() = delete;
114 
124  size_t const &numberGraphDuplications,
125  bool iota = false) {
126  std::vector<int> deviceIds(numberGraphDuplications, 0);
127  if (iota) { std::iota(deviceIds.begin(), deviceIds.end(), 0); }
128  graph_ = graph;
129  coreExecutionPipeline_ = std::make_shared<core::CoreDefaultExecutionPipeline<GraphOutput, GraphInputs...>>(
130  "AbstractExecutionPipeline", this,
131  std::dynamic_pointer_cast<core::CoreGraph<GraphOutput, GraphInputs...>>(graph->core()),
132  numberGraphDuplications, deviceIds, false);
133  }
134 
144  size_t const &numberGraphDuplications,
145  std::vector<int> const deviceIds, bool automaticStart = false)
146  : graph_(graph),
147  coreExecutionPipeline_(std::make_shared<core::CoreDefaultExecutionPipeline<GraphOutput, GraphInputs...>>(
148  "AbstractExecutionPipeline",
149  this,
150  std::dynamic_pointer_cast<core::CoreGraph<GraphOutput, GraphInputs...>>(graph->core()),
151  numberGraphDuplications,
152  deviceIds, automaticStart)) {}
153 
163  AbstractExecutionPipeline(std::string_view const &name,
164  std::shared_ptr<Graph<GraphOutput, GraphInputs...>> const &graph,
165  size_t const &numberGraphDuplications,
166  std::vector<int> const &deviceIds,
167  bool automaticStart = false)
168  : graph_(graph),
169  coreExecutionPipeline_(std::make_shared<core::CoreDefaultExecutionPipeline<GraphOutput, GraphInputs...>>(
170  name,
171  this,
172  std::dynamic_pointer_cast<core::CoreGraph<GraphOutput, GraphInputs...>>(graph->core()),
173  numberGraphDuplications,
174  deviceIds,
175  automaticStart)
176  ) {}
177 
179  virtual ~AbstractExecutionPipeline() = default;
180 
183  std::shared_ptr<core::CoreNode> core() override { return this->coreExecutionPipeline_; }
184 
187  std::shared_ptr<Graph<GraphOutput, GraphInputs...>> const &graph() const { return graph_; }
188 };
189 }
190 
191 #endif //HEDGEHOG_ABSTRACT_EXECUTION_PIPELINE_H
std::shared_ptr< Graph< GraphOutput, GraphInputs... > > graph_
Original Graph that will be duplicated.
virtual ~AbstractExecutionPipeline()=default
Default destructor.
Hedgehog main namespace.
Sender Behavior definition, node has an output type.
Definition: sender.h:32
Node core for the default execution pipeline.
Node interface made for duplicating a graph, for example in the case of multi-GPU computation...
std::shared_ptr< core::CoreDefaultExecutionPipeline< GraphOutput, GraphInputs... > > coreExecutionPipeline_
Execution Pipeline core.
AbstractExecutionPipeline(std::shared_ptr< Graph< GraphOutput, GraphInputs... >> graph, size_t const &numberGraphDuplications, bool iota=false)
Constructor to set an execution pipeline with a graph and the total number of graphs.
std::shared_ptr< Graph< GraphOutput, GraphInputs... > > const & graph() const
Inner graph accessor.
Main Hedgehog object that does computation.
Definition: graph.h:85
AbstractExecutionPipeline()=delete
Deleted default constructor, an execution pipeline need to be constructed with a compatible graph...
STL namespace.
MultiReceivers Behavior definition, node has a list of input types.
std::shared_ptr< core::CoreNode > core() override
Execution Pipeline accessor core.
AbstractExecutionPipeline(std::shared_ptr< Graph< GraphOutput, GraphInputs... >> graph, size_t const &numberGraphDuplications, std::vector< int > const deviceIds, bool automaticStart=false)
Constructor to set an execution pipeline with a graph, the total number of graphs, the device Ids, and set the execution to automatically start.
Core associated to the Graph.
Definition: core_graph.h:63
AbstractExecutionPipeline(std::string_view const &name, std::shared_ptr< Graph< GraphOutput, GraphInputs... >> const &graph, size_t const &numberGraphDuplications, std::vector< int > const &deviceIds, bool automaticStart=false)
Constructor to set an execution pipeline with a graph, the total number of graphs, the device Ids and set the execution to automatically start.
Behavior definition for dispatching data to a Graph managed by an AbstractExecutionPipeline.
Definition: switch_rule.h:30