Skip to content

Commit 3afe583

Browse files
authored
Merge pull request #2101 from oscarcheng105/librrgraph_vpr
Move rr_graph_reader & rr_graph_writer to librrgraph.
2 parents 97faab3 + 1b8d060 commit 3afe583

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+7610
-7663
lines changed

vpr/src/base/device_grid.cpp renamed to libs/libarchfpga/src/device_grid.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "device_grid.h"
2-
#include "vpr_utils.h"
32

43
DeviceGrid::DeviceGrid(std::string grid_name, vtr::Matrix<t_grid_tile> grid)
54
: name_(grid_name)
File renamed without changes.
File renamed without changes.
File renamed without changes.

libs/librrgraph/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ file(GLOB_RECURSE LIB_SOURCES src/*/*.cpp)
77
file(GLOB_RECURSE LIB_HEADERS src/*/*.h)
88
files_to_dirs(LIB_HEADERS LIB_INCLUDE_DIRS)
99

10+
if(${VTR_ENABLE_CAPNPROTO})
11+
add_definitions("-DVTR_ENABLE_CAPNPROTO")
12+
endif()
13+
1014
#Create the library
1115
add_library(librrgraph STATIC
1216
${LIB_HEADERS}
@@ -23,6 +27,10 @@ target_link_libraries(librrgraph
2327
libarchfpga
2428
)
2529

30+
if(${VTR_ENABLE_CAPNPROTO})
31+
target_link_libraries(librrgraph libvtrcapnproto)
32+
endif()
33+
2634
target_compile_definitions(librrgraph PUBLIC ${INTERCHANGE_SCHEMA_HEADERS})
2735

2836
# Unit tests
@@ -33,3 +41,21 @@ target_compile_definitions(librrgraph PUBLIC ${INTERCHANGE_SCHEMA_HEADERS})
3341

3442
# Run unit tests: comment out for now
3543
#add_test(NAME test_rr_graph COMMAND test_rr_graph --use-colour=yes)
44+
45+
add_custom_target(
46+
generate_rr_graph_serializers
47+
COMMAND ${CMAKE_COMMAND} -E remove_directory rr_graph_generate
48+
COMMAND ${CMAKE_COMMAND} -E make_directory rr_graph_generate
49+
COMMAND ${CMAKE_COMMAND} -E chdir rr_graph_generate git clone https://github.com/duck2/uxsdcxx
50+
COMMAND python3 -mpip install --user -r rr_graph_generate/uxsdcxx/requirements.txt
51+
COMMAND ${CMAKE_COMMAND} -E chdir rr_graph_generate python3 uxsdcxx/uxsdcxx.py ${CMAKE_CURRENT_SOURCE_DIR}/src/base/rr_graph.xsd
52+
COMMAND ${CMAKE_COMMAND} -E chdir rr_graph_generate python3 uxsdcxx/uxsdcap.py ${CMAKE_CURRENT_SOURCE_DIR}/src/base/rr_graph.xsd
53+
COMMAND ${CMAKE_COMMAND} -E copy
54+
rr_graph_generate/rr_graph_uxsdcxx.h
55+
rr_graph_generate/rr_graph_uxsdcxx_capnp.h
56+
rr_graph_generate/rr_graph_uxsdcxx_interface.h
57+
${CMAKE_CURRENT_SOURCE_DIR}/src/base/gen
58+
COMMAND ${CMAKE_COMMAND} -E copy rr_graph_generate/rr_graph_uxsdcxx.capnp ${CMAKE_CURRENT_SOURCE_DIR}/../libvtrcapnproto/gen
59+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/base/rr_graph.xsd
60+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
61+
)

vpr/src/route/SCHEMA_GENERATOR.md renamed to libs/librrgraph/src/base/SCHEMA_GENERATOR.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@ mediated via RrGraphBase located in `rr_graph_uxsdcxx_interface.h`.
66

77
If `rr_graph.xsd` is modified, then the following files must be updated:
88

9-
- `vpr/src/route/gen/rr_graph_uxsdcxx.h`
10-
- `vpr/src/route/gen/rr_graph_uxsdcxx_capnp.h`
11-
- `vpr/src/route/gen/rr_graph_uxsdcxx_interface.h`
9+
- `libs/librrgraph/src/io/gen/rr_graph_uxsdcxx.h`
10+
- `libs/librrgraph/src/io/gen/rr_graph_uxsdcxx_capnp.h`
11+
- `libs/librrgraph/src/io/gen/rr_graph_uxsdcxx_interface.h`
1212
- `libs/libvtrcapnproto/rr_graph_uxsdcxx.capnp`
1313

1414
### Instructions to update generated files (using CMake)
1515

1616
1. Run target `generate_rr_graph_serializers`, e.g. run `make generate_rr_graph_serializers`.
1717
2. Run target `format`, e.g. run `make format`.
18-
3. Update `vpr/src/route/rr_graph_uxsdcxx_interface_impl.h`, implement or
18+
3. Update `libs/librrgraph/src/io/rr_graph_uxsdcxx_interface_impl.h`, implement or
1919
update interfaces that are new or are changed. The compiler will complain
2020
that virtual methods are missing if the schema has changed.
2121

2222
### Instructions to update generated files (manually)
2323

2424
1. Clone https://github.com/duck2/uxsdcxx/
2525
2. Run `python3 -mpip install --user -r requirements.txt`
26-
3. Run `python3 uxsdcxx.py vpr/src/route/rr_graph.xsd`
27-
3. Run `python3 uxsdcap.py vpr/src/route/rr_graph.xsd`
26+
3. Run `python3 uxsdcxx.py libs/librrgraph/src/io/rr_graph.xsd`
27+
3. Run `python3 uxsdcap.py libs/librrgraph/src/io/rr_graph.xsd`
2828
4. Copy `rr_graph_uxsdcxx.h`, `rr_graph_uxsdcxx_capnp.h`,
29-
`rr_graph_uxsdcxx_interface.h` to `vpr/src/route/`
30-
5. Copy `rr_graph_uxsdcxx.capnp` to `libs/libvtrcapnproto/`
29+
`rr_graph_uxsdcxx_interface.h` to `libs/librrgraph/src/io/`
30+
5. Copy `rr_graph_uxsdcxx.capnp` to `../libvtrcapnproto/`
3131
6. Run `make format`
32-
7. Update `vpr/src/route/rr_graph_uxsdcxx_interface_impl.h`, implement or
32+
7. Update `libs/librrgraph/src/io/rr_graph_uxsdcxx_interface_impl.h`, implement or
3333
update interfaces that are new or are changed. The compiler will complain
3434
that virtual methods are missing if the schema has changed.
3535

vpr/src/route/check_rr_graph.cpp renamed to libs/librrgraph/src/base/check_rr_graph.cpp

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
#include "vtr_log.h"
22
#include "vtr_memory.h"
3+
#include "vtr_util.h"
34

4-
#include "vpr_types.h"
55
#include "vpr_error.h"
6-
7-
#include "globals.h"
8-
#include "rr_graph.h"
96
#include "check_rr_graph.h"
107

8+
#include "rr_node.h"
9+
#include "physical_types_util.h"
10+
11+
#include "describe_rr_node.h"
12+
1113
/*********************** Subroutines local to this module *******************/
1214

13-
static bool rr_node_is_global_clb_ipin(RRNodeId inode);
15+
static bool rr_node_is_global_clb_ipin(const RRGraphView& rr_graph, const DeviceGrid& grid, RRNodeId inode);
1416

15-
static void check_unbuffered_edges(int from_node);
17+
static void check_unbuffered_edges(const RRGraphView& rr_graph, int from_node);
1618

17-
static bool has_adjacent_channel(const t_rr_node& node, const DeviceGrid& grid);
19+
static bool has_adjacent_channel(const RRGraphView& rr_graph, const DeviceGrid& grid, const t_rr_node& node);
1820

19-
static void check_rr_edge(int from_node, int from_edge, int to_node);
21+
static void check_rr_edge(const RRGraphView& rr_graph, const DeviceGrid& grid, const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data, int from_node, int from_edge, int to_node);
2022

2123
/************************ Subroutine definitions ****************************/
2224

@@ -39,17 +41,18 @@ class node_edge_sorter {
3941
}
4042
};
4143

