-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathvnoc.cpp
1836 lines (1596 loc) · 74.4 KB
/
vnoc.cpp
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <math.h>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <limits.h>
#include "vnoc.h"
#include "vnoc_event.h"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
//
// PREDICTOR_MODULE
//
////////////////////////////////////////////////////////////////////////////////
void PREDICTOR_MODULE::maintain_for_prediction_SYNC(ROUTER *my_router)
{
// called each time a given router is "simulated" simulate_one_router();
// does only maintainance (as opposed to ASYNC version, which does
// both maintainance and prediction);
// prediction is done once every "_history_window" base cycles
// through events of type EVENT::SYNC_PREDICT_DVFS_SET; that
// way, each router performs prediction immediately after its
// time is greater or equal than "_history_window" base cycles;
// it's basically the first part of maintain_or_perform_prediction_ASYNC();
// (1) history based prediction;
if ( _predictor_type == HISTORY) {
// (a) maintain;
for (long i = 1; i < 5; i++) {
_BU_predicted_out_i[i] +=
my_router->compute_BU_for_downstream_driven_by_out_i( i);
}
_BU_predicted_all_inputs +=
my_router->compute_BU_overall_input_buffers_this_r();
_counter_router_own_cycles ++;
my_router->incr_cycle_counter_4_prediction(); // not used for SYNC;
}
// (2) exponential averaging; not used currently;
else if ( _predictor_type == EXPONENTIAL_AVERAGING) {
}
}
void PREDICTOR_MODULE::perform_prediction_SYNC(ROUTER *my_router)
{
// (1) history based prediction;
if ( _predictor_type == HISTORY) {
// (b) perform; because we are at end of history window;
for ( long i = 1; i < 5; i++) {
// ---> last cycle of this history window;
// finish eq.3 in Li Shang paper;
_BU_predicted_out_i[i] = _BU_predicted_out_i[i] /
_counter_router_own_cycles;
// then, do actual prediction: eq.5 in Li Shang paper;
_BU_predicted_out_i[i] =
( (_history_weight * _BU_predicted_out_i[i]) +
_BU_predicted_out_i_last[i] ) / ( _history_weight + 1 );
//printf(" p:%.1f a:%.1f", _BU_predicted_out_i[i], _BU_predicted_out_i_last[i]);
//printf(" %.1f", _BU_predicted_out_i[i]);
// record current prediction in "last" for next time
// that is, for the end of a new history window;
_BU_predicted_out_i_last[i] = _BU_predicted_out_i[i];
// ---> finish eq.2 in Li Shang paper;
_LU_predicted_out_i[i] = _counter_flits_sent_during_hw[i] /
_counter_router_own_cycles;
// then, do actual prediction: eq.5 in Li Shang paper;
_LU_predicted_out_i[i] =
( (_history_weight * _LU_predicted_out_i[i]) +
_LU_predicted_out_i_last[i] ) / ( _history_weight + 1 );
// record current prediction in "last" for next time
// that is, for the end of a new history window;
_LU_predicted_out_i_last[i] = _LU_predicted_out_i[i];
// reset LU counter of flits transmitted to have it ready
// for the next period's calculations;
_counter_flits_sent_during_hw[i] = 0;
}
// last cycle calculation for overall BU of this router;
_BU_predicted_all_inputs = _BU_predicted_all_inputs /
_counter_router_own_cycles; // should equal _history_window for ASYNC mode;
// do also actual prediction;
_BU_predicted_all_inputs =
( (_history_weight * _BU_predicted_all_inputs) +
_BU_predicted_all_inputs_last ) / ( _history_weight + 1 );
// record it as "last" for next time;
_BU_predicted_all_inputs_last = _BU_predicted_all_inputs;
//printf(" %.2f ", _BU_predicted_all_inputs);
// also, reset the counter that keeps track where
// we are inside this history window;
my_router->reset_cycle_counter_4_prediction();
// also, reset LU counter of router own cycles for the next period;
// prepare it for the calculation of LU during the next hw;
_counter_router_own_cycles = 0;
// () then, update DVFS settings;
// Note: inside this call, the function that does the actual
// dvfs settings change (if indeed they change compared to
// prev. history window) will also call the function
// scale_and_accumulate_energy(), to keep track of scaled
// energy so far;
// Note: this was initially in set_frequencies_and_vdd()
// and meant to be called only if dvfs was done; but I had the issues
// of no DVFS setting to be done and scaled energy would
// remain 0; I brought it here so that in that case scaled energy
// would be the same as the not scaled energy;
// (2) because dvfs settings may be changed here we also call
// scale_and_accumulate_energy(), to keep track of scaled
// energy so far; we accumulate the energy
// with the appropriate scaling because the power module accumulate
// the energy, unscaled as computed by Orion;
my_router->power_module().scale_and_accumulate_energy();
if ( my_router->vnoc()->topology()->use_freq_boost()) {
update_DVFS_settings_throttle_and_boost( my_router);
// also, reset all BU related variable to prepare them
// for calculations during the next history window
// period;
reset_all_BU_related_variables();
} else {
update_DVFS_settings_throttle_only( my_router);
// also, reset all BU related variable to prepare them
// for calculations during the next history window
// period;
reset_all_BU_related_variables();
}
}
// (2) exponential averaging; not used currently;
else if ( _predictor_type == EXPONENTIAL_AVERAGING) {
}
}
void PREDICTOR_MODULE::maintain_or_perform_prediction_ASYNC(ROUTER *my_router)
{
// called each time a given router is "simulated" simulate_one_router();
// because a given router counts its own cycles and only when
// a number "_history_window" router cycles are gone, prediction is made
// for the given router, predictions happen for different routers
// at different times; not all routers are updated in terms
// of dvfs at the same synchronous time, say "_history_window"
// of base cycles;
// each router is processed to perform prediction exactly after
// "_history_window" router cycles; because the router may be
// already throttled, the prediction and hence changes in its dvfs
// settings may be at a different (asynchronous) time than
// othe rrouter that may be runing at the base freq.
// (1) history based prediction;
if ( _predictor_type == HISTORY) {
// (a) maintain;
if (my_router->cycle_counter_4_prediction() < _history_window) {
for (long i = 1; i < 5; i++) {
// ---> compute input buffer occupancy of input buffer
// of downstream router and accumulate it; actual
// average (eq.3 in Li Shang paper) will be done in the
// last cycle of this history window, when the actual
// prediction (eq.5 in Li Shang paper) will also be made;
_BU_predicted_out_i[i] +=
my_router->compute_BU_for_downstream_driven_by_out_i( i);
//printf(" %.1f", _BU_predicted_out_i[i]);
}
// accumulate also the overall buffer utilization of all
// input buffers of this router (used by freq throttle portion);
_BU_predicted_all_inputs +=
my_router->compute_BU_overall_input_buffers_this_r();
// ---> do link utilization bookeeping;
// here we only count the clock cycles of this router
// that pass during the "_history_window"; if dvfs settings
// are done for each router (ASYNC) individually, after each "_history_window"
// of this router clock cycles, then the counter incremented here
// will be the same as "_history_window" at the end of the
// "_history_window" period;
// if however, all routers have dvfs settings updated (SYNC) synchronously
// after "_history_window" of base cycles, then this counter
// incremented here may be different than the actual "_history_window"
// as a number; this depends on whether this router has been throttled
// or boosted at the end of the last control period;
// the counter incremented here is the N variable in the
// denuminator of eq. 2 in Li Shang paper; this counter is
// reset at the end of the control period when actaul predictions
// are made;
_counter_router_own_cycles ++;
// Note: the numerator of eq. 2 in Li Shang paper is another
// counter that gets incremented each time a flit is sent
// over the link;
// this is done inside send_flit_via_physical_link()
// by calling record_flit_transmission_for_LU_calculation();
// also, increment the counter that keeps track where
// we are inside this history window;
my_router->incr_cycle_counter_4_prediction();
}
// (b) perform; because we are at end of history window;
else {
for (long i = 1; i < 5; i++) {
// ---> last cycle of this history window;
// finish eq.3 in Li Shang paper;
_BU_predicted_out_i[i] = _BU_predicted_out_i[i] /
_counter_router_own_cycles; // should equal _history_window for ASYNC mode;
// printf(" %.1f", _BU_predicted_out_i[i]);
// then, do actual prediction: eq.5 in Li Shang paper;
_BU_predicted_out_i[i] =
( (_history_weight * _BU_predicted_out_i[i]) +
_BU_predicted_out_i_last[i] ) / ( _history_weight + 1 );
//printf(" p:%.1f a:%.1f", _BU_predicted_out_i[i], _BU_predicted_out_i_last[i]);
//printf(" %.1f", _BU_predicted_out_i[i]);
// record current prediction in "last" for next time
// that is, for the end of a new history window;
_BU_predicted_out_i_last[i] = _BU_predicted_out_i[i];
//printf(" %.2f", _BU_predicted_out_i[i]);
// ---> finish eq.2 in Li Shang paper;
_LU_predicted_out_i[i] = double(_counter_flits_sent_during_hw[i]) /
double(_counter_router_own_cycles);
//printf(" %.1f", _LU_predicted_out_i[i]);
//printf(" %d %d ",_counter_flits_sent_during_hw[i],_counter_router_own_cycles);
// then, do actual prediction: eq.5 in Li Shang paper;
_LU_predicted_out_i[i] =
( (_history_weight * _LU_predicted_out_i[i]) +
_LU_predicted_out_i_last[i] ) / ( _history_weight + 1 );
//printf(" %.1f", _LU_predicted_out_i[i]);
// record current prediction in "last" for next time
// that is, for the end of a new history window;
_LU_predicted_out_i_last[i] = _LU_predicted_out_i[i];
// reset LU counter of flits transmitted to have it ready
// for the next period's calculations;
_counter_flits_sent_during_hw[i] = 0;
}
// last cycle calculation for overall BU of this router;
_BU_predicted_all_inputs = _BU_predicted_all_inputs /
_counter_router_own_cycles; // should equal _history_window for ASYNC mode;
// do also actual prediction;
_BU_predicted_all_inputs =
( (_history_weight * _BU_predicted_all_inputs) +
_BU_predicted_all_inputs_last ) / ( _history_weight + 1 );
// record it as "last" for next time;
_BU_predicted_all_inputs_last = _BU_predicted_all_inputs;
//printf(" %.2f ", _BU_predicted_all_inputs);
// record the prediction error;
// Note: _BU_predicted_all_inputs just computed is basically what
// happened during just ended history window; this is actual BU
// which I want to compare with the previous value, that we used
// as a prediction of what would happend duing this just ended
// window;
//_predictions_count ++;
//double this_prediction_error =
// fabs(_BU_predicted_all_inputs - _BU_predicted_all_inputs_last);
//_BU_all_prediction_err_as_percentage +=
// this_prediction_error / double(my_router->overall_size_input_buffs());
//printf(" p:%.1f a:%.1f", _BU_predicted_all_inputs_last, _BU_predicted_all_inputs);
//printf(" %.1f %.1f", this_prediction_error, double(my_router->overall_size_input_buffs()));
// also, reset the counter that keeps track where
// we are inside this history window;
my_router->reset_cycle_counter_4_prediction();
// also, reset LU counter of router own cycles for the next period;
// prepare it for the calculation of LU during the next hw;
_counter_router_own_cycles = 0;
// () then, update DVFS settings;
// Note: inside this call, the function that does the actual
// dvfs settings change (if indeed they change compared to
// prev. fistory window) will also call the function
// scale_and_accumulate_energy(), to keep track of scaled
// energy so far;
// Note: this was initially in set_frequencies_and_vdd()
// and meant to be called only if dvfs was done; but I had the issues
// of no DVFS setting to be done and scaled energy would
// remain 0; I brought it here so that in that case scaled energy
// would be the same as the not scaled energy;
// (2) because dvfs settings may be changed here we also call
// scale_and_accumulate_energy(), to keep track of scaled
// energy so far; we accumulate the energy
// with the appropriate scaling because the power module accumulate
// the energy, unscaled as computed by Orion;
my_router->power_module().scale_and_accumulate_energy();
if ( my_router->vnoc()->topology()->use_freq_boost()) {
update_DVFS_settings_throttle_and_boost( my_router);
// also, reset all BU related variable to prepare them
// for calculations during the next history window
// period;
reset_all_BU_related_variables();
} else {
update_DVFS_settings_throttle_only( my_router);
// also, reset all BU related variable to prepare them
// for calculations during the next history window
// period;
reset_all_BU_related_variables();
}
}
}
// (2) exponential averaging; not used currently;
else if ( _predictor_type == EXPONENTIAL_AVERAGING) {
//_predicted_BU = (long)( _alpha * _actual_BU + (1 - _alpha) * _last_predicted_BU);
}
}
void PREDICTOR_MODULE::update_DVFS_settings_throttle_only( ROUTER *my_router)
{
// here we implement the logic of the frequency tuning for router
// and links; that is frequency throttle from Asit Mishra (see
// tables 1,2 in his paper, but w/o using boost frequency) and link
// control from Li Shang paper; frequency throttle is done using predicted
// values for BU; link control is done the same way but only with
// three f,V levels to keep hardware cost low;
// (1) use link prediction; this is similar to Li Shang paper;
if ( my_router->vnoc()->topology()->use_link_pred() == true) {
// this follows the logic of algo 1 from Li Shang paper;
long num_of_shift_freq_up = 0;
long num_of_shift_freq_down = 0;
long num_of_shift_freq_down_bu_low = 0;
long num_of_shift_freq_down_bu_high = 0;
long num_of_keep_freq_same = 0;
double TL_low = 0.3, TL_high = 0.4;
double TH_low = 0.6, TH_high = 0.7;
double T_low = 0.0, T_high = 0.0;
for (long i = 1; i < 5; i++) {
if ( _BU_predicted_out_i[i] < 0.5) {
T_low = TL_low;
T_high = TL_high;
} else {
T_low = TH_low;
T_high = TH_high;
}
if ( _LU_predicted_out_i[i] < T_low) {
num_of_shift_freq_down ++;
if (_BU_predicted_out_i[i] < 0.5) {
num_of_shift_freq_down_bu_low ++;
} else {
num_of_shift_freq_down_bu_high ++;
}
} else if ( _LU_predicted_out_i[i] > T_high) {
num_of_shift_freq_up ++;
} else {
num_of_keep_freq_same ++;
}
}
// at this time we know how many links should have freq changed
// up, down, or kept as is;
if ( num_of_shift_freq_up > 0) {
if (my_router->dvfs_level() == DVFS_THROTTLE_2) {
my_router->set_frequencies_and_vdd(DVFS_THROTTLE_1);
} else if (my_router->dvfs_level() == DVFS_THROTTLE_1) {
my_router->set_frequencies_and_vdd(DVFS_BASE);
} else {
// do nothing; freq is already the highest;
}
}
else if ( num_of_shift_freq_down > 0) {
if (my_router->dvfs_level() == DVFS_BASE) {
my_router->set_frequencies_and_vdd(DVFS_THROTTLE_1);
} else if (my_router->dvfs_level() == DVFS_THROTTLE_1) {
my_router->set_frequencies_and_vdd(DVFS_THROTTLE_2);
} else {
// do nothing; freq is already the lowest;
}
}
else {
// do nothing; freq is kept unchanged;
}
}
// (2) do not use link prediction; this is similar to Asit Mishra paper;
else {
long num_of_congestion_low_signals = 0;
long num_of_congestion_high_signals = 0;
for (long i = 1; i < 5; i++) {
if ( _BU_predicted_out_i[i] > 0.65) {
// the prediction done locally here at the output of this
// router about the BU of the downstream input-port router
// represents basically the "congestion_high" signal discussed
// in Asit Mishra paper;
num_of_congestion_high_signals ++;
} else if ( _BU_predicted_out_i[i] < 0.35) {
num_of_congestion_low_signals ++;
}
}
// see Asit Mishra paper, tables 1,2;
//printf(" %.1f", _BU_predicted_all_inputs);
if ( _BU_predicted_all_inputs >= 0.15) { // 0.6
// irrespective of what the signals from neighbors say
// we set the frequency to the highest freq, f_H, because
// this router itself is on the verge of congestion
my_router->set_frequencies_and_vdd( DVFS_BASE);
} else if ( _BU_predicted_all_inputs < 0.1 && // 0.6..0.4
_BU_predicted_all_inputs >= 0.05) {
if ( num_of_congestion_high_signals > 0) {
// set frequency to the middle freq, f_M
my_router->set_frequencies_and_vdd( DVFS_THROTTLE_1);
}
else {
my_router->set_frequencies_and_vdd( DVFS_BASE);
}
} else {
if ( num_of_congestion_high_signals > 0) {
// set frequency to the low freq, f_L
my_router->set_frequencies_and_vdd( DVFS_THROTTLE_2);
}
else {
my_router->set_frequencies_and_vdd( DVFS_BASE);
}
}
}
}
void PREDICTOR_MODULE::update_DVFS_settings_throttle_and_boost( ROUTER *my_router)
{
// here we implement the logic of the frequency tuning for router
// and links; that is frequency throttle from Asit Mishra (see
// tables 1,2 in his paper, but w/o using boost freqymcy) and link
// control from Li Shang paper; frequency throttle is done using predicted
// values for BU; link control is done the same way but only with
// three f,V levels to keep hardware cost low;
// (1) use link prediction; this is similar to Li Shang paper;
if ( my_router->vnoc()->topology()->use_link_pred() == true) {
// this follows the logic of algo 1 from Li Shang paper;
long num_of_shift_freq_up = 0;
long num_of_shift_freq_down = 0;
long num_of_shift_freq_down_bu_low = 0;
long num_of_shift_freq_down_bu_high = 0;
long num_of_keep_freq_same = 0;
double TL_low = 0.3, TL_high = 0.4;
double TH_low = 0.6, TH_high = 0.7;
double T_low = 0.0, T_high = 0.0;
for (long i = 1; i < 5; i++) {
if ( _BU_predicted_out_i[i] < 0.5) {
T_low = TL_low;
T_high = TL_high;
} else {
T_low = TH_low;
T_high = TH_high;
}
if ( _LU_predicted_out_i[i] < T_low) {
num_of_shift_freq_down ++;
if (_BU_predicted_out_i[i] < 0.5) {
num_of_shift_freq_down_bu_low ++;
} else {
num_of_shift_freq_down_bu_high ++;
}
} else if ( _LU_predicted_out_i[i] > T_high) {
num_of_shift_freq_up ++;
} else {
num_of_keep_freq_same ++;
}
}
// at this time we know how many links should have freq changed
// up, down, or kept as is;
// 1
if ( num_of_shift_freq_up > 0) {
if (my_router->dvfs_level() == DVFS_THROTTLE_2) {
my_router->set_frequencies_and_vdd(DVFS_THROTTLE_1);
} else if (my_router->dvfs_level() == DVFS_THROTTLE_1) {
my_router->set_frequencies_and_vdd(DVFS_BASE);
} else if (my_router->dvfs_level() == DVFS_BASE) {
my_router->set_frequencies_and_vdd(DVFS_BOOST);
} else {
// do nothing; freq is already the highest;
}
}
else if ( num_of_shift_freq_down > 0) {
if (my_router->dvfs_level() == DVFS_BOOST) {
my_router->set_frequencies_and_vdd(DVFS_BASE);
} else if (my_router->dvfs_level() == DVFS_BASE) {
my_router->set_frequencies_and_vdd(DVFS_THROTTLE_1);
} else if (my_router->dvfs_level() == DVFS_THROTTLE_1) {
my_router->set_frequencies_and_vdd(DVFS_THROTTLE_2);
} else {
// do nothing; freq is already the lowest;
}
}
else {
// do nothing; freq is kept unchanged;
}
}
// (2) do not use link prediction; this is similar to Asit Mishra paper;
else {
long num_of_congestion_low_signals = 0;
long num_of_congestion_high_signals = 0;
for (long i = 1; i < 5; i++) {
if ( _BU_predicted_out_i[i] > 0.65) {
// the prediction done locally here at the output of this
// router about the BU of the downstream input-port router
// represents basically the "congestion_high" signal discussed
// in Asit Mishra paper;
num_of_congestion_high_signals ++;
} else if ( _BU_predicted_out_i[i] < 0.35) {
num_of_congestion_low_signals ++;
}
}
// see Asit Mishra paper, tables 1,2;
//printf(" %.1f", _BU_predicted_all_inputs);
if ( _BU_predicted_all_inputs >= 0.15) { // 0.6
// irrespective of what the signals from neighbors say
// we set the frequency to the highest freq, f_H, because
// this router itself is on the verge of congestion
my_router->set_frequencies_and_vdd( DVFS_BOOST);
} else if ( _BU_predicted_all_inputs < 0.1 && // 0.6..0.4
_BU_predicted_all_inputs >= 0.05) {
if ( num_of_congestion_high_signals > 0) {
// set frequency to the middle freq, f_M
my_router->set_frequencies_and_vdd( DVFS_THROTTLE_1);
}
else {
my_router->set_frequencies_and_vdd( DVFS_BASE);
}
} else {
if ( num_of_congestion_high_signals > 0) {
// set frequency to the low freq, f_L
my_router->set_frequencies_and_vdd( DVFS_THROTTLE_2);
}
else {
my_router->set_frequencies_and_vdd( DVFS_BASE);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// POWER_MODULE
//
////////////////////////////////////////////////////////////////////////////////
POWER_MODULE::POWER_MODULE( long physical_ports_count, long vc_count,
long flit_size, double link_length) :
_flit_size( flit_size),
_router_info(),
_router_power(),
_router_area(),
_arbiter_vc_power(),
_link_power(),
_buffer_write(),
_buffer_read(),
_crossbar_read(),
_crossbar_write(),
_link_traversal(),
_crossbar_input(),
_arbiter_vc_req(),
_arbiter_vc_grant()
{
// () buffer init
// orion3:
//router_initialize(
// &_router_info, // router_info_t *info
// &_router_power, // router_power_t *router_power
// NULL); // router_area_t *router_area
//router_initialize(
// &_router_info, // router_info_t *info
// NULL, // router_power_t *router_power
// &_router_area); // router_area_t *router_area
// orion2:
SIM_router_init( // see SIM_router.c
&_router_info, // SIM_router_info_t *info
&_router_power, // SIM_router_power_t *SIM_router_power
NULL); // SIM_router_area_t *SIM_router_area
// the above calls SIM_router_power_init():
//SIM_router_power_init( // see SIM_router_power.c
// &_router_info, // SIM_router_info_t *info
// &_router_power); // SIM_router_power_t *SIM_router_power
//SIM_router_init( // not interested in area for now;
// &_router_info, // SIM_router_info_t *info
// NULL, // SIM_router_power_t *SIM_router_power
// &_router_area); // SIM_router_area_t *SIM_router_area
// orion1:
//FUNC(SIM_router_power_init, &_router_info, &_router_power);
_buffer_write.resize( physical_ports_count);
_buffer_read.resize( physical_ports_count);
_crossbar_read.resize( physical_ports_count);
_crossbar_write.resize( physical_ports_count);
_link_traversal.resize( physical_ports_count);
_crossbar_input.resize( physical_ports_count,0);
for (long i = 0; i < physical_ports_count; i ++) {
_buffer_write[i].resize( _flit_size, 0);
_buffer_read[i].resize( _flit_size, 0);
_crossbar_read[i].resize( _flit_size, 0);
_crossbar_write[i].resize( _flit_size, 0);
_link_traversal[i].resize( _flit_size, 0);
}
// () arbiter init
SIM_arbiter_init(
&_arbiter_vc_power, // SIM_arbiter_t *arb
1, // int arbiter_model
1, // int ff_model
physical_ports_count * vc_count, // u_int req_width
0, // double length
NULL); // SIM_array_info_t *info
_arbiter_vc_req.resize( physical_ports_count);
_arbiter_vc_grant.resize( physical_ports_count);
for (long i = 0; i < physical_ports_count; i ++) {
_arbiter_vc_req[i].resize( vc_count, 1);
_arbiter_vc_grant[i].resize( vc_count, 1);
}
// () crossbar init
SIM_crossbar_init(
&( _router_power.crossbar), //SIM_crossbar_t *crsbar
MATRIX_CROSSBAR, // int model; MATRIX_CROSSBAR, MULTREE_CROSSBAR
physical_ports_count, // u_int n_in
physical_ports_count, // u_int n_out
1, // u_int in_seg
1, // u_int out_seg
ATOM_WIDTH, // u_int data_width; it's 64 fixed - do not change 'coz of orion3;
1, // u_int degree
TRISTATE_GATE, // int connect_type; TRANS_GATE, TRISTATE_GATE
NP_GATE, // int trans_type
1, // double in_len
1, // double out_len
NULL); // double *req_len
// () bus/link init
SIM_bus_init(
&_link_power, // SIM_bus_t *bus
GENERIC_BUS, // int model; RESULT_BUS, GENERIC_BUS
IDENT_ENC, // int encoding
ATOM_WIDTH, // u_int width; 64;
0, // u_int grp_width; grp_width only matters for BUSINV_ENC
1, // u_int n_snd; # of senders
1, // u_int n_rcv; # of receivers
link_length, // double length
0); // double time; rise and fall time, 0 means using default transistor sizes
// () DVFS related;
_scaled_energy = 0.0;
_prev_unscaled_energy = 0.0;
_scaled_energy_buffer = 0.0;
_prev_unscaled_energy_buffer = 0.0;
_scaled_energy_crossbar = 0.0;
_prev_unscaled_energy_crossbar = 0.0;
_scaled_energy_arbiter = 0.0;
_prev_unscaled_energy_arbiter = 0.0;
_scaled_energy_link = 0.0;
_prev_unscaled_energy_link = 0.0;
_scaled_energy_clock = 0.0;
_prev_unscaled_energy_clock = 0.0;
_current_vdd = VDD_BASE;
_current_period = PIPE_DELAY_BASE;
_energy_scaling_factor = SCALING_BASE;
}
void POWER_MODULE::power_buffer_write(long in_port, DATA &write_d)
{
// orion2:
for (long i = 0; i < _flit_size; i ++) {
DATA_ATOMIC_UNIT old_d = _buffer_write[in_port][i];
DATA_ATOMIC_UNIT new_d = write_d[i];
// eqivalent of: FUNC(SIM_buf_power_data_write,...) from orion1;
SIM_buf_power_data_write( // see SIM_router.c
&( _router_info.in_buf_info), // SIM_array_info_t *info
&( _router_power.in_buf), // SIM_array_t *arr
(u_char *) (&old_d), // u_char *data_line
(u_char *) (&old_d), // u_char *old_data
(u_char *) (&new_d)); // u_char *new_data
_buffer_write[in_port][i] = write_d[i];
}
/*---
// debugging purposes only:
for (long i = 0; i < _flit_size; i ++) {
DATA_ATOMIC_UNIT old_d = _buffer_write[in_port][i];
DATA_ATOMIC_UNIT new_d = write_d[i];
SIM_array_data_write( // see SIM_array_m.c
&( _router_info.in_buf_info), // SIM_array_info_t *info
&( _router_power.in_buf), // SIM_array_t *arr
NULL, // SIM_array_set_state_t *set
8, // u_int n_item; PARM(flit_width) / 8; works only for flit_width=64;
(u_char *) (&old_d), // u_char *data_line
(u_char *) (&old_d), // u_char *old_data
(u_char *) (&new_d)); // u_char *new_data
//FUNC(SIM_reg_power_data_write, // see SIM_reg.c
// &( _router_info.in_buf_info), // &( SIM_array_info_t in_buf_info)
// &( _router_power.in_buf), // &( SIM_array_t in_buf)
// (u_int) in_port,
// (LIB_Type_max_uint) old_d,
// (LIB_Type_max_uint) new_d);
_buffer_write[in_port][i] = write_d[i];
}
---*/
// orion1:
//for (long i = 0; i < _flit_size; i ++) {
// DATA_ATOMIC_UNIT old_d = _buffer_write[in_port][i];
// DATA_ATOMIC_UNIT new_d = write_d[i];
// FUNC(SIM_buf_power_data_write,
// &( _router_info.in_buf_info),
// &( _router_power.in_buf),
// (char *) (&old_d),
// (char *) (&old_d),
// (char *) (&new_d));
// _buffer_write[in_port][i] = write_d[i];
//}
}
void POWER_MODULE::power_buffer_read(long in_port, DATA &read_d)
{
// orion2:
for (long i = 0; i < _flit_size; i++) {
// eqivalent of: FUNC(SIM_buf_power_data_read,...) from orion1;
SIM_buf_power_data_read( // see SIM_router.c
&( _router_info.in_buf_info), // SIM_array_info_t *info
&( _router_power.in_buf), // SIM_array_t *arr
read_d[i]); // LIB_Type_max_uint data
_buffer_read[in_port][i] = read_d[i];
}
/*---
// debugging purposes only:
for (long i = 0; i < _flit_size; i++) {
SIM_array_data_read( // see SIM_array_m.c
&( _router_info.in_buf_info), // SIM_array_info_t *info
&( _router_power.in_buf), // SIM_array_t *arr
read_d[i]); // LIB_Type_max_uint data
//FUNC(SIM_reg_power_data_read, // see SIM_reg.c
// &( _router_info.in_buf_info), // SIM_array_info_t in_buf_info;
// &( _router_power.in_buf), // SIM_array_t in_buf;
// (P_DATA_T) read_d[i]);
_buffer_read[in_port][i] = read_d[i];
}
---*/
// orion1:
//for (long i = 0; i < _flit_size; i++) {
// FUNC(SIM_buf_power_data_read,
// &( _router_info.in_buf_info),
// &( _router_power.in_buf),
// read_d[i]);
// _buffer_read[in_port][i] = read_d[i];
//}
}
void POWER_MODULE::power_vc_arbit(long pc, long vc,
DATA_ATOMIC_UNIT req, unsigned long gra)
{
// orion2:
SIM_arbiter_record(
&_arbiter_vc_power, // SIM_arbiter_t *arb
(LIB_Type_max_uint) req, // LIB_Type_max_uint new_req
(LIB_Type_max_uint) _arbiter_vc_req[pc][vc], // LIB_Type_max_uint old_req
(u_int) gra, // u_int new_grant
(u_int) _arbiter_vc_grant[pc][vc]); // u_int old_grant
_arbiter_vc_req[pc][vc] = req;
_arbiter_vc_grant[pc][vc] = gra;
// orion1:
//SIM_arbiter_record( &_arbiter_vc_power, req,
// _arbiter_vc_req[pc][vc], gra,
// _arbiter_vc_grant[pc][vc]);
//_arbiter_vc_req[pc][vc] = req;
//_arbiter_vc_grant[pc][vc] = gra;
}
void POWER_MODULE::power_crossbar_trav(long in_port, long out_port, DATA &trav_d)
{
// orion2:
for (long i = 0; i < _flit_size; i++) {
SIM_crossbar_record(
&( _router_power.crossbar), // SIM_crossbar_t *xb
1, // int io
(LIB_Type_max_uint) trav_d[i], // LIB_Type_max_uint new_data
(LIB_Type_max_uint) _crossbar_read[in_port][i], // LIB_Type_max_uint old_data
1, // u_int new_port
1); // u_int old_port
SIM_crossbar_record(
&( _router_power.crossbar),
0,
(LIB_Type_max_uint) trav_d[i],
(LIB_Type_max_uint) _crossbar_write[out_port][i],
(u_int) _crossbar_input[out_port],
(u_int) in_port);
_crossbar_read[in_port][i] = trav_d[i];
_crossbar_write[out_port][i] = trav_d[i];
_crossbar_input[out_port] = in_port;
}
// orion1:
//for (long i = 0; i < _flit_size; i++) {
// SIM_crossbar_record(
// &( _router_power.crossbar), 1, trav_d[i],
// _crossbar_read[in_port][i], 1, 1);
// SIM_crossbar_record(
// &( _router_power.crossbar), 0, trav_d[i],
// _crossbar_write[out_port][i],
// _crossbar_input[out_port], in_port);
// _crossbar_read[in_port][i] = trav_d[i];
// _crossbar_write[out_port][i] = trav_d[i];
// _crossbar_input[out_port] = in_port;
//}
}
void POWER_MODULE::power_link_traversal(long in_port, DATA &read_d)
{
// orion2:
for (long i = 0; i < _flit_size; i++) {
DATA_ATOMIC_UNIT old_d = _link_traversal[in_port][i];
DATA_ATOMIC_UNIT new_d = read_d[i];
SIM_bus_record(
&_link_power, // SIM_bus_t *bus
(LIB_Type_max_uint) old_d, // LIB_Type_max_uint old_state
(LIB_Type_max_uint) new_d); // LIB_Type_max_uint new_state
_link_traversal[in_port][i] = read_d[i];
}
// orion1:
//for (long i = 0; i < _flit_size; i++) {
// DATA_ATOMIC_UNIT old_d = _link_traversal[in_port][i];
// DATA_ATOMIC_UNIT new_d = read_d[i];
// SIM_bus_record( &_link_power, old_d, new_d);
// _link_traversal[in_port][i] = read_d[i];
//}
}
void POWER_MODULE::power_clock_record()
{
// record a simulation cycle of the NoC;
SIM_simulation_cycles_record( &_router_info); // SIM_router_info_t *info
}
double POWER_MODULE::power_buffer_report()
{
double buffer_energy = 0.0;
// orion2:
// this function is used inside orion_router.c also for the case of orion2
// simulations; calls SIM_array_stat_energy() to get energy of in_buf,
// which is described in SIM_array_m.c; it returns the energy of the whole
// router;
// Note: do NOT use this function; it returns always the same values
// for all routers; it's the way orion3 "cooked" its power estimation;
// does not take into account all activity during NoC simulation;
/*---
// debugging purposes only:
buffer_energy = SIM_router_stat_energy( // see SIM_router_power.c
&( _router_info),
&( _router_power),
0, // print_depth
NULL, // name
AVG_ENERGY, // max_flag
0.5, // load
0, // plot_flag
2e9); // Freq.
// energy of one array only; this is called a few times by the above one;
return SIM_array_stat_energy( // see SIM_array_m.c
&( _router_info.in_buf_info), // SIM_array_info_t *info
&( _router_power.in_buf), // SIM_array_t *arr
_router_info.n_in, // double n_read
_router_info.n_in, // double n_write
0, // int print_depth
NULL, // char *path
2e9); // int max_avg; PARM(Freq)
---*/
// power of array only;
buffer_energy = SIM_array_power_report( // see SIM_array_l.c
&( _router_info.in_buf_info), // &( SIM_array_info_t in_buf_info)
&( _router_power.in_buf)); // &( SIM_array_t in_buf)
//printf("\n buffer_energy: %g", buffer_energy);
// orion1:
//return SIM_array_power_report(
// &( _router_info.in_buf_info),
// &( _router_power.in_buf));
return buffer_energy;
}
double POWER_MODULE::power_arbiter_report()
{
return SIM_arbiter_report( &_arbiter_vc_power);
}
double POWER_MODULE::power_crossbar_report()
{
return SIM_crossbar_report( &( _router_power.crossbar));
}
double POWER_MODULE::power_link_report()
{
// Note: this repots actually energy in J;
// Note: the way orion2 computes energy is: n_switch * e_switch
// where e_switch = EnergyFactor * (TCap), where EnergyFactor = Vdd^2
// and TCap = CC2metal * length [F/um * um];
return SIM_bus_report( &_link_power);
}
double POWER_MODULE::power_clock_report()
{
double clock_energy = 0.0;
// Note: this repots actually energy in J; this is a function that calls
// SIM_total_clockEnergy();
clock_energy = SIM_total_during_n_cycles_clockEnergy(
&_router_info, // SIM_router_info_t *info
&_router_power); // SIM_router_power_t *SIM_router_power
//printf("\n clock_energy: %g", clock_energy);
return clock_energy;
}
void POWER_MODULE::scale_and_accumulate_energy()
{
// used for DVFS; read detailed comments in declaration of this class;
// retrieve Orion power and compute "delta" energy consumed since
// last call of this routine;
double curr_unscaled_energy =
power_buffer_report() + power_crossbar_report() +
power_arbiter_report() + power_link_report() +
power_clock_report();
double delta_unscaled_energy =
curr_unscaled_energy - _prev_unscaled_energy;
_prev_unscaled_energy = curr_unscaled_energy; // prepare for next time;
// accumulate and store locally the total scaled energy consumed so far;
_scaled_energy += (delta_unscaled_energy * _energy_scaling_factor);
// compute also individual components;
_scaled_energy_buffer +=
((power_buffer_report() - _prev_unscaled_energy_buffer) * _energy_scaling_factor);
_scaled_energy_crossbar +=
((power_crossbar_report() - _prev_unscaled_energy_crossbar) * _energy_scaling_factor);
_scaled_energy_arbiter +=
((power_arbiter_report() - _prev_unscaled_energy_arbiter) * _energy_scaling_factor);
_scaled_energy_link +=
((power_link_report() - _prev_unscaled_energy_link) * _energy_scaling_factor);
_scaled_energy_clock +=
((power_clock_report() - _prev_unscaled_energy_clock) * _energy_scaling_factor);
_prev_unscaled_energy_buffer = power_buffer_report();
_prev_unscaled_energy_crossbar = power_crossbar_report();
_prev_unscaled_energy_arbiter = power_arbiter_report();
_prev_unscaled_energy_link = power_link_report();
_prev_unscaled_energy_clock = power_clock_report();
}
////////////////////////////////////////////////////////////////////////////////