1- /*
2- * This class is used to store a grid for each logical block type that stores the cumulative number of subtiles
3- * for that type available at each location in the grid. The cumulative number of subtiles is the subtiles at the
4- * location plus the subtiles available at the grid locations above and to the right of the locations.
5- * Having these grids allows for O(1) lookups about the number of subtiles available for a given type of block
6- * in a rectangular region.
7- * This lookup class is used during initial placement when sorting blocks by the size of their floorplan constraint
8- * regions.
9- */
101#ifndef VPR_SRC_PLACE_GRID_TILE_LOOKUP_H_
112#define VPR_SRC_PLACE_GRID_TILE_LOOKUP_H_
123
134#include " place_util.h"
145#include " globals.h"
156
7+ /* *
8+ * @class GridTileLookup
9+ * @brief This class is used to store a grid for each logical block type that stores the cumulative number of subtiles
10+ * for that type available at each location in the grid.
11+ *
12+ * The cumulative number of subtiles is the subtiles at the location plus the subtiles available at the grid locations
13+ * above and to the right of the locations. Having these grids allows for O(1) lookups about the number of subtiles
14+ * available for a given type of block in a rectangular region.
15+ * This lookup class is used during initial placement when sorting blocks by the size of their floorplan constraint regions.
16+ */
1617class GridTileLookup {
17- public:
18- GridTileLookup () {
19- auto & device_ctx = g_vpr_ctx.device ();
20-
21- // Will store the max number of tile locations for each logical block type
22- max_placement_locations.resize (device_ctx.logical_block_types .size ());
23-
24- for (const auto & type : device_ctx.logical_block_types ) {
25- int num_layers = device_ctx.grid .get_num_layers ();
26- vtr::NdMatrix<int , 3 > type_count ({static_cast <unsigned long >(num_layers), device_ctx.grid .width (), device_ctx.grid .height ()});
27- fill_type_matrix (&type, type_count);
28- block_type_matrices.push_back (type_count);
29- }
30- }
31-
32- void fill_type_matrix (t_logical_block_type_ptr block_type, vtr::NdMatrix<int , 3 >& type_count);
33-
34- int region_tile_count (const Region& reg, t_logical_block_type_ptr block_type) const ;
35-
36- int region_with_subtile_count (const Region& reg, t_logical_block_type_ptr block_type) const ;
37-
38- int total_type_tiles (t_logical_block_type_ptr block_type) const ;
39-
40- private:
41- /*
42- * Stores the cumulative total of subtiles available at each location in the grid for each block type.
43- * Therefore, the length of the vector will be the number of logical block types. To access the cumulative
44- * number of subtiles at a location, you would use block_type_matrices[iblock_type][x][y] - this would
45- * give the number of placement locations that are at, or above and to the right of the given [x,y] for
46- * the given block type.
47- */
48- std::vector<vtr::NdMatrix<int , 3 >> block_type_matrices;
49-
50- /*
51- * Stores the total number of placement locations (i.e. compatible subtiles) for each block type.
52- * To access the max_placement locations for a particular block type, use max_placement_locations[block_type->index]
53- */
54- std::vector<int > max_placement_locations;
18+ public:
19+ /* *
20+ * @brief Constructs a new GridTileLookup object.
21+ *
22+ * Creates a grid for each logical type and fills it with the cumulative number
23+ * of subtiles of that type.
24+ */
25+ GridTileLookup ();
26+
27+ /* *
28+ * @brief Returns the number of subtiles available in the specified region for the given block type.
29+ *
30+ * This routine uses pre-computed values from the grids for each block type to get the number of grid tiles
31+ * covered by a region.
32+ * For a region with no subtiles specified, the number of grid tiles can be calculated by adding
33+ * and subtracting four values from within/at the edge of the region.
34+ * The region with subtile case is taken care of by a helper routine, region_with_subtile_count().
35+ *
36+ * @param reg The region to be queried.
37+ * @param block_type The type of logical block.
38+ * @return int The number of available subtiles.
39+ */
40+ int region_tile_count (const Region& reg, t_logical_block_type_ptr block_type) const ;
41+
42+ /* *
43+ * @brief Returns the number of subtiles that can be placed in the specified region for the given block type.
44+ *
45+ * This routine is for the subtile specified case; an O(region_size) scan needs to be done to check whether each grid
46+ * location in the region is compatible for the block at the subtile specified.
47+ *
48+ * @param reg The region to be queried.
49+ * @param block_type The type of logical block.
50+ * @return int The number of subtiles with placement.
51+ */
52+ int region_with_subtile_count (const Region& reg, t_logical_block_type_ptr block_type) const ;
53+
54+ /* *
55+ * @brief Returns the total number of tiles available for the specified block type.
56+ *
57+ * @param block_type The type of logical block.
58+ * @return int The total number of available tiles.
59+ */
60+ int total_type_tiles (t_logical_block_type_ptr block_type) const ;
61+
62+ private:
63+ /* *
64+ * @brief Fills the type matrix with cumulative subtiles count for the given block type.
65+ *
66+ * @param block_type The type of logical block.
67+ * @param type_count The matrix to be filled with cumulative subtiles count.
68+ */
69+ void fill_type_matrix (t_logical_block_type_ptr block_type, vtr::NdMatrix<int , 3 >& type_count);
70+
71+ /* *
72+ * @brief Stores the cumulative total of subtiles available at each location in the grid for each block type.
73+ *
74+ * Therefore, the length of the vector will be the number of logical block types. To access the cumulative
75+ * number of subtiles at a location, you would use block_type_matrices[iblock_type][x][y] - this would
76+ * give the number of placement locations that are at, or above and to the right of the given [x,y] for
77+ * the given block type.
78+ */
79+ std::vector<vtr::NdMatrix<int , 3 >> block_type_matrices;
80+
81+ /* *
82+ * @brief Stores the total number of placement locations (i.e. compatible subtiles) for each block type.
83+ *
84+ * To access the max_placement locations for a particular block type, use max_placement_locations[block_type->index]
85+ */
86+ std::vector<int > max_placement_locations;
5587};
5688
57- #endif /* VPR_SRC_PLACE_GRID_TILE_LOOKUP_H_ */
89+ #endif /* VPR_SRC_PLACE_GRID_TILE_LOOKUP_H_ */
0 commit comments