Workaround for serialization of user-defined simple data types (in 2018.9.0 release)

Issue #197 resolved
Amin M. Khan created an issue

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)

  1. Dan Bonachea

    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:

    #include <upcxx/upcxx.hpp>
    #include <iostream>
    
    template<class T, class D>
    class Rect {
    public:
        T id;
        D length;
        D width;
    
        T area() {
            return length * width;
        }
    };
    
    using myRect = Rect<int,int>;
    
    int main() {
      upcxx::init();
      upcxx::rpc(0,[](int from, myRect r) {
       std::cout << from << ": " << r.id << "," << r.length << "," << r.width << std::endl;
      }, upcxx::rank_me(), myRect{1,2,3}).wait();
      upcxx::finalize();
    }
    

    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 and D TriviallyCopyable types? The question that needs to be answered here is whether it's safe for the UPC++ library to byte-copy your Rect 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:

    namespace upcxx {
      template<class T, class D>
      struct is_definitely_trivially_serializable<Rect<T, D>> : std::true_type {};
    }
    

    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

  2. Log in to comment