Skip to content

Commit 1dff246

Browse files
authored
Merge pull request #2977 from verilog-to-routing/temp_clean_rrgraph_gen
Clean RR graph generation code
2 parents 5090124 + 0b1c8ae commit 1dff246

27 files changed

+499
-674
lines changed

libs/libarchfpga/src/device_grid.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class DeviceGrid {
8080
inline int get_height_offset(const t_physical_tile_loc& tile_loc) const {
8181
return grid_[tile_loc.layer_num][tile_loc.x][tile_loc.y].height_offset;
8282
}
83+
///@brief Returns true if the given location is the root location (bottom left corner) of a tile.
84+
inline bool is_root_location(const t_physical_tile_loc& tile_loc) const {
85+
return get_width_offset(tile_loc) == 0 && get_height_offset(tile_loc) == 0;
86+
}
8387

8488
///@brief Returns a rectangle which represents the bounding box of the tile at the given location.
8589
inline vtr::Rect<int> get_tile_bb(const t_physical_tile_loc& tile_loc) const {

libs/libarchfpga/src/physical_types.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,13 @@ struct t_port_power {
540540
bool reverse_scaled; /* Scale by (1-prob) */
541541
};
542542

543-
//The type of Fc specification
543+
/**
544+
* @enum e_fc_type
545+
* @brief The type of Fc specification
546+
*/
544547
enum class e_fc_type {
545-
IN, //The fc specification for an input pin
546-
OUT //The fc specification for an output pin
548+
IN, /**< Fc specification for an input pin. */
549+
OUT /**< Fc specification for an output pin. */
547550
};
548551

549552
//The value type of the Fc specification
@@ -1562,6 +1565,7 @@ enum e_directionality {
15621565
UNI_DIRECTIONAL,
15631566
BI_DIRECTIONAL
15641567
};
1568+
15651569
/* X_AXIS: Data that describes an x-directed wire segment (CHANX) *
15661570
* Y_AXIS: Data that describes an y-directed wire segment (CHANY) *
15671571
* BOTH_AXIS: Data that can be applied to both x-directed and y-directed wire segment */

libs/librrgraph/src/base/check_rr_graph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ void check_rr_graph(const RRGraphView& rr_graph,
5353
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
5454
const DeviceGrid& grid,
5555
const t_chan_width& chan_width,
56-
const t_graph_type graph_type,
56+
const e_graph_type graph_type,
5757
bool is_flat) {
5858
e_route_type route_type = DETAILED;
59-
if (graph_type == GRAPH_GLOBAL) {
59+
if (graph_type == e_graph_type::GLOBAL) {
6060
route_type = GLOBAL;
6161
}
6262

libs/librrgraph/src/base/check_rr_graph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void check_rr_graph(const RRGraphView& rr_graph,
1010
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
1111
const DeviceGrid& grid,
1212
const t_chan_width& chan_width,
13-
const t_graph_type graph_type,
13+
const e_graph_type graph_type,
1414
bool is_flat);
1515

1616
void check_rr_node(const RRGraphView& rr_graph,

libs/librrgraph/src/base/get_parallel_segs.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "get_parallel_segs.h"
22

3-
/*Gets t_segment_inf for parallel segments as defined by the user.
4-
*Segments that have BOTH_AXIS attribute value are always included in the returned vector.*/
53
std::vector<t_segment_inf> get_parallel_segs(const std::vector<t_segment_inf>& segment_inf,
64
t_unified_to_parallel_seg_index& seg_index_map,
75
enum e_parallel_axis parallel_axis) {

libs/librrgraph/src/base/get_parallel_segs.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
#include "rr_graph_type.h"
55
#include "physical_types.h"
66

7+
/**
8+
* @brief Returns segments aligned with a given axis, including BOTH_AXIS segments.
9+
*
10+
* Filters the unified segment list (`segment_inf`) to include only segments matching
11+
* the specified `parallel_axis` or marked as `BOTH_AXIS`. Also populates `seg_index_map`
12+
* to map unified indices to axis-specific ones.
13+
*
14+
* @param segment_inf Unified list of all segments.
15+
* @param seg_index_map Map from unified to axis-specific segment indices.
16+
* @param parallel_axis Axis to filter segments by.
17+
* @return Filtered list of segments for the given axis.
18+
*/
719
std::vector<t_segment_inf> get_parallel_segs(const std::vector<t_segment_inf>& segment_inf,
820
t_unified_to_parallel_seg_index& seg_index_map,
921
enum e_parallel_axis parallel_axis);

libs/librrgraph/src/base/rr_graph_type.h

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,32 @@ enum e_route_type {
1919
DETAILED
2020
};
2121

22-
enum e_graph_type {
23-
GRAPH_GLOBAL, /* One node per channel with wire capacity > 1 and full connectivity */
24-
GRAPH_BIDIR, /* Detailed bidirectional graph */
25-
GRAPH_UNIDIR, /* Detailed unidir graph, untilable */
26-
/* RESEARCH TODO: Get this option debugged */
27-
GRAPH_UNIDIR_TILEABLE /* Detail unidir graph with wire groups multiples of 2*L */
22+
/**
23+
* @enum e_graph_type
24+
* @brief Represents the type of routing resource graph
25+
*/
26+
enum class e_graph_type {
27+
GLOBAL, ///< One node per channel with wire capacity > 1 and full connectivity
28+
BIDIR, ///< Detailed bidirectional routing graph
29+
UNIDIR, ///< Detailed unidirectional routing graph (non-tileable)
30+
UNIDIR_TILEABLE ///< Tileable unidirectional graph with wire groups in multiples of 2 * L (experimental)
2831
};
29-
typedef enum e_graph_type t_graph_type;
3032

31-
/* This map is used to get indices w.r.t segment_inf_x or segment_inf_y based on parallel_axis of a segment,
32-
* from indices w.r.t the **unified** segment vector, segment_inf in devices context which stores all segments
33-
* regardless of their axis. (see get_parallel_segs for more details)*/
33+
/**
34+
* @typedef t_unified_to_parallel_seg_index
35+
* @brief Maps indices from the unified segment list to axis-specific segment lists.
36+
*
37+
* This map is used to translate indices from the unified segment vector
38+
* (`segment_inf` in the device context, which contains all segments regardless of axis)
39+
* to axis-specific segment vectors (`segment_inf_x` or `segment_inf_y`), based on the
40+
* segment's parallel axis.
41+
*
42+
* Each entry maps a unified segment index to a pair containing:
43+
* - The index in the corresponding axis-specific segment vector
44+
* - The axis of the segment (X or Y)
45+
*
46+
* @see get_parallel_segs for more details.
47+
*/
3448
typedef std::unordered_multimap<size_t, std::pair<size_t, e_parallel_axis>> t_unified_to_parallel_seg_index;
3549

3650
#endif

libs/librrgraph/src/base/rr_node_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef uint16_t t_edge_size;
6666
/**
6767
* @brief An iterator that dereferences to an edge index
6868
*
69-
* Used inconjunction with vtr::Range to return ranges of edge indices
69+
* Used in conjunction with vtr::Range to return ranges of edge indices
7070
*/
7171
class edge_idx_iterator {
7272
public:
@@ -101,7 +101,7 @@ typedef vtr::Range<edge_idx_iterator> edge_idx_range;
101101
typedef std::vector<std::map<int, int>> t_arch_switch_fanin;
102102

103103
/*
104-
* Reistance/Capacitance data for an RR Nodes
104+
* Resistance/Capacitance data for an RR Nodes
105105
*
106106
* In practice many RR nodes have the same values, so they are fly-weighted
107107
* to keep t_rr_node small. Each RR node holds an rc_index which allows

libs/librrgraph/src/io/rr_graph_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder,
4646
std::vector<t_rr_rc_data>* rr_rc_data,
4747
const DeviceGrid& grid,
4848
const std::vector<t_arch_switch_inf>& arch_switch_inf,
49-
const t_graph_type graph_type,
49+
e_graph_type graph_type,
5050
const t_arch* arch,
5151
t_chan_width* chan_width,
5252
const enum e_base_cost_type base_cost_type,

libs/librrgraph/src/io/rr_graph_reader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder,
2121
std::vector<t_rr_rc_data>* rr_rc_data,
2222
const DeviceGrid& grid,
2323
const std::vector<t_arch_switch_inf>& arch_switch_inf,
24-
const t_graph_type graph_type,
24+
e_graph_type graph_type,
2525
const t_arch* arch,
2626
t_chan_width* chan_width,
2727
const enum e_base_cost_type base_cost_type,

libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ struct RrGraphContextTypes : public uxsd::DefaultRrGraphContextTypes {
270270
class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
271271
public:
272272
RrGraphSerializer(
273-
const t_graph_type graph_type,
273+
const e_graph_type graph_type,
274274
const enum e_base_cost_type base_cost_type,
275275
int* wire_to_rr_ipin_switch,
276276
int* wire_to_rr_ipin_switch_between_dice,
@@ -823,7 +823,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
823823
auto node = (*rr_nodes_)[inode];
824824
RRNodeId node_id = node.id();
825825

826-
if (GRAPH_GLOBAL == graph_type_) {
826+
if (e_graph_type::GLOBAL == graph_type_) {
827827
rr_graph_builder_->set_node_cost_index(node_id, RRIndexedDataId(0));
828828
} else if (rr_graph.node_type(node.id()) == CHANX) {
829829
int seg_ind_x = find_segment_index_along_axis(segment_id, X_AXIS);
@@ -2166,7 +2166,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
21662166
std::vector<t_rr_rc_data>* rr_rc_data_;
21672167

21682168
// Constant data for loads and writes.
2169-
const t_graph_type graph_type_;
2169+
const e_graph_type graph_type_;
21702170
const enum e_base_cost_type base_cost_type_;
21712171
const bool do_check_rr_graph_;
21722172
const char* read_rr_graph_name_;

libs/librrgraph/src/io/rr_graph_writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void write_rr_graph(RRGraphBuilder* rr_graph_builder,
4242
bool is_flat) {
4343

4444
RrGraphSerializer reader(
45-
/*graph_type=*/t_graph_type(),
45+
/*graph_type=*/e_graph_type(),
4646
/*base_cost_type=*/e_base_cost_type(),
4747
/*wire_to_rr_ipin_switch=*/nullptr,
4848
/*wire_to_rr_ipin_switch_between_dice=*/nullptr,

vpr/src/base/place_and_route.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
/******************* Subroutines local to this module ************************/
3030

31-
static int compute_chan_width(int cfactor, t_chan chan_dist, float distance, float separation, t_graph_type graph_directionality);
31+
static int compute_chan_width(int cfactor, t_chan chan_dist, float distance, float separation, e_graph_type graph_directionality);
3232
static float comp_width(t_chan* chan, float x, float separation);
3333

3434
/************************* Subroutine Definitions ****************************/
@@ -68,8 +68,8 @@ int binary_search_place_and_route(const Netlist<>& placement_net_list,
6868
int udsd_multiplier;
6969
int warnings;
7070

71-
t_graph_type graph_type;
72-
t_graph_type graph_directionality;
71+
e_graph_type graph_type;
72+
e_graph_type graph_directionality;
7373

7474
/* We have chosen to pass placer_opts_ref by reference because of its large size. *
7575
* However, since the value is mutated later in the function, we declare a *
@@ -80,11 +80,11 @@ int binary_search_place_and_route(const Netlist<>& placement_net_list,
8080
/* Allocate the major routing structures. */
8181

8282
if (router_opts.route_type == GLOBAL) {
83-
graph_type = GRAPH_GLOBAL;
84-
graph_directionality = GRAPH_BIDIR;
83+
graph_type = e_graph_type::GLOBAL;
84+
graph_directionality = e_graph_type::BIDIR;
8585
} else {
86-
graph_type = (det_routing_arch->directionality == BI_DIRECTIONAL ? GRAPH_BIDIR : GRAPH_UNIDIR);
87-
graph_directionality = (det_routing_arch->directionality == BI_DIRECTIONAL ? GRAPH_BIDIR : GRAPH_UNIDIR);
86+
graph_type = (det_routing_arch->directionality == BI_DIRECTIONAL ? e_graph_type::BIDIR : e_graph_type::UNIDIR);
87+
graph_directionality = (det_routing_arch->directionality == BI_DIRECTIONAL ? e_graph_type::BIDIR : e_graph_type::UNIDIR);
8888
}
8989

9090
VTR_ASSERT(!net_delay.empty());
@@ -408,7 +408,7 @@ t_chan_width setup_chan_width(const t_router_opts& router_opts,
408408
/*we give plenty of tracks, this increases routability for the */
409409
/*lookup table generation */
410410

411-
t_graph_type graph_directionality;
411+
e_graph_type graph_directionality;
412412
int width_fac;
413413

414414
if (router_opts.fixed_channel_width == NO_FIXED_CHANNEL_WIDTH) {
@@ -425,9 +425,9 @@ t_chan_width setup_chan_width(const t_router_opts& router_opts,
425425
}
426426

427427
if (router_opts.route_type == GLOBAL) {
428-
graph_directionality = GRAPH_BIDIR;
428+
graph_directionality = e_graph_type::BIDIR;
429429
} else {
430-
graph_directionality = GRAPH_UNIDIR;
430+
graph_directionality = e_graph_type::UNIDIR;
431431
}
432432

433433
return init_chan(width_fac, chan_width_dist, graph_directionality);
@@ -441,7 +441,9 @@ t_chan_width setup_chan_width(const t_router_opts& router_opts,
441441
* is used to determine if the channel width should be rounded to an
442442
* even number.
443443
*/
444-
t_chan_width init_chan(int cfactor, const t_chan_width_dist& chan_width_dist, t_graph_type graph_directionality) {
444+
t_chan_width init_chan(int cfactor,
445+
const t_chan_width_dist& chan_width_dist,
446+
e_graph_type graph_directionality) {
445447
auto& device_ctx = g_vpr_ctx.mutable_device();
446448
auto& grid = device_ctx.grid;
447449

@@ -513,10 +515,10 @@ t_chan_width init_chan(int cfactor, const t_chan_width_dist& chan_width_dist, t_
513515
* @param separation The distance between two channels in the 0 to 1 coordinate system.
514516
* @param graph_directionality The directionality of the graph (unidirectional or bidirectional).
515517
*/
516-
static int compute_chan_width(int cfactor, t_chan chan_dist, float distance, float separation, t_graph_type graph_directionality) {
518+
static int compute_chan_width(int cfactor, t_chan chan_dist, float distance, float separation, e_graph_type graph_directionality) {
517519
int computed_width;
518520
computed_width = (int)floor(cfactor * comp_width(&chan_dist, distance, separation) + 0.5);
519-
if ((GRAPH_BIDIR == graph_directionality) || computed_width % 2 == 0) {
521+
if ((e_graph_type::BIDIR == graph_directionality) || computed_width % 2 == 0) {
520522
return computed_width;
521523
} else {
522524
return computed_width - 1;

vpr/src/base/place_and_route.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ t_chan_width setup_chan_width(const t_router_opts& router_opts,
4141

4242
t_chan_width init_chan(int cfactor,
4343
const t_chan_width_dist& chan_width_dist,
44-
t_graph_type graph_directionality);
44+
e_graph_type graph_directionality);
4545

4646
void post_place_sync();
4747

vpr/src/base/vpr_api.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,14 +1099,14 @@ void vpr_create_rr_graph(t_vpr_setup& vpr_setup, const t_arch& arch, int chan_wi
10991099
auto det_routing_arch = &vpr_setup.RoutingArch;
11001100
auto& router_opts = vpr_setup.RouterOpts;
11011101

1102-
t_graph_type graph_type;
1103-
t_graph_type graph_directionality;
1102+
e_graph_type graph_type;
1103+
e_graph_type graph_directionality;
11041104
if (router_opts.route_type == GLOBAL) {
1105-
graph_type = GRAPH_GLOBAL;
1106-
graph_directionality = GRAPH_BIDIR;
1105+
graph_type = e_graph_type::GLOBAL;
1106+
graph_directionality = e_graph_type::BIDIR;
11071107
} else {
1108-
graph_type = (det_routing_arch->directionality == BI_DIRECTIONAL ? GRAPH_BIDIR : GRAPH_UNIDIR);
1109-
graph_directionality = (det_routing_arch->directionality == BI_DIRECTIONAL ? GRAPH_BIDIR : GRAPH_UNIDIR);
1108+
graph_type = (det_routing_arch->directionality == BI_DIRECTIONAL ? e_graph_type::BIDIR : e_graph_type::UNIDIR);
1109+
graph_directionality = (det_routing_arch->directionality == BI_DIRECTIONAL ? e_graph_type::BIDIR : e_graph_type::UNIDIR);
11101110
}
11111111

11121112
t_chan_width chan_width = init_chan(chan_width_fac, arch.Chans, graph_directionality);

0 commit comments

Comments
 (0)