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

Share convolution buffers to reduce memory usage #2016

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shelhamer
Copy link
Member

@shelhamer shelhamer commented Mar 3, 2015

Share the columnation buffer for im2col / col2im transformations across all Caffe convolution layers. The memory usage is now equal to the maximum buffer size instead of the sum over all layers. In particular this is useful for many-layered architectures like the VGG ILSVRC14 19 layer model.

Advice and Cautions:

  • This is worth it for fully convolutional models where Caffe convolution is faster than cuDNN.
  • No N-D convolution. The buffer shape will be overwritten by other layers.
  • No parallelism. Only a single net can do forward / backward at a time. As the buffer is shared by all layers within and across nets, no convolution can be done in parallel. (A fix for parallel nets is to make the buffer a member of net. DAG parallelism is still out in that case, but isn't currently parallelized anyway.)
  • This has no effect on cuDNN convolution, but that consumes less memory anyway.

All credit to @longjon who reshaped our world in #594 and suggested this patch in #520 (comment).

master edition of #1291.

Do not merge.

@sguada
Copy link
Contributor

sguada commented Mar 3, 2015

Although this a simple and elegant change, maybe it will be worthy to consider a factory of temporary Blobs which could be shared, re-used across layers, or even across nets.

@shelhamer
Copy link
Member Author

For a more mannered take on sharing buffers see #2009.

shelhamer added a commit to longjon/caffe that referenced this pull request Mar 5, 2015
@shelhamer
Copy link
Member Author

As a reminder, the static buffer causes this crash on exit:

F0305 21:14:53.266198 1810 syncedmem.cpp:16] Check failed: error == cudaSuccess (29 vs. 0) driver shutting down

this is a known side effect.

weiliu89 added a commit to weiliu89/caffe that referenced this pull request Apr 4, 2015
Share convolution buffers to reduce memory usage
qinhongwei pushed a commit to qinhongwei/caffe that referenced this pull request Apr 14, 2015
Share convolution buffers to reduce memory usage
elleryrussell pushed a commit to elleryrussell/caffe that referenced this pull request May 1, 2015
Share convolution buffers to reduce memory usage
zlmzju pushed a commit to zlmzju/caffe that referenced this pull request Jun 17, 2015
@naibaf7 naibaf7 mentioned this pull request Jun 26, 2015
ybkuang added a commit to ybkuang/caffe that referenced this pull request Jan 19, 2016
Share convolution buffers to reduce memory usage
@cheer37
Copy link

cheer37 commented Mar 4, 2016

i got the this problem.
CUDA_CHECK(cudaFreeHost(ptr)); in syncedmem.cpp causes crash on exit.
what is the reason of this?
How can i solve this?
Thanks.

@naibaf7
Copy link
Member

naibaf7 commented Mar 4, 2016

@shelhamer
In my Caffe branch, I have shared convolution buffers for both CUDA and OpenCL without compromising ND convolution. If you are interested in fixing this soon, I could probably make a PR out of the CUDA part.

@shelhamer
Copy link
Member Author

@naibaf7 that sounds promising, but I won't have a chance to review it until after the ECCV deadline 03/14, and we'll have to check it with the NVIDIA/Flickr parallelism too. Feel free to open the PR when ready all the same. Thanks.

share the im2col / col2im buffers among convolution + deconvolution
layers by making the buffer a static member.

@longjon deserves all the credit for the reshaping BVLC#594 and this patch.
@shelhamer
Copy link
Member Author

Rebased to master @ a1c81ac for use after the great layer reckoning that split headers.

shelhamer added a commit to shelhamer/caffe that referenced this pull request Mar 4, 2016
Share convolution buffers to reduce memory usage

* shelhamer/share-col-buffer:
  share columnation buffers for convolution to save memory
@cheer37
Copy link

cheer37 commented Mar 9, 2016

@shelhamer
how can i solve this side effect?

kashefy added a commit to kashefy/caffe that referenced this pull request Apr 5, 2016
Share convolution buffers to reduce memory usage
zhengmzong referenced this pull request in happynear/MTCNN_face_detection_alignment Jan 9, 2017
frolenkov-nikita added a commit to frolenkov-nikita/caffe that referenced this pull request Jun 14, 2017
jmerkow added a commit to DR08/caffe that referenced this pull request Jun 27, 2017
Share convolution buffers to reduce memory usage
jmerkow added a commit to DR08/caffe that referenced this pull request Jun 27, 2017
Share convolution buffers to reduce memory usage
@naibaf7
Copy link
Member

naibaf7 commented Jun 12, 2018

This problem was recently solved for fast inference on the OpenCL branch. No layers are broken.

@aaron-michaux
Copy link

This bug prevents other "atexit" handlers from running. It's sloppy to have an error and say "Hey, don't worry about it, it doesn't have side effects!"

Is there a function that can be set to safely shut down caffe? That should be all that's required, right?

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.

None yet

5 participants