Skip to content

Commit 521c9e3

Browse files
apply PR comments
1 parent 4598234 commit 521c9e3

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

libs/libvtrutil/src/vtr_memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace vtr {
1414
/**
1515
* @brief This function will force the container to be cleared
1616
*
17-
* It release its held memory.
17+
* It releases its held memory.
1818
* For efficiency, STL containers usually don't
1919
* release their actual heap-allocated memory until
2020
* destruction (even if Container::clear() is called).

vpr/src/base/blk_loc_registry.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include "move_transactions.h"
55
#include "globals.h"
66

7+
BlkLocRegistry::BlkLocRegistry()
8+
: expected_transaction_(e_expected_transaction::APPLY) {}
9+
710
const vtr::vector_map<ClusterBlockId, t_block_loc>& BlkLocRegistry::block_locs() const {
811
return block_locs_;
912
}
@@ -118,6 +121,8 @@ void BlkLocRegistry::place_sync_external_block_connections(ClusterBlockId iblk)
118121
void BlkLocRegistry::apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
119122
auto& device_ctx = g_vpr_ctx.device();
120123

124+
VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::APPLY);
125+
121126
// Swap the blocks, but don't swap the nets or update place_ctx.grid_blocks
122127
// yet since we don't know whether the swap will be accepted
123128
for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks) {
@@ -139,9 +144,13 @@ void BlkLocRegistry::apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_aff
139144
place_sync_external_block_connections(blk);
140145
}
141146
}
147+
148+
expected_transaction_ = e_expected_transaction::COMMIT_REVERT;
142149
}
143150

144151
void BlkLocRegistry::commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
152+
VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::COMMIT_REVERT);
153+
145154
// Swap physical location
146155
for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks) {
147156
ClusterBlockId blk = moved_block.block_num;
@@ -163,11 +172,15 @@ void BlkLocRegistry::commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_af
163172
grid_blocks_.set_block_at_location(to, blk);
164173

165174
} // Finish updating clb for all blocks
175+
176+
expected_transaction_ = e_expected_transaction::APPLY;
166177
}
167178

168179
void BlkLocRegistry::revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
169180
auto& device_ctx = g_vpr_ctx.device();
170181

182+
VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::COMMIT_REVERT);
183+
171184
// Swap the blocks back, nets not yet swapped they don't need to be changed
172185
for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks) {
173186
ClusterBlockId blk = moved_block.block_num;
@@ -191,4 +204,6 @@ void BlkLocRegistry::revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_af
191204
VTR_ASSERT_SAFE_MSG(grid_blocks_.block_at_location(old_loc) == blk,
192205
"Grid blocks should only have been updated if swap committed (not reverted)");
193206
}
207+
208+
expected_transaction_ = e_expected_transaction::APPLY;
194209
}

vpr/src/base/blk_loc_registry.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct t_pl_blocks_to_be_moved;
2020
*/
2121
class BlkLocRegistry {
2222
public:
23-
BlkLocRegistry() = default;
23+
BlkLocRegistry();
2424
~BlkLocRegistry() = default;
2525
BlkLocRegistry(const BlkLocRegistry&) = delete;
2626
BlkLocRegistry& operator=(const BlkLocRegistry&) = default;
@@ -83,22 +83,38 @@ class BlkLocRegistry {
8383
void place_sync_external_block_connections(ClusterBlockId iblk);
8484

8585
/**
86-
* @brief Moves the blocks in blocks_affected to their new locations
86+
* @brief Moves the blocks in blocks_affected to their new locations.
87+
* This method only updates `grid_blocks_` member variable and not `grid_blocks_`.
88+
* After this method is called, either commit_move_blocks() or revert_move_blocks()
89+
* must be called to either revert the new locations or commit them to `grid_block_`
8790
* @param blocks_affected Clustered blocks affected by a swap and their old and new locations.
8891
*/
8992
void apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected);
9093

9194
/**
9295
* @brief Commits the blocks in blocks_affected to their new locations (updates inverse lookups in grid_blocks)
96+
* This method can only be called after a call to apply_move_blocks() to commit the block location changes
97+
* to `grid_block_`. If this method is called after apply_move_blocks(), revert_move_blocks() must not be called
98+
* until the next call to apply_move_blocks() is made.
9399
* @param blocks_affected Clustered blocks affected by a swap and their old and new locations.
94100
*/
95101
void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected);
96102

97103
/**
98-
* @brief Moves the blocks in blocks_affected to their old locations
104+
* @brief Moves the blocks in blocks_affected to their old locations by updating `block_locs_` member variable.
105+
* This method can only be called after a call to apply_move_blocks() to revert the block location changes
106+
* applied to `block_locs_`. If this method is called after apply_move_blocks(), commit_move_blocks() must not be called
107+
* until the next call to apply_move_blocks() is made.
99108
* @param blocks_affected Clustered blocks affected by a swap and their old and new locations.
100109
*/
101110
void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected);
111+
112+
enum class e_expected_transaction {
113+
APPLY,
114+
COMMIT_REVERT
115+
};
116+
117+
e_expected_transaction expected_transaction_;
102118
};
103119

