Skip to content

Commit 4cf678a

Browse files
Merge pull request #3264 from verilog-to-routing/temp_num_layers_size_t
Cleanups in RR graph generation
2 parents 7f476db + eee12de commit 4cf678a

Some content is hidden

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

43 files changed

+724
-884
lines changed

libs/libarchfpga/src/device_grid.h

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ class DeviceGrid {
3232
const std::string& name() const { return name_; }
3333

3434
///@brief Return the number of layers(number of dies)
35-
inline int get_num_layers() const {
36-
return (int)grid_.dim_size(0);
35+
inline size_t get_num_layers() const {
36+
return grid_.dim_size(0);
3737
}
38-
3938
///@brief Return the width of the grid at the specified layer
4039
size_t width() const { return grid_.dim_size(1); }
4140
///@brief Return the height of the grid at the specified layer
@@ -54,7 +53,8 @@ class DeviceGrid {
5453
void clear();
5554

5655
/**
57-
* @brief Return the number of instances of the specified tile type on the specified layer. If the layer_num is -1, return the total number of instances of the specified tile type on all layers.
56+
* @brief Return the number of instances of the specified tile type on the specified layer.
57+
* If the layer_num is -1, return the total number of instances of the specified tile type on all layers.
5858
* @note This function should be used if count_instances() is called in the constructor.
5959
*/
6060
size_t num_instances(t_physical_tile_type_ptr type, int layer_num) const;
@@ -84,6 +84,15 @@ class DeviceGrid {
8484
return get_width_offset(tile_loc) == 0 && get_height_offset(tile_loc) == 0;
8585
}
8686

87+
///@brief Given a location, return the root location (bottom-left corner) of the tile instance
88+
inline t_physical_tile_loc get_root_location(const t_physical_tile_loc& tile_loc) const {
89+
t_physical_tile_loc root_loc;
90+
root_loc.layer_num = tile_loc.layer_num;
91+
root_loc.x = tile_loc.x - get_width_offset(tile_loc);
92+
root_loc.y = tile_loc.y - get_height_offset(tile_loc);
93+
return root_loc;
94+
}
95+
8796
///@brief Returns a rectangle which represents the bounding box of the tile at the given location.
8897
inline vtr::Rect<int> get_tile_bb(const t_physical_tile_loc& tile_loc) const {
8998
t_physical_tile_type_ptr tile_type = get_physical_type(tile_loc);
@@ -96,6 +105,58 @@ class DeviceGrid {
96105
return {{tile_xlow, tile_ylow}, {tile_xhigh, tile_yhigh}};
97106
}
98107

108+
// Forward const-iterator over (layer, x, y)
109+
class loc_const_iterator {
110+
public:
111+
using value_type = t_physical_tile_loc;
112+
using difference_type = std::ptrdiff_t;
113+
using iterator_category = std::forward_iterator_tag;
114+
115+
loc_const_iterator(const DeviceGrid* g, size_t layer, size_t x, size_t y)
116+
: g_(g) {
117+
loc_.layer_num = static_cast<int>(layer);
118+
loc_.x = static_cast<int>(x);
119+
loc_.y = static_cast<int>(y);
120+
}
121+
122+
value_type operator*() const { return loc_; }
123+
124+
// pre-increment
125+
loc_const_iterator& operator++() {
126+
// advance y, then x, then layer
127+
++loc_.y;
128+
if (loc_.y >= static_cast<int>(g_->height())) {
129+
loc_.y = 0;
130+
++loc_.x;
131+
if (loc_.x >= static_cast<int>(g_->width())) {
132+
loc_.x = 0;
133+
++loc_.layer_num;
134+
}
135+
}
136+
return *this;
137+
}
138+
139+
bool operator==(const loc_const_iterator& o) const {
140+
return loc_.x == o.loc_.x
141+
&& loc_.y == o.loc_.y
142+
&& loc_.layer_num == o.loc_.layer_num
143+
&& g_ == o.g_;
144+
}
145+
bool operator!=(const loc_const_iterator& o) const { return !(*this == o); }
146+
147+
private:
148+
const DeviceGrid* g_ = nullptr;
149+
t_physical_tile_loc loc_{0, 0, 0};
150+
};
151+
152+
/// Iterate every (layer, x, y) location
153+
inline auto all_locations() const {
154+
return vtr::make_range(
155+
loc_const_iterator(this, /*layer*/ 0, /*x*/ 0, /*y*/ 0),
156+
loc_const_iterator(this, /*layer*/ get_num_layers(), /*x*/ 0, /*y*/ 0) // end sentinel
157+
);
158+
}
159+
99160
///@brief Return the metadata of the tile at the specified location
100161
inline const t_metadata_dict* get_metadata(const t_physical_tile_loc& tile_loc) const {
101162
return grid_[tile_loc.layer_num][tile_loc.x][tile_loc.y].meta;

libs/libarchfpga/src/physical_types_util.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ static std::vector<int> get_pb_pin_src_pins(t_physical_tile_type_ptr physical_ty
7878
const t_pb_graph_pin* pin);
7979

8080
/**
81-
*
8281
* @param physical_type physical tile which pin belongs to
8382
* @param sub_tile sub_tile in which physical tile located
8483
* @param logical_block logical block mapped to the sub_tile
@@ -108,20 +107,12 @@ static t_pb_graph_pin* get_mutable_tile_pin_pb_pin(t_physical_tile_type* physica
108107
int pin_physical_num);
109108

110109
/**
111-
*
112-
* @param physical_tile
113-
* @param class_physical_num
114110
* @return A vector containing all of the parent pb_graph_nodes and the pb_graph_node of the class_physical_num itself
115111
*/
116112
static std::vector<const t_pb_graph_node*> get_sink_hierarchical_parents(t_physical_tile_type_ptr physical_tile,
117113
int class_physical_num);
118114

119115
/**
120-
*
121-
* @param physical_tile
122-
* @param pin_physcial_num
123-
* @param ref_sink_num
124-
* @param sink_grp
125116
* @return Return zero if the ref_sink_num is not reachable by pin_physical_num, otherwise return the number sinks in sink_grp
126117
* reachable by pin_physical_num
127118
*/
@@ -618,21 +609,21 @@ bool is_opin(int ipin, t_physical_tile_type_ptr type) {
618609
return false;
619610
}
620611

621-
bool is_pin_conencted_to_layer(t_physical_tile_type_ptr type, int ipin, int from_layer, int to_layer, int num_of_avail_layer) {
622-
if (type->is_empty()) { //if type is empty, there is no pins
612+
bool is_pin_conencted_to_layer(t_physical_tile_type_ptr type, int ipin, int from_layer, int to_layer, unsigned num_of_avail_layer) {
613+
// if type is empty, there is no pins
614+
if (type->is_empty()) {
623615
return false;
624616
}
625-
//ipin should be a valid pin in physical type
617+
618+
// ipin should be a valid pin in physical type
626619
VTR_ASSERT(ipin < type->num_pins);
627-
int pin_layer = from_layer + type->pin_layer_offset[ipin];
628-
//if pin_offset specifies a layer that doesn't exist in arch file, we do a wrap around
620+
unsigned pin_layer = from_layer + type->pin_layer_offset[ipin];
621+
// if pin_offset specifies a layer that doesn't exist in arch file, we do a wrap around
629622
pin_layer = (pin_layer < num_of_avail_layer) ? pin_layer : pin_layer % num_of_avail_layer;
630-
if (from_layer == to_layer || pin_layer == to_layer) {
623+
if (from_layer == to_layer || int(pin_layer) == to_layer) {
631624
return true;
632-
} else {
633-
return false;
634625
}
635-
//not reachable
626+
636627
return false;
637628
}
638629

@@ -643,7 +634,7 @@ std::string block_type_pin_index_to_name(t_physical_tile_type_ptr type, int pin_
643634
std::string pin_name = type->name;
644635

645636
int sub_tile_index, inst_num, logical_num, pb_type_idx;
646-
std::tie<int, int, int, int, int>(pin_index, sub_tile_index, inst_num, logical_num, pb_type_idx) = get_pin_index_for_inst(type, pin_physical_num, is_flat);
637+
std::tie(pin_index, sub_tile_index, inst_num, logical_num, pb_type_idx) = get_pin_index_for_inst(type, pin_physical_num, is_flat);
647638
if (type->sub_tiles[sub_tile_index].capacity.total() > 1) {
648639
pin_name += "[" + std::to_string(inst_num) + "]";
649640
}

libs/libarchfpga/src/physical_types_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
bool is_opin(int ipin, t_physical_tile_type_ptr type);
117117

118118
///@brief Returns true if the specified pin is located at "from_layer" and it is connected to "to_layer"
119-
bool is_pin_conencted_to_layer(t_physical_tile_type_ptr type, int ipin, int from_layer, int to_layer, int num_of_avail_layer);
119+
bool is_pin_conencted_to_layer(t_physical_tile_type_ptr type, int ipin, int from_layer, int to_layer, unsigned num_of_avail_layer);
120120

121121
/**
122122
* @brief Returns the corresponding physical pin based on the input parameters:

libs/libvtrutil/src/vtr_math.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ResultTy median(Container c) {
8383
///@brief Returns the median of a whole container, assuming that it is already
8484
/// sorted.
8585
template<typename ResultTy = double, typename Container>
86-
ResultTy median_presorted(const Container &c) {
86+
ResultTy median_presorted(const Container& c) {
8787
return median_presorted<ResultTy>(std::begin(c), std::end(c));
8888
}
8989

@@ -116,7 +116,7 @@ double geomean(const InputIterator first, const InputIterator last, double init
116116

117117
///@brief Returns the geometric mean of a whole container
118118
template<typename Container>
119-
double geomean(const Container &c) {
119+
double geomean(const Container& c) {
120120
return geomean(std::begin(c), std::end(c));
121121
}
122122

@@ -139,7 +139,7 @@ double arithmean(const InputIterator first, const InputIterator last, double ini
139139

140140
///@brief Returns the aritmatic mean of a whole container
141141
template<typename Container>
142-
double arithmean(const Container &c) {
142+
double arithmean(const Container& c) {
143143
return arithmean(std::begin(c), std::end(c));
144144
}
145145

vpr/src/analytical_place/analytical_placement_flow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ static void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_plac
111111
} else {
112112
if (current_loc_x != -1 && current_loc_y != -1) {
113113
atom_loc_x = std::clamp(current_loc_x, 0.0f,
114-
static_cast<float>(g_vpr_ctx.device().grid.width() -1));
114+
static_cast<float>(g_vpr_ctx.device().grid.width() - 1));
115115
atom_loc_y = std::clamp(current_loc_y, 0.0f,
116-
static_cast<float>(g_vpr_ctx.device().grid.height() -1));
116+
static_cast<float>(g_vpr_ctx.device().grid.height() - 1));
117117
// If current_loc_layer or current_loc_sub_tile are unset (-1), default to layer 0 and sub_tile 0.
118118
if (current_loc_layer == -1)
119119
current_loc_layer = 0;
@@ -155,7 +155,7 @@ static void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_plac
155155
}
156156
}
157157
VTR_LOG("%zu of %zu molecules placed at device center (no atoms of these molecules found in flat placement).\n",
158-
num_mols_assigned_to_center, ap_netlist.blocks().size());
158+
num_mols_assigned_to_center, ap_netlist.blocks().size());
159159
}
160160

161161
/**

0 commit comments

Comments
 (0)