Rewrite crop layer GPU implementation#5548
Merged
shelhamer merged 2 commits intoBVLC:masterfrom May 4, 2017
Merged
Conversation
Member
|
Thanks for the speed-up Eric! |
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.
The crop layer currently in Caffe is really slow on GPU. For example, in fcn8s on a 500x375 image, the final crop layer alone takes 8.3ms out of a 65.1ms forward pass (12.7%)!
This seems to be a result of the fact that the original GPU implementation is a fairly faithful reproduction of the CPU version. The CPU version is a series of recursive calls that eventually delegates to
caffe_copyto copy a contiguous portion of the crop. The original GPU version is thus a similar series of recursive calls that eventually delegates to a CUDA kernel. This ends up being horribly inefficient in practice, since we are forced to sync after each copy, and we do a large number of copies (one for each leaf of the recursion tree).This PR rewrites the GPU implementation to do the entire operation in a single kernel call. Under the same conditions as before, the new implementation takes 0.3ms for a forward pass, which is roughly a 28x speedup. In practice, the speedup depends on the size of the input, with the largest gains on the largest input blobs.
I think this should be good to go. Let me know if anything seems off.