Cache device on TensorImpl; clean up TensorImpl constructors. (#18833)
authorGregory Chanan <gchanan@fb.com>
Fri, 5 Apr 2019 14:18:38 +0000 (07:18 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 5 Apr 2019 14:21:39 +0000 (07:21 -0700)
commit043e363c6c2bea3652ace954e4e70707cad0cf5e
tree556dfe2af313f2b292177105a10642924a8e0277
parentb7c830b916879a69a5ef361b3cbdc73cd833f92d
Cache device on TensorImpl; clean up TensorImpl constructors. (#18833)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18833
ghimport-source-id: 6f2be25fcc5e6be3ffe20582e604bd2c1fbab66b

Stack from [ghstack](https://github.com/ezyang/ghstack):
* **#18833 [STACK] Cache device on TensorImpl; clean up TensorImpl constructors.**
* #18832 [STACK] Disallow changing the device of a tensor via set_.
* #18831 [STACK] Stop swapping in Storages of the wrong device for Tensors.

1) We cache device on TensorImpl.  This means we can access the device without a virtual function and allows us to more easily extend TensorImpls (because they don't need to figure out how to store the Device for themselves).

2) Clean up TensorImpl APIs.  We had a constructor that took a TensorTypeId and an allocator and would allocate a Storage based on the recognized types of TensorTypeIds.  Instead, we just have two different constructors: one for types with a storage, one without.

Reviewed By: dzhulgakov

Differential Revision: D14766230

fbshipit-source-id: 745b8db84dcd6cb58f1a8675ad3ff8d033bc50df
aten/src/ATen/SparseTensorImpl.cpp
aten/src/ATen/SparseTensorImpl.h
aten/src/ATen/function_wrapper.py
aten/src/ATen/test/xla_tensor_test.cpp
c10/core/TensorImpl.cpp
c10/core/TensorImpl.h
c10/core/UndefinedTensorImpl.cpp
torch/csrc/autograd/variable.cpp
torch/csrc/autograd/variable.h
torch/csrc/jit/interpreter.cpp