Skip to content

Commit 304de90

Browse files
Update test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_costs, test_recompute_noc_costs to check congestion
1 parent 5eed8ae commit 304de90

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

vpr/test/test_noc_place_utils.cpp

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,17 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
507507
t_noc_opts noc_opts;
508508
noc_opts.noc_latency_constraints_weighting = dist_3(double_engine);
509509
noc_opts.noc_latency_weighting = dist_3(double_engine);
510+
noc_opts.noc_congestion_weighting = dist_3(double_engine);
510511

511512
// setting the NoC parameters
512513
noc_ctx.noc_model.set_noc_link_latency(1);
513514
noc_ctx.noc_model.set_noc_router_latency(1);
514515
noc_ctx.noc_model.set_noc_link_bandwidth(1);
516+
515517
// needs to be the same as above
516518
double router_latency = noc_ctx.noc_model.get_noc_router_latency();
517519
double link_latency = noc_ctx.noc_model.get_noc_link_latency();
520+
double link_bandwidth = noc_ctx.noc_model.get_noc_link_bandwidth();
518521

519522
// keeps track of which hard router each cluster block is placed
520523
vtr::vector<ClusterBlockId, NocRouterId> router_where_cluster_is_placed;
@@ -622,7 +625,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
622625
noc_ctx.noc_flows_router = std::make_unique<XYRouting>();
623626

624627
// create a local routing algorithm for the unit test
625-
NocRouting* routing_algorithm = new XYRouting();
628+
auto routing_algorithm = std::make_unique<XYRouting>();
626629

627630
// store the traffic flow routes found
628631
vtr::vector<NocTrafficFlowId, std::vector<NocLinkId>> golden_traffic_flow_routes;
@@ -632,6 +635,9 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
632635
vtr::vector<NocTrafficFlowId, double> golden_traffic_flow_latency_costs;
633636
golden_traffic_flow_bandwidth_costs.resize(noc_ctx.noc_traffic_flows_storage.get_number_of_traffic_flows());
634637
golden_traffic_flow_latency_costs.resize(noc_ctx.noc_traffic_flows_storage.get_number_of_traffic_flows());
638+
// store link congestion costs
639+
vtr::vector<NocLinkId, double> golden_link_congestion_costs;
640+
golden_link_congestion_costs.resize(noc_ctx.noc_model.get_number_of_noc_links());
635641

636642
// stores the change in bandwidth and latency costs from the test function
637643
NocCostTerms test_noc_costs{0.0, 0.0, 0.0};
@@ -680,12 +686,20 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
680686
test_noc_costs.latency += golden_traffic_flow_latency_costs[(NocTrafficFlowId)traffic_flow_number];
681687
}
682688

689+
// initialize golden congestion cost for all links
690+
for (const auto& link : noc_ctx.noc_model.get_noc_links()) {
691+
auto link_id = link.get_link_id();
692+
golden_link_congestion_costs[link_id] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link_id] - link_bandwidth, 0.0);
693+
test_noc_costs.congestion += golden_link_congestion_costs[link_id];
694+
}
695+
683696
// initialize noc placement structs
684697
allocate_and_load_noc_placement_structs();
685698

686-
// We need to run these functions as they initialize local variables needed to run the test function within this unit test. we assume thi is correct
699+
// We need to run these functions as they initialize local variables needed to run the test function within this unit test. we assume this is correct
687700
comp_noc_aggregate_bandwidth_cost();
688701
comp_noc_latency_cost(noc_opts);
702+
comp_noc_congestion_cost(noc_opts);
689703

690704
// datastructure that keeps track of moved blocks during placement
691705
t_pl_blocks_to_be_moved blocks_affected(NUM_OF_LOGICAL_ROUTER_BLOCKS_NOC_PLACE_UTILS_TEST);
@@ -753,6 +767,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
753767
// go through the current traffic flow and reduce the bandwidths of the links
754768
for (auto& link : golden_traffic_flow_routes[traffic_flow]) {
755769
golden_link_bandwidths[link] -= curr_traffic_flow.traffic_flow_bandwidth;
770+
golden_link_congestion_costs[link] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link] - link_bandwidth, 0.0);
756771
}
757772

758773
// re-route the traffic flow
@@ -761,6 +776,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
761776
// go through the current traffic flow and increase the bandwidths of the links
762777
for (auto& link : golden_traffic_flow_routes[traffic_flow]) {
763778
golden_link_bandwidths[link] += curr_traffic_flow.traffic_flow_bandwidth;
779+
golden_link_congestion_costs[link] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link] - link_bandwidth, 0.0);
764780
}
765781

