From 5be70f436f2114d4e4e50701399fc30a7a4895b2 Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Tue, 5 Nov 2024 10:21:26 -0800 Subject: [PATCH] Added stdout flush and statistical info for debug --- passes/cmds/activity.cc | 12 ++++++++++-- passes/sat/sim.cc | 22 ++++++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/passes/cmds/activity.cc b/passes/cmds/activity.cc index ab85a387c..b0185ab93 100644 --- a/passes/cmds/activity.cc +++ b/passes/cmds/activity.cc @@ -27,6 +27,7 @@ PRIVATE_NAMESPACE_BEGIN struct ActivityProp { Module *module; SigMap sigmap; + uint32_t nbBitsWithActivity = 0; // Split a string based on separator, returns a vector of tokens as reference argument // If skipEmpty is true, return "" for string " ", when separator is " " @@ -81,8 +82,10 @@ struct ActivityProp { if (i < activities.size()) { ActivityMap.emplace(bit, activities[i]); DutyMap.emplace(bit, duties[i]); + nbBitsWithActivity++; } else { - log_warning("Zeroing out activity for module: %s, wire: %s, wiresize: %d, actisize: %ld", module->name.c_str(), wire->name.c_str(), GetSize(sig), activities.size()); + log_warning("Zeroing out activity for module: %s, wire: %s, wire_size: %d, activ_size: %ld", module->name.c_str(), + wire->name.c_str(), GetSize(sig), activities.size()); ActivityMap.emplace(bit, "0.0"); DutyMap.emplace(bit, "0.0"); } @@ -131,6 +134,8 @@ struct ActivityProp { cell->set_string_attribute("$DUTY:", cell_ports_duty); } } + + uint32_t getNbBitsWithActivity() { return nbBitsWithActivity; } }; struct ActivityClear { @@ -168,10 +173,13 @@ struct ActivityPropPass : public Pass { break; } extra_args(args, argidx, design); - + uint32_t totalNbBitsWithActivity = 0; for (auto module : design->modules()) { ActivityProp worker(module); + totalNbBitsWithActivity += worker.getNbBitsWithActivity(); } + log("Collected %d bits with activity", totalNbBitsWithActivity); + log_flush(); } } ActivityPropPass; diff --git a/passes/sat/sim.cc b/passes/sat/sim.cc index 5492b3fb1..ec14ef2ea 100644 --- a/passes/sat/sim.cc +++ b/passes/sat/sim.cc @@ -1576,7 +1576,7 @@ struct SimWorker : SimShared } catch(fst_end_of_data_exception) { // end of data detected } - + log_flush(); write_output_files(); delete fst; } @@ -2414,6 +2414,7 @@ struct AnnotateActivity : public OutputWriter { // Init map SignalActivityDataMap dataMap; // For each event (new time when a value changed) + uint32_t nbTotalBits = 0; for (auto &d : worker->output_data) { // For each signal/values in that time slice for (auto &data : d.second) { @@ -2425,6 +2426,7 @@ struct AnnotateActivity : public OutputWriter { if (itr == dataMap.end()) { Const value = data.second; std::vector vals(GetSize(value), 0); + nbTotalBits += GetSize(value); std::vector dvals(GetSize(value), 0); SignalActivityData data; data.highTimes = vals; @@ -2436,7 +2438,8 @@ struct AnnotateActivity : public OutputWriter { } } } - + log("Computing signal activity for %ld signals (%d bits)", use_signal.size(), nbTotalBits); + log_flush(); // Max simulation time int max_time = 0; // Inititalization of totalEventCounts and max_time @@ -2544,6 +2547,8 @@ struct AnnotateActivity : public OutputWriter { std::cout << "Clock period: " << clk_period << "\n"; std::cout << "Frequency: " << frequency << "\n"; } + double totalActivity = 0.0f; + double totalDuty = 0.0f; worker->top->write_output_header( [this, debug](IdString name) { if (debug) @@ -2553,8 +2558,8 @@ struct AnnotateActivity : public OutputWriter { if (debug) std::cout << "endmodule\n"; }, - [this, &use_signal, &dataMap, max_time, real_timescale, clk_period, debug](const char *name, int size, Wire *w, int id, - bool) { + [this, &use_signal, &dataMap, max_time, real_timescale, clk_period, debug, &totalActivity, &totalDuty] + (const char *name, int size, Wire *w, int id, bool) { if (!use_signal.at(id) || (w == nullptr)) return; SignalActivityDataMap::const_iterator itr = dataMap.find(id); @@ -2576,9 +2581,14 @@ struct AnnotateActivity : public OutputWriter { std::cout << " ACK: "; } std::string activity_str; + if ((uint32_t) size != toggleCounts.size()) { + std::string full_name = form_vcd_name(name, size, w); + log_warning("Signal size/value mismatch for %s: %d vs %ld", full_name.c_str(), size, toggleCounts.size()); + } for (uint32_t i = 0; i < (uint32_t)size; i++) { // Compute Activity double activity = toggleCounts[i] / (((double)max_time * real_timescale / clk_period) * 2.0); + totalActivity += activity; activity_str += std::to_string(activity) + " "; } if (debug) { @@ -2590,6 +2600,7 @@ struct AnnotateActivity : public OutputWriter { for (uint32_t i = 0; i < (uint32_t)size; i++) { // Compute Duty cycle double duty = (double)highTimes[i] / (double)max_time; + totalDuty += duty; duty_str += std::to_string(duty) + " "; } if (debug) { @@ -2599,6 +2610,9 @@ struct AnnotateActivity : public OutputWriter { w->set_string_attribute("$ACKT", activity_str); w->set_string_attribute("$DUTY", duty_str); }); + log("Average activity: %f\n", totalActivity / nbTotalBits); + log("Average duty : %f\n", totalDuty / nbTotalBits); + log_flush(); } };