Workaround for serialization of user-defined simple data types (in 2018.9.0 release)
Issue #197
resolved
The current UPC++ 1.0 Draft 8 Specification explains user-defined Serialization interface, which is not yet implemented in latest release upcxx-2018.9.0
.
So given a simple user-defined type as below, is there a possible workaround to pass such types to functions like upcxx::rpc
?
template<class T, class D>
class Rect {
T id;
D length;
D width;
T area() {
return length * width;
}
};
Alternatively, is there a nightly build with some preliminary support for user-defined Serialization interface to try out, or is the feature expected to be supported in a near release?
(Just a note that the older release upcxx-2017.9.0
let such objects be passed to upcxx::rpc
, while in the current version all rpc arguments must be DefinitelySerializable.)
Comments (3)
-
-
reporter Yes, sprinkling
is_definitely_trivially_serializable
over our codebase did the work! -
- changed status to resolved
- Log in to comment
Hi @aminmkhan - very good question!
First, can you provide a complete example demonstrating the problem you are trying to solve? For example, when I try the following, it works:
The key issue here is the UPC++ runtime needs to know how to serialize your objects into a byte stream before sending them over the wire. For types satisfying the TriviallyCopyable C++ concept, this is simple. I suspect your real example must contain something that makes the Rect type not TriviallyCopyable. Does it contain a non-trivial destructor or copy/move constructor/assignment-operator? Are
T
andD
TriviallyCopyable types? The question that needs to be answered here is whether it's safe for the UPC++ library to byte-copy yourRect
objects, or do they contain raw pointers or references that actually require user-defined serialization methods? I suspect they are byte-copyable, otherwise the old release probably would have failed to correctly transfer your objects.If your objects are safely byte-copyable, then all you need to do is "tell" the UPC++ runtime that your type is byte-copyable (aka "DefinitelyTriviallySerializable"). You do this via a declaration like the following:
The UPC++ support for non-trivial serialization (for types that are NOT byte-copyable) is forthcoming in a future release. If you're interested, there is already a proposed API in the works, but not yet fully implemented.
CC: @shofmeyr, @akamil