104120
#endif //VTR_BLK_LOC_REGISTRY_H

vpr/src/place/move_generator.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
void MoveGenerator::calculate_reward_and_process_outcome(const MoveOutcomeStats& move_outcome_stats,
77
double delta_c,
88
float timing_bb_factor) {
9+
/*
10+
* To learn about different reward functions refer to the following paper:
11+
* Elgammal MA, Murray KE, Betz V. RLPlace: Using reinforcement learning and
12+
* smart perturbations to optimize FPGA placement.
13+
* IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems.
14+
* 2021 Sep 3;41(8):2532-45.
15+
*
16+
* For runtime-aware reward function, the reward value is divided by a normalized
17+
* runtime in the implementation of process_outcome()
18+
*/
919
switch (reward_func_) {
1020
case e_reward_function::WL_BIASED_RUNTIME_AWARE:
1121
if (delta_c < 0) {
@@ -25,6 +35,7 @@ void MoveGenerator::calculate_reward_and_process_outcome(const MoveOutcomeStats&
2535
process_outcome(-1 * delta_c, reward_func_);
2636
break;
2737

38+
2839
case e_reward_function::NON_PENALIZING_BASIC:
2940
case e_reward_function::RUNTIME_AWARE:
3041
if (delta_c < 0) {

vpr/src/place/net_cost_handler.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @file net_cost_handler.h
3+
* @brief This file contains the declaration of NetCostHandler class used to update placement cost when a new move is proposed/committed.
4+
* For more details on the overall algorithm, refer to the comment at the top of the net_cost_handler.cpp
5+
*/
6+
17
#pragma once
28

39
#include "place_delay_model.h"
@@ -38,9 +44,10 @@ class NetCostHandler {
3844
NetCostHandler& operator=(NetCostHandler&&) = delete;
3945

4046
/**
41-
* @brief Resize temporary swap data structures needed to determine which nets are affected by a move and data needed per net
42-
* about where their terminals are in order to quickly (incrementally) update their wirelength costs. These data structures are
43-
* (layer_)ts_bb_edge_new, (layer_)ts_bb_coord_new, ts_layer_sink_pin_count, and ts_nets_to_update.
47+
* @brief Initializes a NetCostHandler object, which contains temporary swap data structures needed to determine which nets
48+
* are affected by a move and data needed per net about where their terminals are in order to quickly (incrementally) update
49+
* their wirelength costs. These data structures are (layer_)ts_bb_edge_new, (layer_)ts_bb_coord_new, ts_layer_sink_pin_count,
50+
* and ts_nets_to_update.
4451
* @param num_nets Number of nets in the netlist used by the placement engine (currently clustered netlist)
4552
* @param cube_bb True if the 3D bounding box should be used, false otherwise.
4653
* @param place_cost_exp It is an exponent to which you take the average inverse channel
@@ -423,7 +430,20 @@ class NetCostHandler {
423430
std::vector<t_2D_bb>& bb_edge_new,
424431
std::vector<t_2D_bb>& bb_coord_new);
425432

433+
/**
434+
* @brief Computes the bounding box from scratch using 2D bounding boxes (per-layer mode)
435+
* @param method The method used to calculate placement cost. Specifies whether the cost is
436+
* computed from scratch or incrementally.
437+
* @return Computed bounding box cost.
438+
*/
426439
double comp_per_layer_bb_cost_(e_cost_methods method);
440+
441+
/**
442+
* @brief Computes the bounding box from scratch using 3D bounding boxes (cube mode)
443+
* @param method The method used to calculate placement cost. Specifies whether the cost is
444+
* computed from scratch or incrementally.
445+
* @return Computed bounding box cost.
446+
*/
427447
double comp_cube_bb_cost_(e_cost_methods method);
428448

429449
/**

0 commit comments

Comments
 (0)