Skip to content

Commit d3449e8

Browse files
authored
Merge pull request #1800 from verilog-to-routing/rr_graph_reader_writer_refactor
Deploy ``RRGraphBuilder`` in RRGraph Reader and Writer to replace the use of ``rr_node_indices``
2 parents 78cd631 + 0845c14 commit d3449e8

File tree

5 files changed

+54
-136
lines changed

5 files changed

+54
-136
lines changed

vpr/src/device/rr_graph_builder.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "vtr_log.h"
12
#include "rr_graph_builder.h"
23

34
RRGraphBuilder::RRGraphBuilder(t_rr_graph_storage* node_storage,
@@ -13,3 +14,37 @@ t_rr_graph_storage& RRGraphBuilder::node_storage() {
1314
RRSpatialLookup& RRGraphBuilder::node_lookup() {
1415
return node_lookup_;
1516
}
17+
18+
void RRGraphBuilder::add_node_to_all_locs(RRNodeId node) {
19+
t_rr_type node_type = node_storage_.node_type(node);
20+
short node_ptc_num = node_storage_.node_ptc_num(node);
21+
for (int ix = node_storage_.node_xlow(node); ix <= node_storage_.node_xhigh(node); ix++) {
22+
for (int iy = node_storage_.node_ylow(node); iy <= node_storage_.node_yhigh(node); iy++) {
23+
switch (node_type) {
24+
case SOURCE:
25+
case SINK:
26+
case CHANY:
27+
node_lookup_.add_node(node, ix, iy, node_type, node_ptc_num, SIDES[0]);
28+
break;
29+
case CHANX:
30+
/* Currently need to swap x and y for CHANX because of chan, seg convention
31+
* TODO: Once the builders is reworked for use consistent (x, y) convention,
32+
* the following swapping can be removed
33+
*/
34+
node_lookup_.add_node(node, iy, ix, node_type, node_ptc_num, SIDES[0]);
35+
break;
36+
case OPIN:
37+
case IPIN:
38+
for (const e_side& side : SIDES) {
39+
if (node_storage_.is_node_on_specific_side(node, side)) {
40+
node_lookup_.add_node(node, ix, iy, node_type, node_ptc_num, side);
41+
}
42+
}
43+
break;
44+
default:
45+
VTR_LOG_ERROR("Invalid node type for node '%lu' in the routing resource graph file", size_t(node));
46+
break;
47+
}
48+
}
49+
}
50+
}

vpr/src/device/rr_graph_builder.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ class RRGraphBuilder {
3737
t_rr_graph_storage& node_storage();
3838
/* Return a writable object for update the fast look-up of rr_node */
3939
RRSpatialLookup& node_lookup();
40+
/* Add an existing rr_node in the node storage to the node look-up
41+
* This function requires a valid node which has already been allocated in the node storage, with
42+
* - a valid node id
43+
* - valid geometry information: xlow/ylow/xhigh/yhigh
44+
* - a valid node type
45+
* - a valid node ptc number
46+
* - a valid side (applicable to OPIN and IPIN nodes only
47+
*/
48+
void add_node_to_all_locs(RRNodeId node);
4049

4150
/* -- Internal data storage -- */
4251
private:

vpr/src/route/rr_graph_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ void load_rr_file(const t_graph_type graph_type,
5959
read_edge_metadata,
6060
&device_ctx.chan_width,
6161
&device_ctx.rr_nodes,
62+
&device_ctx.rr_graph_builder,
6263
&device_ctx.rr_graph,
6364
&device_ctx.rr_switch_inf,
6465
&device_ctx.rr_indexed_data,
65-
&device_ctx.rr_node_indices,
6666
device_ctx.num_arch_switches,
6767
device_ctx.arch_switch_inf,
6868
device_ctx.rr_segments,

vpr/src/route/rr_graph_uxsdcxx_serializer.h

Lines changed: 8 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
259259
bool read_edge_metadata,
260260
t_chan_width* chan_width,
261261
t_rr_graph_storage* rr_nodes,
262+
RRGraphBuilder* rr_graph_builder,
262263
RRGraphView* rr_graph,
263264
std::vector<t_rr_switch_inf>* rr_switch_inf,
264265
std::vector<t_rr_indexed_data>* rr_indexed_data,
265-
t_rr_node_indices* rr_node_indices,
266266
const size_t num_arch_switches,
267267
const t_arch_switch_inf* arch_switch_inf,
268268
const std::vector<t_segment_inf>& segment_inf,
@@ -274,10 +274,10 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
274274
: wire_to_rr_ipin_switch_(wire_to_rr_ipin_switch)
275275
, chan_width_(chan_width)
276276
, rr_nodes_(rr_nodes)
277+
, rr_graph_builder_(rr_graph_builder)
277278
, rr_graph_(rr_graph)
278279
, rr_switch_inf_(rr_switch_inf)
279280
, rr_indexed_data_(rr_indexed_data)
280-
, rr_node_indices_(rr_node_indices)
281281
, read_rr_graph_filename_(read_rr_graph_filename)
282282
, graph_type_(graph_type)
283283
, base_cost_type_(base_cost_type)
@@ -1566,148 +1566,21 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
15661566
/*Allocates and load the rr_node look up table. SINK and SOURCE, IPIN and OPIN
15671567
*share the same look up table. CHANX and CHANY have individual look ups */
15681568
void process_rr_node_indices() {
1569-
const auto& rr_graph = (*rr_graph_);
1570-
/* Alloc the lookup table */
1571-
auto& indices = *rr_node_indices_;
1572-
1573-
typedef struct max_ptc {
1574-
short chanx_max_ptc = 0;
1575-
short chany_max_ptc = 0;
1576-
} t_max_ptc;
1577-
1578-
/*
1579-
* Local multi-dimensional vector to hold max_ptc for every coordinate.
1580-
* It has same height and width as CHANY and CHANX are inverted
1581-
*/
1582-
vtr::Matrix<t_max_ptc> coordinates_max_ptc; /* [x][y] */
1583-
size_t max_coord_size = std::max(grid_.width(), grid_.height());
1584-
coordinates_max_ptc.resize({max_coord_size, max_coord_size}, t_max_ptc());
1569+
auto& rr_graph_builder = (*rr_graph_builder_);
15851570

15861571
/* Alloc the lookup table */
15871572
for (t_rr_type rr_type : RR_TYPES) {
15881573
if (rr_type == CHANX) {
1589-
indices[rr_type].resize({grid_.height(), grid_.width(), NUM_SIDES});
1574+
rr_graph_builder.node_lookup().resize_nodes(grid_.height(), grid_.width(), rr_type, NUM_SIDES);
15901575
} else {
1591-
indices[rr_type].resize({grid_.width(), grid_.height(), NUM_SIDES});
1576+
rr_graph_builder.node_lookup().resize_nodes(grid_.width(), grid_.height(), rr_type, NUM_SIDES);
15921577
}
15931578
}
15941579

1595-
/*
1596-
* Add the correct node into the vector
1597-
* For CHANX and CHANY no node is added yet, but the maximum ptc is counted for each
1598-
* x/y location. This is needed later to add the correct node corresponding to CHANX
1599-
* and CHANY.
1600-
*
1601-
* Note that CHANX and CHANY 's x and y are swapped due to the chan and seg convention.
1602-
*/
1580+
/* Add the correct node into the vector */
16031581
for (size_t inode = 0; inode < rr_nodes_->size(); inode++) {
16041582
auto node = (*rr_nodes_)[inode];
1605-
if (rr_graph.node_type(node.id()) == SOURCE || rr_graph.node_type(node.id()) == SINK) {
1606-
for (int ix = node.xlow(); ix <= node.xhigh(); ix++) {
1607-
for (int iy = node.ylow(); iy <= node.yhigh(); iy++) {
1608-
if (node.ptc_num() >= (int)indices[SOURCE][ix][iy][0].size()) {
1609-
indices[SOURCE][ix][iy][0].resize(node.ptc_num() + 1, OPEN);
1610-
}
1611-
if (node.ptc_num() >= (int)indices[SINK][ix][iy][0].size()) {
1612-
indices[SINK][ix][iy][0].resize(node.ptc_num() + 1, OPEN);
1613-
}
1614-
indices[rr_graph.node_type(node.id())][ix][iy][0][node.ptc_num()] = inode;
1615-
}
1616-
}
1617-
} else if (rr_graph.node_type(node.id()) == IPIN || rr_graph.node_type(node.id()) == OPIN) {
1618-
for (int ix = node.xlow(); ix <= node.xhigh(); ix++) {
1619-
for (int iy = node.ylow(); iy <= node.yhigh(); iy++) {
1620-
for (const e_side& side : SIDES) {
1621-
if (!node.is_node_on_specific_side(side)) {
1622-
continue;
1623-
}
1624-
if (node.ptc_num() >= (int)indices[OPIN][ix][iy][side].size()) {
1625-
indices[OPIN][ix][iy][side].resize(node.ptc_num() + 1, OPEN);
1626-
}
1627-
if (node.ptc_num() >= (int)indices[IPIN][ix][iy][side].size()) {
1628-
indices[IPIN][ix][iy][side].resize(node.ptc_num() + 1, OPEN);
1629-
}
1630-
indices[rr_graph.node_type(node.id())][ix][iy][side][node.ptc_num()] = inode;
1631-
}
1632-
}
1633-
}
1634-
} else if (rr_graph.node_type(node.id()) == CHANX) {
1635-
for (int ix = node.xlow(); ix <= node.xhigh(); ix++) {
1636-
for (int iy = node.ylow(); iy <= node.yhigh(); iy++) {
1637-
coordinates_max_ptc[iy][ix].chanx_max_ptc = std::max(coordinates_max_ptc[iy][ix].chanx_max_ptc, node.ptc_num());
1638-
}
1639-
}
1640-
} else if (rr_graph.node_type(node.id()) == CHANY) {
1641-
for (int ix = node.xlow(); ix <= node.xhigh(); ix++) {
1642-
for (int iy = node.ylow(); iy <= node.yhigh(); iy++) {
1643-
coordinates_max_ptc[ix][iy].chany_max_ptc = std::max(coordinates_max_ptc[ix][iy].chany_max_ptc, node.ptc_num());
1644-
}
1645-
}
1646-
}
1647-
}
1648-
1649-
/* Alloc the lookup table */
1650-
for (t_rr_type rr_type : RR_TYPES) {
1651-
if (rr_type == CHANX) {
1652-
for (size_t y = 0; y < grid_.height(); ++y) {
1653-
for (size_t x = 0; x < grid_.width(); ++x) {
1654-
indices[CHANX][y][x][0].resize(coordinates_max_ptc[y][x].chanx_max_ptc + 1, OPEN);
1655-
}
1656-
}
1657-
} else if (rr_type == CHANY) {
1658-
for (size_t x = 0; x < grid_.width(); ++x) {
1659-
for (size_t y = 0; y < grid_.height(); ++y) {
1660-
indices[CHANY][x][y][0].resize(coordinates_max_ptc[x][y].chany_max_ptc + 1, OPEN);
1661-
}
1662-
}
1663-
}
1664-
}
1665-
1666-
int count;
1667-
/* CHANX and CHANY need to reevaluated with its ptc num as the correct index*/
1668-
for (size_t inode = 0; inode < rr_nodes_->size(); inode++) {
1669-
auto node = (*rr_nodes_)[inode];
1670-
if (rr_graph.node_type(node.id()) == CHANX) {
1671-
for (int iy = node.ylow(); iy <= node.yhigh(); iy++) {
1672-
for (int ix = node.xlow(); ix <= node.xhigh(); ix++) {
1673-
count = node.ptc_num();
1674-
if (count >= int(indices[CHANX][iy][ix][0].size())) {
1675-
report_error(
1676-
"Ptc index %d for CHANX (%d, %d) is out of bounds, size = %zu",
1677-
count, ix, iy, indices[CHANX][iy][ix][0].size());
1678-
}
1679-
indices[CHANX][iy][ix][0][count] = inode;
1680-
}
1681-
}
1682-
} else if (rr_graph.node_type(node.id()) == CHANY) {
1683-
for (int ix = node.xlow(); ix <= node.xhigh(); ix++) {
1684-
for (int iy = node.ylow(); iy <= node.yhigh(); iy++) {
1685-
count = node.ptc_num();
1686-
if (count >= int(indices[CHANY][ix][iy][0].size())) {
1687-
report_error(
1688-
"Ptc index %d for CHANY (%d, %d) is out of bounds, size = %zu",
1689-
count, ix, iy, indices[CHANY][ix][iy][0].size());
1690-
}
1691-
indices[CHANY][ix][iy][0][count] = inode;
1692-
}
1693-
}
1694-
}
1695-
}
1696-
1697-
//Copy the SOURCE/SINK nodes to all offset positions for blocks with width > 1 and/or height > 1
1698-
// This ensures that look-ups on non-root locations will still find the correct SOURCE/SINK
1699-
for (size_t x = 0; x < grid_.width(); x++) {
1700-
for (size_t y = 0; y < grid_.height(); y++) {
1701-
int width_offset = grid_[x][y].width_offset;
1702-
int height_offset = grid_[x][y].height_offset;
1703-
if (width_offset != 0 || height_offset != 0) {
1704-
int root_x = x - width_offset;
1705-
int root_y = y - height_offset;
1706-
1707-
indices[SOURCE][x][y][0] = indices[SOURCE][root_x][root_y][0];
1708-
indices[SINK][x][y][0] = indices[SINK][root_x][root_y][0];
1709-
}
1710-
}
1583+
rr_graph_builder.add_node_to_all_locs(node.id());
17111584
}
17121585
}
17131586

@@ -1976,6 +1849,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
19761849
int* wire_to_rr_ipin_switch_;
19771850
t_chan_width* chan_width_;
19781851
t_rr_graph_storage* rr_nodes_;
1852+
RRGraphBuilder* rr_graph_builder_;
19791853
RRGraphView* rr_graph_;
19801854
std::vector<t_rr_switch_inf>* rr_switch_inf_;
19811855
std::vector<t_rr_indexed_data>* rr_indexed_data_;

vpr/src/route/rr_graph_writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ void write_rr_graph(const char* file_name) {
3636
/*read_edge_metadata=*/false,
3737
&device_ctx.chan_width,
3838
&device_ctx.rr_nodes,
39+
&device_ctx.rr_graph_builder,
3940
&device_ctx.rr_graph,
4041
&device_ctx.rr_switch_inf,
4142
&device_ctx.rr_indexed_data,
42-
&device_ctx.rr_node_indices,
4343
device_ctx.num_arch_switches,
4444
device_ctx.arch_switch_inf,
4545
device_ctx.rr_segments,

0 commit comments

Comments
 (0)