Skip to content

Commit abbd495

Browse files
add comments and code cleaning
1 parent 15fab24 commit abbd495

File tree

7 files changed

+61
-50
lines changed

7 files changed

+61
-50
lines changed

vpr/src/base/load_flat_place.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ static void print_flat_cluster(FILE* fp, ClusterBlockId iblk,
99

1010
static void print_flat_cluster(FILE* fp, ClusterBlockId iblk,
1111
std::vector<AtomBlockId>& atoms) {
12+
const auto& atom_ctx = g_vpr_ctx.atom();
13+
const auto& block_locs = g_vpr_ctx.placement().block_locs();
1214

13-
auto& atom_ctx = g_vpr_ctx.atom();
14-
t_pl_loc loc = g_vpr_ctx.placement().block_locs()[iblk].loc;
15+
t_pl_loc loc = block_locs[iblk].loc;
1516
size_t bnum = size_t(iblk);
1617

1718
for (auto atom : atoms) {
@@ -26,7 +27,6 @@ static void print_flat_cluster(FILE* fp, ClusterBlockId iblk,
2627

2728
/* prints a flat placement file */
2829
void print_flat_placement(const char* flat_place_file) {
29-
3030
FILE* fp;
3131

3232
ClusterAtomsLookup atoms_lookup;

vpr/src/base/read_route.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static void process_nodes(const Netlist<>& net_list, std::ifstream& fp, ClusterN
222222
auto& device_ctx = g_vpr_ctx.mutable_device();
223223
const auto& rr_graph = device_ctx.rr_graph;
224224
auto& route_ctx = g_vpr_ctx.mutable_routing();
225-
auto& place_ctx = g_vpr_ctx.placement();
225+
const auto& grid_blocks = g_vpr_ctx.placement().get_grid_blocks();
226226

227227
t_trace* head_ptr = nullptr;
228228
t_trace* tptr = nullptr;
@@ -337,12 +337,10 @@ static void process_nodes(const Netlist<>& net_list, std::ifstream& fp, ClusterN
337337
int width_offset = device_ctx.grid.get_width_offset({x, y, layer_num});
338338
int height_offset = device_ctx.grid.get_height_offset({x, y, layer_num});
339339
auto physical_tile = device_ctx.grid.get_physical_type({x, y, layer_num});
340-
const t_sub_tile* sub_tile;
341-
int sub_tile_rel_cap;
342-
std::tie(sub_tile, sub_tile_rel_cap) = get_sub_tile_from_pin_physical_num(physical_tile, pin_num);
340+
auto [sub_tile, sub_tile_rel_cap] = get_sub_tile_from_pin_physical_num(physical_tile, pin_num);
343341
int sub_tile_offset = sub_tile->capacity.low + sub_tile_rel_cap;
344342

345-
ClusterBlockId iblock = place_ctx.get_grid_blocks().block_at_location({x - width_offset, y - height_offset, sub_tile_offset, layer_num});
343+
ClusterBlockId iblock = grid_blocks.block_at_location({x - width_offset, y - height_offset, sub_tile_offset, layer_num});
346344
VTR_ASSERT(iblock);
347345

348346
const t_pb_graph_pin* pb_pin;
@@ -571,7 +569,7 @@ static bool check_rr_graph_connectivity(RRNodeId prev_node, RRNodeId node) {
571569
void print_route(const Netlist<>& net_list,
572570
FILE* fp,
573571
bool is_flat) {
574-
auto& place_ctx = g_vpr_ctx.placement();
572+
const auto& grid_blocks = g_vpr_ctx.placement().get_grid_blocks();
575573
auto& device_ctx = g_vpr_ctx.device();
576574
const auto& rr_graph = device_ctx.rr_graph;
577575
auto& route_ctx = g_vpr_ctx.mutable_routing();
@@ -644,13 +642,11 @@ void print_route(const Netlist<>& net_list,
644642
int pin_num = rr_graph.node_pin_num(inode);
645643
int xoffset = device_ctx.grid.get_width_offset({ilow, jlow, layer_num});
646644
int yoffset = device_ctx.grid.get_height_offset({ilow, jlow, layer_num});
647-
const t_sub_tile* sub_tile;
648-
int sub_tile_rel_cap;
649-
std::tie(sub_tile, sub_tile_rel_cap) = get_sub_tile_from_pin_physical_num(physical_tile, pin_num);
645+
auto [sub_tile, sub_tile_rel_cap] = get_sub_tile_from_pin_physical_num(physical_tile, pin_num);
650646
int sub_tile_offset = sub_tile->capacity.low + sub_tile_rel_cap;
651647

652-
ClusterBlockId iblock = place_ctx.get_grid_blocks().block_at_location({ilow - xoffset, jlow - yoffset,
653-
sub_tile_offset, layer_num});
648+
ClusterBlockId iblock = grid_blocks.block_at_location({ilow - xoffset, jlow - yoffset,
649+
sub_tile_offset, layer_num});
654650
VTR_ASSERT(iblock);
655651
const t_pb_graph_pin* pb_pin;
656652
if (is_pin_on_tile(physical_tile, pin_num)) {

vpr/src/base/stats.cpp

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
#include <cstdio>
2-
#include <cstring>
31
#include <cmath>
42
#include <set>
53

64
#include "route_tree.h"
75
#include "vtr_assert.h"
86
#include "vtr_log.h"
9-
#include "vtr_math.h"
107
#include "vtr_ndmatrix.h"
118

129
#include "vpr_types.h"
@@ -55,12 +52,10 @@ void routing_stats(const Netlist<>& net_list,
5552
enum e_directionality directionality,
5653
int wire_to_ipin_switch,
5754
bool is_flat) {
58-
float area, used_area;
59-
6055
auto& device_ctx = g_vpr_ctx.device();
6156
auto& rr_graph = device_ctx.rr_graph;
6257
auto& cluster_ctx = g_vpr_ctx.clustering();
63-
auto& block_locs = g_vpr_ctx.placement().block_locs();
58+
const auto& block_locs = g_vpr_ctx.placement().block_locs();
6459

6560
int num_rr_switch = rr_graph.num_rr_switches();
6661

@@ -70,7 +65,7 @@ void routing_stats(const Netlist<>& net_list,
7065

7166
VTR_LOG("Logic area (in minimum width transistor areas, excludes I/Os and empty grid tiles)...\n");
7267

73-
area = 0;
68+
float area = 0;
7469
for (int layer_num = 0; layer_num < device_ctx.grid.get_num_layers(); layer_num++) {
7570
for (int i = 0; i < (int)device_ctx.grid.width(); i++) {
7671
for (int j = 0; j < (int)device_ctx.grid.height(); j++) {
@@ -93,7 +88,7 @@ void routing_stats(const Netlist<>& net_list,
9388
/* Todo: need to add pitch of routing to blocks with height > 3 */
9489
VTR_LOG("\tTotal logic block area (Warning, need to add pitch of routing to blocks with height > 3): %g\n", area);
9590

96-
used_area = 0;
91+
float used_area = 0;
9792
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
9893
t_pl_loc block_loc = block_locs[blk_id].loc;
9994
auto type = physical_tile_type(block_loc);
@@ -123,26 +118,20 @@ void routing_stats(const Netlist<>& net_list,
123118
* and net length in the routing.
124119
*/
125120
void length_and_bends_stats(const Netlist<>& net_list, bool is_flat) {
126-
int bends, total_bends, max_bends;
127-
int length, total_length, max_length;
128-
int segments, total_segments, max_segments;
129-
float av_bends, av_length, av_segments;
130-
int num_global_nets, num_clb_opins_reserved, num_absorbed_nets;
131-
132-
bool is_absorbed;
133-
134-
max_bends = 0;
135-
total_bends = 0;
136-
max_length = 0;
137-
total_length = 0;
138-
max_segments = 0;
139-
total_segments = 0;
140-
num_global_nets = 0;
141-
num_clb_opins_reserved = 0;
142-
num_absorbed_nets = 0;
121+
int max_bends = 0;
122+
int total_bends = 0;
123+
int max_length = 0;
124+
int total_length = 0;
125+
int max_segments = 0;
126+
int total_segments = 0;
127+
int num_global_nets = 0;
128+
int num_clb_opins_reserved = 0;
129+
int num_absorbed_nets = 0;
143130

144131
for (auto net_id : net_list.nets()) {
145132
if (!net_list.net_is_ignored(net_id) && net_list.net_sinks(net_id).size() != 0) { /* Globals don't count. */
133+
int bends, length, segments;
134+
bool is_absorbed;
146135
get_num_bends_and_length(net_id, &bends, &length, &segments, &is_absorbed);
147136

148137
total_bends += bends;
@@ -165,20 +154,20 @@ void length_and_bends_stats(const Netlist<>& net_list, bool is_flat) {
165154
}
166155
}
167156

168-
av_bends = (float)total_bends / (float)((int)net_list.nets().size() - num_global_nets);
157+
float av_bends = (float)total_bends / (float)((int)net_list.nets().size() - num_global_nets);
169158
VTR_LOG("\n");
170159
VTR_LOG("Average number of bends per net: %#g Maximum # of bends: %d\n", av_bends, max_bends);
171160
VTR_LOG("\n");
172161

173-
av_length = (float)total_length / (float)((int)net_list.nets().size() - num_global_nets);
162+
float av_length = (float)total_length / (float)((int)net_list.nets().size() - num_global_nets);
174163
VTR_LOG("Number of global nets: %d\n", num_global_nets);
175164
VTR_LOG("Number of routed nets (nonglobal): %d\n", (int)net_list.nets().size() - num_global_nets);
176165
VTR_LOG("Wire length results (in units of 1 clb segments)...\n");
177166
VTR_LOG("\tTotal wirelength: %d, average net length: %#g\n", total_length, av_length);
178167
VTR_LOG("\tMaximum net length: %d\n", max_length);
179168
VTR_LOG("\n");
180169

181-
av_segments = (float)total_segments / (float)((int)net_list.nets().size() - num_global_nets);
170+
float av_segments = (float)total_segments / (float)((int)net_list.nets().size() - num_global_nets);
182171
VTR_LOG("Wire length results in terms of physical segments...\n");
183172
VTR_LOG("\tTotal wiring segments used: %d, average wire segments per net: %#g\n", total_segments, av_segments);
184173
VTR_LOG("\tMaximum segments used by a net: %d\n", max_segments);
@@ -425,9 +414,7 @@ void print_wirelen_prob_dist(bool is_flat) {
425414
* (i.e. the clock when it is marked global).
426415
*/
427416
void print_lambda() {
428-
int ipin;
429417
int num_inputs_used = 0;
430-
float lambda;
431418

432419
auto& cluster_ctx = g_vpr_ctx.clustering();
433420
auto& block_locs = g_vpr_ctx.placement().block_locs();
@@ -437,7 +424,7 @@ void print_lambda() {
437424
auto type = physical_tile_type(block_loc);
438425
VTR_ASSERT(type != nullptr);
439426
if (!is_io_type(type)) {
440-
for (ipin = 0; ipin < type->num_pins; ipin++) {
427+
for (int ipin = 0; ipin < type->num_pins; ipin++) {
441428
if (get_pin_type_from_pin_physical_num(type, ipin) == RECEIVER) {
442429
ClusterNetId net_id = cluster_ctx.clb_nlist.block_net(blk_id, ipin);
443430
if (net_id != ClusterNetId::INVALID()) /* Pin is connected? */
@@ -448,7 +435,7 @@ void print_lambda() {
448435
}
449436
}
450437

451-
lambda = (float)num_inputs_used / (float)cluster_ctx.clb_nlist.blocks().size();
438+
float lambda = (float)num_inputs_used / (float)cluster_ctx.clb_nlist.blocks().size();
452439
VTR_LOG("Average lambda (input pins used per clb) is: %g\n", lambda);
453440
}
454441

vpr/src/base/vpr_context.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,18 @@ struct PackingMultithreadingContext : public Context {
384384
*/
385385
struct PlacementContext : public Context {
386386
private:
387+
/**
388+
* Determines if place_loc_vars_ can be accessed by calling getter methods.
389+
* This flag should be set to false at the beginning of the placement stage,
390+
* and set to true at the end of placement. This ensures that variables that
391+
* are subject to change during placement are kept local to the placement stage.
392+
*/
387393
bool loc_vars_are_accessible_ = true;
394+
395+
/**
396+
* @brief Stores block location information, which is subject to change during the
397+
* placement stage.
398+
*/
388399
PlaceLocVars place_loc_vars_;
389400

390401
public:
@@ -398,7 +409,21 @@ struct PlacementContext : public Context {
398409
PlaceLocVars& mutable_place_loc_vars() { VTR_ASSERT(loc_vars_are_accessible_); return place_loc_vars_; }
399410
const PlaceLocVars& place_loc_vars() const { VTR_ASSERT(loc_vars_are_accessible_); return place_loc_vars_; }
400411

412+
/**
413+
* @brief Makes place_loc_vars_ inaccessible through the getter methods.
414+
*
415+
* This method should be called at the beginning of the placement stage to
416+
* guarantee that the placement stage code does not access block location variables
417+
* stored in the global state.
418+
*/
401419
void lock_loc_vars() { loc_vars_are_accessible_ = false; }
420+
421+
/**
422+
* @brief Makes place_loc_vars_ accessible through the getter methods.
423+
*
424+
* This method should be called at the end of the placement stage to
425+
* make the block location information accessible for subsequent stages.
426+
*/
402427
void unlock_loc_vars() { loc_vars_are_accessible_ = true; }
403428

404429
///@brief The pl_macros array stores all the placement macros (usually carry chains).

vpr/src/base/vpr_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ void t_cluster_placement_stats::free_primitives() {
562562
int PlaceLocVars::net_pin_to_tile_pin_index(const ClusterNetId net_id, int net_pin_index) const {
563563
auto& cluster_ctx = g_vpr_ctx.clustering();
564564

565-
// Get the logical pin index of pin within it's logical block type
565+
// Get the logical pin index of pin within its logical block type
566566
ClusterPinId pin_id = cluster_ctx.clb_nlist.net_pin(net_id, net_pin_index);
567567

568568
return this->tile_pin_index(pin_id);

vpr/src/base/vpr_types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,11 +922,11 @@ class PlaceLocVars {
922922
inline const vtr::vector_map<ClusterPinId, int>& physical_pins() const { return physical_pins_; }
923923
inline vtr::vector_map<ClusterPinId, int>& mutable_physical_pins() { return physical_pins_; }
924924

925-
//Returns the physical pin of the tile, related to the given ClusterPinId
925+
///@brief Returns the physical pin of the tile, related to the given ClusterPinId
926926
inline int tile_pin_index(const ClusterPinId pin) const { return physical_pins_[pin]; }
927927

928-
//Returns the physical pin of the tile, related to the given ClusterNedId, and the net pin index.
929-
int net_pin_to_tile_pin_index(const ClusterNetId net_id, int net_pin_index) const;
928+
///@brief Returns the physical pin of the tile, related to the given ClusterNedId, and the net pin index.
929+
inline int net_pin_to_tile_pin_index(const ClusterNetId net_id, int net_pin_index) const;
930930
};
931931

932932
///@brief Names of various files

vpr/src/draw/draw.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,9 @@ void init_draw_coords(float width_val, const PlaceLocVars& place_loc_vars) {
580580
const auto& device_ctx = g_vpr_ctx.device();
581581
const auto& rr_graph = device_ctx.rr_graph;
582582

583+
/* Store a reference to block location variables so that other drawing
584+
* functions can access block location information without accessing
585+
* the global placement state, which is inaccessible during placement.*/
583586
set_graphics_place_loc_vars_ref(place_loc_vars);
584587

585588
if (!draw_state->show_graphics && !draw_state->save_graphics

0 commit comments

Comments
 (0)