提交 8cb20186 编写于 作者: M Megvii Engine Team

fix(mgb): fix fastrun cache serialization method

GitOrigin-RevId: cd8bed3cc9dc497ee25912cfb1f17beed2044b00
上级 88c1eedb
......@@ -212,6 +212,10 @@ public:
result.append(val, strlen(val));
}
static void serialize_write_pod(const std::string& val, std::string& result) {
result.append(val.data(), val.size());
}
template <typename T>
static T deserialize_read_pod(const std::string& data, size_t offset = 0) {
static_assert(std::is_trivially_copyable<T>::value, "invalid type");
......@@ -227,6 +231,12 @@ public:
return ret;
}
static std::string deserialize_read_pod(const std::string& data,
size_t offset = 0,
size_t size = 0) {
return std::string(data.data() + offset, size);
}
template <typename T>
static T deserialize_read_pod(const char* data, size_t offset = 0) {
static_assert(std::is_trivially_copyable<T>::value, "invalid type");
......
......@@ -304,8 +304,8 @@ static void serialize_write_pod(const Algorithm::Info::Desc& val,
uint32_t name_size = val.name.size();
megdnn::Algorithm::serialize_write_pod<uint32_t>(param_size, result);
megdnn::Algorithm::serialize_write_pod<uint32_t>(name_size, result);
result += val.param;
result += val.name;
megdnn::Algorithm::serialize_write_pod(val.param, result);
megdnn::Algorithm::serialize_write_pod(val.name, result);
}
static Algorithm::Info::Desc deserialize_read_pod(const std::string& data,
......@@ -325,11 +325,13 @@ static Algorithm::Info::Desc deserialize_read_pod(const std::string& data,
cb(name_size, uint32_t);
if (param_size > 0) {
ret.param = std::string(data.data() + offset, param_size);
ret.param = megdnn::Algorithm::deserialize_read_pod(data, offset,
param_size);
offset += param_size;
}
if (name_size > 0) {
ret.name = std::string(data.data() + offset, name_size);
ret.name = megdnn::Algorithm::deserialize_read_pod(data, offset,
name_size);
offset += name_size;
}
return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册