-
Notifications
You must be signed in to change notification settings - Fork 401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vpr][place] moved_block uses size() to indicate valid elements #2657
Conversation
} | ||
|
||
size_t t_pl_blocks_to_be_moved::get_size_and_increment() { | ||
VTR_ASSERT(moved_blocks.size() < moved_blocks.capacity()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make this a VTR_ASSERT_SAFE as it is in a hot routine (VTR_ASSERT_SAFE is taken out of release build).
@@ -40,7 +49,7 @@ void apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { | |||
|
|||
//Swap the blocks, but don't swap the nets or update place_ctx.grid_blocks | |||
//yet since we don't know whether the swap will be accepted | |||
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { | |||
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be safe, could do num_moved = blocks_affected.moved_blocks.size() before the loop -- it is slightly safer from a compiler optimization point of view, as otherwise we are counting on the compiler to figure out .size() doesn't need to be called each time.
@@ -67,7 +76,7 @@ void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { | |||
auto& place_ctx = g_vpr_ctx.mutable_placement(); | |||
|
|||
/* Swap physical location */ | |||
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { | |||
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same optimization (local variable)
@@ -97,7 +106,7 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { | |||
auto& device_ctx = g_vpr_ctx.device(); | |||
|
|||
// Swap the blocks back, nets not yet swapped they don't need to be changed | |||
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { | |||
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same local loop count optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or use range-based for (Alex figured this out!)
@@ -488,7 +488,7 @@ std::set<t_pl_loc> determine_locations_emptied_by_move(t_pl_blocks_to_be_moved& | |||
std::set<t_pl_loc> moved_from; | |||
std::set<t_pl_loc> moved_to; | |||
|
|||
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { | |||
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range-based for
/* Reset the net cost function flags first. */ | ||
for (int inet_affected = 0; inet_affected < num_nets_affected; | ||
for (size_t inet_affected = 0; inet_affected < ts_nets_to_update.size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range-based for
@@ -136,7 +136,7 @@ void find_affected_noc_routers_and_update_noc_costs(const t_pl_blocks_to_be_move | |||
affected_noc_links.clear(); | |||
|
|||
// go through the moved blocks and process them only if they are NoC routers | |||
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { | |||
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range-based for
@@ -291,7 +291,7 @@ void revert_noc_traffic_flow_routes(const t_pl_blocks_to_be_moved& blocks_affect | |||
std::unordered_set<NocTrafficFlowId> reverted_traffic_flows; | |||
|
|||
// go through the moved blocks and process them only if they are NoC routers | |||
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { | |||
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range-based for
@@ -45,7 +45,7 @@ enum e_cost_methods { | |||
* @param timing_delta_c | |||
* @return The number of affected nets. | |||
*/ | |||
int find_affected_nets_and_update_costs( | |||
void find_affected_nets_and_update_costs( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if this function modifies (and doesn't clear/reset) the ts_* variables; if it changes their state (and leaves it changed) it should be mentioned briefly here.
@@ -100,7 +100,7 @@ void print_macro_constraint_error(const t_pl_macro& pl_macro); | |||
inline bool floorplan_legal(const t_pl_blocks_to_be_moved& blocks_affected) { | |||
bool floorplan_legal; | |||
|
|||
for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { | |||
for (size_t i = 0; i < blocks_affected.moved_blocks.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range-based for
Looks good; please run on a single controlled machine (can be one design) to get a precise cpu time too, after the review comments. |
std::vector<t_pl_moved_block>& moved_blocks
has as many entries as the total number of blocks, and we pass an integer to show how many entries are valid. size() can be used instead.https://docs.google.com/spreadsheets/d/1CvJ-HcgW1FnkkrhhhtByHFcUm5zOhWdfVIwBDf5DpAI/edit?usp=sharing
The run time was not affected.