Skip to content

Commit 211c270

Browse files
committed
[libs][rr_graph] add comment for tileable rr graph
1 parent 7beed40 commit 211c270

File tree

12 files changed

+150
-89
lines changed

12 files changed

+150
-89
lines changed

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,6 +4137,7 @@ static void process_bend(pugi::xml_node Node, t_segment_inf& segment, const int
41374137
tmp.c_str());
41384138
}
41394139

4140+
// TODO: Add a comment to explain this and this function overall
41404141
int tmp_len = 1;
41414142
int sum_len = 0;
41424143
for (size_t i_len = 0; i_len < list.size(); i_len++) {

libs/libarchfpga/src/read_xml_util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ void bad_attribute_value(const pugi::xml_attribute attr,
2424
InstPort make_inst_port(std::string str, pugi::xml_node node, const pugiutil::loc_data& loc_data);
2525
InstPort make_inst_port(pugi::xml_attribute attr, pugi::xml_node node, const pugiutil::loc_data& loc_data);
2626

27+
/**
28+
* @brief Returns the number of layers in the device layout.
29+
*
30+
* @param layout_type_tag The XML node pointing to the <layout> tag.
31+
* @param loc_data Points to the location in the architecture file where the parser is reading.
32+
*/
2733
int get_number_of_layers(pugi::xml_node layout_type_tag, const pugiutil::loc_data& loc_data);
2834

2935
/**

libs/libarchfpga/src/vib_inf.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#pragma once
2+
/**
3+
* @file
4+
* @brief Methods and classes related to the Versatile Interconnect Blocks (VIB) architecture.
5+
* VIB is an alternative approach for creating the Routing Resource (RR) graph, where the connection block,
6+
* switch block, and intra-cluster crossbar are combined into a single block. This means that each tile has
7+
* only two blocks: a VIB block and a functional block. For further details, please refer to the following paper:
8+
* https://doi.org/10.1109/ICFPT59805.2023.00014
9+
*/
210

311
#include <functional>
412
#include <utility>

libs/librrgraph/src/base/check_rr_graph.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ void check_rr_node(const RRGraphView& rr_graph,
450450

451451
int class_max_ptc = get_tile_class_max_ptc(type, is_flat);
452452
int pin_max_ptc = get_tile_pin_max_ptc(type, is_flat);
453+
454+
// TODO: This is a temporary fix to ensure that the VIB architecture is supported.
455+
// This should be removed and ** grid ** should be used instead.
456+
// If VIB architecture is not used, these are not going to have any effect.
453457
int mux_max_ptc = -1;
454458
const VibInf* vib_type = nullptr;
455459
if (vib_grid.get_num_layers() > 0) {
@@ -458,6 +462,8 @@ void check_rr_node(const RRGraphView& rr_graph,
458462
if (vib_type) {
459463
mux_max_ptc = (int)vib_type->get_first_stages().size();
460464
}
465+
466+
461467
e_pin_type class_type = OPEN;
462468
int class_num_pins = -1;
463469
switch (rr_type) {

libs/librrgraph/src/base/check_rr_graph.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ void check_rr_graph(const RRGraphView& rr_graph,
1313
const e_graph_type graph_type,
1414
bool is_flat);
1515

16+
/**
17+
* @brief Checks the validity of the given node in the RR graph.
18+
*
19+
* @note This function checks for the following:
20+
* - The node's location is within the legal range.
21+
* - The node's capacity and other properties are consistent with the node's type.
22+
* - The node's type is valid.
23+
* - The node's capacity is consistent with the node's type.
24+
* - The node's capacitance and resistance are non-negative.
25+
*
26+
* @note vib_grid is added and used only of VIB architecture is used. This data strucutre
27+
* is used to check for MUX node type PTC number. Ideally, this should be removed and
28+
* ** grid ** should be used instead.
29+
*
30+
*/
1631
void check_rr_node(const RRGraphView& rr_graph,
1732
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
1833
const DeviceGrid& grid,

libs/librrgraph/src/base/rr_graph_builder.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ vtr::vector<RRNodeId, std::vector<RREdgeId>>& RRGraphBuilder::node_in_edge_stora
3232
}
3333

3434
vtr::vector<RRNodeId, std::vector<short>>& RRGraphBuilder::node_ptc_storage() {
35-
return node_ptc_nums_;
35+
return node_tilable_track_nums_;
3636
}
3737

3838
void RRGraphBuilder::add_node_to_all_locs(RRNodeId node) {
@@ -75,7 +75,7 @@ RRNodeId RRGraphBuilder::create_node(int layer, int x, int y, e_rr_type type, in
7575
node_side = side;
7676
}
7777
node_storage_.emplace_back();
78-
node_ptc_nums_.emplace_back();
78+
node_tilable_track_nums_.emplace_back();
7979
RRNodeId new_node = RRNodeId(node_storage_.size() - 1);
8080
node_storage_.set_node_layer(new_node, layer);
8181
node_storage_.set_node_type(new_node, type);
@@ -84,7 +84,6 @@ RRNodeId RRGraphBuilder::create_node(int layer, int x, int y, e_rr_type type, in
8484
if (e_rr_type::OPIN == type || e_rr_type::IPIN == type) {
8585
node_storage_.add_node_side(new_node, node_side);
8686
}
87-
// Special for CHANX, being consistent with the rule in find_node()
8887
node_lookup_.add_node(new_node, layer, x, y, type, ptc, node_side);
8988

9089
return new_node;
@@ -102,7 +101,7 @@ void RRGraphBuilder::clear() {
102101
node_lookup_.clear();
103102
node_storage_.clear();
104103
node_in_edges_.clear();
105-
node_ptc_nums_.clear();
104+
node_tilable_track_nums_.clear();
106105
rr_node_metadata_.clear();
107106
rr_edge_metadata_.clear();
108107
rr_segments_.clear();
@@ -182,7 +181,7 @@ void RRGraphBuilder::reorder_nodes(e_rr_node_reorder_algorithm reorder_rr_graph_
182181
});
183182
}
184183

185-
void RRGraphBuilder::create_edge(RRNodeId src, RRNodeId dest, RRSwitchId edge_switch, bool remapped) {
184+
void RRGraphBuilder::create_edge_in_cache(RRNodeId src, RRNodeId dest, RRSwitchId edge_switch, bool remapped) {
186185
edges_to_build_.emplace_back(src, dest, size_t(edge_switch), remapped);
187186
is_edge_dirty_ = true; // Adding a new edge revokes the flag
188187
is_incoming_edge_dirty_ = true;
@@ -231,53 +230,53 @@ void RRGraphBuilder::set_node_ptc_nums(RRNodeId node, const std::string& ptc_str
231230
VTR_ASSERT(ptc_tokens.size() >= 1);
232231
set_node_ptc_num(node, std::stoi(ptc_tokens[0]));
233232
if (ptc_tokens.size() > 1) {
234-
VTR_ASSERT(size_t(node) < node_ptc_nums_.size());
235-
node_ptc_nums_[node].resize(ptc_tokens.size());
233+
VTR_ASSERT(size_t(node) < node_tilable_track_nums_.size());
234+
node_tilable_track_nums_[node].resize(ptc_tokens.size());
236235
for (size_t iptc = 0; iptc < ptc_tokens.size(); iptc++) {
237-
node_ptc_nums_[node][iptc] = std::stoi(ptc_tokens[iptc]);
236+
node_tilable_track_nums_[node][iptc] = std::stoi(ptc_tokens[iptc]);
238237
}
239238
}
240239
}
241240

242241
std::string RRGraphBuilder::node_ptc_nums_to_string(RRNodeId node) const {
243-
if (node_ptc_nums_.empty()) {
242+
if (node_tilable_track_nums_.empty()) {
244243
return std::to_string(size_t(node_storage_.node_ptc_num(node)));
245244
}
246-
VTR_ASSERT(size_t(node) < node_ptc_nums_.size());
247-
if (node_ptc_nums_[node].empty()) {
245+
VTR_ASSERT(size_t(node) < node_tilable_track_nums_.size());
246+
if (node_tilable_track_nums_[node].empty()) {
248247
return std::to_string(size_t(node_storage_.node_ptc_num(node)));
249248
}
250249
std::string ret;
251-
for (size_t iptc = 0; iptc < node_ptc_nums_[node].size(); iptc++) {
252-
ret += std::to_string(size_t(node_ptc_nums_[node][iptc])) + ",";
250+
for (size_t iptc = 0; iptc < node_tilable_track_nums_[node].size(); iptc++) {
251+
ret += std::to_string(size_t(node_tilable_track_nums_[node][iptc])) + ",";
253252
}
254253
// Remove the last comma
255254
ret.pop_back();
256255
return ret;
257256
}
258257

259258
bool RRGraphBuilder::node_contain_multiple_ptc(RRNodeId node) const {
260-
if (node_ptc_nums_.empty()) {
259+
if (node_tilable_track_nums_.empty()) {
261260
return false;
262261
}
263-
return node_ptc_nums_[node].size() > 1;
262+
return node_tilable_track_nums_[node].size() > 1;
264263
}
265264

266265
void RRGraphBuilder::add_node_track_num(RRNodeId node, vtr::Point<size_t> node_offset, short track_id) {
267266
VTR_ASSERT(size_t(node) < node_storage_.size());
268-
VTR_ASSERT(size_t(node) < node_ptc_nums_.size());
267+
VTR_ASSERT(size_t(node) < node_tilable_track_nums_.size());
269268
VTR_ASSERT_MSG(node_storage_.node_type(node) == e_rr_type::CHANX || node_storage_.node_type(node) == e_rr_type::CHANY, "Track number valid only for CHANX/CHANY RR nodes");
270269

271270
size_t node_length = std::abs(node_storage_.node_xhigh(node) - node_storage_.node_xlow(node))
272271
+ std::abs(node_storage_.node_yhigh(node) - node_storage_.node_ylow(node));
273-
if (node_length + 1 != node_ptc_nums_[node].size()) {
274-
node_ptc_nums_[node].resize(node_length + 1);
272+
if (node_length + 1 != node_tilable_track_nums_[node].size()) {
273+
node_tilable_track_nums_[node].resize(node_length + 1);
275274
}
276275

277276
size_t offset = node_offset.x() - node_storage_.node_xlow(node) + node_offset.y() - node_storage_.node_ylow(node);
278-
VTR_ASSERT(offset < node_ptc_nums_[node].size());
277+
VTR_ASSERT(offset < node_tilable_track_nums_[node].size());
279278

280-
node_ptc_nums_[node][offset] = track_id;
279+
node_tilable_track_nums_[node][offset] = track_id;
281280
}
282281

283282
void RRGraphBuilder::add_track_node_to_lookup(RRNodeId node) {
@@ -301,9 +300,9 @@ void RRGraphBuilder::add_track_node_to_lookup(RRNodeId node) {
301300
e_rr_type node_type = node_storage_.node_type(node);
302301
// Routing channel nodes may have different ptc num
303302
// Find the track ids using the x/y offset
304-
// FIXME: Special case on assigning CHANX (x,y) should be changed to a natural way!
305303
if (e_rr_type::CHANX == node_type || e_rr_type::CHANY == node_type) {
306-
ptc = node_type == e_rr_type::CHANX ? node_ptc_nums_[node][x - node_storage_.node_xlow(node)] : node_ptc_nums_[node][y - node_storage_.node_ylow(node)];
304+
ptc = (node_type == e_rr_type::CHANX) ? node_tilable_track_nums_[node][x - node_storage_.node_xlow(node)] :
305+
node_tilable_track_nums_[node][y - node_storage_.node_ylow(node)];
307306
node_lookup_.add_node(node, node_storage_.node_layer(node), x, y, node_type, ptc);
308307
}
309308
}

libs/librrgraph/src/base/rr_graph_builder.h

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,21 @@ class RRGraphBuilder {
3636
public:
3737
/** @brief Return a writable object for rr_nodes */
3838
t_rr_graph_storage& rr_nodes();
39+
3940
/** @brief Return a writable object for update the fast look-up of rr_node */
4041
RRSpatialLookup& node_lookup();
42+
4143
/** @warning The Metadata should stay as an independent data structure from the rest of the internal data,
4244
* e.g., node_lookup! */
4345
/** @brief Return a writable object for the meta data on the nodes */
4446
MetadataStorage<int>& rr_node_metadata();
47+
4548
/** @brief Return a writable object for the meta data on the edge */
4649
MetadataStorage<std::tuple<int, int, short>>& rr_edge_metadata();
50+
4751
/** @brief Return a writable object fo the incoming edge storage */
4852
vtr::vector<RRNodeId, std::vector<RREdgeId>>& node_in_edge_storage();
53+
4954
/** @brief Return a writable object of the node ptc storage (for tileable routing resource graph) */
5055
vtr::vector<RRNodeId, std::vector<short>>& node_ptc_storage();
5156

@@ -241,9 +246,16 @@ class RRGraphBuilder {
241246
node_storage_.set_node_track_num(id, new_track_num);
242247
}
243248

249+
// ** The following functions are only used for tileable routing resource graph generator **
250+
244251
/** @brief Add a track id for a given node base on the offset in coordinate, applicable only to CHANX and CHANY nodes.
245252
* This API is used by tileable routing resource graph generator, which requires each routing track has a different
246253
* track id depending their location in FPGA fabric.
254+
*
255+
* @param node The node to add the track id to.
256+
* @param node_offset Location of the portion of the node being considered. It is used
257+
* to calculate the relative location from the beginning of the node.
258+
* @param track_id The track id to add to the node.
247259
*/
248260
void add_node_track_num(RRNodeId node, vtr::Point<size_t> node_offset, short track_id);
249261

@@ -256,17 +268,17 @@ class RRGraphBuilder {
256268
}
257269

258270
/** @brief set_node_mux_num() is designed for routing mux nodes */
259-
inline void set_node_mux_num(RRNodeId id, int new_class_num) {
260-
node_storage_.set_node_mux_num(id, new_class_num);
271+
inline void set_node_mux_num(RRNodeId id, int new_mux_num) {
272+
node_storage_.set_node_mux_num(id, new_mux_num);
261273
}
262274

263-
/** @brief Add a list of ptc number in string (split by comma) to a given node. This function is used by rr graph reader only. Not suggested for internal builder!!! */
275+
/** @brief Add a list of ptc number in string (split by comma) to a given node. This function is used by rr graph reader only. */
264276
void set_node_ptc_nums(RRNodeId node, const std::string& ptc_str);
265277

266-
/** @brief With a given node, output ptc numbers into a string (use comma as delima). This function is used by rr graph writer only. Not suggested for internal builder!!! */
278+
/** @brief With a given node, output ptc numbers into a string (use comma as delima). This function is used by rr graph writer only. */
267279
std::string node_ptc_nums_to_string(RRNodeId node) const;
268280

269-
/** @brief Identify if a node contains multiple ptc numbers. Mainly used by I/O reader only. Not suggest for internal builder */
281+
/** @brief Identify if a node contains multiple ptc numbers. It is used for tileable RR Graph and mainly used by I/O reader only. */
270282
bool node_contain_multiple_ptc(RRNodeId node) const;
271283

272284
/** @brief Set the node direction; The node direction is only available of routing channel nodes, such as x-direction routing tracks (CHANX) and y-direction routing tracks (CHANY). For other nodes types, this value is not meaningful and should be set to NONE. */
@@ -275,8 +287,8 @@ class RRGraphBuilder {
275287
}
276288

277289
/** @brief Add a new edge to the cache of edges to be built
278-
* .. note:: This will not add an edge to storage! You need to call build_edges() after all the edges are cached! */
279-
void create_edge(RRNodeId src, RRNodeId dest, RRSwitchId edge_switch, bool remapped);
290+
* @note This will not add an edge to storage. You need to call build_edges() after all the edges are cached. */
291+
void create_edge_in_cache(RRNodeId src, RRNodeId dest, RRSwitchId edge_switch, bool remapped);
280292

281293
/** @brief Allocate and build actual edges in storage.
282294
* Once called, the cached edges will be uniquified and added to routing resource nodes,
@@ -295,6 +307,8 @@ class RRGraphBuilder {
295307
*/
296308
std::vector<RREdgeId> node_in_edges(RRNodeId node) const;
297309

310+
// ** End of functions for tileable routing resource graph generator **
311+
298312
/** @brief Set the node id for clock network virtual sink */
299313
inline void set_virtual_clock_network_root_idx(RRNodeId virtual_clock_network_root_idx) {
300314
node_storage_.set_virtual_clock_network_root_idx(virtual_clock_network_root_idx);
@@ -370,11 +384,6 @@ class RRGraphBuilder {
370384
return node_storage_.count_rr_switches(arch_switch_inf, arch_switch_fanins);
371385
}
372386

373-
/**
374-
* @brief Unlock storage; required to modify an routing resource graph after edge is read
375-
*/
376-
inline void unlock_storage() { node_storage_.edges_read_ = false; node_storage_.partitioned_ = false; node_storage_.clear_node_first_edge();}
377-
378387
/** @brief Reserve the lists of nodes, edges, switches etc. to be memory efficient.
379388
* This function is mainly used to reserve memory space inside RRGraph,
380389
* when adding a large number of nodes/edge/switches/segments,
@@ -393,9 +402,9 @@ class RRGraphBuilder {
393402
inline void resize_nodes(size_t size) {
394403
node_storage_.resize(size);
395404
}
396-
/** @brief This function resize node ptc nums. Only used by RR graph I/O reader and writers. Do not use for internal builder */
405+
/** @brief This function resize node ptc nums. Only used by RR graph I/O reader and writers. */
397406
inline void resize_node_ptc_nums(size_t size) {
398-
node_ptc_nums_.resize(size);
407+
node_tilable_track_nums_.resize(size);
399408
}
400409

401410

@@ -404,7 +413,8 @@ class RRGraphBuilder {
404413
rr_switch_inf_.resize(size);
405414
}
406415

407-
/** @brief Validate that edge data is partitioned correctly. Also there are no edges left to be built!
416+
/** @brief Validate that edge data is partitioned correctly. This function should be called
417+
* when all edges in cache are added.
408418
* @note This function is used to validate the correctness of the routing resource graph in terms
409419
* of graph attributes. Strongly recommend to call it when you finish the building a routing resource
410420
* graph. If you need more advance checks, which are related to architecture features, you should
@@ -459,8 +469,13 @@ class RRGraphBuilder {
459469

460470
/**
461471
* @brief A cache for edge-related information, required to build edges for routing resource nodes.
462-
* @note It is used when building a routing resource graph by considering memory efficiency.
463-
* It will be clear up after calling build_edges().
472+
* @note It is used when building a routing resource graph. It is a set of edges that have not yet been
473+
* added to the main rr-graph edge storage to avoid an expensive edge-by-edge reallocation or re-shuffling
474+
* of edges in the main rr-graph edge storage.
475+
*
476+
* @note It will be cleared after calling build_edges().
477+
*
478+
* @note This data structure is only used for tileable routing resource graph generator.
464479
*
465480
* @warning This is a temporary data which is used to collect edges to be built for nodes
466481
*/
@@ -490,15 +505,16 @@ class RRGraphBuilder {
490505
/**
491506
* @brief A list of incoming edges for each routing resource node.
492507
* @note This can be built optionally, as required by applications.
493-
* By default, it is empty! Call build_in_edges() to construct it!!!
508+
* By default, it is empty! Call build_in_edges() to construct it.
494509
*/
495510
vtr::vector<RRNodeId, std::vector<RREdgeId>> node_in_edges_;
496511

497512
/**
498513
* @brief Extra ptc number for each routing resource node.
499-
* @note This is required by tileable routing resource graph.
514+
* @note This is required by tileable routing resource graphs. The first index is the node id, and
515+
* the second index is is the relative distance from the starting point of the node.
500516
* @details
501-
* In a tileable routing architecture, routing tracks, e.g., CHANX and CHANY, follows a staggered organization.
517+
* In a tileable routing architecture, routing tracks, e.g., CHANX and CHANY, follow a staggered organization.
502518
* Hence, a routing track may appear in different routing channels, representing different ptc/track id.
503519
* Here is an illustrative example of a X-direction routing track (CHANX) in INC direction, which is organized in staggered way.
504520
*
@@ -514,7 +530,7 @@ class RRGraphBuilder {
514530
* | |
515531
* starting point ending point
516532
*/
517-
vtr::vector<RRNodeId, std::vector<short>> node_ptc_nums_;
533+
vtr::vector<RRNodeId, std::vector<short>> node_tilable_track_nums_;
518534

519535
/** @warning The Metadata should stay as an independent data structure from the rest of the internal data,
520536
* e.g., node_lookup! */
@@ -542,8 +558,15 @@ class RRGraphBuilder {
542558
*/
543559
MetadataStorage<std::tuple<int, int, short>> rr_edge_metadata_;
544560

545-
/** @brief a flag to mark the status of edge storage
546-
* dirty means that the edge storage is not complete, should call related APIs to build */
561+
/**
562+
* @brief This flag indicates if all the edges in cache are added to the main rr-graph edge storage.
563+
* To add all edges in cache to the main rr-graph edge storage, call build_edges().
564+
*/
547565
bool is_edge_dirty_;
566+
567+
/**
568+
* @brief This flag indicates whether node_in_edges_ is updated with
569+
* edges in the main rr-graph edge storage.
570+
*/
548571
bool is_incoming_edge_dirty_;
549572
};

0 commit comments

Comments
 (0)