Always Use cudaMallocHost to allocate and pin CPU memory #3060
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.
Unless in CPU_ONLY build, always use cudaMallocHost and cudaFreeHost to allocate (and pin) and free cpu memory, so that it does not depend on Caffe::mode(), which is changable during runtime and can result in inconsistency between host memory allocation and free. This should fix #3053.
Eventually it is better to give mode and device to net and layers, in the spirit of #1500. But it seems like a short-term fix to always use
cudaMallocHost
to allocate cpu memory regardless of the mode of the net to avoid this crash without significant overhead.However, although mode/device is right now not a member of Net and Layer and thus changable in runtime, it is better to set them in advance and not change them during a lifecycle of a net.