Skip to content

Fix serialization to build in both mapped and un-mapped mode#1268

Closed
leekillough wants to merge 5 commits intosstsimulator:develfrom
leekillough:fix_serialization
Closed

Fix serialization to build in both mapped and un-mapped mode#1268
leekillough wants to merge 5 commits intosstsimulator:develfrom
leekillough:fix_serialization

Conversation

@leekillough
Copy link
Contributor

@leekillough leekillough commented Mar 20, 2025

Fixes tactcomplabs/sst-tools#5 (cross-repo).

Remove the name parameter from serialization operator()(T&, serializer& ser, const char* name), since it makes it too complicated, and caused compilation errors. It would be better to store mapped information in the serializer class state than to pass mapped name arguments at every level of the call hierarchy and to need to split the serialization functions into mapped and non-mapped versions.

Add ser.setMapName() and ser.getMapName() to set and get mapped names, which are only used in certain places (right now it's just a const char* pointer, but it can be turned into a std::string if necessary). The SST_SER() macro will call the sst_map_object() function, which will set the quoted variable name to be used in the map before the serialization call, and clear the name after the serialization call, so that the name does not need to be passed around in every call.

operator() functions which used to be duplicated with a mapped and a non-mapped version, the mapped version of which was only valid in serializer::MAP mode, are now combined into one where the serializer::MAP mode, already handled in a switch statement, expects getMapName() to return the name.

Rewrite the default serialize_impl<> class to use modern C++ techniques like if constexpr and decltype(auto). tPtr is a const reference variable which refers to either t or &t depending on whether t is a pointer or not, so that pointer and non-pointer code can be merged into one, by using the tPtr pointer to make method calls, and tPtr also reflects the new value of t when t is a pointer which gets assigned to in UNPACK mode. The dependent_false template is not needed anymore, since we can simply use a single static_assert() at the top of our function to assert that the type, with any top-level pointer removed, is a non-polymorphic class type.

Write a generalized SST::Core::to_string() which operates like std::to_string and also handles enumeration types, and generalize SST::Core::from_string() to handle enumeration types. Right now, enumeration types are inputted and outputted as integers of the underlying type. There were build errors when the mapped and non-mapped serialization codes were merged, because the mapped code depended on std::to_string which isn't defined for enumeration types but which was depended on when the serialize_impl for "fundamental and enum types" created a mapping object.

For array serialization templates, use size_t instead of int for the size of the array.

The Core tests pass, and Elements builds, but there are some Elements test failures which need investigating and fixing.

…kes it too

    complicated, and caused compilation errors. It would be better to store mapped
    information in the serializer class state than to pass mapped "name" arguments
    at every level of the call hierarchy and to need to split the serialization
    functions into mapped and unmapped versions.

    Add ser.setMapName() and ser.getMapName() to set and get mapped names, which
    are only used in certain places (right now it's just a const char* pointer,
    but it can be turned into a std::string if necessary). The SST_SER() macro
    will call sst_map_object() function, which will set the quoted variable name
    used to be used in the map before the serialization call, and clear the name
    after the serialization call, so that the name does not need to be passed
    around in every call.

    operator() functions which used to be duplicated with a mapped and an unmapped
    version, the mapped of which was only valid in serializer::MAP mode, are now
    combined into one where the serializer::MAP mode, alread handled in a switch
    statement, expects getMapName() to return the name.

    Rewrite the default serialize_impl<> class to use modern C++ techniques like
    "if constexpr" and "decltype(auto)". tPtr is a new const reference variable
    which refers to either t or &t depending on whether t is a pointer or not, so
    that pointer and non-pointer code can be merged into one, by using the pointer
    version of the code, and it also uses the new t when it is a pointer which
    gets allocated in UNPACK mode. The dependent_false template is not needed
    anymore, since we can simply use a single static_assert() at the top of our
    function to assert that the type, with any top-level pointer removed, is a
    non-polymorphic class type.

    Write a generalized SST::Core:to_string() which operates like std::to_string
    and also handles enumeration types, and generalize SST::Core::from_string()
    to handle enumeration types. Right now, enumeration types are inputted and
    outputted as integers of the underlying type. There were build errors when
    the mapped and non-mapped serialization codes were merged, because the mapped
    code depended on std::to_string which isn't defined for enumeration types but
    which was depended on when the serialize_impl for "fundamental and enum types"
    created a mapping object.
@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) AT: CLANG-FORMAT FAIL labels Mar 20, 2025
@github-actions
Copy link

CLANG-FORMAT TEST - FAILED (on last commit):
Run > ./scripts/clang-format-test.sh using clang-format v12 to check formatting

@github-actions github-actions bot added AT: CMAKE-FORMAT PASS and removed AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) labels Mar 20, 2025
@github-actions
Copy link

CMAKE-FORMAT TEST - PASSED

@sst-autotester
Copy link
Contributor

Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging
NO INSPECTION HAS BEEN PERFORMED ON THIS PULL REQUEST! - This PR must be inspected by setting label 'AT: PRE-TEST INSPECTED'.

@github-actions github-actions bot added the AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) label Mar 20, 2025
@github-actions
Copy link

CLANG-FORMAT TEST - FAILED (on last commit):
Run > ./scripts/clang-format-test.sh using clang-format v12 to check formatting

@github-actions github-actions bot removed the AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) label Mar 20, 2025
@github-actions
Copy link

CMAKE-FORMAT TEST - PASSED

@sst-autotester
Copy link
Contributor

Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging
NO INSPECTION HAS BEEN PERFORMED ON THIS PULL REQUEST! - This PR must be inspected by setting label 'AT: PRE-TEST INSPECTED'.

@feldergast
Copy link
Contributor

Thanks for putting this together. Minus a few details, this looks very similar to how I first implemented things (including holding name state in the serializer) and was my preferred solution. However, some constraints in the interactions between using serialization for checkpointing and mapping mode (where performance requirements are low) and using the same serialization for event synchronization (where performance requirements are high) led me to the two function solution. I’m on vacation for spring break this week and saw this as I was triaging emails and wanted to give a heads up so you don’t spend too much time on it before we can talk about it. I was under a time constraint in the original implementation and gave up on the one function solution, but maybe we can work something out that gets us back there while fulfilling all the constraints (which haven’t been fully documented yet since mapping mode is still experimental).

@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) and removed AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) labels Mar 20, 2025
@github-actions
Copy link

CMAKE-FORMAT TEST - PASSED

@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) AT: CLANG-FORMAT PASS and removed AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) AT: CLANG-FORMAT FAIL labels Mar 20, 2025
@github-actions
Copy link

CLANG-FORMAT TEST - PASSED

@sst-autotester
Copy link
Contributor

Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging
NO INSPECTION HAS BEEN PERFORMED ON THIS PULL REQUEST! - This PR must be inspected by setting label 'AT: PRE-TEST INSPECTED'.

@leekillough leekillough deleted the fix_serialization branch March 31, 2025 04:05
@berquist berquist added this to the SST V15.0.0 milestone Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AT: CLANG-FORMAT PASS AT: CMAKE-FORMAT PASS AT: WIP Mark PR as a Work in Progress (No Autotesting Performed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants