blob: 0c4ab914bb0b86dc9481d43ef6d16684be18f614 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#include "time_monitor.h"
#include "optical_output_port.h"
#include "specs.h"
#include "sysc_utils.h"
#include <vector>
#include <set>
using namespace std;
string vec2str(const vector<bool> &v)
{
string str;
for (const auto &x : v)
if (x)
str += "1|";
else
str += "0|";
return str;
}
void TimeMonitor::on_trigger() {
auto first = system_clock::now();
auto last = first;
set<OpticalOutputPort *> oops = sc_get_all_module_by_type<OpticalOutputPort>();
sc_time delay = sc_time(m_poll_period, SC_SEC);
//wait(1, SC_PS);
while (true) {
// Wait for next polling event
if (!sc_pending_activity())
{
// cout << "a" << endl;
wait();
}
else if (sc_pending_activity_at_current_time() && delay.value() != 0)
{
// cout << "b" << endl;
wait(delay);
}
else if (sc_pending_activity_at_current_time() && delay.value() == 0)
{
//cout << "c" << endl;
wait(delay);
}
else if (sc_pending_activity_at_future_time() && delay.value() != 0)
{
// cout << "d" << endl;
wait(delay);
}
else if (sc_pending_activity_at_future_time() && delay.value() == 0)
{
// cout << "e" << endl;
wait(sc_time_to_pending_activity());
}
else
cerr << "How did you get here ?" << endl;
// Get current wall clock
auto now = system_clock::now();
std::chrono::duration<double> elapsed_seconds = now - last;
// Report if it's time to do it
if (elapsed_seconds.count() >= m_wallclock_period)
{
#if 0
double error_sum = 0;
double max_error = 0;
double emitted_power_sum = 0;
double max_emitted_power = 0;
string max_error_name;
complex<double> culprit_emitted;
double culprit_emitted_pow = 0.0;
complex<double> culprit_wanted;
vector<bool> is_empty(oops.size(), false);
int i = 0;
int max_i = 0;
for (const auto &oop : oops)
{
is_empty[i] = oop->isempty();
error_sum += oop->current_err_fd();
max_error = max(max_error, oop->current_err_fd());
if (max_error == oop->current_err_fd())
// if (strcmp(oop->name(), "crow.dc_0.out1_delayed_writer") == 0)
{
max_error_name = oop->name();
// deprecated following lines on 05/04:
// culprit_emitted = oop->m_emitted_val_fd;
// culprit_emitted_pow = oop->m_emitted_val_fd.power();
culprit_wanted = oop->m_cur_val_fd;
max_i = i;
}
// deprecated following lines on 05/04:
// emitted_power_sum += oop->m_emitted_val_fd.power();
// max_emitted_power = max(max_emitted_power, oop->m_emitted_val_fd.power());
i++;
}
#endif
std::chrono::duration<double> elapsed_seconds_since_start = now - first;
last = now;
auto t = sc_time_stamp().to_seconds();
cout << "---------------------------------------------------------------------------" << endl;
cerr << "Time monitor incompatible with new multi-wavelength features" << endl;
exit(1);
cout << "Current simulation time (after "<< (int)(elapsed_seconds_since_start.count()) <<"s): " << endl
<< "\tIn NS: " << t*1e9 << endl
<< "\tIn PS: " << t*1e12 << endl
<< "\tDelta-cycles at current time: " << sc_delta_count_at_current_time() << endl
//<< "\tCumulated error in ports: " << error_sum << endl
//<< "\tIsempty: " << vec2str(is_empty) << endl
//<< "\tCulprit: " << max_error_name << endl
//<< "\tCulprit i: " << max_i << endl
//<< setprecision(12)
//<< "\tWanted: " << norm(culprit_wanted) << "W " << arg(culprit_wanted) << "rad" << endl
//<< "\tEmitted: " << norm(culprit_emitted) << "W " << arg(culprit_emitted) << "rad" << endl
//<< "\tDiff: " << abs(norm(culprit_emitted) - norm(culprit_wanted)) << "W " << abs(arg(culprit_emitted) - arg(culprit_wanted)) << "rad" << endl
//<< "\tMax error in ports: " << max_error << endl
//<< "\tCumulated power output of all ports: " << emitted_power_sum << endl
//<< "\tMax port power output: " << max_emitted_power << endl
<< "\tSimulation speed (NS/s): " << t*1e9 / elapsed_seconds_since_start.count() << endl;
// if (max_error < specsGlobalConfig.oop_configs[0]->m_abs_tol_power)
if (false)
{
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// DOES NOT WORK IF CODE IS COMPILED WITH -O3 ???
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
specsGlobalConfig.drop_all_events = true;
wait(SC_ZERO_TIME);
while (true) {
volatile bool isempty = true;
for (const auto &oop : oops) {
isempty &= oop->isempty();
if (oop->isempty())
{
cout << oop->name() << " didnt empty its queue" << endl;
}
}
if (isempty)
break;
wait(SC_ZERO_TIME);
}
specsGlobalConfig.drop_all_events = false;
wait(sc_time::from_value(1));
}
}
}
}
|