Skip to content

Commit f47ebe8

Browse files
Merge pull request #1349 from sstsimulator/devel
Automatically Merged using SST Master Branch Merger
2 parents d8a1719 + c5adebf commit f47ebe8

File tree

13 files changed

+533
-0
lines changed

13 files changed

+533
-0
lines changed

src/sst/core/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,18 @@ nobase_dist_sst_HEADERS = \
101101
serialization/impl/serialize_adapter.h \
102102
serialization/impl/serialize_array.h \
103103
serialization/impl/serialize_atomic.h \
104+
serialization/impl/serialize_bitset.h \
104105
serialization/impl/ser_buffer_accessor.h \
105106
serialization/impl/serialize_insertable.h \
107+
serialization/impl/serialize_optional.h \
106108
serialization/impl/serialize_tuple.h \
107109
serialization/impl/serialize_utility.h \
110+
serialization/impl/serialize_variant.h \
108111
serialization/impl/mapper.h \
109112
serialization/impl/packer.h \
110113
serialization/impl/sizer.h \
111114
serialization/impl/serialize_string.h \
115+
serialization/impl/serialize_valarray.h \
112116
serialization/impl/unpacker.h \
113117
serialization/serializer.h \
114118
serialization/serializer_fwd.h \

src/sst/core/impl/interactive/simpleDebug.cc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,44 @@ SimpleDebugger::tokenize(std::vector<std::string>& tokens, const std::string& in
5757
return tokens;
5858
}
5959

60+
void
61+
SimpleDebugger::cmd_help(std::vector<std::string>& UNUSED(tokens))
62+
{
63+
std::string help = "SimpleDebug Console Commands\n";
64+
help.append(" Navigation: Navigate the current object map\n");
65+
help.append(" - pwd: print the current working directory in the object map\n");
66+
help.append(" - cd: change directory level in the object map\n");
67+
help.append(" - ls: list the objects in the current level of the object map\n");
68+
69+
help.append(" Current State: Print information about the current simulation state\n");
70+
help.append(" - time: print current simulation time in cycles\n");
71+
help.append(" - print [-rN][<obj>]: print objects in the current level of the object map;\n");
72+
help.append(" if -rN is provided print recursive N levels (default N=4)\n");
73+
74+
help.append(" Modify State: Modify simulation variables\n");
75+
help.append(" - set <obj> <value>: sets an object in the current scope to the provided value;\n");
76+
help.append(" object must be a \"fundamental type\" e.g. int \n");
77+
78+
help.append(" Watch Points: Manage watch points which break into interactive console when triggered\n");
79+
help.append(" - watch: prints the current list of watch points and their associated indices\n");
80+
help.append(" watch <var>: adds var to the watch list; triggered when value changes\n");
81+
help.append(" watch <var> <comp> <val>: add var to watch list; triggered when comparison with val is true\n");
82+
help.append(" Valid <comp> operators: <, <=, >, >=, ==, !=\n");
83+
help.append(" - unwatch <index>: removes the indexed watch point from the watch list;\n");
84+
help.append(" <index> is the associated index from the list of watch points\n");
85+
86+
help.append(" Execute: Execute the simulation for a specified duration\n");
87+
help.append(" - run [TIME]: runs the simulation from the current point for TIME and then returns to\n");
88+
help.append(" interactive mode; if no time is given, the simulation runs to completion;\n");
89+
help.append(" TIME is of the format <Number><unit> e.g. 4us\n");
90+
91+
help.append(" Exit: Exit the interactive console\n");
92+
help.append(" - exit or quit: exits the interactive console and resumes simulation execution\n");
93+
help.append(" - shutdown: exits the interactive console and does a clean shutdown of the simulation\n");
94+
95+
printf("%s", help.c_str());
96+
}
97+
6098
void
6199
SimpleDebugger::cmd_pwd(std::vector<std::string>& UNUSED(tokens))
62100
{
@@ -378,6 +416,15 @@ SimpleDebugger::cmd_unwatch(std::vector<std::string>& tokens)
378416
watch_points_.erase(watch_points_.begin() + index);
379417
}
380418