766782
// update the costs now
@@ -785,6 +801,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
785801
// go through the current traffic flow and reduce the bandwidths of the links
786802
for (auto& link : golden_traffic_flow_routes[traffic_flow]) {
787803
golden_link_bandwidths[link] -= curr_traffic_flow.traffic_flow_bandwidth;
804+
golden_link_congestion_costs[link] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link] - link_bandwidth, 0.0);
788805
}
789806

790807
// re-route the traffic flow
@@ -793,6 +810,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
793810
// go through the current traffic flow and increase the bandwidths of the links
794811
for (auto& link : golden_traffic_flow_routes[traffic_flow]) {
795812
golden_link_bandwidths[link] += curr_traffic_flow.traffic_flow_bandwidth;
813+
golden_link_congestion_costs[link] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link] - link_bandwidth, 0.0);
796814
}
797815

798816
// update the costs now
@@ -813,9 +831,10 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
813831
// call the test function
814832
find_affected_noc_routers_and_update_noc_costs(blocks_affected, delta_cost, noc_opts);
815833

816-
// update the test total noc bandwidth and latency costs based on the cost changes found by the test functions
834+
// update the test total noc bandwidth, latency, and congestion costs based on the cost changes found by the test functions
817835
test_noc_costs.aggregate_bandwidth += delta_cost.aggregate_bandwidth;
818836
test_noc_costs.latency += delta_cost.latency;
837+
test_noc_costs.congestion += delta_cost.congestion;
819838

820839
// need this function to update the local datastructures that store all the traffic flow costs
821840
commit_noc_costs();
@@ -890,6 +909,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
890909
// go through the current traffic flow and reduce the bandwidths of the links
891910
for (auto& link : golden_traffic_flow_routes[traffic_flow]) {
892911
golden_link_bandwidths[link] -= curr_traffic_flow.traffic_flow_bandwidth;
912+
golden_link_congestion_costs[link] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link] - link_bandwidth, 0.0);
893913
}
894914

895915
// re-route the traffic flow
@@ -898,6 +918,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
898918
// go through the current traffic flow and increase the bandwidths of the links
899919
for (auto& link : golden_traffic_flow_routes[traffic_flow]) {
900920
golden_link_bandwidths[link] += curr_traffic_flow.traffic_flow_bandwidth;
921+
golden_link_congestion_costs[link] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link] - link_bandwidth, 0.0);
901922
}
902923

903924
// update the costs now
@@ -918,6 +939,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
918939
// go through the current traffic flow and reduce the bandwidths of the links
919940
for (auto& link : golden_traffic_flow_routes[traffic_flow]) {
920941
golden_link_bandwidths[link] -= curr_traffic_flow.traffic_flow_bandwidth;
942+
golden_link_congestion_costs[link] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link] - link_bandwidth, 0.0);
921943
}
922944

923945
// re-route the traffic flow
@@ -926,6 +948,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
926948
// go through the current traffic flow and increase the bandwidths of the links
927949
for (auto& link : golden_traffic_flow_routes[traffic_flow]) {
928950
golden_link_bandwidths[link] += curr_traffic_flow.traffic_flow_bandwidth;
951+
golden_link_congestion_costs[link] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link] - link_bandwidth, 0.0);
929952
}
930953

931954
// update the costs now
@@ -946,6 +969,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
946969
// update the test total noc bandwidth and latency costs based on the cost changes found by the test functions
947970
test_noc_costs.aggregate_bandwidth += delta_cost.aggregate_bandwidth;
948971
test_noc_costs.latency += delta_cost.latency;
972+
test_noc_costs.congestion += delta_cost.congestion;
949973

950974
// need this function to update the local datastructures that store all the traffic flow costs
951975
commit_noc_costs();
@@ -1008,6 +1032,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
10081032
// go through the current traffic flow and reduce the bandwidths of the links
10091033
for (auto& link : golden_traffic_flow_routes[traffic_flow]) {
10101034
golden_link_bandwidths[link] -= curr_traffic_flow.traffic_flow_bandwidth;
1035+
golden_link_congestion_costs[link] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link] - link_bandwidth, 0.0);
10111036
}
10121037

10131038
// re-route the traffic flow
@@ -1016,6 +1041,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
10161041
// go through the current traffic flow and increase the bandwidths of the links
10171042
for (auto& link : golden_traffic_flow_routes[traffic_flow]) {
10181043
golden_link_bandwidths[link] += curr_traffic_flow.traffic_flow_bandwidth;
1044+
golden_link_congestion_costs[link] = noc_opts.noc_congestion_weighting * std::max(golden_link_bandwidths[link] - link_bandwidth, 0.0);
10191045
}
10201046

10211047
// update the costs now
@@ -1037,6 +1063,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
10371063
// update the test total noc bandwidth and latency costs based on the cost changes found by the test functions
10381064
test_noc_costs.aggregate_bandwidth += delta_cost.aggregate_bandwidth;
10391065
test_noc_costs.latency += delta_cost.latency;
1066+
test_noc_costs.congestion += delta_cost.congestion;
10401067

