forked from sstsimulator/sst-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseComponent.cc
More file actions
1243 lines (1079 loc) · 39.4 KB
/
baseComponent.cc
File metadata and controls
1243 lines (1079 loc) · 39.4 KB
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
// Copyright 2009-2025 NTESS. Under the terms
// of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Copyright (c) 2009-2025, NTESS
// All rights reserved.
//
// This file is part of the SST software package. For license
// information, see the LICENSE file in the top level directory of the
// distribution.
#include "sst_config.h"
#include "sst/core/baseComponent.h"
#include "sst/core/component.h"
#include "sst/core/configGraph.h"
#include "sst/core/factory.h"
#include "sst/core/link.h"
#include "sst/core/linkMap.h"
#include "sst/core/portModule.h"
#include "sst/core/profile/clockHandlerProfileTool.h"
#include "sst/core/profile/eventHandlerProfileTool.h"
#include "sst/core/serialization/serialize.h"
#include "sst/core/simulation_impl.h"
#include "sst/core/statapi/statoutput.h"
#include "sst/core/stringize.h"
#include "sst/core/subcomponent.h"
#include "sst/core/timeConverter.h"
#include "sst/core/timeLord.h"
#include "sst/core/unitAlgebra.h"
#include "sst/core/warnmacros.h"
#include "sst/core/watchPoint.h"
#include <string>
namespace SST {
BaseComponent::BaseComponent(ComponentId_t id) :
SST::Core::Serialization::serializable_base(),
my_info_(Simulation_impl::getSimulation()->getComponentInfo(id)),
sim_(Simulation_impl::getSimulation())
{
if ( my_info_->component == nullptr ) {
// If it's already set, then this is a ComponentExtension and
// we shouldn't reset it.
my_info_->component = this;
}
}
BaseComponent::~BaseComponent()
{
// Need to cleanup my ComponentInfo and delete all my children.
// If my_info_ is nullptr, then we are being deleted by our
// ComponentInfo object. This happens at the end of execution
// when the simulation destructor fires.
if ( !my_info_ ) return;
if ( isExtension() ) return;
// Start by deleting children
std::map<ComponentId_t, ComponentInfo>& subcomps = my_info_->getSubComponents();
for ( auto& ci : subcomps ) {
// Delete the subcomponent
// Remove the parent info from the child so that it won't try
// to delete itself out of the map. We'll clear the map
// after deleting everything.
ci.second.parent_info = nullptr;
delete ci.second.component;
ci.second.component = nullptr;
}
// Now clear the map. This will delete all the ComponentInfo
// objects; since the component field was set to nullptr, it will
// not try to delete the component again.
subcomps.clear();
// Now for the tricky part, I need to remove myself from my
// parent's subcomponent map (if I have a parent).
my_info_->component = nullptr;
if ( my_info_->parent_info ) {
std::map<ComponentId_t, ComponentInfo>& parent_subcomps = my_info_->parent_info->getSubComponents();
size_t deleted = parent_subcomps.erase(my_info_->id_);
if ( deleted != 1 ) {
// Should never happen, but issue warning just in case
sim_->getSimulationOutput().output(
"Warning: BaseComponent destructor failed to remove ComponentInfo from parent.\n");
}
}
// Delete all clock handlers. We need to delete here because
// handlers are not always registered with the clock object.
for ( auto* handler : clock_handlers_ ) {
delete handler;
}
// Delete any portModules
for ( auto port : portModules ) {
delete port;
}
}
void
BaseComponent::setDefaultTimeBaseForLinks(TimeConverter tc)
{
LinkMap* myLinks = my_info_->getLinkMap();
if ( nullptr != myLinks ) {
for ( std::pair<std::string, Link*> p : myLinks->getLinkMap() ) {
if ( nullptr == p.second->getDefaultTimeBase() && p.second->isConfigured() ) {
p.second->setDefaultTimeBase(tc);
}
}
}
}
void
BaseComponent::pushValidParams(Params& params, const std::string& type)
{
params.pushAllowedKeys(Factory::getFactory()->getParamNames(type));
}
void
BaseComponent::registerClock_impl(TimeConverter* tc, Clock::HandlerBase* handler, bool regAll)
{
// Need to see if I already know about this clock handler
bool found = false;
for ( auto* x : clock_handlers_ ) {
if ( handler == x ) {
found = true;
break;
}
}
if ( !found ) clock_handlers_.push_back(handler);
// Check to see if there is a profile tool installed
auto tools = sim_->getProfileTool<Profile::ClockHandlerProfileTool>("clock");
for ( auto* tool : tools ) {
ClockHandlerMetaData mdata(my_info_->getID(), getName(), getType());
// Add the receive profiler to the handler
handler->attachTool(tool, mdata);
}
// if regAll is true set tc as the default for the component and
// for all the links
if ( regAll ) {
setDefaultTimeBaseForLinks(tc);
my_info_->defaultTimeBase = tc;
}
}
TimeConverter*
BaseComponent::registerClock(const std::string& freq, Clock::HandlerBase* handler, bool regAll)
{
TimeConverter* tc = sim_->registerClock(freq, handler, CLOCKPRIORITY);
registerClock_impl(tc, handler, regAll);
return tc;
}
TimeConverter*
BaseComponent::registerClock(const UnitAlgebra& freq, Clock::HandlerBase* handler, bool regAll)
{
TimeConverter* tc = sim_->registerClock(freq, handler, CLOCKPRIORITY);
registerClock_impl(tc, handler, regAll);
return tc;
}
TimeConverter*
BaseComponent::registerClock(TimeConverter tc, Clock::HandlerBase* handler, bool regAll)
{
TimeConverter* tcRet = sim_->registerClock(tc, handler, CLOCKPRIORITY);
registerClock_impl(tcRet, handler, regAll);
return tcRet;
}
TimeConverter*
BaseComponent::registerClock(TimeConverter* tc, Clock::HandlerBase* handler, bool regAll)
{
TimeConverter* tcRet = sim_->registerClock(tc, handler, CLOCKPRIORITY);
registerClock_impl(tcRet, handler, regAll);
return tcRet;
}
Cycle_t
BaseComponent::reregisterClock(TimeConverter freq, Clock::HandlerBase* handler)
{
return sim_->reregisterClock(freq, handler, CLOCKPRIORITY);
}
Cycle_t
BaseComponent::reregisterClock(TimeConverter* freq, Clock::HandlerBase* handler)
{
return sim_->reregisterClock(freq, handler, CLOCKPRIORITY);
}
Cycle_t
BaseComponent::getNextClockCycle(TimeConverter* freq)
{
return sim_->getNextClockCycle(freq, CLOCKPRIORITY);
}
Cycle_t
BaseComponent::getNextClockCycle(TimeConverter freq)
{
return sim_->getNextClockCycle(freq, CLOCKPRIORITY);
}
void
BaseComponent::unregisterClock(TimeConverter* tc, Clock::HandlerBase* handler)
{
sim_->unregisterClock(tc, handler, CLOCKPRIORITY);
}
TimeConverter*
BaseComponent::registerTimeBase(const std::string& base, bool regAll)
{
TimeConverter* tc = Simulation_impl::getTimeLord()->getTimeConverter(base);
// if regAll is true set tc as the default for the component and
// for all the links
if ( regAll ) {
setDefaultTimeBaseForLinks(tc);
my_info_->defaultTimeBase = tc;
}
return tc;
}
TimeConverter*
BaseComponent::getTimeConverter(const std::string& base) const
{
return Simulation_impl::getTimeLord()->getTimeConverter(base);
}
TimeConverter*
BaseComponent::getTimeConverter(const UnitAlgebra& base) const
{
return Simulation_impl::getTimeLord()->getTimeConverter(base);
}
bool
BaseComponent::isPortConnected(const std::string& name) const
{
return (my_info_->getLinkMap()->getLink(name) != nullptr);
}
// Looks at parents' shared ports and returns the link connected to
// the port of the correct name in one of my parents. If I find the
// correct link, and it hasn't been configured yet, I return it to the
// child and remove it from my linkmap. The child will insert it into
// their link map.
Link*
BaseComponent::getLinkFromParentSharedPort(const std::string& port, std::vector<ConfigPortModule>& port_modules)
{
LinkMap* myLinks = my_info_->getLinkMap();
// See if the link is found, and if not see if my parent shared
// their ports with me
if ( nullptr != myLinks ) {
Link* tmp = myLinks->getLink(port);
if ( nullptr != tmp ) {
// Found the link in my linkmap
// Check to see if it has been configured. If not, remove
// it from my link map and return it to the child.
if ( !tmp->isConfigured() ) {
myLinks->removeLink(port);
// Need to see if there are any associated PortModules
if ( my_info_->portModules != nullptr ) {
auto it = my_info_->portModules->find(port);
if ( it != my_info_->portModules->end() ) {
// Found PortModules, swap them into
// port_modules and remove from my map
port_modules.swap(it->second);
my_info_->portModules->erase(it);
}
}
return tmp;
}
}
}
// If we get here, we didn't find the link. Check to see if my
// parent shared with me and if so, call
// getLinkFromParentSharedPort on them
if ( my_info_->sharesPorts() ) {
return my_info_->parent_info->component->getLinkFromParentSharedPort(port, port_modules);
}
else {
return nullptr;
}
}
Link*
BaseComponent::configureLink_impl(const std::string& name, SimTime_t time_base, Event::HandlerBase* handler)
{
LinkMap* myLinks = my_info_->getLinkMap();
Link* tmp = nullptr;
// If I have a linkmap, check to see if a link was connected to
// port "name"
if ( nullptr != myLinks ) {
tmp = myLinks->getLink(name);
}
// If tmp is nullptr, then I didn't have the port connected, check
// with parents if sharing is turned on
if ( nullptr == tmp ) {
if ( my_info_->sharesPorts() ) {
std::vector<ConfigPortModule> port_modules;
tmp = my_info_->parent_info->component->getLinkFromParentSharedPort(name, port_modules);
// If I got a link from my parent, I need to put it in my
// link map
if ( nullptr != tmp ) {
if ( nullptr == myLinks ) {
myLinks = new LinkMap();
my_info_->link_map = myLinks;
}
myLinks->insertLink(name, tmp);
// Need to set the link's defaultTimeBase to uninitialized
tmp->resetDefaultTimeBase();
// Need to see if I got any port_modules, if so, need
// to add them to my_info_->portModules
if ( port_modules.size() > 0 ) {
if ( nullptr == my_info_->portModules ) {
// This memory is currently leaked as portModules is otherwise a pointer to ConfigComponent
// ConfigComponent does not exist for anonymous subcomponents
my_info_->portModules = new std::map<std::string, std::vector<ConfigPortModule>>();
}
(*my_info_->portModules)[name].swap(port_modules);
}
}
}
}
// If I got a link, configure it
if ( nullptr != tmp ) {
// If no functor, this is a polling link
if ( handler == nullptr ) {
tmp->setPolling();
}
else {
tmp->setFunctor(handler);
// Check to see if there is a profile tool installed
auto tools = sim_->getProfileTool<Profile::EventHandlerProfileTool>("event");
for ( auto& tool : tools ) {
EventHandlerMetaData mdata(my_info_->getID(), getName(), getType(), name);
// Add the receive profiler to the handler
if ( tool->profileReceives() ) handler->attachTool(tool, mdata);
// Add the send profiler to the link
if ( tool->profileSends() ) tmp->attachTool(tool, mdata);
}
}
// Check for PortModules
// portModules pointer may be invalid after wire up
// Only SelfLinks can be initialized after wire up and SelfLinks do not support PortModules
if ( !sim_->isWireUpFinished() && my_info_->portModules != nullptr ) {
auto it = my_info_->portModules->find(name);
if ( it != my_info_->portModules->end() ) {
EventHandlerMetaData mdata(my_info_->getID(), getName(), getType(), name);
for ( auto& portModule : it->second ) {
auto* pm = Factory::getFactory()->CreateWithParams<PortModule>(
portModule.type, portModule.params, portModule.params);
pm->setComponent(this);
if ( pm->installOnSend() ) tmp->attachTool(pm, mdata);
if ( pm->installOnReceive() ) {
if ( handler )
handler->attachInterceptTool(pm, mdata);
else
fatal(
CALL_INFO_LONG, 1, "ERROR: Trying to install a receive PortModule on a Polling Link\n");
}
portModules.push_back(pm);
}
}
}
tmp->setDefaultTimeBase(time_base);
#ifdef __SST_DEBUG_EVENT_TRACKING__
tmp->setSendingComponentInfo(my_info_->getName(), my_info_->getType(), name);
#endif
}
return tmp;
}
Link*
BaseComponent::configureLink(const std::string& name, TimeConverter* time_base, Event::HandlerBase* handler)
{
// Lookup core-owned time_base in case it differs from the one passed in (unlikely but possible)
SimTime_t factor = 0;
if ( nullptr != time_base )
factor = time_base->getFactor();
else if ( my_info_->defaultTimeBase.isInitialized() )
factor = my_info_->defaultTimeBase.getFactor();
return configureLink_impl(name, factor, handler);
}
Link*
BaseComponent::configureLink(const std::string& name, TimeConverter time_base, Event::HandlerBase* handler)
{
return configureLink_impl(name, time_base.getFactor(), handler);
}
Link*
BaseComponent::configureLink(const std::string& name, const std::string& time_base, Event::HandlerBase* handler)
{
SimTime_t factor = Simulation_impl::getTimeLord()->getTimeConverter(time_base)->getFactor();
return configureLink_impl(name, factor, handler);
}
Link*
BaseComponent::configureLink(const std::string& name, const UnitAlgebra& time_base, Event::HandlerBase* handler)
{
SimTime_t factor = Simulation_impl::getTimeLord()->getTimeConverter(time_base)->getFactor();
return configureLink_impl(name, factor, handler);
}
Link*
BaseComponent::configureLink(const std::string& name, Event::HandlerBase* handler)
{
SimTime_t factor = my_info_->defaultTimeBase ? my_info_->defaultTimeBase.getFactor() : 0;
return configureLink_impl(name, factor, handler);
}
void
BaseComponent::addSelfLink(const std::string& name)
{
LinkMap* myLinks = my_info_->getLinkMap();
myLinks->addSelfPort(name);
if ( myLinks->getLink(name) != nullptr ) {
printf("Attempting to add self link with duplicate name: %s\n", name.c_str());
abort();
}
Link* link = new SelfLink();
// Set default time base to the component time base
link->setDefaultTimeBase(my_info_->defaultTimeBase);
myLinks->insertLink(name, link);
}
Link*
BaseComponent::configureSelfLink(const std::string& name, TimeConverter time_base, Event::HandlerBase* handler)
{
addSelfLink(name);
return configureLink(name, time_base, handler);
}
Link*
BaseComponent::configureSelfLink(const std::string& name, TimeConverter* time_base, Event::HandlerBase* handler)
{
addSelfLink(name);
return configureLink(name, *time_base, handler);
}
Link*
BaseComponent::configureSelfLink(const std::string& name, const std::string& time_base, Event::HandlerBase* handler)
{
addSelfLink(name);
return configureLink(name, time_base, handler);
}
Link*
BaseComponent::configureSelfLink(const std::string& name, const UnitAlgebra& time_base, Event::HandlerBase* handler)
{
addSelfLink(name);
return configureLink(name, time_base, handler);
}
Link*
BaseComponent::configureSelfLink(const std::string& name, Event::HandlerBase* handler)
{
addSelfLink(name);
return configureLink(name, handler);
}
UnitAlgebra
BaseComponent::getCoreTimeBase() const
{
return sim_->getTimeLord()->getTimeBase();
}
SimTime_t
BaseComponent::getCurrentSimCycle() const
{
return sim_->getCurrentSimCycle();
}
int
BaseComponent::getCurrentPriority() const
{
return sim_->getCurrentPriority();
}
UnitAlgebra
BaseComponent::getElapsedSimTime() const
{
return sim_->getElapsedSimTime();
}
SimTime_t
BaseComponent::getEndSimCycle() const
{
return sim_->getEndSimCycle();
}
UnitAlgebra
BaseComponent::getEndSimTime() const
{
return sim_->getEndSimTime();
}
RankInfo
BaseComponent::getRank() const
{
return sim_->getRank();
}
RankInfo
BaseComponent::getNumRanks() const
{
return sim_->getNumRanks();
}
Output&
BaseComponent::getSimulationOutput() const
{
return Simulation_impl::getSimulationOutput();
}
SimTime_t
BaseComponent::getCurrentSimTime(TimeConverter tc) const
{
return tc.convertFromCoreTime(sim_->getCurrentSimCycle());
}
SimTime_t
BaseComponent::getCurrentSimTime(TimeConverter* tc) const
{
return getCurrentSimTime(*tc);
}
SimTime_t
BaseComponent::processCurrentTimeWithUnderflowedBase(const std::string& base) const
{
// Use UnitAlgebra to compute because core timebase was too big to
// represent the requested units
UnitAlgebra uabase(base);
UnitAlgebra curr_time = sim_->getElapsedSimTime();
UnitAlgebra result = curr_time / uabase;
auto value = result.getValue();
if ( value > static_cast<uint64_t>(MAX_SIMTIME_T) ) {
throw std::overflow_error("Error: Current time (" + curr_time.toStringBestSI() +
") is too large to fit into a 64-bit integer when using requested base (" + base +
")");
}
return value.toUnsignedLong();
}
SimTime_t
BaseComponent::getCurrentSimTime(const std::string& base) const
{
SimTime_t ret;
try {
TimeConverter* tc = Simulation_impl::getTimeLord()->getTimeConverter(base);
ret = getCurrentSimTime(*tc);
}
catch ( std::underflow_error& e ) {
// base is too small for the core timebase, fall back to using UnitAlgebra
ret = processCurrentTimeWithUnderflowedBase(base);
}
return ret;
}
SimTime_t
BaseComponent::getCurrentSimTimeNano() const
{
TimeConverter* tc = Simulation_impl::getTimeLord()->getNano();
if ( tc ) return tc->convertFromCoreTime(sim_->getCurrentSimCycle());
return getCurrentSimTime("1 ns");
}
SimTime_t
BaseComponent::getCurrentSimTimeMicro() const
{
TimeConverter* tc = Simulation_impl::getTimeLord()->getMicro();
if ( tc ) return tc->convertFromCoreTime(sim_->getCurrentSimCycle());
return getCurrentSimTime("1 us");
}
SimTime_t
BaseComponent::getCurrentSimTimeMilli() const
{
TimeConverter* tc = Simulation_impl::getTimeLord()->getMilli();
if ( tc ) return tc->convertFromCoreTime(sim_->getCurrentSimCycle());
return getCurrentSimTime("1 ms");
}
double
BaseComponent::getRunPhaseElapsedRealTime() const
{
return sim_->getRunPhaseElapsedRealTime();
}
double
BaseComponent::getInitPhaseElapsedRealTime() const
{
return sim_->getInitPhaseElapsedRealTime();
}
double
BaseComponent::getCompletePhaseElapsedRealTime() const
{
return sim_->getCompletePhaseElapsedRealTime();
}
bool
BaseComponent::isSimulationRunModeInit() const
{
return sim_->getSimulationMode() == SimulationRunMode::INIT;
}
bool
BaseComponent::isSimulationRunModeRun() const
{
return sim_->getSimulationMode() == SimulationRunMode::RUN;
}
bool
BaseComponent::isSimulationRunModeBoth() const
{
return sim_->getSimulationMode() == SimulationRunMode::BOTH;
}
std::string&
BaseComponent::getOutputDirectory() const
{
return sim_->getOutputDirectory();
}
void
BaseComponent::requireLibrary(const std::string& name)
{
sim_->requireLibrary(name);
}
bool
BaseComponent::doesComponentInfoStatisticExist(const std::string& statisticName) const
{
const std::string& type = my_info_->getType();
return Factory::getFactory()->DoesComponentInfoStatisticNameExist(type, statisticName);
}
StatisticProcessingEngine*
BaseComponent::getStatEngine()
{
return &sim_->stat_engine;
}
void
BaseComponent::vfatal(
uint32_t line, const char* file, const char* func, int exit_code, const char* format, va_list arg) const
{
Output abort("Rank: @R,@I, time: @t - called in file: @f, line: @l, function: @p", 5, -1, Output::STDOUT);
// Get info about the simulation
std::string name = my_info_->getName();
std::string type = my_info_->getType();
// Build up the full list of types all the way to parent component
std::string type_tree = my_info_->getType();
ComponentInfo* parent = my_info_->parent_info;
while ( parent != nullptr ) {
type_tree = parent->type + "." + type_tree;
parent = parent->parent_info;
}
std::string prologue = format_string(
"Element name: %s, type: %s (full type tree: %s)", name.c_str(), type.c_str(), type_tree.c_str());
std::string msg = vformat_string(format, arg);
abort.fatal(line, file, func, exit_code, "\n%s\n%s\n", prologue.c_str(), msg.c_str());
}
void
BaseComponent::fatal(uint32_t line, const char* file, const char* func, int exit_code, const char* format, ...) const
{
va_list arg;
va_start(arg, format);
vfatal(line, file, func, exit_code, format, arg);
va_end(arg);
}
void
BaseComponent::sst_assert(
bool condition, uint32_t line, const char* file, const char* func, int exit_code, const char* format, ...) const
{
if ( !condition ) {
va_list arg;
va_start(arg, format);
vfatal(line, file, func, exit_code, format, arg);
va_end(arg);
}
}
SubComponentSlotInfo*
BaseComponent::getSubComponentSlotInfo(const std::string& name, bool fatalOnEmptyIndex)
{
SubComponentSlotInfo* info = new SubComponentSlotInfo(this, name);
if ( info->getMaxPopulatedSlotNumber() < 0 ) {
// Nothing registered on this slot
delete info;
return nullptr;
}
if ( !info->isAllPopulated() && fatalOnEmptyIndex ) {
Simulation_impl::getSimulationOutput().fatal(CALL_INFO, 1,
"SubComponent slot %s requires a dense allocation of SubComponents and did not get one.\n", name.c_str());
}
return info;
}
TimeConverter*
BaseComponent::getDefaultTimeBase()
{
return Simulation_impl::getTimeLord()->getTimeConverter(my_info_->defaultTimeBase.getFactor());
}
const TimeConverter*
BaseComponent::getDefaultTimeBase() const
{
return Simulation_impl::getTimeLord()->getTimeConverter(my_info_->defaultTimeBase.getFactor());
}
bool
BaseComponent::doesSubComponentExist(const std::string& type)
{
return Factory::getFactory()->doesSubComponentExist(type);
}
uint8_t
BaseComponent::getComponentInfoStatisticEnableLevel(const std::string& statisticName) const
{
return Factory::getFactory()->GetComponentInfoStatisticEnableLevel(my_info_->type, statisticName);
}
void
BaseComponent::configureCollectionMode(Statistics::StatisticBase* statistic, const std::string& name)
{
StatisticBase::StatMode_t statCollectionMode = StatisticBase::STAT_MODE_COUNT;
Output& out = Simulation_impl::getSimulationOutput();
UnitAlgebra collectionRate = statistic->getCollectionRate();
// make sure we have a valid collection rate
// Check that the Collection Rate is a valid unit type that we can use
if ( collectionRate.hasUnits("s") || collectionRate.hasUnits("hz") ) {
// Rate is Periodic Based
statCollectionMode = StatisticBase::STAT_MODE_PERIODIC;
}
else if ( collectionRate.hasUnits("event") ) {
// Rate is Count Based
statCollectionMode = StatisticBase::STAT_MODE_COUNT;
}
else if ( collectionRate.getValue() == 0 ) {
// Collection rate is zero
// so we just dump at beginning and end
collectionRate = UnitAlgebra("0ns");
statCollectionMode = StatisticBase::STAT_MODE_PERIODIC;
}
else {
// collectionRate is a unit type we dont recognize
out.fatal(CALL_INFO, 1, "ERROR: Statistic %s - Collection Rate = %s not valid; exiting...\n", name.c_str(),
collectionRate.toString().c_str());
}
if ( !statistic->isStatModeSupported(statCollectionMode) ) {
if ( StatisticBase::STAT_MODE_PERIODIC == statCollectionMode ) {
out.fatal(CALL_INFO, 1,
" Warning: Statistic %s Does not support Periodic Based Collections; Collection Rate = %s\n",
name.c_str(), collectionRate.toString().c_str());
}
else {
out.fatal(CALL_INFO, 1,
" Warning: Statistic %s Does not support Event Based Collections; Collection Rate = %s\n", name.c_str(),
collectionRate.toString().c_str());
}
}
statistic->setRegisteredCollectionMode(statCollectionMode);
}
Statistics::StatisticBase*
BaseComponent::createStatistic(Params& cpp_params, const Params& python_params, const std::string& name,
const std::string& subId, bool check_load_level, StatCreateFunction fxn)
{
auto* engine = getStatEngine();
if ( check_load_level ) {
uint8_t my_load_level = getStatisticLoadLevel();
uint8_t stat_load_level =
my_load_level == STATISTICLOADLEVELUNINITIALIZED ? engine->statLoadLevel() : my_load_level;
if ( stat_load_level == 0 ) {
Simulation_impl::getSimulationOutput().verbose(CALL_INFO, 1, 0,
" Warning: Statistic Load Level = 0 (all statistics disabled); statistic '%s' is disabled...\n",
name.c_str());
return fxn(this, engine, "sst.NullStatistic", name, subId, cpp_params);
}
uint8_t stat_enable_level = getComponentInfoStatisticEnableLevel(name);
if ( stat_enable_level > stat_load_level ) {
Simulation_impl::getSimulationOutput().verbose(CALL_INFO, 1, 0,
" Warning: Load Level %d is too low to enable Statistic '%s' "
"with Enable Level %d, statistic will not be enabled...\n",
int(stat_load_level), name.c_str(), int(stat_enable_level));
return fxn(this, engine, "sst.NullStatistic", name, subId, cpp_params);
}
}
// this is enabled
configureAllowedStatParams(cpp_params);
cpp_params.insert(python_params);
std::string type = cpp_params.find<std::string>("type", "sst.AccumulatorStatistic");
auto* stat = fxn(this, engine, type, name, subId, cpp_params);
configureCollectionMode(stat, name);
engine->registerStatisticWithEngine(stat);
return stat;
}
Statistics::StatisticBase*
BaseComponent::createEnabledAllStatistic(
Params& params, const std::string& name, const std::string& statSubId, StatCreateFunction fxn)
{
auto iter = m_enabled_all_stats_.find(name);
if ( iter != m_enabled_all_stats_.end() ) {
auto& submap = iter->second;
auto subiter = submap.find(statSubId);
if ( subiter != submap.end() ) {
return subiter->second;
}
}
// a matching statistic was not found
auto* stat = createStatistic(params, my_info_->all_stat_config_->params, name, statSubId, true, std::move(fxn));
if ( !stat->isNullStatistic() ) {
m_enabled_all_stats_[name][statSubId] = stat;
}
return stat;
}
Statistics::StatisticBase*
BaseComponent::createExplicitlyEnabledStatistic(
Params& params, StatisticId_t id, const std::string& name, const std::string& statSubId, StatCreateFunction fxn)
{
Output& out = Simulation_impl::getSimulationOutput();
if ( my_info_->parent_info ) {
out.fatal(CALL_INFO, 1, "Creating explicitly enabled statistic '%s' should only happen in parent component",
name.c_str());
}
auto piter = my_info_->stat_configs_->find(id);
if ( piter == my_info_->stat_configs_->end() ) {
out.fatal(
CALL_INFO, 1, "Explicitly enabled statistic '%s' does not have parameters mapped to its ID", name.c_str());
}
auto& cfg = piter->second;
if ( cfg.shared ) {
auto iter = m_explicitlyEnabledSharedStats.find(id);
if ( iter != m_explicitlyEnabledSharedStats.end() ) {
return iter->second;
}
else {
// no subid
auto* stat = createStatistic(params, cfg.params, cfg.name, "", false, std::move(fxn));
m_explicitlyEnabledSharedStats[id] = stat;
return stat;
}
}
else {
auto iter = m_explicitlyEnabledUniqueStats.find(id);
if ( iter != m_explicitlyEnabledUniqueStats.end() ) {
auto& map = iter->second;
auto subiter = map.find(name);
if ( subiter != map.end() ) {
auto& submap = subiter->second;
auto subsubiter = submap.find(statSubId);
if ( subsubiter != submap.end() ) {
return subsubiter->second;
}
}
}
// stat does not exist yet
auto* stat = createStatistic(params, cfg.params, name, statSubId, false, std::move(fxn));
m_explicitlyEnabledUniqueStats[id][name][statSubId] = stat;
return stat;
}
// unreachable
return nullptr;
}
void
BaseComponent::configureAllowedStatParams(SST::Params& params)
{
// Identify what keys are Allowed in the parameters
std::vector<std::string> allowedKeySet;
allowedKeySet.push_back("type");
allowedKeySet.push_back("rate");
allowedKeySet.push_back("startat");
allowedKeySet.push_back("stopat");
allowedKeySet.push_back("resetOnOutput");
params.pushAllowedKeys(allowedKeySet);
}
void
BaseComponent::performStatisticOutput(StatisticBase* stat)
{
sim_->getStatisticsProcessingEngine()->performStatisticOutput(stat);
}
void
BaseComponent::performGlobalStatisticOutput()
{
sim_->getStatisticsProcessingEngine()->performGlobalStatisticOutput(false);
}
std::vector<Profile::ComponentProfileTool*>
BaseComponent::getComponentProfileTools(const std::string& point)
{
return sim_->getProfileTool<Profile::ComponentProfileTool>(point);
}
void
BaseComponent::initiateInteractive(const std::string& msg)
{
sim_->enter_interactive_ = true;
sim_->interactive_msg_ = msg;
}
void
BaseComponent::serialize_order(SST::Core::Serialization::serializer& ser)
{
SST_SER(my_info_);
SST_SER(component_state_);
switch ( ser.mode() ) {
case SST::Core::Serialization::serializer::SIZER:
case SST::Core::Serialization::serializer::PACK:
{
// Need to serialize each handler
std::pair<Clock::HandlerBase*, SimTime_t> p;
size_t num_handlers = clock_handlers_.size();
SST_SER(num_handlers);
for ( auto* handler : clock_handlers_ ) {
p.first = handler;
// See if it's currently registered with a clock
p.second = sim_->getClockForHandler(handler);
SST_SER(p);
}
break;
}
case SST::Core::Serialization::serializer::UNPACK:
{
sim_ = Simulation_impl::getSimulation();
if ( isStateDoNotEndSim() ) {
// First set state to OKToEndSim to suppress warning in
// primaryComponentDoNotEndSim().
setStateOKToEndSim();
primaryComponentDoNotEndSim();
}
std::pair<Clock::HandlerBase*, SimTime_t> p;
size_t num_handlers;
SST_SER(num_handlers);
for ( size_t i = 0; i < num_handlers; ++i ) {
SST_SER(p);
// Add handler to clock_handlers list
clock_handlers_.push_back(p.first);
// If it was previously registered, register it now
if ( p.second ) {
sim_->registerClock(p.second, p.first, CLOCKPRIORITY);
}
}
break;