419+
void
420+
SimpleDebugger::cmd_shutdown(std::vector<std::string>& UNUSED(tokens))
421+
{
422+
simulationShutdown();
423+
done = true;
424+
printf("Exiting ObjectExplorer and shutting down simulation\n");
425+
return;
426+
}
427+
381428
void
382429
SimpleDebugger::dispatch_cmd(std::string cmd)
383430
{
@@ -415,6 +462,12 @@ SimpleDebugger::dispatch_cmd(std::string cmd)
415462
else if ( tokens[0] == "unwatch" ) {
416463
cmd_unwatch(tokens);
417464
}
465+
else if ( tokens[0] == "shutdown" ) {
466+
cmd_shutdown(tokens);
467+
}
468+
else if ( tokens[0] == "help" ) {
469+
cmd_help(tokens);
470+
}
418471
else {
419472
printf("Unknown command: %s\n", tokens[0].c_str());
420473
}

src/sst/core/impl/interactive/simpleDebug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class SimpleDebugger : public SST::InteractiveConsole
6666
6767
std::vector<std::string> tokenize(std::vector<std::string>& tokens, const std::string& input);
6868
69+
void cmd_help(std::vector<std::string>& tokens);
6970
void cmd_pwd(std::vector<std::string>& tokens);
7071
void cmd_ls(std::vector<std::string>& tokens);
7172
void cmd_cd(std::vector<std::string>& tokens);
@@ -75,6 +76,7 @@ class SimpleDebugger : public SST::InteractiveConsole
7576
void cmd_run(std::vector<std::string>& tokens);
7677
void cmd_watch(std::vector<std::string>& tokens);
7778
void cmd_unwatch(std::vector<std::string>& tokens);
79+
void cmd_shutdown(std::vector<std::string>& tokens);
7880
7981
void dispatch_cmd(std::string cmd);
8082
};

src/sst/core/interactiveConsole.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,11 @@ InteractiveConsole::getComponentObjectMap()
111111
return Simulation_impl::getSimulation()->getComponentObjectMap();
112112
}
113113

114+
void
115+
InteractiveConsole::simulationShutdown()
116+
{
117+
Simulation_impl::getSimulation()->endSimulation();
118+
}
119+
120+
114121
} // namespace SST

src/sst/core/interactiveConsole.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class InteractiveConsole
124124

125125
SST::Core::Serialization::ObjectMap* getComponentObjectMap();
126126

