Skip to content

Commit 4896984

Browse files
Comment some functions and data structures
1 parent 0827d99 commit 4896984

File tree

3 files changed

+118
-15
lines changed

3 files changed

+118
-15
lines changed

vpr/src/place/noc_place_utils.cpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ static vtr::vector<NocTrafficFlowId, TrafficFlowPlaceCost> traffic_flow_costs, p
88
/* Keeps track of traffic flows that have been updated at each attempted placement move*/
99
static std::vector<NocTrafficFlowId> affected_traffic_flows;
1010

11+
/* Proposed and actual congestion cost of a NoC link used for each move assessment */
1112
static vtr::vector<NocLinkId , double> link_congestion_costs, proposed_link_congestion_costs;
1213

14+
/* Keeps track of NoC links whose bandwidth usage have been updated at each attempted placement move*/
1315
static std::unordered_set<NocLinkId> affected_noc_links;
1416
/*********************************************************** *****************************/
1517

@@ -23,9 +25,21 @@ static std::unordered_set<NocLinkId> affected_noc_links;
2325
* False if there are no NoC routers in the netlist or the
2426
* selected NoC router is fixed/
2527
*/
26-
static bool select_random_router_cluster(ClusterBlockId& b_from, t_pl_loc& from, t_logical_block_type_ptr& cluster_from_type);
28+
static bool select_random_router_cluster(ClusterBlockId& b_from,
29+
t_pl_loc& from,
30+
t_logical_block_type_ptr& cluster_from_type);
2731

28-
static std::vector<NocLinkId> find_affected_links_by_flow_reroute(std::vector<NocLinkId>& prev_links, std::vector<NocLinkId>& curr_links);
32+
/**
33+
* @brief Given two traffic flow routes, finds links that appear
34+
* only in one route.
35+
*
36+
* @param prev_links Previous route before re-routing the traffic flow
37+
* @param curr_links Current route after re-routing the traffic flow
38+
*
39+
* @return Unique links that appear only in one of the given routes
40+
*/
41+
static std::vector<NocLinkId> find_affected_links_by_flow_reroute(std::vector<NocLinkId>& prev_links,
42+
std::vector<NocLinkId>& curr_links);
2943

