Skip to content

Commit 26da1ec

Browse files
authored
Merge pull request #2060 from verilog-to-routing/terminate_if_timing_fails
Terminate if timing fails
2 parents 75981e0 + d867d54 commit 26da1ec

File tree

17 files changed

+150
-2
lines changed

17 files changed

+150
-2
lines changed

doc/src/vpr/command_line_usage.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ General Options
283283
.. warning:: Exercise extreme caution when turning this option off -- be sure you completely understand why the issue is being flagged, and why it is OK to treat as a warning instead of an error.
284284

285285
**Default:** ``on``
286+
287+
.. option:: --terminate_if_timing_fails {on, off}
288+
289+
Controls whether VPR should terminate if timing is not met after routing.
290+
291+
**Default:** ``off``
286292

287293
.. _filename_options:
288294

vpr/src/base/read_options.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,12 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
14751475
.default_value("off")
14761476
.show_in(argparse::ShowIn::HELP_ONLY);
14771477

1478+
gen_grp.add_argument<bool, ParseOnOff>(args.terminate_if_timing_fails, "--terminate_if_timing_fails")
1479+
.help(
1480+
"During final timing analysis after routing, if a negative slack anywhere is returned and this option is set, \n"
1481+
"VPR_FATAL_ERROR is called and processing ends.")
1482+
.default_value("off");
1483+
14781484
auto& file_grp = parser.add_argument_group("file options");
14791485

14801486
file_grp.add_argument<e_arch_format, ParseArchFormat>(args.arch_format, "--arch_format")

vpr/src/base/read_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct t_options {
6969
argparse::ArgValue<std::string> disable_errors;
7070
argparse::ArgValue<std::string> suppress_warnings;
7171
argparse::ArgValue<bool> allow_dangling_combinational_nodes;
72+
argparse::ArgValue<bool> terminate_if_timing_fails;
7273

7374
/* Atom netlist options */
7475
argparse::ArgValue<bool> absorb_buffer_luts;

vpr/src/base/vpr_api.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "vpr_constraints_reader.h"
7474
#include "place_constraints.h"
7575
#include "place_util.h"
76+
#include "timing_fail_error.h"
7677

7778
#include "vpr_constraints_writer.h"
7879

@@ -342,6 +343,9 @@ void vpr_init_with_options(const t_options* options, t_vpr_setup* vpr_setup, t_a
342343
vtr::ScopedStartFinishTimer t("Load Timing Constraints");
343344
timing_ctx.constraints = read_sdc(vpr_setup->Timing, atom_ctx.nlist, atom_ctx.lookup, *timing_ctx.graph);
344345
}
346+
{
347+
set_terminate_if_timing_fails(options->terminate_if_timing_fails);
348+
}
345349
}
346350

347351
//Initialize vpr floorplanning constraints

vpr/src/base/vpr_context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ struct TimingContext : public Context {
113113
std::shared_ptr<tatum::TimingConstraints> constraints;
114114

115115
t_timing_analysis_profile_info stats;
116+
117+
/* Represents whether or not VPR should fail if timing constraints aren't met. */
118+
bool terminate_if_timing_fails = false;
116119
};
117120