127+
void simulationShutdown();
128+
127129
private:
128130
InteractiveConsole(const InteractiveConsole&) = delete;
129131
InteractiveConsole& operator=(const InteractiveConsole&) = delete;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2009-2025 NTESS. Under the terms
2+
// of Contract DE-NA0003525 with NTESS, the U.S.
3+
// Government retains certain rights in this software.
4+
//
5+
// Copyright (c) 2009-2025, NTESS
6+
// All rights reserved.
7+
//
8+
// This file is part of the SST software package. For license
9+
// information, see the LICENSE file in the top level directory of the
10+
// distribution.
11+
12+
#ifndef SST_CORE_SERIALIZATION_IMPL_SERIALIZE_BITSET_H
13+
#define SST_CORE_SERIALIZATION_IMPL_SERIALIZE_BITSET_H
14+
15+
#ifndef SST_INCLUDING_SERIALIZE_H
16+
#warning \
17+
"The header file sst/core/serialization/impl/serialize_bitset.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serialize.h"
18+
#endif
19+
20+
#include "sst/core/serialization/serializer.h"
21+
22+
#include <bitset>
23+
#include <cstddef>
24+
#include <type_traits>
25+
26+
namespace SST::Core::Serialization {
27+
28+
// Serialize std::bitset
29+
template <size_t N>
30+
class serialize_impl<std::bitset<N>>
31+
{
32+
using T = std::bitset<N>;
33+
void operator()(T& t, serializer& ser, ser_opt_t UNUSED(options))
34+
{
35+
switch ( ser.mode() ) {
36+
case serializer::MAP:
37+
{
38+
// TODO: Should this be mapped as an array? It will have the same problems as std::vector<bool>
39+
break;
40+
}
41+
42+
default:
43+
static_assert(std::is_trivially_copyable_v<T> && std::is_standard_layout_v<T>);
44+
ser.primitive(t);
45+
break;
46+
}
47+
}
48+
SST_FRIEND_SERIALIZE();
49+
};
50+
51+
template <size_t N>
52+
class serialize_impl<std::bitset<N>*>
53+
{
54+
using T = std::bitset<N>;
55+
void operator()(T*& t, serializer& ser, ser_opt_t UNUSED(options))
56+
{
57+
if ( ser.mode() == serializer::UNPACK ) t = new T {};
58+
SST_SER(*t);
59+
}
60+
SST_FRIEND_SERIALIZE();
61+
};
62+
63+
} // namespace SST::Core::Serialization
64+
65+
#endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_BITSET_H
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2009-2025 NTESS. Under the terms
2+
// of Contract DE-NA0003525 with NTESS, the U.S.
3+
// Government retains certain rights in this software.
4+
//
5+
// Copyright (c) 2009-2025, NTESS
6+
// All rights reserved.
7+
//
8+
// This file is part of the SST software package. For license
9+
// information, see the LICENSE file in the top level directory of the
10+
// distribution.
11+
12+
#ifndef SST_CORE_SERIALIZATION_IMPL_SERIALIZE_OPTIONAL_H
13+
#define SST_CORE_SERIALIZATION_IMPL_SERIALIZE_OPTIONAL_H
14+
15+
#ifndef SST_INCLUDING_SERIALIZE_H
16+
#warning \
17+
"The header file sst/core/serialization/impl/serialize_optional.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serialize.h"
18+
#endif
19+
20+
#include "sst/core/serialization/serializer.h"
21+
22+
#include <optional>
23+
24+
namespace SST::Core::Serialization {
25+
26+
// Serialize std::optional
27+
template <typename T>
28+
class serialize_impl<std::optional<T>>
29+
{
30+
void operator()(std::optional<T>& obj, serializer& ser, ser_opt_t options)
31+
{
32+
bool has_value = false;
33+
34+
switch ( ser.mode() ) {
35+
case serializer::SIZER:
36+
has_value = obj.has_value();
37+
ser.size(has_value);
38+
break;
39+
40+
case serializer::PACK:
41+
has_value = obj.has_value();
42+
ser.pack(has_value);
43+
break;
44+
45+
case serializer::UNPACK:
46+
ser.unpack(has_value);
47+
if ( has_value )
48+
obj.emplace();
49+
else
50+
obj.reset();
51+
break;
52+
53+
case serializer::MAP:
54+
{
55+
// TODO: how to map std::optional ?
56+
return;
57+
}
58+
}
59+
60+
// Serialize the optional object if it is present
61+
if ( has_value ) sst_ser_object(ser, *obj, options, nullptr);
62+
}
63+
64+
SST_FRIEND_SERIALIZE();
65+
};
66+
67+
} // namespace SST::Core::Serialization
68+
69+
#endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_OPTIONAL_H
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2009-2025 NTESS. Under the terms
2+
// of Contract DE-NA0003525 with NTESS, the U.S.
3+
// Government retains certain rights in this software.
4+
//
5+
// Copyright (c) 2009-2025, NTESS
6+
// All rights reserved.
7+
//
8+
// This file is part of the SST software package. For license
9+
// information, see the LICENSE file in the top level directory of the
10+
// distribution.
11+
12+
#ifndef SST_CORE_SERIALIZATION_IMPL_SERIALIZE_VALARRAY_H
13+
#define SST_CORE_SERIALIZATION_IMPL_SERIALIZE_VALARRAY_H
14+
15+
#ifndef SST_INCLUDING_SERIALIZE_H
16+
#warning \
17+
"The header file sst/core/serialization/impl/serialize_valarray.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serialize.h"
18+
#endif
19+
20+
#include "sst/core/serialization/serializer.h"
21+
22+
#include <string>
23+
#include <type_traits>
24+
#include <valarray>
25+
26+
namespace SST::Core::Serialization {
27+
28+
// Whether a type is a std::valarray type
29+
template <typename>
30+
constexpr bool is_valarray_v = false;
31+
32+
// We must make sure that T is trivially copyable and standard layout type, although this is almost always true
33+
template <typename T>
34+
constexpr bool is_valarray_v<std::valarray<T>> = std::is_trivially_copyable_v<T> && std::is_standard_layout_v<T>;
35+
36+
// Serialize std::valarray and pointers to std::valarray
37+
template <typename T>
38+
class serialize_impl<T, std::enable_if_t<is_valarray_v<std::remove_pointer_t<T>>>>
39+
{
40+
void operator()(T& obj, serializer& ser, ser_opt_t UNUSED(options))
41+
{
42+
const auto& objPtr = get_ptr(obj);
43+
size_t size = 0;
44+
switch ( ser.mode() ) {
45+
case serializer::SIZER:
46+
size = objPtr->size();
47+
ser.size(size);
48+
break;
49+
50+
case serializer::PACK:
51+
size = objPtr->size();
52+
ser.pack(size);
53+
break;
54+
55+
case serializer::UNPACK:
56+
ser.unpack(size);
57+
if constexpr ( std::is_pointer_v<T> )
58+
obj = new std::remove_pointer_t<T>(size);
59+
else
60+
obj.resize(size);
61+
break;
62+
63+
case serializer::MAP:
64+
size = objPtr->size();
65+
ser.mapper().map_hierarchy_start(
66+
ser.getMapName(), new ObjectMapContainer<std::remove_pointer_t<T>>(objPtr));
67+
for ( size_t i = 0; i < size; ++i )
68+
sst_ser_object(ser, (*objPtr)[i], SerOption::none, std::to_string(i).c_str());
69+
ser.mapper().map_hierarchy_end();
70+
return;
71+
}
72+
ser.raw(&(*objPtr)[0], size * sizeof((*objPtr)[0]));
73+
}
74+
75+
SST_FRIEND_SERIALIZE();
76+
};
77+
78+
} // namespace SST::Core::Serialization
79+
80+
#endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_VALARRAY_H

0 commit comments

Comments
 (0)