SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
network.h
1 #ifndef _CORE_NETWORK_H_
2 #define _CORE_NETWORK_H_
3 
4 #include <exception>
5 #include <map>
6 #include <set>
7 #include <string>
8 #include <vector>
9 #include <utility>
10 
11 #include "smaug/core/typedefs.h"
12 #include "smaug/core/operator.h"
13 #include "smaug/core/workspace.h"
14 #include "smaug/operators/common.h"
15 
16 namespace smaug {
17 
23  public:
24  DataflowGraphWriter(const Graph& _graph) : graph(_graph) {}
25  void operator()(std::ostream& out, const Vertex& v) {
26  Operator* op = get(boost::vertex_op, graph, v);
27  out << "[label=\"" << op->getName() << "\"]";
28  }
29 
30  protected:
31  const Graph& graph;
32 };
33 
39 class Network {
40  protected:
41  typedef std::map<std::string, Operator*> OperatorMap;
42 
43  public:
44  Network(std::string _name) : name(_name) {}
45  ~Network() {
46  for (auto& op : operators)
47  delete op.second;
48  }
49 
50  void addOperator(Operator* op);
51  void addEdge(Operator* src, Operator* dest, TensorIndices indices);
52  const OperatorMap& getOperators() const { return operators; }
53  Operator* getOperator(const std::string& name) {
54  return operators.at(name);
55  }
56  const Graph& getGraph() const { return graph; }
57  void dumpDataflowGraph() const;
58 
59  void printSummary() const;
60  bool validate() const;
61  OperatorMap::iterator begin() { return operators.begin(); }
62  OperatorMap::iterator end() { return operators.end(); }
63 
64  void setSamplingInfo(const SamplingInfo& _sampling) {
65  sampling = _sampling;
66  }
67  SamplingInfo& getSamplingInfo() { return sampling; }
68 
69  protected:
71  Operator* newOp;
72  Operator* sourceOp;
73  std::vector<Operator*> targetOps;
74  };
75 
77  Graph graph;
78 
80  OperatorMap operators;
81 
84 
86  std::string name;
87 };
88 
89 } // namespace smaug
90 
91 #endif
smaug::Network
Network encapsulates all of the information SMAUG will use during execution: the overall computation ...
Definition: network.h:39
_SamplingInfo
Simulation sampling information maintained by the Operator and passed to the accelerated kernel.
Definition: common.h:262
smaug::TensorIndices
Additional metadata for edges in the graph.
Definition: typedefs.h:22
smaug::Network::name
std::string name
Name of the model.
Definition: network.h:86
smaug::Network::graph
Graph graph
The dataflow graph.
Definition: network.h:77
smaug::DataflowGraphWriter
DataflowGraphWriter writes the current network as a dot-graph file to the given ostream.
Definition: network.h:22
smaug::Network::sampling
SamplingInfo sampling
The sampling information of the model.
Definition: network.h:83
smaug::Network::OperatorInsertion
Definition: network.h:70
smaug::Operator
Operator is the base class for all graph operators supported by SMAUG.
Definition: operator.h:28
smaug
The smaug namespace is the parent namespace of all C++ code in SMAUG.
Definition: backend.cpp:38
smaug::Network::operators
OperatorMap operators
Global map of operator names to their operator objects.
Definition: network.h:80
common.h
Utilities for writing and invoking Aladdin kernels from Operators.