-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
common, xe: consolidate serialization API #2802
base: main
Are you sure you want to change the base?
Conversation
namespace primitive_serialization { | ||
|
||
void serialize_post_ops( | ||
serialization_stream_t &sstream, const post_ops_t &post_ops); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code seems excessively verbose and the style is unaligned with how the GPU serialization tends to work. What if we just use a templated function instead?
namespace primitive {
template <typename T> void serialize(serialization_stream_t sstream, const T &t);
}
And then use extern template
in this file. After that, usage is primitive::serialize(stream, data)
which seems more readable. Debatably, we could also drop the namespace, it doesn't seem like it serves much of a purpose, as implementing multiple serializers for these core types seems like it would be an antipattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, switching to overloading + dropping the namespace look reasonable to me.
@densamoilov please confirm if these changes are fine with you as I see you implemented this originally.
make test |
#include "common/primitive_attr.hpp" | ||
#include "common/serialization.hpp" | ||
#include "common/type_helpers.hpp" | ||
#include "oneapi/dnnl/dnnl.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: probably can skip this one in favor of c_types_map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed, thanks.
size_t idx; | ||
const serialization_stream_t &s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make them private
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated.
static const bool value = (sizeof(test<T>(0)) == sizeof(yes_t)); | ||
}; | ||
|
||
// Append helper function for structures with the member function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QQ: is append
supposed to be public? Or should a ctor be the only user-facing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's supposed to be public as it's used as sstream.append(...)
in many places.
I put some suggestions to unify API in the description (e.g. switch to uniform serialize(sstream, obj)
usage) but I'd left it for the future.
make test |
PR consolidates serialization API in
src/gpu/intel
andsrc/common
.List of changes:
serialized_t
/serialized_data_t
/deserializer_t
functionality fromsrc/gpu/intel
tosrc/common
serialized_data_t
,serialized_t
andserialization_stream_t
functionality intoserialization_stream_t
src/common/{serialization_stream.hpp => serialization.hpp}
as it now includes broad serialization API (not just stream)src/common/{serialization.hpp => primitive_serialization.hpp}
I'm not 100% sure on the names so please share your suggestions if any.
I'm also listing API changes to simplify/unify serialization API for review:
serialized_t
andserialized_data_t
into a single abstraction (implemented in this PR)obj.serialize(stream)
. Now there are two versions: see (1) belowserialize(sstream, obj)
obj = deserialize<Object>(deserializer)
ordeserialize(deserializer, obj)
sstream.append()
tosstream.serialize()
to have a single namedeserializer.pop()
todeserializer.deserialize()
to have a single namedeserialize(sstream, obj)
which would construct a temporarydeserializer_t
on-the-fly and forward the call todeserialize(deserializer, obj)
(1)