Add local cache of double buffer reader#9535
Merged
JiayiFeng merged 9 commits intoPaddlePaddle:developfrom Apr 2, 2018
Merged
Conversation
wangkuiyi
reviewed
Mar 31, 2018
| void DoubleBufferReader::PrefetchThreadFunc() { | ||
| VLOG(5) << "A new prefetch thread starts."; | ||
| size_t gpu_ctx_offset = 0; | ||
| std::vector<std::vector<framework::LoDTensor>> cpu_tensor_cache(4); |
Collaborator
There was a problem hiding this comment.
Why is the size of the outer vector 4? It seems empirical. Should we have
const int kEmpiricalCacheSize = 4;
std::vector<std::vector<framework::LoDTensor>> gpu_tensor_cache(kEmpiricalCacheSize);| reader_->ReadNext(&batch.payloads_); | ||
| if (platform::is_gpu_place(place_)) { | ||
| std::vector<framework::LoDTensor> gpu_batch; | ||
| tensor_cache_id %= 4; |
Collaborator
There was a problem hiding this comment.
It seems that here we need 4 because of the above 4.
| tensor_cache_id %= 4; | ||
| auto& gpu_batch = gpu_tensor_cache[tensor_cache_id]; | ||
| auto& cpu_batch = cpu_tensor_cache[tensor_cache_id]; | ||
| cpu_batch = batch.payloads_; |
Collaborator
There was a problem hiding this comment.
I am a little lost here -- it seems that L159 and L160 can be merged into a single line:
auto& cpu_batch = batch.payloads_;Am I wrong?
Collaborator
|
I have just updated this PR. Did some code clean. Maybe you could take a look at it. Thanks! @wangkuiyi |
chengduoZH
reviewed
Apr 2, 2018
| }; | ||
|
|
||
| bool DoubleBufferReader::HasNext() const { | ||
| while (!channel_->IsClosed() && !channel_->CanReceive()) { |
Contributor
There was a problem hiding this comment.
Maybe it will be better to use semaphore here. Or add TODO.
chengduoZH
approved these changes
Apr 2, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.