CPUGeneratorImpl.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <ATen/core/Generator.h>
  3. #include <ATen/core/MT19937RNGEngine.h>
  4. #include <c10/core/GeneratorImpl.h>
  5. #include <c10/util/Optional.h>
  6. namespace at {
  7. struct TORCH_API CPUGeneratorImpl : public c10::GeneratorImpl {
  8. // Constructors
  9. CPUGeneratorImpl(uint64_t seed_in = default_rng_seed_val);
  10. ~CPUGeneratorImpl() override = default;
  11. // CPUGeneratorImpl methods
  12. std::shared_ptr<CPUGeneratorImpl> clone() const;
  13. void set_current_seed(uint64_t seed) override;
  14. uint64_t current_seed() const override;
  15. uint64_t seed() override;
  16. void set_state(const c10::TensorImpl& new_state) override;
  17. c10::intrusive_ptr<c10::TensorImpl> get_state() const override;
  18. static DeviceType device_type();
  19. uint32_t random();
  20. uint64_t random64();
  21. c10::optional<float> next_float_normal_sample();
  22. c10::optional<double> next_double_normal_sample();
  23. void set_next_float_normal_sample(c10::optional<float> randn);
  24. void set_next_double_normal_sample(c10::optional<double> randn);
  25. at::mt19937 engine();
  26. void set_engine(at::mt19937 engine);
  27. private:
  28. CPUGeneratorImpl* clone_impl() const override;
  29. at::mt19937 engine_;
  30. c10::optional<float> next_float_normal_sample_;
  31. c10::optional<double> next_double_normal_sample_;
  32. };
  33. namespace detail {
  34. TORCH_API const Generator& getDefaultCPUGenerator();
  35. TORCH_API Generator
  36. createCPUGenerator(uint64_t seed_val = default_rng_seed_val);
  37. } // namespace detail
  38. } // namespace at