CGRA-ME
UserArchs.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * The software programs comprising "CGRA-ME" and the documentation provided
3  * with them are copyright by its authors and the University of Toronto. Only
4  * non-commercial, not-for-profit use of this software is permitted without ex-
5  * plicit permission. This software is provided "as is" with no warranties or
6  * guarantees of support. See the LICENCE for more details. You should have re-
7  * ceived a copy of the full licence along with this software. If not, see
8  * <http://cgra-me.ece.utoronto.ca/license/>.
9  ******************************************************************************/
10 
11 #ifndef __USERARCHS__H__
12 #define __USERARCHS__H__
13 
14 #include <CGRA/CGRA.h>
15 #include <CGRA/ConfigStore.h>
16 #include <CGRA/Module.h>
17 #include <CGRA/ModuleComposites.h>
18 
19 #include <functional>
20 #include <map>
21 #include <string>
22 #include <utility>
23 
24 using ArchGenFunctionSig = std::unique_ptr<CGRA>(const ConfigStore&);
26  std::string description; //< arbitrary string used for display purposes
27  std::function<ArchGenFunctionSig> gen;
28  ConfigStore args_and_defaults; //< the complete list of arguments for this generator (and their default values)
29 
36  std::unique_ptr<CGRA> operator()(const ConfigStore& overrides = {}) const {
38  override_all(conf, overrides);
39  return gen(std::move(conf));
40  }
41 };
42 
43 class UserArchs
44 {
45  public:
46 
48  : all_identifiers()
50  {
63  registerGenerator("adres", ArchitectureGenerator{"Adres CGRA Architecture", createAdresArch, {
64  {
65  {"cols", "4"}, // Columns
66  {"rows", "4"}, // Rows
67  {"II", "1"}, // II of the arch
68  {"toroid", "1"}, // Toroid Connection
69  {"fu_type", "0"}, // Heterogeneous Function Unit Type (0 = homogeneous, 1 = alternate-by-row, 2 = alternate-by-column
70  {"fu_latency", "0"},
71  {"fu_II", "1"},
72  {"rf_cols", "1"}, // Register File Columns
73  {"rf_rows", "1"}, // Register File Rows
74  {"num_const_addresses", "0"}, // number of const addresses each memory port can provide
75  {"op_div", "0"}, // VLIW PEs will come with op divide
76  {"pe_conn", "15"}, // Inter-PE Connectivity Enabling 8-bit Representation:
77  {"pred", "0"}, // Predication (0 = off, 1 = on)
78  {"reg_bypass", "0"}, // Register the bypass through the PE register file
79  {"pred_scheme", "partial"}, // Pred scheme to be used partial or event
80  {"extra_mem", "0"}, // Switch the right IOs with memory ports
81  {"frac", "0"}, // Instantiate PE Type: 0 = AdresPE, 1 = FracAdresPE
82  /*
83  * bit-0: N Connection
84  * bit-1: E Connection
85  * bit-2: S Connection
86  * bit-3: W Connection
87  * bit-4: NW Connection
88  * bit-5: NE Connection
89  * bit-6: SE Connection
90  * bit-7: SW Connection
91  * e.g. 0d15 = 0x0f = orthogonal, 0d255 = 0xff = full-diagonal
92  * NOTE: value of 0~14 are legal, but may not be useful...
93  */
94  }
95  }});
96 
97  registerGenerator("hycube", ArchitectureGenerator{"HyCUBE CGRA Architecture", createHyCUBEArch, {
98  {
99  {"cols", "4"}, // Columns
100  {"rows", "4"}, // Rows
101  {"II", "1"}, // II of the arch
102  {"pred", "0"}, // Predication (0 = off, 1 = on)
103  {"fu_II", "1"}, // Allowed number of FuncUnit Initiation Intervals
104  {"fu_latency", "0"}, // Latency of FuncUnit
105  {"num_const_addresses", "0"}, // number of const addresses each memory port can provide
106  {"pe_conn", "15"}, // Specifying inter-Processing Element connections
107  {"pred", "0"}, // Predication (0 = off, 1 = on)
108  {"phi", "0"}, // Phi mux in crossbar (0 = off, 1 = on)
109  {"pred_scheme", "partial"}, // Pred scheme to be used partial or event
110  {"extra_mem", "0"} // Switch the right IOs with memory ports
111  /*
112  * bit-0: N Connection
113  * bit-1: E Connection
114  * bit-2: S Connection
115  * bit-3: W Connection
116  * bit-4: NW Connection
117  * bit-5: NE Connection
118  * bit-6: SE Connection
119  * bit-7: SW Connection
120  * e.g. 0d15 = 0x0f = orthogonal, 0d255 = 0xff = full-diagonal
121  * NOTE: value of 0~14 are legal, but may not be useful...
122  */
123  }
124  }});
125 
126  registerGenerator("elastic_RIKEN", ArchitectureGenerator{"Elastic RIKEN Architecture", createElasticRIKENArch, {
127  {
128  {"cols", "4"}, // Columns
129  {"rows", "4"}, // Rows
130  {"II", "1"}, // II of the arch
131  {"eb_depth", "2"}, // Elastic Buffer Depth
132  {"eb_enable", "true"}, // Elastic Buffer Depth
133  {"type", "0"}, // PE TYPE (deprecated IGNORE) // janders
134  {"fu_latency", "0"}, // Latency of FuncUnit (IGNORE) // janders
135  {"pe_conn", "255"}, // Specifying inter-Processing Element connections (0xFF, 8 conns)
136  {"fu_II", "1"}, // MUST BE LOCKED TO 1 for RIKEN janders
137  }
138  }});
139 
140  // backwards compat. Do not recommend adding to this list.
141  registerGenerator("1", getGenerator("adres"));
142  registerGenerator("2", getGenerator("hycube"));
143  registerGenerator("3", getGenerator("elastic_RIKEN"));
144  // for (int i = 0; i <= 2; ++i) {
145  // generator_storage.at(std::to_string(i)).description += " (deprecated ID)";
146  // }
147  }
148 
149  void registerGenerator(std::string identifer, ArchitectureGenerator generator) {
150  all_identifiers.push_back(identifer);
151  generator_storage.emplace(std::move(identifer), std::move(generator));
152  }
153 
154  const ArchitectureGenerator& getGenerator(const std::string& identifer) const {
155  const auto search_result = generator_storage.find(identifer);
156  if (search_result == generator_storage.end()) {
157  make_and_throw<cgrame_error>([&](auto&& s) {
158  s << "id `" << identifer << "' has no associated architecture generator";
159  });
160  } else {
161  return search_result->second;
162  }
163  }
164 
165  auto begin() const { return generator_storage.begin(); }
166  auto end() const { return generator_storage.end(); }
167 
168  private:
169  std::vector<std::string> all_identifiers; //< the key set for `generator_storage`
170  std::map<std::string, ArchitectureGenerator> generator_storage;
171 
172  // Add your function that create the CGRA in-memory architecture, following the prototype below
173  static std::unique_ptr<CGRA> createAdresArch(const ConfigStore& args);
174  static std::unique_ptr<CGRA> createHyCUBEArch(const ConfigStore& args);
175  static std::unique_ptr<CGRA> createElasticRIKENArch(const ConfigStore& args);
176 };
177 
178 struct XY : std::pair<int,int> {
179  using std::pair<int,int>::pair;
180  auto x() { return first; }
181  auto y() { return second; }
182 };
183 
184 inline std::string xyName(const std::string& prefix, XY xy) {
185  return string_from_stream([&](auto&& s) {
186  s << prefix << "_c" << xy.x() << "_r" << xy.y();
187  });
188 }
189 
190 inline std::string xyidName(const std::string& prefix, XY xy, int id) {
191  return xyName(prefix, xy) + string_from_stream([&](auto&& s) {
192  s << "_i" << id;
193  });
194 }
195 
196 #endif
197 
ModuleComposites.h
ArchitectureGenerator::gen
std::function< ArchGenFunctionSig > gen
Definition: UserArchs.h:27
xyidName
std::string xyidName(const std::string &prefix, XY xy, int id)
Definition: UserArchs.h:190
Module.h
ConfigStore.h
UserArchs::UserArchs
UserArchs()
Definition: UserArchs.h:47
ArchitectureGenerator::description
std::string description
Definition: UserArchs.h:26
override_all
ConfigStore & override_all(ConfigStore &into, const ConfigStore &from)
Definition: ConfigStore.h:257
ConfigStore
Definition: ConfigStore.h:76
XY::y
auto y()
Definition: UserArchs.h:181
UserArchs::begin
auto begin() const
Definition: UserArchs.h:165
UserArchs::all_identifiers
std::vector< std::string > all_identifiers
Definition: UserArchs.h:169
UserArchs::createHyCUBEArch
static std::unique_ptr< CGRA > createHyCUBEArch(const ConfigStore &args)
Definition: HyCUBE.cpp:168
XY::x
auto x()
Definition: UserArchs.h:180
string_from_stream
std::string string_from_stream(F &&f)
Definition: Exception.h:95
UserArchs::end
auto end() const
Definition: UserArchs.h:166
CGRA.h
xyName
std::string xyName(const std::string &prefix, XY xy)
Definition: UserArchs.h:184
UserArchs::createAdresArch
static std::unique_ptr< CGRA > createAdresArch(const ConfigStore &args)
Definition: AdresArch.cpp:141
UserArchs::getGenerator
const ArchitectureGenerator & getGenerator(const std::string &identifer) const
Definition: UserArchs.h:154
ArchitectureGenerator
Definition: UserArchs.h:25
UserArchs
Definition: UserArchs.h:43
UserArchs::generator_storage
std::map< std::string, ArchitectureGenerator > generator_storage
Definition: UserArchs.h:170
UserArchs::registerGenerator
void registerGenerator(std::string identifer, ArchitectureGenerator generator)
Definition: UserArchs.h:149
ArchGenFunctionSig
std::unique_ptr< CGRA >(const ConfigStore &) ArchGenFunctionSig
Definition: UserArchs.h:24
ArchitectureGenerator::args_and_defaults
ConfigStore args_and_defaults
Definition: UserArchs.h:28
UserArchs::createElasticRIKENArch
static std::unique_ptr< CGRA > createElasticRIKENArch(const ConfigStore &args)
Definition: ElasticRIKEN.cpp:129
ArchitectureGenerator::operator()
std::unique_ptr< CGRA > operator()(const ConfigStore &overrides={}) const
Definition: UserArchs.h:36
XY
Definition: UserArchs.h:178