From 0a80a54524aaf79a73128200713d3615f61959cc Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 28 Feb 2025 18:19:00 -0500 Subject: [PATCH 1/8] [vpr][place] fix grid_loc_to_compressed_loc_approx --- vpr/src/place/compressed_grid.h | 39 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/vpr/src/place/compressed_grid.h b/vpr/src/place/compressed_grid.h index c9030a39376..2cc95034e8c 100644 --- a/vpr/src/place/compressed_grid.h +++ b/vpr/src/place/compressed_grid.h @@ -111,31 +111,32 @@ struct t_compressed_block_grid { * * Useful when the point is of a different block type from coords. * - * @param point represents a coordinate in one dimension of the point - * @param coords represents vector of coordinate values of a single type only - * - * Hence, the exact point coordinate will not be found in coords if they are of different block types. In this case the function will return - * the nearest compressed location to point by rounding it down + * @param grid_loc non-compressed physical tile location in the grid + * @return Neared x and y compressed locations in the grid (in the same layer) */ inline t_physical_tile_loc grid_loc_to_compressed_loc_approx(t_physical_tile_loc grid_loc) const { auto find_closest_compressed_point = [](int loc, const std::vector& compressed_grid_dim) -> int { + VTR_ASSERT(compressed_grid_dim.size() > 0); + + // Find the first element not less than loc auto itr = std::lower_bound(compressed_grid_dim.begin(), compressed_grid_dim.end(), loc); - int cx; - if (itr < compressed_grid_dim.end() - 1) { - int dist_prev = abs(loc - *itr); - int dist_next = abs(loc - *(itr+1)); - if (dist_prev < dist_next) { - cx = std::distance(compressed_grid_dim.begin(), itr); - } else { - cx = std::distance(compressed_grid_dim.begin(), itr + 1); - } - } else if (itr == compressed_grid_dim.end()) { - cx = std::distance(compressed_grid_dim.begin(), itr - 1); - } else { - cx = std::distance(compressed_grid_dim.begin(), itr); + + // If we found exact match or at beginning, return current position + if (itr == compressed_grid_dim.begin() || (itr != compressed_grid_dim.end() && *itr == loc)) { + return std::distance(compressed_grid_dim.begin(), itr); + } + + // If we're past the end, return last element + if (itr == compressed_grid_dim.end()) { + return compressed_grid_dim.size() - 1; } - return cx; + // Compare distances to previous and current elements + int dist_prev = loc - *(itr - 1); + int dist_next = *itr - loc; + + return std::distance(compressed_grid_dim.begin(), + (dist_prev <= dist_next) ? (itr - 1) : itr); }; const int layer_num = grid_loc.layer_num; From 5cf1b67ec048178fc0de64bd28b57a14511cd4c6 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 3 Mar 2025 08:59:46 -0500 Subject: [PATCH 2/8] vpr/src/place/compressed_grid.h --- vpr/src/place/compressed_grid.h | 56 +++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/vpr/src/place/compressed_grid.h b/vpr/src/place/compressed_grid.h index 2cc95034e8c..72ebff4dbc8 100644 --- a/vpr/src/place/compressed_grid.h +++ b/vpr/src/place/compressed_grid.h @@ -1,6 +1,7 @@ #ifndef VPR_COMPRESSED_GRID_H #define VPR_COMPRESSED_GRID_H +#include #include "physical_types.h" #include "vtr_geometry.h" @@ -60,18 +61,22 @@ struct t_compressed_block_grid { * * This function takes a physical tile location in the grid and converts it to the corresponding * compressed location. The conversion approximates by rounding up to the nearest valid compressed location. + * If all the compressed locations are less than the grid location, the function will return the last compressed location. * * @param grid_loc The physical tile location in the grid. * @return The corresponding compressed location with the same layer number. */ inline t_physical_tile_loc grid_loc_to_compressed_loc_approx_round_up(t_physical_tile_loc grid_loc) const { auto find_compressed_index = [](const std::vector& compressed, int value) -> int { - auto itr = std::upper_bound(compressed.begin(), compressed.end(), value); - if (itr == compressed.begin()) - return 0; - if (itr == compressed.end() || *(itr - 1) == value) - return (int)std::distance(compressed.begin(), itr - 1); - return (int)std::distance(compressed.begin(), itr); + // Get the first element that is not less than the value + auto itr = std::lower_bound(compressed.begin(), compressed.end(), value); + if (itr == compressed.end()) { + // If all the compressed locations are less than the grid location, return the last compressed location + return compressed.size() - 1; + } else { + // Return the index of the first element that is not less than the value + return std::distance(compressed.begin(), itr); + } }; int layer_num = grid_loc.layer_num; @@ -86,17 +91,22 @@ struct t_compressed_block_grid { * * This function takes a physical tile location in the grid and converts it to the corresponding * compressed location. The conversion approximates by rounding down to the nearest valid compressed location. + * If all the compressed locations are bigger than the grid location, the function will return the first compressed location. * * @param grid_loc The physical tile location in the grid. * @return The corresponding compressed location with the same layer number. */ inline t_physical_tile_loc grid_loc_to_compressed_loc_approx_round_down(t_physical_tile_loc grid_loc) const { auto find_compressed_index = [](const std::vector& compressed, int value) -> int { - auto itr = std::lower_bound(compressed.begin(), compressed.end(), value); - if (itr == compressed.end()) { - return (int)std::distance(compressed.begin(), itr - 1); + // Get the first element that is strictly bigger than the value + auto itr = std::upper_bound(compressed.begin(), compressed.end(), value); + if (itr == compressed.begin()) { + // If all the compressed locations are less than the grid location, return the first compressed location + return 0; + } else { + // Return the index of the first element that is less than or equal to the value + return std::distance(compressed.begin(), itr - 1); } - return (int)std::distance(compressed.begin(), itr); }; int layer_num = grid_loc.layer_num; @@ -120,23 +130,21 @@ struct t_compressed_block_grid { // Find the first element not less than loc auto itr = std::lower_bound(compressed_grid_dim.begin(), compressed_grid_dim.end(), loc); - - // If we found exact match or at beginning, return current position - if (itr == compressed_grid_dim.begin() || (itr != compressed_grid_dim.end() && *itr == loc)) { - return std::distance(compressed_grid_dim.begin(), itr); - } - - // If we're past the end, return last element + if (itr == compressed_grid_dim.end()) { + // If all the compressed locations are less than the grid location, return the last compressed location return compressed_grid_dim.size() - 1; + } else if (*itr == loc) { + // If we found exact match, return the index of the element + return std::distance(compressed_grid_dim.begin(), itr); + } else { + // If we didn't find exact match, return the index of the closest compressed location + int dist_prev = loc - *(itr - 1); + int dist_next = *itr - loc; + VTR_ASSERT_DEBUG(dist_prev > 0 && dist_next > 0); + return (dist_prev <= dist_next) ? (std::distance(compressed_grid_dim.begin(), itr - 1)) : + (std::distance(compressed_grid_dim.begin(), itr)); } - - // Compare distances to previous and current elements - int dist_prev = loc - *(itr - 1); - int dist_next = *itr - loc; - - return std::distance(compressed_grid_dim.begin(), - (dist_prev <= dist_next) ? (itr - 1) : itr); }; const int layer_num = grid_loc.layer_num; From c8fd5b2ca825933d39c81d93b3471ecc9e7e5d03 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 3 Mar 2025 09:08:23 -0500 Subject: [PATCH 3/8] [vpr][place] fix a typo --- vpr/src/place/compressed_grid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpr/src/place/compressed_grid.h b/vpr/src/place/compressed_grid.h index 72ebff4dbc8..0b1370de47a 100644 --- a/vpr/src/place/compressed_grid.h +++ b/vpr/src/place/compressed_grid.h @@ -101,7 +101,7 @@ struct t_compressed_block_grid { // Get the first element that is strictly bigger than the value auto itr = std::upper_bound(compressed.begin(), compressed.end(), value); if (itr == compressed.begin()) { - // If all the compressed locations are less than the grid location, return the first compressed location + // If all the compressed locations are bigger than the grid location, return the first compressed location return 0; } else { // Return the index of the first element that is less than or equal to the value From c25f067594654d564891f8fbf768873e3ed475e3 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Tue, 4 Mar 2025 08:47:28 -0500 Subject: [PATCH 4/8] [vpr][place] add the case when all compressed loc are bigger or equal than the given loc --- vpr/src/place/compressed_grid.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vpr/src/place/compressed_grid.h b/vpr/src/place/compressed_grid.h index 0b1370de47a..05bd547941b 100644 --- a/vpr/src/place/compressed_grid.h +++ b/vpr/src/place/compressed_grid.h @@ -4,6 +4,7 @@ #include #include "physical_types.h" +#include "vtr_assert.h" #include "vtr_geometry.h" #include "vtr_flat_map.h" @@ -126,17 +127,17 @@ struct t_compressed_block_grid { */ inline t_physical_tile_loc grid_loc_to_compressed_loc_approx(t_physical_tile_loc grid_loc) const { auto find_closest_compressed_point = [](int loc, const std::vector& compressed_grid_dim) -> int { - VTR_ASSERT(compressed_grid_dim.size() > 0); + VTR_ASSERT_DEBUG(compressed_grid_dim.size() > 0); // Find the first element not less than loc auto itr = std::lower_bound(compressed_grid_dim.begin(), compressed_grid_dim.end(), loc); - if (itr == compressed_grid_dim.end()) { - // If all the compressed locations are less than the grid location, return the last compressed location + if (itr == compressed_grid_dim.begin()) { + // If all the compressed locations are bigger that or equal to loc, return the first compressed location + return 0; + } else if (itr == compressed_grid_dim.end()) { + // If all the compressed locations are less than loc, return the last compressed location return compressed_grid_dim.size() - 1; - } else if (*itr == loc) { - // If we found exact match, return the index of the element - return std::distance(compressed_grid_dim.begin(), itr); } else { // If we didn't find exact match, return the index of the closest compressed location int dist_prev = loc - *(itr - 1); From 2dd9eeefb9415a96cccf381f57085148e4295eb0 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Tue, 4 Mar 2025 08:49:30 -0500 Subject: [PATCH 5/8] [vpr][place] fix a typo --- vpr/src/place/compressed_grid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpr/src/place/compressed_grid.h b/vpr/src/place/compressed_grid.h index 05bd547941b..e1bb83c96e0 100644 --- a/vpr/src/place/compressed_grid.h +++ b/vpr/src/place/compressed_grid.h @@ -123,7 +123,7 @@ struct t_compressed_block_grid { * Useful when the point is of a different block type from coords. * * @param grid_loc non-compressed physical tile location in the grid - * @return Neared x and y compressed locations in the grid (in the same layer) + * @return Nearest x and y compressed locations in the grid (in the same layer) */ inline t_physical_tile_loc grid_loc_to_compressed_loc_approx(t_physical_tile_loc grid_loc) const { auto find_closest_compressed_point = [](int loc, const std::vector& compressed_grid_dim) -> int { From b1dd20b0f69177644740a72e3b130c4feb6ea290 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Tue, 4 Mar 2025 08:53:32 -0500 Subject: [PATCH 6/8] [vpr][pack] fix a typo --- vpr/src/pack/prepack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpr/src/pack/prepack.cpp b/vpr/src/pack/prepack.cpp index da89aab9abf..345987c5870 100644 --- a/vpr/src/pack/prepack.cpp +++ b/vpr/src/pack/prepack.cpp @@ -1668,7 +1668,7 @@ static void print_chain_starting_points(t_pack_patterns* chain_pattern) { Prepacker::Prepacker(const AtomNetlist& atom_nlist, const std::vector& logical_block_types) { - VTR_ASSERT(pack_molecules_.empty() && "Prepacker cannot be initialized twice."); + VTR_ASSERT_MSG(pack_molecules_.empty(), "Prepacker cannot be initialized twice."); // Allocate the pack patterns from the logical block types. list_of_pack_patterns = alloc_and_load_pack_patterns(logical_block_types); From 9e07127a87fa1fc015559c9675485501353f79a3 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Tue, 4 Mar 2025 08:57:09 -0500 Subject: [PATCH 7/8] [vpr][place] fix comment --- vpr/src/place/compressed_grid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpr/src/place/compressed_grid.h b/vpr/src/place/compressed_grid.h index e1bb83c96e0..3f767e7b8a6 100644 --- a/vpr/src/place/compressed_grid.h +++ b/vpr/src/place/compressed_grid.h @@ -139,7 +139,7 @@ struct t_compressed_block_grid { // If all the compressed locations are less than loc, return the last compressed location return compressed_grid_dim.size() - 1; } else { - // If we didn't find exact match, return the index of the closest compressed location + // Find the nearest compressed location. int dist_prev = loc - *(itr - 1); int dist_next = *itr - loc; VTR_ASSERT_DEBUG(dist_prev > 0 && dist_next > 0); From e287e30a084c5157fb34845dbe3f65c8e2a818b2 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Thu, 6 Mar 2025 11:39:20 -0500 Subject: [PATCH 8/8] [vpr][place] assert if dist is less than zero --- vpr/src/place/compressed_grid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpr/src/place/compressed_grid.h b/vpr/src/place/compressed_grid.h index 3f767e7b8a6..83a78a76291 100644 --- a/vpr/src/place/compressed_grid.h +++ b/vpr/src/place/compressed_grid.h @@ -142,7 +142,7 @@ struct t_compressed_block_grid { // Find the nearest compressed location. int dist_prev = loc - *(itr - 1); int dist_next = *itr - loc; - VTR_ASSERT_DEBUG(dist_prev > 0 && dist_next > 0); + VTR_ASSERT_DEBUG(dist_prev >= 0 && dist_next >= 0); return (dist_prev <= dist_next) ? (std::distance(compressed_grid_dim.begin(), itr - 1)) : (std::distance(compressed_grid_dim.begin(), itr)); }