Skip to content

Commit 8e28113

Browse files
replace std::vector with NdMatrix in MoveTypeStat
1 parent 88fb2e1 commit 8e28113

File tree

6 files changed

+39
-41
lines changed

6 files changed

+39
-41
lines changed

libs/libarchfpga/src/device_grid.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#include "device_grid.h"
22

3+
#include <utility>
4+
35
DeviceGrid::DeviceGrid(std::string grid_name, vtr::NdMatrix<t_grid_tile, 3> grid)
4-
: name_(grid_name)
5-
, grid_(grid) {
6+
: name_(std::move(grid_name))
7+
, grid_(std::move(grid)) {
68
count_instances();
79
}
810

911
DeviceGrid::DeviceGrid(std::string grid_name, vtr::NdMatrix<t_grid_tile, 3> grid, std::vector<t_logical_block_type_ptr> limiting_res)
10-
: DeviceGrid(grid_name, grid) {
11-
limiting_resources_ = limiting_res;
12+
: DeviceGrid(std::move(grid_name), std::move(grid)) {
13+
limiting_resources_ = std::move(limiting_res);
1214
}
1315

1416
size_t DeviceGrid::num_instances(t_physical_tile_type_ptr type, int layer_num) const {

libs/libvtrutil/src/vtr_ndmatrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class NdMatrixProxy<T, 1> {
139139
* This should improve memory usage (no extra pointers to store for each dimension),
140140
* and cache locality (less indirection via pointers, predictable strides).
141141
*
142-
* The indices are calculated based on the dimensions to access the appropriate elements.
142+
* The indicies are calculated based on the dimensions to access the appropriate elements.
143143
* Since the indexing calculations are visible to the compiler at compile time they can be
144144
* optimized to be efficient.
145145
*/

vpr/src/base/SetupGrid.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ using vtr::t_formula_data;
3131

3232
static DeviceGrid auto_size_device_grid(const std::vector<t_grid_def>& grid_layouts, const std::map<t_logical_block_type_ptr, size_t>& minimum_instance_counts, float maximum_device_utilization);
3333
static std::vector<t_logical_block_type_ptr> grid_overused_resources(const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t> instance_counts);
34-
static bool grid_satisfies_instance_counts(const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t> instance_counts, float maximum_utilization);
35-
static DeviceGrid build_device_grid(const t_grid_def& grid_def, size_t width, size_t height, bool warn_out_of_range = true, std::vector<t_logical_block_type_ptr> limiting_resources = std::vector<t_logical_block_type_ptr>());
34+
static bool grid_satisfies_instance_counts(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts, float maximum_utilization);
35+
static DeviceGrid build_device_grid(const t_grid_def& grid_def, size_t width, size_t height, bool warn_out_of_range = true, const std::vector<t_logical_block_type_ptr>& limiting_resources = std::vector<t_logical_block_type_ptr>());
3636

3737
static void CheckGrid(const DeviceGrid& grid);
3838

@@ -316,8 +316,8 @@ static std::vector<t_logical_block_type_ptr> grid_overused_resources(const Devic
316316
return overused_resources;
317317
}
318318

319-
static bool grid_satisfies_instance_counts(const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t> instance_counts, float maximum_utilization) {
320-
//Are the resources satisified?
319+
static bool grid_satisfies_instance_counts(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts, float maximum_utilization) {
320+
//Are the resources satisfied?
321321
auto overused_resources = grid_overused_resources(grid, instance_counts);
322322

323323
if (!overused_resources.empty()) {
@@ -335,7 +335,7 @@ static bool grid_satisfies_instance_counts(const DeviceGrid& grid, std::map<t_lo
335335
}
336336

337337
///@brief Build the specified device grid
338-
static DeviceGrid build_device_grid(const t_grid_def& grid_def, size_t grid_width, size_t grid_height, bool warn_out_of_range, const std::vector<t_logical_block_type_ptr> limiting_resources) {
338+
static DeviceGrid build_device_grid(const t_grid_def& grid_def, size_t grid_width, size_t grid_height, bool warn_out_of_range, const std::vector<t_logical_block_type_ptr>& limiting_resources) {
339339
if (grid_def.grid_type == GridDefType::FIXED) {
340340
if (grid_def.width != int(grid_width) || grid_def.height != int(grid_height)) {
341341
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
@@ -754,7 +754,7 @@ static void CheckGrid(const DeviceGrid& grid) {
754754
}
755755
}
756756

757-
float calculate_device_utilization(const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t> instance_counts) {
757+
float calculate_device_utilization(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts) {
758758
//Record the resources of the grid
759759
std::map<t_physical_tile_type_ptr, size_t> grid_resources;
760760
for (int layer_num = 0; layer_num < grid.get_num_layers(); ++layer_num) {

vpr/src/base/SetupGrid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ DeviceGrid create_device_grid(std::string layout_name, const std::vector<t_grid_
2727
* Calculate the device utilization (i.e. fraction of used grid tiles)
2828
* foor the specified grid and resource requirements
2929
*/
30-
float calculate_device_utilization(const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t> instance_counts);
30+
float calculate_device_utilization(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts);
3131

3232
/**
3333
* @brief Returns the effective size of the device

vpr/src/place/move_generator.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ struct MoveOutcomeStats {
2323
/**
2424
* @brief A Struct to hold statistics about the different move types
2525
*
26-
* blk_type_moves: the block type index of each proposed move (e.g. [0..NUM_PL_MOVE_TYPES * (agent_available_types.size()-1)])
27-
* accepted_moves: the number of accepted moves of each move and block type (e.g. [0..NUM_PL_MOVE_TYPES * (agent_available_types.size()-1)] )
28-
* rejected_moves: the number of rejected moves of each move and block type (e.g. [0..NUM_PL_MOVE_TYPES * (agent_available_types.size()-1)] )
26+
* blk_type_moves: the block type index of each proposed move (e.g. [0..NUM_PL_MOVE_TYPES][agent_available_types.size()-1)])
27+
* accepted_moves: the number of accepted moves of each move and block type (e.g. [0..NUM_PL_MOVE_TYPES][agent_available_types.size()-1)] )
28+
* rejected_moves: the number of rejected moves of each move and block type (e.g. [0..NUM_PL_MOVE_TYPES][agent_available_types.size()-1)] )
2929
*
3030
*/
3131
struct MoveTypeStat {
32-
std::vector<int> blk_type_moves;
33-
std::vector<int> accepted_moves;
34-
std::vector<int> rejected_moves;
32+
vtr::NdMatrix<int, 2> blk_type_moves;
33+
vtr::NdMatrix<int, 2> accepted_moves;
34+
vtr::NdMatrix<int, 2> rejected_moves;
3535
};
3636

3737
/**

vpr/src/place/place.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,7 @@ static void print_resources_utilization();
543543

544544
static void print_placement_swaps_stats(const t_annealing_state& state);
545545

546-
static void print_placement_move_types_stats(
547-
const MoveTypeStat& move_type_stat);
546+
static void print_placement_move_types_stats(const MoveTypeStat& move_type_stat);
548547

549548
/*****************************************************************************/
550549
void try_place(const Netlist<>& net_list,
@@ -936,9 +935,9 @@ void try_place(const Netlist<>& net_list,
936935

937936
//allocate move type statistics vectors
938937
MoveTypeStat move_type_stat;
939-
move_type_stat.blk_type_moves.resize(device_ctx.logical_block_types.size() * (int)e_move_type::NUMBER_OF_AUTO_MOVES, 0);
940-
move_type_stat.accepted_moves.resize(device_ctx.logical_block_types.size() * (int)e_move_type::NUMBER_OF_AUTO_MOVES, 0);
941-
move_type_stat.rejected_moves.resize(device_ctx.logical_block_types.size() * (int)e_move_type::NUMBER_OF_AUTO_MOVES, 0);
938+
move_type_stat.blk_type_moves.resize({device_ctx.logical_block_types.size(), (int)e_move_type::NUMBER_OF_AUTO_MOVES}, 0);
939+
move_type_stat.accepted_moves.resize({device_ctx.logical_block_types.size(), (int)e_move_type::NUMBER_OF_AUTO_MOVES}, 0);
940+
move_type_stat.rejected_moves.resize({device_ctx.logical_block_types.size(), (int)e_move_type::NUMBER_OF_AUTO_MOVES}, 0);
942941

943942
/* Get the first range limiter */
944943
first_rlim = (float)max(device_ctx.grid.width() - 1,
@@ -1725,7 +1724,7 @@ static e_move_result try_swap(const t_annealing_state* state,
17251724
}
17261725

17271726
if (proposed_action.logical_blk_type_index != -1) { //if the agent proposed the block type, then collect the block type stat
1728-
++move_type_stat.blk_type_moves[(proposed_action.logical_blk_type_index * (int)e_move_type::NUMBER_OF_AUTO_MOVES) + (int)proposed_action.move_type];
1727+
++move_type_stat.blk_type_moves[proposed_action.logical_blk_type_index][(int)proposed_action.move_type];
17291728
}
17301729
LOG_MOVE_STATS_PROPOSED(t, blocks_affected);
17311730

@@ -1876,7 +1875,7 @@ static e_move_result try_swap(const t_annealing_state* state,
18761875
commit_move_blocks(blocks_affected);
18771876

18781877
if (proposed_action.logical_blk_type_index != -1) { //if the agent proposed the block type, then collect the block type stat
1879-
++move_type_stat.accepted_moves[(proposed_action.logical_blk_type_index * (int)e_move_type::NUMBER_OF_AUTO_MOVES) + (int)proposed_action.move_type];
1878+
++move_type_stat.accepted_moves[proposed_action.logical_blk_type_index][(int)proposed_action.move_type];
18801879
}
18811880
if (noc_opts.noc) {
18821881
commit_noc_costs();
@@ -1927,7 +1926,7 @@ static e_move_result try_swap(const t_annealing_state* state,
19271926
}
19281927

19291928
if (proposed_action.logical_blk_type_index != -1) { //if the agent proposed the block type, then collect the block type stat
1930-
++move_type_stat.rejected_moves[(proposed_action.logical_blk_type_index * (int)e_move_type::NUMBER_OF_AUTO_MOVES) + (int)proposed_action.move_type];
1929+
++move_type_stat.rejected_moves[proposed_action.logical_blk_type_index][(int)proposed_action.move_type];
19311930
}
19321931
/* Revert the traffic flow routes within the NoC*/
19331932
if (noc_opts.noc) {
@@ -4350,10 +4349,7 @@ static void print_placement_swaps_stats(const t_annealing_state& state) {
43504349
num_swap_aborted, 100 * abort_rate);
43514350
}
43524351

4353-
static void print_placement_move_types_stats(
4354-
const MoveTypeStat& move_type_stat) {
4355-
float moves, accepted, rejected, aborted;
4356-
4352+
static void print_placement_move_types_stats(const MoveTypeStat& move_type_stat) {
43574353
VTR_LOG("\n\nPlacement perturbation distribution by block and move type: \n");
43584354

43594355
VTR_LOG(
@@ -4363,11 +4359,12 @@ static void print_placement_move_types_stats(
43634359
VTR_LOG(
43644360
"------------------ ----------------- ---------------- ---------------- --------------- ------------ \n");
43654361

4366-
float total_moves = 0;
4367-
for (int blk_type_move : move_type_stat.blk_type_moves) {
4368-
total_moves += blk_type_move;
4362+
int total_moves = 0;
4363+
for (size_t i = 0; i < move_type_stat.blk_type_moves.size(); ++i) {
4364+
total_moves += move_type_stat.blk_type_moves.get(i);
43694365
}
43704366

4367+
43714368
auto& device_ctx = g_vpr_ctx.device();
43724369
auto& cluster_ctx = g_vpr_ctx.clustering();
43734370
int count = 0;
@@ -4381,24 +4378,23 @@ static void print_placement_move_types_stats(
43814378
}
43824379

43834380
count = 0;
4384-
43854381
for (int imove = 0; imove < num_of_avail_moves; imove++) {
43864382
const auto& move_name = move_type_to_string(e_move_type(imove));
4387-
moves = move_type_stat.blk_type_moves[itype.index * num_of_avail_moves + imove];
4383+
int moves = move_type_stat.blk_type_moves[itype.index][imove];
43884384
if (moves != 0) {
4389-
accepted = move_type_stat.accepted_moves[itype.index * num_of_avail_moves + imove];
4390-
rejected = move_type_stat.rejected_moves[itype.index * num_of_avail_moves + imove];
4391-
aborted = moves - (accepted + rejected);
4385+
int accepted = move_type_stat.accepted_moves[itype.index][imove];
4386+
int rejected = move_type_stat.rejected_moves[itype.index][imove];
4387+
int aborted = moves - (accepted + rejected);
43924388
if (count == 0) {
43934389
VTR_LOG("%-18.20s", itype.name);
43944390
} else {
43954391
VTR_LOG(" ");
43964392
}
43974393
VTR_LOG(
43984394
" %-22.20s %-16.2f %-15.2f %-14.2f %-13.2f\n",
4399-
move_name.c_str(), 100 * moves / total_moves,
4400-
100 * accepted / moves, 100 * rejected / moves,
4401-
100 * aborted / moves);
4395+
move_name.c_str(), 100.0f * (float)moves / (float)total_moves,
4396+
100.0f * (float)accepted / (float)moves, 100.0f * (float)rejected / (float)moves,
4397+
100.0f * (float)aborted / (float)moves);
44024398
}
44034399
count++;
44044400
}

0 commit comments

Comments
 (0)