Feature tensor zeros #14
Open
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.
After an interesting deep dive into how torch initializes tensors with zeros(1), and several detours on how calloc and malloc actually behave (2) + why it is better to use calloc than malloc+memset (3), decided to use calloc for initializing tensor with 0s.
Also learned that Memory coming from the OS will be zeroed for security reasons.* ! (4)
(1) - Uses memset (https://github.com/pytorch/pytorch/blob/50595ecef4a4f9882a02539019b11a5e50295244/aten/src/ATen/native/Fill.cpp#L150)
(2) - https://stackoverflow.com/questions/1538420/difference-between-malloc-and-calloc
(3) - https://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc?lq=1
(4) - https://stackoverflow.com/a/8029624/2697940