118121
namespace std {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <fstream>
2+
#include <sstream>
3+
4+
#include "vtr_log.h"
5+
#include "vtr_assert.h"
6+
#include "vtr_math.h"
7+
8+
#include "globals.h"
9+
#include "timing_util.h"
10+
#include "timing_fail_error.h"
11+
12+
/* Sets terminate_if_timing_fails in the timing context if the user has indicated
13+
* terminate_if_timing_fails option should be on.
14+
*/
15+
void set_terminate_if_timing_fails(bool cmd_opt_terminate_if_timing_fails) {
16+
auto& timing_ctx = g_vpr_ctx.mutable_timing();
17+
timing_ctx.terminate_if_timing_fails = cmd_opt_terminate_if_timing_fails;
18+
}

vpr/src/timing/timing_fail_error.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef VPR_FAIL_ERROR_H
2+
#define VPR_FAIL_ERROR_H
3+
#include <memory>
4+
5+
#include "timing_info_fwd.h"
6+
#include "tatum/analyzer_factory.hpp"
7+
#include "tatum/timing_paths.hpp"
8+
#include "timing_util.h"
9+
10+
/* Represents whether or not VPR should fail if timing constraints aren't met. */
11+
void set_terminate_if_timing_fails(bool cmd_opt_terminate_if_timing_fails);
12+
13+
#endif

vpr/src/timing/timing_util.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "globals.h"
99
#include "timing_util.h"
1010
#include "timing_info.h"
11+
#include "timing_fail_error.h"
1112

1213
double sec_to_nanosec(double seconds) {
1314
return 1e9 * seconds;
@@ -415,6 +416,15 @@ void print_setup_timing_summary(const tatum::TimingConstraints& constraints,
415416
sec_to_mhz(fanout_weighted_geomean_intra_domain_cpd));
416417

417418
VTR_LOG("\n");
419+
420+
/* If the terminate_if_timing fails option is on, this checks if slack is negative and if user wants VPR
421+
* flow to fail if their design doesn't meet timing constraints. If both conditions are true, the function
422+
* adds details about the negative slack to a string that will be printed when VPR throws an error.
423+
*/
424+
if (timing_ctx.terminate_if_timing_fails && (setup_worst_neg_slack < 0 || setup_total_neg_slack < 0) && prefix == "Final ") {
425+
std::string msg = "\nDesign did not meet timing constraints.\nTiming failed and terminate_if_timing_fails set -- exiting";
426+
VPR_FATAL_ERROR(VPR_ERROR_TIMING, msg.c_str());
427+
}
418428
}
419429

420430
/*
@@ -593,8 +603,14 @@ std::vector<HistogramBucket> create_hold_slack_histogram(const tatum::HoldTiming
593603
}
594604

595605
void print_hold_timing_summary(const tatum::TimingConstraints& constraints, const tatum::HoldTimingAnalyzer& hold_analyzer, std::string prefix) {
596-
VTR_LOG("%shold Worst Negative Slack (hWNS): %g ns\n", prefix.c_str(), sec_to_nanosec(find_hold_worst_negative_slack(hold_analyzer)));
597-
VTR_LOG("%shold Total Negative Slack (hTNS): %g ns\n", prefix.c_str(), sec_to_nanosec(find_hold_total_negative_slack(hold_analyzer)));
606+
auto& timing_ctx = g_vpr_ctx.timing();
607+
608+
auto hold_worst_neg_slack = sec_to_nanosec(find_hold_worst_negative_slack(hold_analyzer));
609+
auto hold_total_neg_slack = sec_to_nanosec(find_hold_total_negative_slack(hold_analyzer));
610+
611+
VTR_LOG("%shold Worst Negative Slack (hWNS): %g ns\n", prefix.c_str(), hold_worst_neg_slack);
612+
VTR_LOG("%shold Total Negative Slack (hTNS): %g ns\n", prefix.c_str(), hold_total_neg_slack);
613+
598614
/*For testing*/
599615
//VTR_LOG("Hold Total Negative Slack within clbs: %g ns\n", sec_to_nanosec(find_total_negative_slack_within_clb_blocks(hold_analyzer)));
600616
VTR_LOG("\n");
@@ -637,6 +653,15 @@ void print_hold_timing_summary(const tatum::TimingConstraints& constraints, cons
637653
}
638654
}
639655
VTR_LOG("\n");
656+
657+
/* If the terminate_if_timing fails option is on, this checks if slack is negative and if user wants VPR
658+
* flow to fail if their design doesn't meet timing constraints. If both conditions are true, the function
659+
* adds details about the negative slack to a string that will be printed when VPR throws an error.
660+
*/
661+
if (timing_ctx.terminate_if_timing_fails && (hold_worst_neg_slack < 0 || hold_total_neg_slack < 0) && prefix == "Final ") {
662+
std::string msg = "\nDesign did not meet timing constraints.\nTiming failed and terminate_if_timing_fails set -- exiting";
663+
VPR_FATAL_ERROR(VPR_ERROR_TIMING, msg.c_str());
664+
}
640665
}
641666

642667
/*

vpr/src/util/vpr_utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "string.h"
2020
#include "pack_types.h"
2121
#include "device_grid.h"
22+
#include "timing_fail_error.h"
2223

2324
/* This module contains subroutines that are used in several unrelated parts *
2425
* of VPR. They are VPR-specific utility routines. */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vpr_status;Equal()
2+
error;Equal()

0 commit comments

Comments
 (0)