Skip to content

Commit 267fac7

Browse files
committed
Add some comments in device_grid.h - initialize instance_count befor do the counting - apply the review comments
1 parent 6074b87 commit 267fac7

File tree

4 files changed

+43
-30
lines changed

4 files changed

+43
-30
lines changed

libs/libarchfpga/src/device_grid.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ void DeviceGrid::count_instances() {
4848
instance_counts_.clear();
4949
instance_counts_.resize(num_layers);
5050

51+
//Initialize the instance counts
52+
for (int layer_num = 0; layer_num < num_layers; ++layer_num) {
53+
for (size_t x = 0; x < width(); ++x) {
54+
for (size_t y = 0; y < height(); ++y) {
55+
auto type = grid_[layer_num][x][y].type;
56+
57+
if (grid_[layer_num][x][y].width_offset == 0 && grid_[layer_num][x][y].height_offset == 0) {
58+
//Add capacity only if this is the root location
59+
instance_counts_[layer_num][type] = 0;
60+
}
61+
}
62+
}
63+
}
64+
5165
//Count the number of blocks in the grid
5266
for (int layer_num = 0; layer_num < num_layers; ++layer_num) {
5367
for (size_t x = 0; x < width(); ++x) {

libs/libarchfpga/src/device_grid.h

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/**
1111
* @brief s_grid_tile is the minimum tile of the fpga
12-
* @note This struct shouldn't be directly accessed by other functions. Use helper function in DeviceGrid instead.
12+
* @note This struct shouldn't be directly accessed by other functions. Use the helper functions in DeviceGrid instead.
1313
*/
1414
struct t_grid_tile {
1515
t_physical_tile_type_ptr type = nullptr; ///<Pointer to type descriptor, NULL for illegal
@@ -38,32 +38,12 @@ class DeviceGrid {
3838
///@brief Return the height of the grid at the specified layer
3939
size_t height() const { return grid_.dim_size(2); }
4040

41-
///@brief Given t_grid_tile, return the x coordinate of the tile on the given layer
42-
inline int get_grid_loc_x(const t_grid_tile*& grid_loc) const {
43-
int layer_num = std::floor(static_cast<int>(grid_loc - &grid_.get(0)) / (width() * height()));
44-
auto diff = grid_loc - &grid_.get(layer_num * height() * width());
45-
46-
return diff / grid_.dim_size(2);
47-
}
48-
49-
///@brief Given t_grid_tile, return the y coordinate of the tile on the given layer
50-
inline int get_grid_loc_y(const t_grid_tile*& grid_loc) const {
51-
int layer_num = std::floor(static_cast<int>(grid_loc - &grid_.get(0)) / (width() * height()));
52-
auto diff = grid_loc - &grid_.get(layer_num * height() * width());
53-
54-
return diff % grid_.dim_size(2);
55-
}
56-
57-
///@brief Return the nth t_grid_tile on the given layer of the flattened grid
58-
inline const t_grid_tile* get_grid_locs_grid_loc(int n) const {
59-
return &grid_.get(n);
60-
}
61-
6241
///@brief Return the size of the flattened grid on the given layer
6342
inline size_t grid_size() const {
6443
return grid_.size();
6544
}
6645

46+
///@brief deallocate members of DeviceGrid
6747
void clear();
6848

6949
/**
@@ -98,20 +78,41 @@ class DeviceGrid {
9878
return grid_[layer_num][x][y].meta;
9979
}
10080

81+
///@brief Given t_grid_tile, return the x coordinate of the tile on the given layer - Used by serializer functions
82+
inline int get_grid_loc_x(const t_grid_tile*& grid_loc) const {
83+
int layer_num = std::floor(static_cast<int>(grid_loc - &grid_.get(0)) / (width() * height()));
84+
auto diff = grid_loc - &grid_.get(layer_num * height() * width());
85+
86+
return diff / grid_.dim_size(2);
87+
}
88+
89+
///@brief Given t_grid_tile, return the y coordinate of the tile on the given layer - Used by serializer functions
90+
inline int get_grid_loc_y(const t_grid_tile*& grid_loc) const {
91+
int layer_num = std::floor(static_cast<int>(grid_loc - &grid_.get(0)) / (width() * height()));
92+
auto diff = grid_loc - &grid_.get(layer_num * height() * width());
93+
94+
return diff % grid_.dim_size(2);
95+
}
96+
97+
///@brief Return the nth t_grid_tile on the given layer of the flattened grid - Used by serializer functions
98+
inline const t_grid_tile* get_grid_locs_grid_loc(int n) const {
99+
return &grid_.get(n);
100+
}
101+
101102
private:
102103
///@brief count_instances() counts the number of each tile type on each layer and store it in instance_counts_. It is called in the constructor.
103104
void count_instances();
104105

105106
std::string name_;
106107

107108
/**
108-
* @brief grid_ is a of 3D grids.
109+
* @brief grid_ is a 3D matrix that represents the grid of the FPGA chip.
109110
* @note The first dimension is the layer number (grid_[0] corresponds to the bottom layer), the second dimension is the x coordinate, and the third dimension is the y coordinate.
110111
* @note Note that vtr::Matrix operator[] returns and intermediate type
111-
* @note which can be used or indexing in the second dimension, allowing
112+
* @note which can be used for indexing in the second dimension, allowing
112113
* @note traditional 2-d indexing to be used
113114
*/
114-
vtr::NdMatrix<t_grid_tile, 3> grid_;
115+
vtr::NdMatrix<t_grid_tile, 3> grid_; //This stores the grid of complex blocks. It is a a 3D matrix: [0..num_layers-1][0..grid.width()-1][0..grid_height()-1]
115116

116117
///@brief instance_counts_ stores the number of each tile type on each layer. It is initialized in count_instances().
117118
std::vector<std::map<t_physical_tile_type_ptr, size_t>> instance_counts_; /* [layer_num][physical_tile_type_ptr] */

vpr/src/base/vpr_api.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,8 @@ void vpr_create_device_grid(const t_vpr_setup& vpr_setup, const t_arch& Arch) {
461461
VTR_LOG("\tArchitecture\n");
462462
for (const auto equivalent_tile : type.equivalent_tiles) {
463463
auto num_instances = 0;
464-
//Count number of equivalent tile at each die and add all up together
465-
for (int layer = 0; layer < device_ctx.grid.get_num_layers(); layer++) {
466-
num_instances += device_ctx.grid.num_instances(equivalent_tile, layer);
467-
}
464+
//get the number of equivalent tile across all layers
465+
num_instances = (int)device_ctx.grid.num_instances(equivalent_tile, -1);
468466

469467
VTR_LOG("\t\t%d\tblocks of type: %s\n",
470468
num_instances, equivalent_tile->name);

vpr/src/base/vpr_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct DeviceContext : public Context {
145145
/**
146146
* @brief The device grid
147147
*
148-
* This represents the physical layout of the device. To get the physical tile at each location (x, y, z) the helper function in this data structure should be used.
148+
* This represents the physical layout of the device. To get the physical tile at each location (layer_num, x, y) the helper functions in this data structure should be used.
149149
*/
150150
DeviceGrid grid;
151151
/*

0 commit comments

Comments
 (0)