add Share{Data,Diff} methods to blobs to enable "virtual" copies#318
Merged
add Share{Data,Diff} methods to blobs to enable "virtual" copies#318
Conversation
include/caffe/blob.hpp
Outdated
Contributor
There was a problem hiding this comment.
Share{Data,Diff}? Adoption usually means that a child is transferred from one family to another one. But in this situation, the shared_ptr is contained in both Blobs.
Contributor
Author
There was a problem hiding this comment.
Good point, thanks.
Member
|
This is a sweet change Jeff! Fewer ops, less memory, and simplified splitting logic are all good. This sets the stage for weight sharing too (which I hope to hack at ICLR). |
shelhamer
added a commit
that referenced
this pull request
Apr 13, 2014
add Share{Data,Diff} methods to blobs to enable "virtual" copies
- reduce operations by not copying values
- spare memory by shared_ptrs
- simplify SplitLayer logic
Merged
mitmul
pushed a commit
to mitmul/caffe
that referenced
this pull request
Sep 30, 2014
add Share{Data,Diff} methods to blobs to enable "virtual" copies
- reduce operations by not copying values
- spare memory by shared_ptrs
- simplify SplitLayer logic
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.
This PR adds methods
ShareDataandShareDiffso that explicit O(N) copies by value can be replaced with O(1) copies by reference using the=operator onshared_ptr<SyncedMem>s which hold the blob data.This makes
FlattenLayers essentially free andSplitLayers substantially cheaper -- only needing to do anaxpyin the backward pass (which is mathematically necessary).On my machine, this speeds up
FlattenLayerTestfrom ~20s to ~12s_, with the vast majority of the speedup due to TestGPUGradient since FlattenLayer no longer actually does any GPU computation. TheSplitLayerTesttiming does not change much because the copies in the unit test are so small to begin with, but when I do the test on a somewhat realistic input size (changetest_split_layerline 27 toblob_bottom_(new Blob<Dtype>(1000, 3, 200, 200))instead of(2, 3, 6, 5)) and run using./build/test/test_split_layer.testbin --gtest_filter="-_Gradient*"(suppresses gradient checking tests because they become absurdly slow with this blob size), I see a speedup from ~176s to ~171s. Not huge, but basically a free improvement.*These unit tests (which I wrote) are way too slow even with this improvement, but that's a problem to address in another PR...