pytorch/test/cpp_extensions
Qifan Lu 4e2ab2cd73 Move generator state APIs to ATen (#49589)
Summary:
## Rationale

While most of the `torch.Generator` properties and methods are implemented as a thin wrapper of the corresponding `at::Generator` methods, `torch.Generator.get_state()` and `torch.Generator.set_state()` are implemented in legacy Torch code and are not dispatched through the `c10::GeneratorImpl` interface. This is not structured well and makes implementing generators for new backends (e.g. `XLAGeneratorImpl` for the XLA backend) inconvenient. As such, this pull request seeks to move these generator state APIs to c10 and ATen.

## What is being refactored?
* Interfaces
  - Added `c10::GeneratorImpl::set_state` and `c10::GeneratorImpl::state` for getting and setting the internal state of a random number generator.
  - `at::Generator::set_state` and `at::Generator::state` wraps the above-mentioned APIs, as it's basically a PIMPL.
  - Added helper function `at::detail::check_rng_state` for checking the validity of new RNG state tensor.
* CPU Generator
  - Renamed and moved `THTensor_(setRNGState)` and `THTensor_(getRNGState)` to `CPUGeneratorImpl::set_state` and `CPUGenerator::state`.
  - Renamed and moved `THGeneratorState` and `THGeneratorStateNew` to `CPUGeneratorStateLegacy` and `CPUGeneratorState`.
* CUDA Generator
  - Renamed and moved `THCRandom_setRNGState` and `THCRandom_getRNGState` to `CUDAGeneratorImpl::set_state` and `CUDAGeneratorImpl::state`.
* PyTorch Bindings
  - `THPGenerator_setState` and `THPGenerator_getState` now simply forward to `at::Generator::set_state` and `at::Generator::state`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/49589

Reviewed By: H-Huang

Differential Revision: D25785774

Pulled By: pbelevich

fbshipit-source-id: 8ed79209c4ffb1a0ae8b19952ac8871ac9e0255f
2021-01-06 18:26:56 -08:00
..
no_python_abi_suffix_test
self_compiler_include_dirs_test allow user passing relative paths in include_dirs within setuptools.setup (#38264) 2020-05-13 20:00:12 -07:00
torch_test_cpp_extension remediation of S205607 2020-07-17 17:19:47 -07:00
cpp_c10d_extension.cpp [c10d] switch ProcessGroup to be managed by intrusive_ptr (#47343) 2020-11-12 07:36:23 -08:00
cpp_c10d_extension.hpp [c10d] switch ProcessGroup to be managed by intrusive_ptr (#47343) 2020-11-12 07:36:23 -08:00
cpp_frontend_extension.cpp Better tests/support for Python/C++ inter-op (#15193) 2018-12-14 08:42:10 -08:00
cuda_extension_kernel.cu Check CUDA kernel launches (/fbcode/caffe2/) (#49145) 2020-12-10 10:43:03 -08:00
cuda_extension_kernel2.cu Check CUDA kernel launches (/fbcode/caffe2/) (#49145) 2020-12-10 10:43:03 -08:00
cuda_extension.cpp Deprecate tensor.type() (#30281) 2019-12-05 10:55:34 -08:00
cuda_extension.cu Check CUDA kernel launches (/fbcode/caffe2/) (#49145) 2020-12-10 10:43:03 -08:00
cudnn_extension.cpp
doubler.h
extension.cpp allow user passing relative paths in include_dirs within setuptools.setup (#38264) 2020-05-13 20:00:12 -07:00
jit_extension.cpp
jit_extension2.cpp
msnpu_extension.cpp Remove .impl_UNBOXED() and functionalities associated with it (#49220) 2021-01-06 14:22:46 -08:00
rng_extension.cpp Move generator state APIs to ATen (#49589) 2021-01-06 18:26:56 -08:00
setup.py Hipify revamp [REDUX] (#48715) 2020-12-02 18:03:23 -08:00
torch_library.cu Test TORCH_LIBRARY in CUDA extension (#47524) 2020-11-16 13:12:22 -08:00