From 496df84b3bd0de7c59a5ecb46a35526b4b8ad11b Mon Sep 17 00:00:00 2001 From: Kelvin Chung Date: Fri, 23 May 2025 10:28:55 +0100 Subject: [PATCH 1/2] timeout for router1 --- common/kernel/command.cc | 4 ++++ common/route/router1.cc | 7 +++++++ common/route/router1.h | 1 + 3 files changed, 12 insertions(+) diff --git a/common/kernel/command.cc b/common/kernel/command.cc index a51f9576..74d83c9c 100644 --- a/common/kernel/command.cc +++ b/common/kernel/command.cc @@ -538,6 +538,10 @@ void CommandHandler::setupContext(Context *ctx) if (vm.count("parallel-refine")) ctx->settings[ctx->id("placerHeap/parallelRefine")] = true; + if (vm.count("router1-timeout")) { + ctx->settings[ctx->id("router1/timeout")] = vm["router1-timeout"].as(); + } + if (vm.count("router2-heatmap")) ctx->settings[ctx->id("router2/heatmap")] = vm["router2-heatmap"].as(); if (vm.count("tmg-ripup") || vm.count("router2-tmg-ripup")) diff --git a/common/route/router1.cc b/common/route/router1.cc index 510065f6..818ef136 100644 --- a/common/route/router1.cc +++ b/common/route/router1.cc @@ -1199,6 +1199,13 @@ bool router1(Context *ctx, const Router1Cfg &cfg) last_arcs_with_ripup = router.arcs_with_ripup; last_arcs_without_ripup = router.arcs_without_ripup; ctx->yield(); + + if (cfg.timeout){ + if (curr_time - rstart > std::chrono::seconds(cfg.timeout)) { + log_error("Timeout reached, stopping routing.\n"); + } + } + #ifndef NDEBUG router.check(); #endif diff --git a/common/route/router1.h b/common/route/router1.h index a7ec5bad..57050a37 100644 --- a/common/route/router1.h +++ b/common/route/router1.h @@ -36,6 +36,7 @@ struct Router1Cfg delay_t netRipupPenalty; delay_t reuseBonus; delay_t estimatePrecision; + int timeout; }; extern bool router1(Context *ctx, const Router1Cfg &cfg); From de38bd34fb7ae08880096163264b693fca5a3b5b Mon Sep 17 00:00:00 2001 From: Kelvin Chung Date: Fri, 23 May 2025 12:19:40 +0100 Subject: [PATCH 2/2] Change the iter count based timeout --- common/kernel/command.cc | 4 +++- common/route/router1.cc | 17 ++++++++--------- common/route/router1.h | 1 - 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/common/kernel/command.cc b/common/kernel/command.cc index 74d83c9c..fc58d383 100644 --- a/common/kernel/command.cc +++ b/common/kernel/command.cc @@ -396,6 +396,8 @@ po::options_description CommandHandler::getGeneralOptions() general.add_options()("parallel-refine", "use new experimental parallelised engine for placement refinement"); #endif + general.add_options()("router1-timeout", po::value(), "Timeout for router1 in iteration count (default: 0, no timeout)"); + general.add_options()("router2-heatmap", po::value(), "prefix for router2 resource congestion heatmaps"); @@ -539,7 +541,7 @@ void CommandHandler::setupContext(Context *ctx) ctx->settings[ctx->id("placerHeap/parallelRefine")] = true; if (vm.count("router1-timeout")) { - ctx->settings[ctx->id("router1/timeout")] = vm["router1-timeout"].as(); + ctx->settings[ctx->id("router1/maxIterCnt")] = std::to_string(std::max(0, vm["router1-timeout"].as())); } if (vm.count("router2-heatmap")) diff --git a/common/route/router1.cc b/common/route/router1.cc index 818ef136..625f68db 100644 --- a/common/route/router1.cc +++ b/common/route/router1.cc @@ -1146,7 +1146,7 @@ NEXTPNR_NAMESPACE_BEGIN Router1Cfg::Router1Cfg(Context *ctx) { - maxIterCnt = ctx->setting("router1/maxIterCnt", 200); + maxIterCnt = ctx->setting("router1/maxIterCnt", 0); cleanupReroute = ctx->setting("router1/cleanupReroute", true); fullCleanupReroute = ctx->setting("router1/fullCleanupReroute", true); useEstimate = ctx->setting("router1/useEstimate", true); @@ -1199,18 +1199,17 @@ bool router1(Context *ctx, const Router1Cfg &cfg) last_arcs_with_ripup = router.arcs_with_ripup; last_arcs_without_ripup = router.arcs_without_ripup; ctx->yield(); - - if (cfg.timeout){ - if (curr_time - rstart > std::chrono::seconds(cfg.timeout)) { - log_error("Timeout reached, stopping routing.\n"); - } - } - + #ifndef NDEBUG router.check(); #endif } - + if (cfg.maxIterCnt){ + if (iter_cnt > cfg.maxIterCnt) { + log_error("Max iteration count reached, stopping routing.\n"); + } + } + if (ctx->debug) log("-- %d --\n", iter_cnt); diff --git a/common/route/router1.h b/common/route/router1.h index 57050a37..a7ec5bad 100644 --- a/common/route/router1.h +++ b/common/route/router1.h @@ -36,7 +36,6 @@ struct Router1Cfg delay_t netRipupPenalty; delay_t reuseBonus; delay_t estimatePrecision; - int timeout; }; extern bool router1(Context *ctx, const Router1Cfg &cfg);