pytorch/torch/csrc/utils
Mads R. B. Kristensen 5d8879cf6d Auto-convert GPU arrays that support the __cuda_array_interface__ protocol (#20584)
Summary:
This PR implements auto-conversion of GPU arrays that support the `__cuda_array_interface__` protocol (fixes #15601).

If an object exposes the `__cuda_array_interface__` attribute, `touch.as_tensor()` and `touch.tensor()` will use the exposed device memory.

#### Zero-copy
When using `touch.as_tensor(...,device=D)` where `D` is the same device as the one used in `__cuda_array_interface__`.

#### Implicit copy
When using `touch.as_tensor(...,device=D)` where `D` is the CPU or another non-CUDA device.

#### Explicit copy
When using `torch.tensor()`.

#### Exception
When using `touch.as_tensor(...,device=D)` where `D` is a CUDA device not used in `__cuda_array_interface__`.

#### Lifetime
`torch.as_tensor(obj)` tensor grabs a reference to `obj` so that the lifetime of `obj` exceeds the tensor
Pull Request resolved: https://github.com/pytorch/pytorch/pull/20584

Differential Revision: D15435610

Pulled By: ezyang

fbshipit-source-id: c423776ba2f2c073b902e0a0ce272d54e9005286
2019-05-21 14:06:46 -07:00
..
auto_gil.h Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
cuda_enabled.h Remove NO_* and WITH_* across codebase, except in setup.py (#8555) 2018-06-15 12:29:48 -04:00
cuda_lazy_init.cpp Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
cuda_lazy_init.h Fix #11430 (CPU only builds raise opaque error message when calling .… (#11533) 2018-09-14 09:10:08 -07:00
disallow_copy.h Move disallow_copy into utils. 2017-09-05 17:48:55 -04:00
hash.h Match parameter names and = default (#9737) 2018-07-30 14:10:00 -07:00
invalid_arguments.cpp Enable performance-unnecessary-value-param in .clang-tidy (#15026) 2018-12-13 16:15:35 -08:00
invalid_arguments.h Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
memory.h [C++ API] Remove virtual forward and implement Sequential based on Any(Module) (#7508) 2018-05-24 12:46:51 -07:00
numpy_stub.h Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
object_ptr.cpp Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
object_ptr.h Split python_ir.h in a more sensible way (#19081) 2019-04-10 10:26:50 -07:00
pybind.h Convert all tabs to spaces, add CI. (#18959) 2019-04-09 08:12:26 -07:00
python_arg_parser.cpp Memory format support for contiguous and is_contiguous (#20455) 2019-05-16 07:18:24 -07:00
python_arg_parser.h Memory format support for contiguous and is_contiguous (#20455) 2019-05-16 07:18:24 -07:00
python_compat.h Fix PySlice_Unpack not available on PyPy 3.6 yet (#17836) 2019-03-09 20:10:16 -08:00
python_numbers.h Cleanup includes in torch/csrc/* (#19924) 2019-05-06 14:03:18 -07:00
python_scalars.h Resolving comments from Bool Tensor for CPU PR (#18165) 2019-03-26 09:59:34 -07:00
python_strings.h Provide a few default args for numpy translation (#20451) 2019-05-15 10:13:17 -07:00
python_stub.h Bag of clang tidy fixes for torch/csrc/ and torch/csrc/autograd (#11050) 2018-09-05 19:55:50 -07:00
python_tuples.h Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
six.h Allow structseq to be input of operators where tuple is expected (#17208) 2019-03-11 11:33:35 -07:00
structseq.cpp Allow structseq to be input of operators where tuple is expected (#17208) 2019-03-11 11:33:35 -07:00
structseq.h Customize the printing of namedtuple return (#17136) 2019-02-28 13:07:26 -08:00
tensor_apply.cpp Introduce DeprecatedTypeProperties class (#17991) 2019-04-04 02:24:13 -07:00
tensor_apply.h Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
tensor_dtypes.cpp Add qint8 type (int8_t) (#19984) 2019-05-17 20:35:05 -07:00
tensor_dtypes.h Add numpy-style dtypes to Variable factories. (#5245) 2018-02-20 11:04:14 -05:00
tensor_flatten.cpp Generate only one Type class per backend (#19295) 2019-04-21 21:16:14 -07:00
tensor_flatten.h C++ changes toward libtorch and libcaffe2 unification (#19554) 2019-04-26 01:38:10 -07:00
tensor_layouts.cpp Cleanup includes in torch/csrc/* (#19924) 2019-05-06 14:03:18 -07:00
tensor_layouts.h Introduce torch.layout and split layout from dtypes. (#6145) 2018-04-02 14:07:50 -04:00
tensor_list.cpp Remove some simple use cases of Type::ScalarType() 2019-03-08 16:42:05 -08:00
tensor_list.h Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
tensor_memoryformats.cpp Memory format support for contiguous and is_contiguous (#20455) 2019-05-16 07:18:24 -07:00
tensor_memoryformats.h Memory format support for contiguous and is_contiguous (#20455) 2019-05-16 07:18:24 -07:00
tensor_new.cpp Auto-convert GPU arrays that support the __cuda_array_interface__ protocol (#20584) 2019-05-21 14:06:46 -07:00
tensor_new.h Pass ScalarType separately from Type in python constructors 2019-04-04 02:24:20 -07:00
tensor_numpy.cpp Auto-convert GPU arrays that support the __cuda_array_interface__ protocol (#20584) 2019-05-21 14:06:46 -07:00
tensor_numpy.h Auto-convert GPU arrays that support the __cuda_array_interface__ protocol (#20584) 2019-05-21 14:06:46 -07:00
tensor_types.cpp Sparse half embeddings on cuda (#19695) 2019-05-10 08:00:55 -07:00
tensor_types.h Generate only one Type class per backend (#19295) 2019-04-21 21:16:14 -07:00
tuple_parser.cpp Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
tuple_parser.h Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
variadic.cpp Use variadic templates instead of initializer lists and overloads. (#4772) 2018-01-26 15:56:39 -05:00
variadic.h Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00