|
4 | 4 | #include "move_utils.h"
|
5 | 5 | #include "place_timing_update.h"
|
6 | 6 | #include "noc_place_utils.h"
|
| 7 | +#include "vtr_math.h" |
7 | 8 |
|
8 | 9 | using std::max;
|
9 | 10 | using std::min;
|
@@ -2026,68 +2027,66 @@ void reset_move_nets(int num_nets_affected) {
|
2026 | 2027 | }
|
2027 | 2028 |
|
2028 | 2029 | void recompute_costs_from_scratch(const t_placer_opts& placer_opts,
|
2029 |
| - const t_noc_opts& noc_opts, |
2030 |
| - const PlaceDelayModel* delay_model, |
2031 |
| - const PlacerCriticalities* criticalities, |
2032 |
| - t_placer_costs* costs) { |
| 2030 | + const t_noc_opts& noc_opts, |
| 2031 | + const PlaceDelayModel* delay_model, |
| 2032 | + const PlacerCriticalities* criticalities, |
| 2033 | + t_placer_costs* costs) { |
| 2034 | + auto check_and_print_cost = [](double new_cost, |
| 2035 | + double old_cost, |
| 2036 | + const std::string& cost_name) { |
| 2037 | + if (!vtr::isclose(new_cost, old_cost, ERROR_TOL, 0.)) { |
| 2038 | + std::string msg = vtr::string_fmt( |
| 2039 | + "in recompute_costs_from_scratch: new_%s = %g, old %s = %g, ERROR_TOL = %g\n", |
| 2040 | + cost_name.c_str(), new_cost, cost_name.c_str(), old_cost, ERROR_TOL); |
| 2041 | + VPR_ERROR(VPR_ERROR_PLACE, msg.c_str()); |
| 2042 | + } |
| 2043 | + }; |
| 2044 | + |
2033 | 2045 | double new_bb_cost = recompute_bb_cost();
|
2034 |
| - if (fabs(new_bb_cost - costs->bb_cost) > costs->bb_cost * ERROR_TOL) { |
2035 |
| - std::string msg = vtr::string_fmt( |
2036 |
| - "in recompute_costs_from_scratch: new_bb_cost = %g, old bb_cost = %g\n", |
2037 |
| - new_bb_cost, costs->bb_cost); |
2038 |
| - VPR_ERROR(VPR_ERROR_PLACE, msg.c_str()); |
2039 |
| - } |
| 2046 | + check_and_print_cost(new_bb_cost, costs->bb_cost, "bb_cost"); |
2040 | 2047 | costs->bb_cost = new_bb_cost;
|
2041 | 2048 |
|
2042 | 2049 | if (placer_opts.place_algorithm.is_timing_driven()) {
|
2043 | 2050 | double new_timing_cost = 0.;
|
2044 | 2051 | comp_td_costs(delay_model, *criticalities, &new_timing_cost);
|
2045 |
| - if (fabs( |
2046 |
| - new_timing_cost |
2047 |
| - - costs->timing_cost) |
2048 |
| - > costs->timing_cost * ERROR_TOL) { |
2049 |
| - std::string msg = vtr::string_fmt( |
2050 |
| - "in recompute_costs_from_scratch: new_timing_cost = %g, old timing_cost = %g, ERROR_TOL = %g\n", |
2051 |
| - new_timing_cost, costs->timing_cost, ERROR_TOL); |
2052 |
| - VPR_ERROR(VPR_ERROR_PLACE, msg.c_str()); |
2053 |
| - } |
| 2052 | + check_and_print_cost(new_timing_cost, costs->timing_cost, "timing_cost"); |
2054 | 2053 | costs->timing_cost = new_timing_cost;
|
2055 | 2054 | } else {
|
2056 | 2055 | VTR_ASSERT(placer_opts.place_algorithm == BOUNDING_BOX_PLACE);
|
2057 |
| - |
2058 | 2056 | costs->cost = new_bb_cost * costs->bb_cost_norm;
|
2059 | 2057 | }
|
2060 | 2058 |
|
2061 | 2059 | if (noc_opts.noc) {
|
2062 |
| - double new_noc_aggregate_bandwidth_cost = 0.; |
2063 |
| - double new_noc_latency_cost = 0.; |
2064 |
| - recompute_noc_costs(new_noc_aggregate_bandwidth_cost, new_noc_latency_cost); |
2065 |
| - |
2066 |
| - if (fabs( |
2067 |
| - new_noc_aggregate_bandwidth_cost |
2068 |
| - - costs->noc_aggregate_bandwidth_cost) |
2069 |
| - > costs->noc_aggregate_bandwidth_cost * ERROR_TOL) { |
2070 |
| - std::string msg = vtr::string_fmt( |
2071 |
| - "in recompute_costs_from_scratch: new_noc_aggregate_bandwidth_cost = %g, old noc_aggregate_bandwidth_cost = %g, ERROR_TOL = %g\n", |
2072 |
| - new_noc_aggregate_bandwidth_cost, costs->noc_aggregate_bandwidth_cost, ERROR_TOL); |
2073 |
| - VPR_ERROR(VPR_ERROR_PLACE, msg.c_str()); |
2074 |
| - } |
2075 |
| - costs->noc_aggregate_bandwidth_cost = new_noc_aggregate_bandwidth_cost; |
| 2060 | + NocCostTerms new_noc_cost; |
| 2061 | + recompute_noc_costs(new_noc_cost); |
| 2062 | + |
| 2063 | + check_and_print_cost(new_noc_cost.aggregate_bandwidth, |
| 2064 | + costs->noc_cost_terms.aggregate_bandwidth, |
| 2065 | + "noc_aggregate_bandwidth"); |
| 2066 | + costs->noc_cost_terms.aggregate_bandwidth = new_noc_cost.aggregate_bandwidth; |
2076 | 2067 |
|
2077 | 2068 | // only check if the recomputed cost and the current noc latency cost are within the error tolerance if the cost is above 1 picosecond.
|
2078 | 2069 | // Otherwise, there is no need to check (we expect the latency cost to be above the threshold of 1 picosecond)
|
2079 |
| - if (new_noc_latency_cost > MIN_EXPECTED_NOC_LATENCY_COST) { |
2080 |
| - if (fabs( |
2081 |
| - new_noc_latency_cost |
2082 |
| - - costs->noc_latency_cost) |
2083 |
| - > costs->noc_latency_cost * ERROR_TOL) { |
2084 |
| - std::string msg = vtr::string_fmt( |
2085 |
| - "in recompute_costs_from_scratch: new_noc_latency_cost = %g, old noc_latency_cost = %g, ERROR_TOL = %g\n", |
2086 |
| - new_noc_latency_cost, costs->noc_latency_cost, ERROR_TOL); |
2087 |
| - VPR_ERROR(VPR_ERROR_PLACE, msg.c_str()); |
2088 |
| - } |
| 2070 | + if (new_noc_cost.latency > MIN_EXPECTED_NOC_LATENCY_COST) { |
| 2071 | + check_and_print_cost(new_noc_cost.latency, |
| 2072 | + costs->noc_cost_terms.latency, |
| 2073 | + "noc_latency_cost"); |
| 2074 | + } |
| 2075 | + costs->noc_cost_terms.latency = new_noc_cost.latency; |
| 2076 | + |
| 2077 | + if (new_noc_cost.latency_overrun > MIN_EXPECTED_NOC_LATENCY_COST) { |
| 2078 | + check_and_print_cost(new_noc_cost.latency_overrun, |
| 2079 | + costs->noc_cost_terms.latency_overrun, |
| 2080 | + "noc_latency_overrun_cost"); |
| 2081 | + } |
| 2082 | + costs->noc_cost_terms.latency_overrun = new_noc_cost.latency_overrun; |
| 2083 | + |
| 2084 | + if (new_noc_cost.congestion > MIN_EXPECTED_NOC_CONGESTION_COST) { |
| 2085 | + check_and_print_cost(new_noc_cost.congestion, |
| 2086 | + costs->noc_cost_terms.congestion, |
| 2087 | + "noc_congestion_cost"); |
2089 | 2088 | }
|
2090 |
| - costs->noc_latency_cost = new_noc_latency_cost; |
| 2089 | + costs->noc_cost_terms.congestion = new_noc_cost.congestion; |
2091 | 2090 | }
|
2092 | 2091 | }
|
2093 | 2092 |
|
|
0 commit comments