Skip to content
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

Double buffer for cpp reader #8841

Merged

Conversation

JiayiFeng
Copy link
Collaborator

@JiayiFeng JiayiFeng commented Mar 7, 2018

fixes #8847

Please review #8913 first.

write_pos_(0),
read_pos_(0) {
std::thread prefetch(
std::bind(&DoubleBufferReader::PrefetchThreadFunc, this));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete the bind is ok here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Thanks.

if (read_pos_ >= kDoubleBufferSize) {
read_pos_ = 0;
}
buffer_not_full_.notify_all();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be notify_one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For there is only one producer and one consumer here, notify_all() and notify_one() is same.

private:
void PrefetchThreadFunc();

std::vector<std::vector<framework::LoDTensor>> buffer_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a thread safe channel (queue) is better here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look at that. Thanks.

Copy link
Contributor

@dzhwinter dzhwinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Great. Only one comment, now we have two runtime type(the real type is decided in runtime -- framework::VarDesc::Raw, ReaderHolder. Could we figure out a better way to unify the runtime type?


prog = fluid.framework.Program()
block = prog.current_block()
startup_prog = fluid.framework.Program()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make the reader operator as a part of startup program?

Copy link
Collaborator Author

@JiayiFeng JiayiFeng Mar 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because a reader should be created only once.

@JiayiFeng JiayiFeng merged commit aa3f505 into PaddlePaddle:develop Mar 9, 2018
@JiayiFeng JiayiFeng deleted the dev_double_buffer_for_cpp_reader branch March 9, 2018 09:21
@JiayiFeng JiayiFeng changed the title Basic double buffer for cpp reader Double buffer for cpp reader Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Double buffer for C++ data feeding
2 participants