42-
void check_rr_graph(const t_graph_type graph_type,
44+
void check_rr_graph(const RRGraphView& rr_graph,
45+
const std::vector<t_physical_tile_type>& types,
46+
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
4347
const DeviceGrid& grid,
44-
const std::vector<t_physical_tile_type>& types) {
48+
const t_chan_width& chan_width,
49+
const t_graph_type graph_type,
50+
const int virtual_clock_network_root_idx) {
4551
e_route_type route_type = DETAILED;
4652
if (graph_type == GRAPH_GLOBAL) {
4753
route_type = GLOBAL;
4854
}
4955

50-
auto& device_ctx = g_vpr_ctx.device();
51-
const auto& rr_graph = device_ctx.rr_graph;
52-
5356
auto total_edges_to_node = std::vector<int>(rr_graph.num_nodes());
5457
auto switch_types_from_current_to_node = std::vector<unsigned char>(rr_graph.num_nodes());
5558
const int num_rr_switches = rr_graph.num_rr_switches();
@@ -66,14 +69,14 @@ void check_rr_graph(const t_graph_type graph_type,
6669
}
6770

6871
// Virtual clock network sink is special, ignore.
69-
if (device_ctx.virtual_clock_network_root_idx == int(inode)) {
72+
if (virtual_clock_network_root_idx == int(inode)) {
7073
continue;
7174
}
7275

7376
t_rr_type rr_type = rr_graph.node_type(rr_node);
7477
int num_edges = rr_graph.num_edges(RRNodeId(inode));
7578

76-
check_rr_node(inode, route_type, device_ctx);
79+
check_rr_node(rr_graph, rr_indexed_data, grid, chan_width, route_type, inode);
7780

7881
/* Check all the connectivity (edges, etc.) information. */
7982
edges.resize(0);
@@ -89,7 +92,7 @@ void check_rr_graph(const t_graph_type graph_type,
8992
inode, to_node);
9093
}
9194

92-
check_rr_edge(inode, iedge, to_node);
95+
check_rr_edge(rr_graph, grid, rr_indexed_data, inode, iedge, to_node);
9396

9497
edges.emplace_back(to_node, iedge);
9598
total_edges_to_node[to_node]++;
@@ -181,7 +184,7 @@ void check_rr_graph(const t_graph_type graph_type,
181184
}
182185

183186
/* Slow test could leave commented out most of the time. */
184-
check_unbuffered_edges(inode);
187+
check_unbuffered_edges(rr_graph, inode);
185188

186189
//Check that all config/non-config edges are appropriately organized
187190
for (auto edge : rr_graph.configurable_edges(RRNodeId(inode))) {
@@ -204,19 +207,19 @@ void check_rr_graph(const t_graph_type graph_type,
204207
* now I check that everything is reachable. */
205208
bool is_fringe_warning_sent = false;
206209

207-
for (const RRNodeId& rr_node : device_ctx.rr_graph.nodes()) {
210+
for (const RRNodeId& rr_node : rr_graph.nodes()) {
208211
size_t inode = (size_t)rr_node;
209212
t_rr_type rr_type = rr_graph.node_type(rr_node);
210213

211214
if (rr_type != SOURCE) {
212-
if (total_edges_to_node[inode] < 1 && !rr_node_is_global_clb_ipin(rr_node)) {
215+
if (total_edges_to_node[inode] < 1 && !rr_node_is_global_clb_ipin(rr_graph, grid, rr_node)) {
213216
/* A global CLB input pin will not have any edges, and neither will *
214217
* a SOURCE or the start of a carry-chain. Anything else is an error.
215218
* For simplicity, carry-chain input pin are entirely ignored in this test
216219
*/
217220
bool is_chain = false;
218221
if (rr_type == IPIN) {
219-
t_physical_tile_type_ptr type = device_ctx.grid[rr_graph.node_xlow(rr_node)][rr_graph.node_ylow(rr_node)].type;
222+
t_physical_tile_type_ptr type = grid[rr_graph.node_xlow(rr_node)][rr_graph.node_ylow(rr_node)].type;
220223
for (const t_fc_specification& fc_spec : types[type->index].fc_specs) {
221224
if (fc_spec.fc_value == 0 && fc_spec.seg_index == 0) {
222225
is_chain = true;
@@ -235,8 +238,8 @@ void check_rr_graph(const t_graph_type graph_type,
235238

236239
if (!is_chain && !is_fringe && !is_wire) {
237240
if (rr_graph.node_type(rr_node) == IPIN || rr_graph.node_type(rr_node) == OPIN) {
238-
if (has_adjacent_channel(node, device_ctx.grid)) {
239-
auto block_type = device_ctx.grid[rr_graph.node_xlow(rr_node)][rr_graph.node_ylow(rr_node)].type;
241+
if (has_adjacent_channel(rr_graph, grid, node)) {
242+
auto block_type = grid[rr_graph.node_xlow(rr_node)][rr_graph.node_ylow(rr_node)].type;
240243
std::string pin_name = block_type_pin_index_to_name(block_type, rr_graph.node_pin_num(rr_node));
241244
/* Print error messages for all the sides that a node may appear */
242245
for (const e_side& node_side : SIDES) {
@@ -268,16 +271,13 @@ void check_rr_graph(const t_graph_type graph_type,
268271
}
269272
}
270273

271-
static bool rr_node_is_global_clb_ipin(RRNodeId inode) {
274+
static bool rr_node_is_global_clb_ipin(const RRGraphView& rr_graph, const DeviceGrid& grid, RRNodeId inode) {
272275
/* Returns true if inode refers to a global CLB input pin node. */
273276

274277
int ipin;
275278
t_physical_tile_type_ptr type;
276279

277-
auto& device_ctx = g_vpr_ctx.device();
278-
const auto& rr_graph = device_ctx.rr_graph;
279-
280-
type = device_ctx.grid[rr_graph.node_xlow(inode)][rr_graph.node_ylow(inode)].type;
280+
type = grid[rr_graph.node_xlow(inode)][rr_graph.node_ylow(inode)].type;
281281

282282
if (rr_graph.node_type(inode) != IPIN)
283283
return (false);
@@ -287,7 +287,12 @@ static bool rr_node_is_global_clb_ipin(RRNodeId inode) {
287287
return type->is_ignored_pin[ipin];
288288
}
289289

290-
void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext& device_ctx) {
290+
void check_rr_node(const RRGraphView& rr_graph,
291+
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
292+
const DeviceGrid& grid,
293+
const t_chan_width& chan_width,
294+
const enum e_route_type route_type,
295+
const int inode) {
291296
/* This routine checks that the rr_node is inside the grid and has a valid
292297
* pin number, etc.
293298
*/
@@ -298,7 +303,6 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
298303
int nodes_per_chan, tracks_per_node, num_edges;
299304
RRIndexedDataId cost_index;
300305
float C, R;
301-
const auto& rr_graph = device_ctx.rr_graph;
302306
RRNodeId rr_node = RRNodeId(inode);
303307

304308
rr_type = rr_graph.node_type(rr_node);
@@ -311,7 +315,6 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
311315
cost_index = rr_graph.node_cost_index(rr_node);
312316
type = nullptr;
313317

314-
const auto& grid = device_ctx.grid;
315318
if (xlow > xhigh || ylow > yhigh) {
316319
VPR_ERROR(VPR_ERROR_ROUTE,
317320
"in check_rr_node: rr endpoints are (%d,%d) and (%d,%d).\n", xlow, ylow, xhigh, yhigh);
@@ -327,13 +330,13 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
327330
"in check_rr_node: inode %d (type %d) had a ptc_num of %d.\n", inode, rr_type, ptc_num);
328331
}
329332

330-
if (!cost_index || (size_t)cost_index >= (size_t)device_ctx.rr_indexed_data.size()) {
333+
if (!cost_index || (size_t)cost_index >= (size_t)rr_indexed_data.size()) {
331334
VPR_FATAL_ERROR(VPR_ERROR_ROUTE,
332335
"in check_rr_node: node %d cost index (%d) is out of range.\n", inode, cost_index);
333336
}
334337

335338
/* Check that the segment is within the array and such. */
336-
type = device_ctx.grid[xlow][ylow].type;
339+
type = grid[xlow][ylow].type;
337340

338341
switch (rr_type) {
339342
case SOURCE:
@@ -439,11 +442,11 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
439442

440443
case CHANX:
441444
if (route_type == DETAILED) {
442-
nodes_per_chan = device_ctx.chan_width.max;
445+
nodes_per_chan = chan_width.max;
443446
tracks_per_node = 1;
444447
} else {
445448
nodes_per_chan = 1;
446-
tracks_per_node = device_ctx.chan_width.x_list[ylow];
449+
tracks_per_node = chan_width.x_list[ylow];
447450
}
448451

449452
if (ptc_num >= nodes_per_chan) {
@@ -459,11 +462,11 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
459462

460463
case CHANY:
461464
if (route_type == DETAILED) {
462-
nodes_per_chan = device_ctx.chan_width.max;
465+
nodes_per_chan = chan_width.max;
463466
tracks_per_node = 1;
464467
} else {
465468
nodes_per_chan = 1;
466-
tracks_per_node = device_ctx.chan_width.y_list[xlow];
469+
tracks_per_node = chan_width.y_list[xlow];
467470
}
468471

469472
if (ptc_num >= nodes_per_chan) {
@@ -494,13 +497,13 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
494497
//Don't worry about disconnect PINs which have no adjacent channels (i.e. on the device perimeter)
495498
bool check_for_out_edges = true;
496499
if (rr_type == IPIN || rr_type == OPIN) {
497-
if (!has_adjacent_channel(rr_graph.rr_nodes()[inode], device_ctx.grid)) {
500+
if (!has_adjacent_channel(rr_graph, grid, rr_graph.rr_nodes()[inode])) {
498501
check_for_out_edges = false;
499502
}
500503
}
501504

502505
if (check_for_out_edges) {
503-
std::string info = describe_rr_node(inode);
506+
std::string info = describe_rr_node(rr_graph, grid, rr_indexed_data, inode);
504507
VTR_LOG_WARN("in check_rr_node: %s has no out-going edges.\n", info.c_str());
505508
}
506509
}
@@ -528,7 +531,7 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
528531
}
529532
}
530533

531-
static void check_unbuffered_edges(int from_node) {
534+
static void check_unbuffered_edges(const RRGraphView& rr_graph, int from_node) {
532535
/* This routine checks that all pass transistors in the routing truly are *
533536
* bidirectional. It may be a slow check, so don't use it all the time. */
534537

@@ -537,9 +540,6 @@ static void check_unbuffered_edges(int from_node) {
537540
short from_switch_type;
538541
bool trans_matched;
539542

540-
auto& device_ctx = g_vpr_ctx.device();
541-
const auto& rr_graph = device_ctx.rr_graph;
542-
543543
from_rr_type = rr_graph.node_type(RRNodeId(from_node));
544544
if (from_rr_type != CHANX && from_rr_type != CHANY)
545545
return;
@@ -584,11 +584,10 @@ static void check_unbuffered_edges(int from_node) {
584584
} /* End for all from_node edges */
585585
}
586586

587-
static bool has_adjacent_channel(const t_rr_node& node, const DeviceGrid& grid) {
587+
static bool has_adjacent_channel(const RRGraphView& rr_graph, const DeviceGrid& grid, const t_rr_node& node) {
588588
/* TODO: this function should be reworked later to adapt RRGraphView interface
589589
* once xlow(), ylow(), side() APIs are implemented
590590
*/
591-
const auto& rr_graph = g_vpr_ctx.device().rr_graph;
592591
VTR_ASSERT(rr_graph.node_type(node.id()) == IPIN || rr_graph.node_type(node.id()) == OPIN);
593592

594593
if ((rr_graph.node_xlow(node.id()) == 0 && !rr_graph.is_node_on_specific_side(node.id(), RIGHT)) //left device edge connects only along block's right side
@@ -601,9 +600,7 @@ static bool has_adjacent_channel(const t_rr_node& node, const DeviceGrid& grid)
601600
return true; //All other blocks will be surrounded on all sides by channels
602601
}
603602

604-
static void check_rr_edge(int from_node, int iedge, int to_node) {
605-
auto& device_ctx = g_vpr_ctx.device();
606-
const auto& rr_graph = device_ctx.rr_graph;
603+
static void check_rr_edge(const RRGraphView& rr_graph, const DeviceGrid& grid, const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data, int from_node, int iedge, int to_node) {
607604

608605
//Check that to to_node's fan-in is correct, given the switch type
609606
int iswitch = rr_graph.edge_switch(RRNodeId(from_node), iedge);
@@ -617,7 +614,7 @@ static void check_rr_edge(int from_node, int iedge, int to_node) {
617614
std::string msg = "Non-configurable BUFFER type switch must have only one driver. ";
618615
msg += vtr::string_fmt(" Actual fan-in was %d (expected 1).\n", to_fanin);
619616
msg += " Possible cause is complex block output pins connecting to:\n";
620-
msg += " " + describe_rr_node(to_node);
617+
msg += " " + describe_rr_node(rr_graph, grid, rr_indexed_data, to_node);
621618

622619
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, msg.c_str());
623620
}

0 commit comments

Comments
 (0)