UGRAMM
Loading...
Searching...
No Matches
UGRAMM.h
Go to the documentation of this file.
1//===================================================================//
2// Universal GRAaph Minor Mapping (UGRAMM) method for CGRA //
3// file : UGRAMM.h //
4// description: contains global variables and associated functions //
5//===================================================================//
6
7#ifndef UGRAMM_H
8#define UGRAMM_H
9
10#include <boost/config.hpp>
11#include <iostream>
12#include <fstream>
13#include <boost/graph/graph_traits.hpp>
14#include <boost/graph/adjacency_list.hpp>
15#include <boost/algorithm/string.hpp>
16#include <boost/graph/dijkstra_shortest_paths.hpp>
17#include <boost/property_map/property_map.hpp>
18#include <boost/graph/graphviz.hpp>
19#include <boost/graph/copy.hpp>
20#include <queue>
21#include <map>
22#include <list>
23#include <bitset>
24#include <algorithm>
25#include <vector>
26#include <limits>
27#include <boost/algorithm/string.hpp>
28#include <sys/time.h>
29#include "spdlog/spdlog.h"
30#include <spdlog/sinks/stdout_color_sinks.h>
31#include <boost/program_options.hpp>
32#include "../lib/json.h"
33
34//-------------------------------------------------------------------//
35//------------------------ GRAMM Configuration ----------------------//
36#define MAX_DIST 10000000
37#define RIKEN 1 //Defining the architecture type (1 --> Riken, 0 --> Adres)
38#define DEBUG 0 //For enbaling the print-statements
39#define computeTopoEnable 0 //Compute topological order and sort the graph based on it while finding the minor.
40#define maxIterations 39
41#define NOT_PLACED -1 //For InvUsers
42#define sortAlgorithm 0 //Randomly sorting the H-graph nodes either with the sort or qsort algorithms (1 --> use Sort algorithm, 0 --> qSort algorithm)
43#define skipFullyLockedNodes 1 //Skip fully locked nodes when mapping application nodes that are not locked (1 --> Skip Fully Locked Nodes, 0 --> otherwise)
44#define allowWildcardInLocking 0 //Allow wildcard in locking names. Wild card is defined as "*" (1 --> allow wildcard in locking name, 0 --> don't allow wildcard in locking name)
45//-------------------------------------------------------------------//
46
47//Struct for defining the node configuration in hConfig and gConfig data-structures:
48struct NodeConfig {
49 // For [G] --> Device Model Graph
50 std::string Cell; //Cell-type --> FuncCell, RouteCell, PinCell
51 std::string Type; //Node-Type --> io, alu, memport....
52 int Latency = 0; //[Optional]
53 bool gLocked = false; //True if the G is locked for a hNode; False otherwise
54
55 // For [H] --> Application Graph
56 std::string Opcode; //OpcodeType --> FADD, FMUL, FSUB, INPUT, OUTPUT, etc.
57 std::string pinName; //Load pin of the PinCell node --> inPinA, inPinB
58 std::string LockGNode; //Contains the name of the G Node for locking
59
60 // For both [G] and [H]
61 int width = 0; //Width for this node
62};
63
64//Struct for defining the expected attributes defined in the h and g graph:
65struct DotVertex {
66 // For [H] --> Application Graph
67 std::string H_Name; //[Required] Contains name of the operation in Application graph (ex: Load_0)
68 std::string H_Opcode; //[Required] Contains the Opcode of the operation (ex: FMUL, FADD, INPUT, OUTPUT etc.)
69 std::string H_Latency; //[Optional] Contains the latency of the operation
70 std::string H_Width; //[Optional] Width of the application-node
71
72 // For [G] --> Device Model Graph
73 std::string G_Name; //[Required] Contains the unique name of the cell in the device model graph.
74 std::string G_CellType; //[Required] Contains the Opcode of the CellType (FuncCell, RouteCell, PinCell)
75 std::string G_NodeType; //[Required] Contains the NodeType of Device Model Graph (For example "ALU" for CellType "FuncCell")
76 std::string G_VisualX; //[Optional] Visual X co-ordinate
77 std::string G_VisualY; //[Optional] Visual Y co-ordinate
78 std::string G_Width; //[Optional] Width of the hardware-node.
79};
80
81//Struct for defining the edge types in the H graph to determine the pin layout
83 // For [H] --> Application Graph
84 std::string H_LoadPin; //[Required]
85 std::string H_DriverPin; //[Required]
86 // For [H] --> Application Graph and [G] --> Device Model Graph
87 int weight;
88};
89
90//Properties of the application and device model graph:
91typedef boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, DotVertex, EdgeProperty> DirectedGraph;
92typedef boost::graph_traits<DirectedGraph>::edge_iterator edge_iterator;
93typedef boost::graph_traits<DirectedGraph>::in_edge_iterator in_edge_iterator;
94typedef boost::graph_traits<DirectedGraph>::out_edge_iterator out_edge_iterator;
95typedef boost::graph_traits<DirectedGraph>::vertex_descriptor vertex_descriptor;
96typedef boost::graph_traits<DirectedGraph>::vertex_iterator vertex_iterator;
97typedef boost::graph_traits<DirectedGraph>::out_edge_iterator OutEdgeIterator;
98typedef DirectedGraph::edge_descriptor Edge;
99
100// the routing tree for a signal
101// explanation for the three fields:
102// for each node in the tree, we have a map that returns a list of its child nodes (i.e. the nodes it drives)
103// for each node in the tree, we have a map that returns its parent node (i.e., the unique node that drives it)
104// we also keep track of the list of all nodes in the routing tree
106 std::map<int, std::list<int>> children;
107 std::map<int, int> parent;
108 std::list<int> nodes;
109};
110
111// Routing related variables:
112extern int max_iter;
113extern std::vector<RoutingTree> *Trees; // routing trees for every node in H
114extern std::vector<std::list<int>> *Users; // for every node in device model G track its users
115extern std::map<int, int> invUsers; // InvUsers, key = hID, value = current_mapped gID
116extern std::vector<int> *HistoryCosts; // for history of congestion in PathFinder
117extern std::vector<int> *TraceBack;
118extern std::vector<int> *TopoOrder; // NOT USED: for topological order
119extern std::map<int, std::string> hNames; // Map for storing the unique names of Application graph
120extern std::map<std::string, int> hNamesInv; // Inverse map for getting HID using the unique names of Application graph
121extern std::map<int, std::string> gNames; // Map for storing the unique names of device model graph
122extern std::map<std::string, int> gNamesInv; // Inverse map for getting GID using the unique names of device model graph
123extern std::map<std::string, int> gNamesInv_FuncCell; // Inverse map for getting GID using the unique names of device model graph. Map only funcCell in gNames
124extern std::bitset<100000> explored;
125
126//Pathefinder cost parameters:
127extern int iterCount; //Number of iteartions pathfinder will run for.
128extern float PFac; //Congestion cost factor
129extern float HFac; //History cost factor
130extern float base_cost; //Base cost of using a wire-segment in Pathfinder!!
131extern float pfac_mul; //Multiplier for present congestion cost
132extern float hfac_mul; //Multiplier for history congestion cost
133extern int capacity; //One wire can be routed via a segment in CGRA
134
135//Logger variable:
136extern std::shared_ptr<spdlog::logger> UGRAMM;
137extern std::shared_ptr<spdlog::logger> drcLogger;
138
139extern std::vector<std::string> inPin;
140extern std::vector<std::string> outPin;
141
142//Setting the JSON type:
143using json = nlohmann::json;
144
145//New way for node and opcode types:
146extern std::map<std::string, std::vector<std::string>> ugrammConfig; //New general way
148
149//JSON parsing for the config file:
150extern json jsonParsed;
151
152//Function declaration:
153
164int findMinorEmbedding(DirectedGraph *H, DirectedGraph *G, std::map<int, NodeConfig> *hConfig, std::map<int, NodeConfig> *gConfig);
165
177int findMinVertexModel(DirectedGraph *G, DirectedGraph *H, int y, std::map<int, NodeConfig> *hConfig, std::map<int, NodeConfig> *gConfig);
178
179#endif //UGRAMM header
std::map< int, int > invUsers
Definition UGRAMM.cpp:29
std::vector< std::string > inPin
Definition UGRAMM.cpp:40
DirectedGraph::edge_descriptor Edge
Definition UGRAMM.h:98
std::vector< std::list< int > > * Users
Definition UGRAMM.cpp:28
std::vector< RoutingTree > * Trees
Definition UGRAMM.cpp:27
json UgrammPragmaConfig
Definition UGRAMM.cpp:53
int max_iter
Definition UGRAMM.cpp:26
std::map< int, std::string > hNames
Definition UGRAMM.cpp:33
std::vector< int > * HistoryCosts
Definition UGRAMM.cpp:30
boost::graph_traits< DirectedGraph >::out_edge_iterator OutEdgeIterator
Definition UGRAMM.h:97
float HFac
Definition UGRAMM.cpp:19
std::map< std::string, int > hNamesInv
Definition UGRAMM.cpp:34
std::map< std::string, int > gNamesInv
Definition UGRAMM.cpp:36
boost::graph_traits< DirectedGraph >::vertex_iterator vertex_iterator
Definition UGRAMM.h:96
std::map< std::string, int > gNamesInv_FuncCell
Definition UGRAMM.cpp:37
std::vector< std::string > outPin
Definition UGRAMM.cpp:41
std::bitset< 100000 > explored
Definition UGRAMM.cpp:38
int iterCount
Definition UGRAMM.cpp:17
boost::adjacency_list< boost::listS, boost::vecS, boost::bidirectionalS, DotVertex, EdgeProperty > DirectedGraph
Definition UGRAMM.h:91
float PFac
Definition UGRAMM.cpp:18
float base_cost
Definition UGRAMM.cpp:22
boost::graph_traits< DirectedGraph >::out_edge_iterator out_edge_iterator
Definition UGRAMM.h:94
float pfac_mul
Definition UGRAMM.cpp:20
nlohmann::json json
Definition UGRAMM.h:143
std::shared_ptr< spdlog::logger > drcLogger
Definition UGRAMM.cpp:45
boost::graph_traits< DirectedGraph >::in_edge_iterator in_edge_iterator
Definition UGRAMM.h:93
std::shared_ptr< spdlog::logger > UGRAMM
Definition UGRAMM.cpp:44
int findMinVertexModel(DirectedGraph *G, DirectedGraph *H, int y, std::map< int, NodeConfig > *hConfig, std::map< int, NodeConfig > *gConfig)
Definition UGRAMM.cpp:60
json jsonParsed
Definition UGRAMM.cpp:52
std::map< int, std::string > gNames
Definition UGRAMM.cpp:35
int capacity
Definition UGRAMM.cpp:23
boost::graph_traits< DirectedGraph >::edge_iterator edge_iterator
Definition UGRAMM.h:92
std::map< std::string, std::vector< std::string > > ugrammConfig
Definition UGRAMM.cpp:49
boost::graph_traits< DirectedGraph >::vertex_descriptor vertex_descriptor
Definition UGRAMM.h:95
int findMinorEmbedding(DirectedGraph *H, DirectedGraph *G, std::map< int, NodeConfig > *hConfig, std::map< int, NodeConfig > *gConfig)
Definition UGRAMM.cpp:363
std::vector< int > * TraceBack
Definition UGRAMM.cpp:31
float hfac_mul
Definition UGRAMM.cpp:21
std::vector< int > * TopoOrder
Definition UGRAMM.cpp:32
Definition UGRAMM.h:65
std::string G_Width
Definition UGRAMM.h:78
std::string G_VisualX
Definition UGRAMM.h:76
std::string G_Name
Definition UGRAMM.h:73
std::string G_NodeType
Definition UGRAMM.h:75
std::string H_Latency
Definition UGRAMM.h:69
std::string H_Opcode
Definition UGRAMM.h:68
std::string G_CellType
Definition UGRAMM.h:74
std::string G_VisualY
Definition UGRAMM.h:77
std::string H_Name
Definition UGRAMM.h:67
std::string H_Width
Definition UGRAMM.h:70
Definition UGRAMM.h:82
std::string H_LoadPin
Definition UGRAMM.h:84
std::string H_DriverPin
Definition UGRAMM.h:85
int weight
Definition UGRAMM.h:87
Definition UGRAMM.h:48
std::string Opcode
Definition UGRAMM.h:56
std::string Type
Definition UGRAMM.h:51
bool gLocked
Definition UGRAMM.h:53
int width
Definition UGRAMM.h:61
std::string LockGNode
Definition UGRAMM.h:58
std::string pinName
Definition UGRAMM.h:57
std::string Cell
Definition UGRAMM.h:50
int Latency
Definition UGRAMM.h:52
Definition UGRAMM.h:105
std::map< int, int > parent
Definition UGRAMM.h:107
std::list< int > nodes
Definition UGRAMM.h:108
std::map< int, std::list< int > > children
Definition UGRAMM.h:106