Adding pin_memory kwarg to zeros, ones, empty, ... tensor constructors. (#18455)
authorVitaly Fedyunin <vitalyf@fb.com>
Tue, 2 Apr 2019 15:44:27 +0000 (08:44 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 2 Apr 2019 15:48:19 +0000 (08:48 -0700)
commitc484cf43a02863efd2f4a76aad43246fb0191ab5
tree5afc7b9dbf8c325300e3c49248a3b189ee2e43c0
parentaed7c9bc96fe35fce6508e19dab1e2cfbc766968
Adding pin_memory kwarg to zeros, ones, empty, ... tensor constructors. (#18455)

Summary:
Make it possible to construct a pinned memory tensor without creating a storage first and without calling pin_memory() function. It is also faster, as copy operation is unnecessary.

Supported functions:
```python
torch.rand_like(t, pin_memory=True)
torch.randn_like(t, pin_memory=True)
torch.empty_like(t, pin_memory=True)
torch.full_like(t, 4, pin_memory=True)
torch.zeros_like(t, pin_memory=True)
torch.ones_like(t, pin_memory=True)
torch.tensor([10,11], pin_memory=True)
torch.randn(3, 5, pin_memory=True)
torch.rand(3, pin_memory=True)
torch.zeros(3, pin_memory=True)
torch.randperm(3, pin_memory=True)
torch.empty(6, pin_memory=True)
torch.ones(6, pin_memory=True)
torch.eye(6, pin_memory=True)
torch.arange(3, 5, pin_memory=True)
```

Part of the bigger: `Remove Storage` plan.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18455

Reviewed By: ezyang

Differential Revision: D14672084

Pulled By: VitalyFedyunin

fbshipit-source-id: 9d0997ec00f59500ee018f8b851934d334012124
19 files changed:
aten/src/ATen/native/TensorFactories.cpp
aten/src/ATen/native/cuda/TensorFactories.cu
aten/src/ATen/native/native_functions.yaml
aten/src/ATen/native/sparse/SparseTensor.cpp
aten/src/ATen/native_parse.py
c10/core/TensorOptions.h
test/test_torch.py
tools/autograd/gen_python_functions.py
tools/autograd/templates/python_torch_functions.cpp
tools/jit/gen_jit_dispatch.py
tools/pyi/gen_pyi.py
torch/_tensor_docs.py
torch/_torch_docs.py
torch/csrc/jit/ir.cpp
torch/csrc/jit/operator.cpp
torch/csrc/jit/passes/shape_analysis.cpp
torch/csrc/jit/tracer.cpp
torch/csrc/utils/tensor_new.cpp
torch/onnx/symbolic.py