SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
network.cpp
1 #include <list>
2 #include <set>
3 #include <vector>
4 #include <boost/format.hpp>
5 
6 #include "smaug/core/datatypes.h"
7 #include "smaug/core/typedefs.h"
8 #include "smaug/core/network.h"
9 #include "smaug/utility/utils.h"
10 
11 using namespace smaug;
12 
13 void Network::addOperator(Operator* op) {
14  Vertex v = add_vertex(VertexProperty(op), graph);
15  op->setVertex(v);
16  operators[op->getName()] = op;
17 }
18 
19 void Network::addEdge(Operator* src, Operator* dest, TensorIndices indices) {
20  assert(src != dest && "Adding an edge to the node itself!");
21  add_edge(src->getVertex(), dest->getVertex(), EdgeProperty(indices), graph);
22 }
23 
24 void Network::dumpDataflowGraph() const {
25  std::ofstream out(name + "_dataflow_graph.dot", std::ofstream::out);
26  write_graphviz(out, graph, DataflowGraphWriter(graph));
27 }
28 
29 bool Network::validate() const {
30  bool success = true;
31  for (auto& iter : operators) {
32  Operator* op = iter.second;
33  if (!op->validate()) {
34  std::cerr << "[ERROR]: " << op->getName()
35  << " was not configured correctly!\n";
36  success = false;
37  }
38  }
39  return success;
40 }
41 
42 void Network::printSummary() const {
43  static const std::string hline(
44  "______________________________________________"
45  "______________________________________________");
46  std::list<Vertex> vertices;
47  boost::topological_sort(graph, std::front_inserter(vertices));
48  std::cout << hline << "\n";
49  std::cout << boost::format(kLayerFormat)
50  % "Layer (type)"
51  % "Output shape"
52  % "Parameters";
53  std::cout << hline << "\n";
54  for (auto vertex : vertices) {
55  Operator* op = get(boost::vertex_op, graph, vertex);
56  op->printSummary(std::cout);
57  std::cout << hline << "\n";
58  }
59 }
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::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
smaug::Operator::validate
virtual bool validate()
Returns true if the parameters/tensors of this operator are all valid.
Definition: operator.h:47