3044
void initial_noc_routing(void) {
3145
// need to update the link usages within after routing all the traffic flows
@@ -43,7 +57,7 @@ void initial_noc_routing(void) {
4357
const t_noc_traffic_flow& curr_traffic_flow = noc_traffic_flows_storage.get_single_noc_traffic_flow(traffic_flow_id);
4458

4559
// update the traffic flow route based on where the router cluster blocks are placed
46-
std::vector<NocLinkId>& curr_traffic_flow_route = route_traffic_flow(traffic_flow_id, noc_ctx.noc_model, noc_traffic_flows_storage, *noc_ctx.noc_flows_router);
60+
std::vector<NocLinkId>& curr_traffic_flow_route = route_traffic_flow(traffic_flow_id, noc_ctx.noc_model,noc_traffic_flows_storage, *noc_ctx.noc_flows_router);
4761

4862
// update the links used in the found traffic flow route, links' bandwidth should be incremented since the traffic flow is routed
4963
update_traffic_flow_link_usage(curr_traffic_flow_route, noc_ctx.noc_model, 1, curr_traffic_flow.traffic_flow_bandwidth);
@@ -70,7 +84,9 @@ void reinitialize_noc_routing(const t_noc_opts& noc_opts, t_placer_costs& costs)
7084
costs.noc_congestion_cost = comp_noc_congestion_cost(noc_opts);
7185
}
7286

73-
void find_affected_noc_routers_and_update_noc_costs(const t_pl_blocks_to_be_moved& blocks_affected, NocCostTerms& delta_c, const t_noc_opts& noc_opts) {
87+
void find_affected_noc_routers_and_update_noc_costs(const t_pl_blocks_to_be_moved& blocks_affected,
88+
NocCostTerms& delta_c,
89+
const t_noc_opts& noc_opts) {
7490
VTR_ASSERT_SAFE(delta_c.aggregate_bandwidth == 0.);
7591
VTR_ASSERT_SAFE(delta_c.latency == 0.);
7692
VTR_ASSERT_SAFE(delta_c.congestion == 0.);
@@ -155,7 +171,10 @@ void commit_noc_costs() {
155171
return;
156172
}
157173

158-
std::vector<NocLinkId>& route_traffic_flow(NocTrafficFlowId traffic_flow_id, const NocStorage& noc_model, NocTrafficFlows& noc_traffic_flows_storage, NocRouting& noc_flows_router) {
174+
std::vector<NocLinkId>& route_traffic_flow(NocTrafficFlowId traffic_flow_id,
175+
const NocStorage& noc_model,
176+
NocTrafficFlows& noc_traffic_flows_storage,
177+
NocRouting& noc_flows_router) {
159178
// provides the positions where the affected blocks have moved to
160179
auto& place_ctx = g_vpr_ctx.placement();
161180

@@ -193,7 +212,11 @@ void update_traffic_flow_link_usage(const std::vector<NocLinkId>& traffic_flow_r
193212
return;
194213
}
195214

196-
void re_route_associated_traffic_flows(ClusterBlockId moved_block_router_id, NocTrafficFlows& noc_traffic_flows_storage, NocStorage& noc_model, NocRouting& noc_flows_router, std::unordered_set<NocTrafficFlowId>& updated_traffic_flows) {
215+
void re_route_associated_traffic_flows(ClusterBlockId moved_block_router_id,
216+
NocTrafficFlows& noc_traffic_flows_storage,
217+
NocStorage& noc_model,
218+
NocRouting& noc_flows_router,
219+
std::unordered_set<NocTrafficFlowId>& updated_traffic_flows) {
197220
// get all the associated traffic flows for the logical router cluster block
198221
const std::vector<NocTrafficFlowId>* assoc_traffic_flows = noc_traffic_flows_storage.get_traffic_flows_associated_to_router_block(moved_block_router_id);
199222

@@ -272,7 +295,10 @@ void revert_noc_traffic_flow_routes(const t_pl_blocks_to_be_moved& blocks_affect
272295
return;
273296
}
274297

275-
void re_route_traffic_flow(NocTrafficFlowId traffic_flow_id, NocTrafficFlows& noc_traffic_flows_storage, NocStorage& noc_model, NocRouting& noc_flows_router) {
298+
void re_route_traffic_flow(NocTrafficFlowId traffic_flow_id,
299+
NocTrafficFlows& noc_traffic_flows_storage,
300+
NocStorage& noc_model,
301+
NocRouting& noc_flows_router) {
276302
// get the current traffic flow info
277303
const t_noc_traffic_flow& curr_traffic_flow = noc_traffic_flows_storage.get_single_noc_traffic_flow(traffic_flow_id);
278304

@@ -798,7 +824,8 @@ void write_noc_placement_file(const std::string& file_name) {
798824
return;
799825
}
800826

801-
static std::vector<NocLinkId> find_affected_links_by_flow_reroute(std::vector<NocLinkId>& prev_links, std::vector<NocLinkId>& curr_links) {
827+
static std::vector<NocLinkId> find_affected_links_by_flow_reroute(std::vector<NocLinkId>& prev_links,
828+
std::vector<NocLinkId>& curr_links) {
802829
// Sort both link containers
803830
std::sort(prev_links.begin(), prev_links.end());
804831
std::sort(curr_links.begin(), curr_links.end());

vpr/src/place/noc_place_utils.h

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ void reinitialize_noc_routing(const t_noc_opts& noc_opts, t_placer_costs& costs)
107107
* NoC latency cost caused by a placer move is stored
108108
* here.
109109
*/
110-
void find_affected_noc_routers_and_update_noc_costs(const t_pl_blocks_to_be_moved& blocks_affected, NocCostTerms& delta_c, const t_noc_opts& noc_opts);
110+
void find_affected_noc_routers_and_update_noc_costs(const t_pl_blocks_to_be_moved& blocks_affected,
111+
NocCostTerms& delta_c,
112+
const t_noc_opts& noc_opts);
111113

112114
/**
113115
* @brief Updates static datastructures found in 'noc_place_utils.cpp'
@@ -154,7 +156,10 @@ void commit_noc_costs();
154156
* flows within the NoC.
155157
* @return std::vector<NocLinkId>& The found route for the traffic flow.
156158
*/
157-
std::vector<NocLinkId>& route_traffic_flow(NocTrafficFlowId traffic_flow_id, const NocStorage& noc_model, NocTrafficFlows& noc_traffic_flows_storage, NocRouting& noc_flows_router);
159+
std::vector<NocLinkId>& route_traffic_flow(NocTrafficFlowId traffic_flow_id,
160+
const NocStorage& noc_model,
161+
NocTrafficFlows& noc_traffic_flows_storage,
162+
NocRouting& noc_flows_router);
158163

159164
/**
160165
* @brief Updates the bandwidth usages of links found in a routed traffic flow.
@@ -202,7 +207,10 @@ void update_traffic_flow_link_usage(const std::vector<NocLinkId>& traffic_flow_r
202207
* @param updated_traffic_flows Keeps track of traffic flows that have been
203208
* re-routed. Used to prevent re-routing the same traffic flow multiple times.
204209
*/
205-
void re_route_associated_traffic_flows(ClusterBlockId moved_router_block_id, NocTrafficFlows& noc_traffic_flows_storage, NocStorage& noc_model, NocRouting& noc_flows_router, std::unordered_set<NocTrafficFlowId>& updated_traffic_flows);
210+
void re_route_associated_traffic_flows(ClusterBlockId moved_router_block_id,
211+
NocTrafficFlows& noc_traffic_flows_storage,
212+
NocStorage& noc_model, NocRouting& noc_flows_router,
213+
std::unordered_set<NocTrafficFlowId>& updated_traffic_flows);
206214

207215
/**
208216
* @brief Used to re-route all the traffic flows associated to logical
@@ -233,7 +241,10 @@ void revert_noc_traffic_flow_routes(const t_pl_blocks_to_be_moved& blocks_affect
233241
* @param noc_flows_router The packet routing algorithm used to route traffic
234242
* flows within the NoC.
235243
*/
236-
void re_route_traffic_flow(NocTrafficFlowId traffic_flow_id, NocTrafficFlows& noc_traffic_flows_storage, NocStorage& noc_model, NocRouting& noc_flows_router);
244+
void re_route_traffic_flow(NocTrafficFlowId traffic_flow_id,
245+
NocTrafficFlows& noc_traffic_flows_storage,
246+
NocStorage& noc_model,
247+
NocRouting& noc_flows_router);
237248

238249
/**
239250
* @brief Recompute the NoC costs (aggregate bandwidth and latency) by
@@ -369,13 +380,44 @@ double calculate_traffic_flow_aggregate_bandwidth_cost(const std::vector<NocLink
369380
* @param traffic_flow_info Contains the traffic flow priority.
370381
* @param noc_opts Contains the user provided weightings of the traffic flow
371382
* latency and its constraint parameters for the cost calculation.
372-
* @return THe computed latency for the provided traffic flow
383+
* @return The computed latency for the provided traffic flow
373384
*/
374-
double calculate_traffic_flow_latency_cost(const std::vector<NocLinkId>& traffic_flow_route, const NocStorage& noc_model, const t_noc_traffic_flow& traffic_flow_info, const t_noc_opts& noc_opts);
385+
double calculate_traffic_flow_latency_cost(const std::vector<NocLinkId>& traffic_flow_route,
386+
const NocStorage& noc_model,
387+
const t_noc_traffic_flow& traffic_flow_info,
388+
const t_noc_opts& noc_opts);
375389

390+
/**
391+
* @brief Determines the congestion cost a NoC link. The cost
392+
* is calculating by measuring how much the current bandwidth
393+
* going through the link exceeds the link's bandwidth capacity.
394+
*
395+
* @param link The NoC link for which the congestion cost is
396+
* to be computed
397+
* @param noc_opts Contains the user provided weighting factor to
398+
* specify the importance of congestion costs compared to other
399+
* NoC-related cost terms.
400+
* @return The computed congestion cost for the given NoC link.
401+
*/
376402
double calculate_link_congestion_cost(const NocLink& link, const t_noc_opts& noc_opts);
377403

378-
double calculate_noc_cost(const NocCostTerms& cost_terms, const t_placer_costs& norm_factors, const t_noc_opts& noc_opts);
404+
/**
405+
* @brief Computes a weighted average of NoC cost term to determine
406+
* NoC's contribution to the total placement cost.
407+
*
408+
* @param cost_terms Different NoC-related cost terms.
409+
* @param norm_factors Normalization factors used to scale
410+
* different NoC-related cost term so that they have similar
411+
* ranges.
412+
* @param noc_opts Contains noc_placement_weighting factor
413+
* to specify the contribution of NoC-related cost to the
414+
* total placement cost.
415+
* @return The computed total NoC-related contribution to the
416+
* total placement cost.
417+
*/
418+
double calculate_noc_cost(const NocCostTerms& cost_terms,
419+
const t_placer_costs& norm_factors,
420+
const t_noc_opts& noc_opts);
379421

380422
/**
381423
* @brief Goes through all the traffic flows and determines whether the
@@ -385,12 +427,37 @@ double calculate_noc_cost(const NocCostTerms& cost_terms, const t_placer_costs&
385427
*/
386428
int get_number_of_traffic_flows_with_latency_cons_met(void);
387429

430+
/**
431+
* @brief Goes through all NoC links and counts the congested ones.
432+
*
433+
* @return The total number of congested NoC links.
434+
*/
388435
int get_number_of_congested_noc_links(void);
389436

437+
/**
438+
* @brief Goes through all NoC links and determines whether they
439+
* are congested or not. Then adds up the congestion ratio of all
440+
* congested links.
441+
*
442+
* @return The total congestion ratio
443+
*/
390444
double get_total_congestion_bandwidth_ratio(void);
391445

446+
/**
447+
* @brief Goes through all NoC links and determines whether they
448+
* are congested or not. Then finds n links that are most congested.
449+
*
450+
* @return n links with highest congestion ratio
451+
*/
392452
std::vector<NocLink> get_top_n_congested_links(int n);
393453

454+
455+
/**
456+
* @brief Goes through all NoC links and determines whether they
457+
* are congested or not. Then finds n links that are most congested.
458+
*
459+
* @return n highest congestion ratios
460+
*/
394461
std::vector<double> get_top_n_congestion_ratios(int n);
395462

396463
/**

vpr/src/place/place_util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
// in NocCostTerms constructor
1717
class t_placer_costs;
1818

19+
/**
20+
* @brief Data structure that stores different cost terms for NoC placement.
21+
*
22+
* @param aggregate_bandwidth The total used bandwidth used in the NoC.
23+
* @param latency A weighted average between aggregate latency and
24+
* latency overruns.
25+
* @param congestion The sum of congestion divided by available bandwidth
26+
* over all NoC links.
27+
*/
1928
struct NocCostTerms {
2029
public:
2130
NocCostTerms() = delete;

0 commit comments

Comments
 (0)