@@ -507,14 +507,17 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
507
507
t_noc_opts noc_opts;
508
508
noc_opts.noc_latency_constraints_weighting = dist_3 (double_engine);
509
509
noc_opts.noc_latency_weighting = dist_3 (double_engine);
510
+ noc_opts.noc_congestion_weighting = dist_3 (double_engine);
510
511
511
512
// setting the NoC parameters
512
513
noc_ctx.noc_model .set_noc_link_latency (1 );
513
514
noc_ctx.noc_model .set_noc_router_latency (1 );
514
515
noc_ctx.noc_model .set_noc_link_bandwidth (1 );
516
+
515
517
// needs to be the same as above
516
518
double router_latency = noc_ctx.noc_model .get_noc_router_latency ();
517
519
double link_latency = noc_ctx.noc_model .get_noc_link_latency ();
520
+ double link_bandwidth = noc_ctx.noc_model .get_noc_link_bandwidth ();
518
521
519
522
// keeps track of which hard router each cluster block is placed
520
523
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_
622
625
noc_ctx.noc_flows_router = std::make_unique<XYRouting>();
623
626
624
627
// create a local routing algorithm for the unit test
625
- NocRouting* routing_algorithm = new XYRouting ();
628
+ auto routing_algorithm = std::make_unique< XYRouting> ();
626
629
627
630
// store the traffic flow routes found
628
631
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_
632
635
vtr::vector<NocTrafficFlowId, double > golden_traffic_flow_latency_costs;
633
636
golden_traffic_flow_bandwidth_costs.resize (noc_ctx.noc_traffic_flows_storage .get_number_of_traffic_flows ());
634
637
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 ());
635
641
636
642
// stores the change in bandwidth and latency costs from the test function
637
643
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_
680
686
test_noc_costs.latency += golden_traffic_flow_latency_costs[(NocTrafficFlowId)traffic_flow_number];
681
687
}
682
688
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
+
683
696
// initialize noc placement structs
684
697
allocate_and_load_noc_placement_structs ();
685
698
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
687
700
comp_noc_aggregate_bandwidth_cost ();
688
701
comp_noc_latency_cost (noc_opts);
702
+ comp_noc_congestion_cost (noc_opts);
689
703
690
704
// datastructure that keeps track of moved blocks during placement
691
705
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_
753
767
// go through the current traffic flow and reduce the bandwidths of the links
754
768
for (auto & link : golden_traffic_flow_routes[traffic_flow]) {
755
769
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 );
756
771
}
757
772
758
773
// re-route the traffic flow
@@ -761,6 +776,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
761
776
// go through the current traffic flow and increase the bandwidths of the links
762
777
for (auto & link : golden_traffic_flow_routes[traffic_flow]) {
763
778
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 );
764
780
}
765
781
766
782
// update the costs now
@@ -785,6 +801,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
785
801
// go through the current traffic flow and reduce the bandwidths of the links
786
802
for (auto & link : golden_traffic_flow_routes[traffic_flow]) {
787
803
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 );
788
805
}
789
806
790
807
// re-route the traffic flow
@@ -793,6 +810,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
793
810
// go through the current traffic flow and increase the bandwidths of the links
794
811
for (auto & link : golden_traffic_flow_routes[traffic_flow]) {
795
812
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 );
796
814
}
797
815
798
816
// update the costs now
@@ -813,9 +831,10 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
813
831
// call the test function
814
832
find_affected_noc_routers_and_update_noc_costs (blocks_affected, delta_cost, noc_opts);
815
833
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
817
835
test_noc_costs.aggregate_bandwidth += delta_cost.aggregate_bandwidth ;
818
836
test_noc_costs.latency += delta_cost.latency ;
837
+ test_noc_costs.congestion += delta_cost.congestion ;
819
838
820
839
// need this function to update the local datastructures that store all the traffic flow costs
821
840
commit_noc_costs ();
@@ -890,6 +909,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
890
909
// go through the current traffic flow and reduce the bandwidths of the links
891
910
for (auto & link : golden_traffic_flow_routes[traffic_flow]) {
892
911
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 );
893
913
}
894
914
895
915
// re-route the traffic flow
@@ -898,6 +918,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
898
918
// go through the current traffic flow and increase the bandwidths of the links
899
919
for (auto & link : golden_traffic_flow_routes[traffic_flow]) {
900
920
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 );
901
922
}
902
923
903
924
// update the costs now
@@ -918,6 +939,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
918
939
// go through the current traffic flow and reduce the bandwidths of the links
919
940
for (auto & link : golden_traffic_flow_routes[traffic_flow]) {
920
941
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 );
921
943
}
922
944
923
945
// re-route the traffic flow
@@ -926,6 +948,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
926
948
// go through the current traffic flow and increase the bandwidths of the links
927
949
for (auto & link : golden_traffic_flow_routes[traffic_flow]) {
928
950
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 );
929
952
}
930
953
931
954
// update the costs now
@@ -946,6 +969,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
946
969
// update the test total noc bandwidth and latency costs based on the cost changes found by the test functions
947
970
test_noc_costs.aggregate_bandwidth += delta_cost.aggregate_bandwidth ;
948
971
test_noc_costs.latency += delta_cost.latency ;
972
+ test_noc_costs.congestion += delta_cost.congestion ;
949
973
950
974
// need this function to update the local datastructures that store all the traffic flow costs
951
975
commit_noc_costs ();
@@ -1008,6 +1032,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
1008
1032
// go through the current traffic flow and reduce the bandwidths of the links
1009
1033
for (auto & link : golden_traffic_flow_routes[traffic_flow]) {
1010
1034
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 );
1011
1036
}
1012
1037
1013
1038
// re-route the traffic flow
@@ -1016,6 +1041,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
1016
1041
// go through the current traffic flow and increase the bandwidths of the links
1017
1042
for (auto & link : golden_traffic_flow_routes[traffic_flow]) {
1018
1043
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 );
1019
1045
}
1020
1046
1021
1047
// update the costs now
@@ -1037,6 +1063,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
1037
1063
// update the test total noc bandwidth and latency costs based on the cost changes found by the test functions
1038
1064
test_noc_costs.aggregate_bandwidth += delta_cost.aggregate_bandwidth ;
1039
1065
test_noc_costs.latency += delta_cost.latency ;
1066
+ test_noc_costs.congestion += delta_cost.congestion ;
1040
1067
1041
1068
// need this function to update the local datastructures that store all the traffic flow costs
1042
1069
commit_noc_costs ();
@@ -1100,6 +1127,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
1100
1127
// update the test total noc bandwidth and latency costs based on the cost changes found by the test functions
1101
1128
test_noc_costs.aggregate_bandwidth += delta_cost.aggregate_bandwidth ;
1102
1129
test_noc_costs.latency += delta_cost.latency ;
1130
+ test_noc_costs.congestion += delta_cost.congestion ;
1103
1131
1104
1132
// need this function to update the local datastructures that store all the traffic flow costs
1105
1133
commit_noc_costs ();
@@ -1112,43 +1140,53 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
1112
1140
for (int link_number = 0 ; link_number < number_of_links; link_number++) {
1113
1141
NocLinkId current_link_id = (NocLinkId)link_number;
1114
1142
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;
1115
1146
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 ());
1117
1150
}
1118
1151
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
1120
1153
double golden_total_noc_aggr_bandwidth_cost = 0 .;
1121
1154
double golden_total_noc_latency_cost = 0 .;
1155
+ double golden_total_noc_congestion_cost = 0 .;
1122
1156
1123
1157
for (int traffic_flow_number = 0 ; traffic_flow_number < number_of_created_traffic_flows; traffic_flow_number++) {
1124
1158
golden_total_noc_aggr_bandwidth_cost += golden_traffic_flow_bandwidth_costs[(NocTrafficFlowId)traffic_flow_number];
1125
1159
golden_total_noc_latency_cost += golden_traffic_flow_latency_costs[(NocTrafficFlowId)traffic_flow_number];
1126
1160
}
1127
1161
1162
+ golden_total_noc_congestion_cost = std::accumulate (golden_link_congestion_costs.begin (), golden_link_congestion_costs.end (), 0.0 );
1163
+
1128
1164
// 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)
1129
1165
REQUIRE (vtr::isclose (golden_total_noc_aggr_bandwidth_cost, test_noc_costs.aggregate_bandwidth ));
1130
1166
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 ));
1131
1169
1132
1170
// now test the recompute cost function //
1133
1171
// 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. //
1134
1172
1135
1173
// start by resetting the test cost variables
1136
1174
test_noc_costs.aggregate_bandwidth = 0 .;
1137
1175
test_noc_costs.latency = 0 .;
1176
+ test_noc_costs.congestion = 0 .;
1138
1177
1139
1178
// now execute the test function
1140
1179
recompute_noc_costs (test_noc_costs);
1141
1180
1142
1181
// now verify
1143
1182
REQUIRE (vtr::isclose (golden_total_noc_aggr_bandwidth_cost, test_noc_costs.aggregate_bandwidth ));
1144
1183
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 ));
1145
1185
1146
1186
// delete local datastructures
1147
1187
free_noc_placement_structs ();
1148
-
1149
- // need to delete local noc routing algorithm
1150
- delete routing_algorithm;
1151
1188
}
1189
+
1152
1190
TEST_CASE (" test_update_noc_normalization_factors" , " [noc_place_utils]" ) {
1153
1191
// creating local parameters needed for the test
1154
1192
t_placer_costs costs;
0 commit comments