10411068
// need this function to update the local datastructures that store all the traffic flow costs
10421069
commit_noc_costs();
@@ -1100,6 +1127,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
11001127
// update the test total noc bandwidth and latency costs based on the cost changes found by the test functions
11011128
test_noc_costs.aggregate_bandwidth += delta_cost.aggregate_bandwidth;
11021129
test_noc_costs.latency += delta_cost.latency;
1130+
test_noc_costs.congestion += delta_cost.congestion;
11031131

11041132
// need this function to update the local datastructures that store all the traffic flow costs
11051133
commit_noc_costs();
@@ -1112,43 +1140,53 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
11121140
for (int link_number = 0; link_number < number_of_links; link_number++) {
11131141
NocLinkId current_link_id = (NocLinkId)link_number;
11141142
const NocLink& current_link = noc_ctx.noc_model.get_single_noc_link(current_link_id);
1143+
double golden_link_bandwidth = golden_link_bandwidths[current_link_id];
1144+
double golden_link_congested_bandwidth = std::max(golden_link_bandwidths[current_link_id] - link_bandwidth, 0.0);
1145+
double golden_link_congested_bandwidth_ratio = golden_link_congested_bandwidth / link_bandwidth;
11151146

1116-
REQUIRE(golden_link_bandwidths[current_link_id] == current_link.get_bandwidth_usage());
1147+
REQUIRE(golden_link_bandwidth == current_link.get_bandwidth_usage());
1148+
REQUIRE(golden_link_congested_bandwidth == current_link.get_congested_bandwidth());
1149+
REQUIRE(golden_link_congested_bandwidth_ratio == current_link.get_congested_bandwidth_ratio());
11171150
}
11181151

1119-
// now find the total expected noc aggregate bandwidth and latency cost
1152+
// now find the total expected noc aggregate bandwidth, latency, and congestion cost
11201153
double golden_total_noc_aggr_bandwidth_cost = 0.;
11211154
double golden_total_noc_latency_cost = 0.;
1155+
double golden_total_noc_congestion_cost = 0.;
11221156

11231157
for (int traffic_flow_number = 0; traffic_flow_number < number_of_created_traffic_flows; traffic_flow_number++) {
11241158
golden_total_noc_aggr_bandwidth_cost += golden_traffic_flow_bandwidth_costs[(NocTrafficFlowId)traffic_flow_number];
11251159
golden_total_noc_latency_cost += golden_traffic_flow_latency_costs[(NocTrafficFlowId)traffic_flow_number];
11261160
}
11271161

1162+
golden_total_noc_congestion_cost = std::accumulate(golden_link_congestion_costs.begin(), golden_link_congestion_costs.end(), 0.0);
1163+
11281164
// now check whether the expected noc costs that we manually calculated above match the noc costs found through the test function (we allow for a tolerance of difference)
11291165
REQUIRE(vtr::isclose(golden_total_noc_aggr_bandwidth_cost, test_noc_costs.aggregate_bandwidth));
11301166
REQUIRE(vtr::isclose(golden_total_noc_latency_cost, test_noc_costs.latency));
1167+
std::cout << golden_total_noc_congestion_cost << " " << test_noc_costs.congestion << std::endl;
1168+
REQUIRE(vtr::isclose(golden_total_noc_congestion_cost, test_noc_costs.congestion));
11311169

11321170
// now test the recompute cost function //
11331171
// The recompute cost function just adds up all traffic flow costs, so it match the expected noc costs that we manually calculated above by summing up all the expected individual traffic flow costs. //
11341172

11351173
// start by resetting the test cost variables
11361174
test_noc_costs.aggregate_bandwidth = 0.;
11371175
test_noc_costs.latency = 0.;
1176+
test_noc_costs.congestion = 0.;
11381177

11391178
// now execute the test function
11401179
recompute_noc_costs(test_noc_costs);
11411180

11421181
// now verify
11431182
REQUIRE(vtr::isclose(golden_total_noc_aggr_bandwidth_cost, test_noc_costs.aggregate_bandwidth));
11441183
REQUIRE(vtr::isclose(golden_total_noc_latency_cost, test_noc_costs.latency));
1184+
REQUIRE(vtr::isclose(golden_total_noc_congestion_cost, test_noc_costs.congestion));
11451185

11461186
// delete local datastructures
11471187
free_noc_placement_structs();
1148-
1149-
// need to delete local noc routing algorithm
1150-
delete routing_algorithm;
11511188
}
1189+
11521190
TEST_CASE("test_update_noc_normalization_factors", "[noc_place_utils]") {
11531191
// creating local parameters needed for the test
11541192
t_placer_costs costs;

0 commit comments

Comments
 (0)