-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
do not copy when deserialize #9209
Conversation
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.
Amazing!
if (!input->GetDirectBufferPointer(&data, &size_to_write)) { | ||
return false; | ||
} | ||
// TODO(gongwb): don't copy if it's aligned? |
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.
Maybe we need to copy anyway? I guess the buffer that we copy from will become invalid afterwards.
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.
ByteBuffer is in userspace, and it uses the Slice to manage discontinuous memory.
If our data is in a single slice, we can use it directly--It needs to serialize the send buffer manually and it's dangerous.
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.
Sorry maybe I did not made it clear, I thought we should not use the underlying buffer, since the buffer belongs to protobuf, and the content could change?
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.
好像内存可以保留下来。另外bytes的对应数据就是一块内存。
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 changed this comment to "Can we avoid copy?".
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.
ok, thanks!
auto* slr = var->GetMutable<framework::SelectedRows>(); | ||
int64_t* rows_data = slr->mutable_rows()->data(); | ||
|
||
// copy rows CPU data, GPU data will be copied lazly |
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.
lazly -> lazily
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.
Done.Thanks.
varmsg.SerializeToString(&str); | ||
|
||
// message bytebuffer | ||
::grpc::Slice slices_2[1]; |
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.
Could you test with a bigger sized buffer? A 1 sized buffer perhaps is not general enough. Or even better, test in a loop, like for i := 1; i < 100; i++
.
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.
There are two styles of repeated field: packed and not packed and protobuf may change it auto even you don't specify packed.
- packed: <tag,data> <tag,data>....
- not packed: <tag,len><data, data,data..>...
This code only guarantees we can parse manual serialized buffer and the standard buffer.
The byte buffer may have many slices already.
return false; | ||
} | ||
// TODO(gongwb): don't copy if it's aligned? | ||
memcpy(reinterpret_cast<void*>(p), data, size_to_write); |
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.
can use memory::Copy here
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.
Done.
return true; | ||
} | ||
|
||
int TensorResponse::Parse(::grpc::ByteBuffer& byte_buffer, |
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.
we don't actually need a class TensorResponse
, just put functions in proto_encoder_helper.h (or .cc) and put this content in DeserializeFromByteBuffer
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 class is needed for parse tensor response.
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.
LGTM except two minor comments.
namespace operators { | ||
namespace detail { | ||
|
||
class TensorResponse { |
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.
Should call it VariableResponse
or VariableMessageParser
because the response contains not only tensor
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.
The file name should also be changed I suppose.
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.
Done.
int Parse(const ::grpc::ByteBuffer& byte_buffer, | ||
const platform::DeviceContext& dev_ctx); | ||
|
||
// should call parse first. |
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.
Interface comments are too simple and not explaining what the function does.
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.
Done.
Move to #9271 which is the whole PR. |
Fix part of #8638