CPUGeneratorImpl.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. #pragma once
  3. #include <ATen/core/Generator.h>
  4. #include <ATen/core/MT19937RNGEngine.h>
  5. #include <c10/core/GeneratorImpl.h>
  6. #include <optional>
  7. namespace at {
  8. struct TORCH_API CPUGeneratorImpl : public c10::GeneratorImpl {
  9. // Constructors
  10. CPUGeneratorImpl(uint64_t seed_in = default_rng_seed_val);
  11. ~CPUGeneratorImpl() override = default;
  12. // CPUGeneratorImpl methods
  13. std::shared_ptr<CPUGeneratorImpl> clone() const;
  14. void set_current_seed(uint64_t seed) override;
  15. void set_offset(uint64_t offset) override;
  16. uint64_t get_offset() const override;
  17. uint64_t current_seed() const override;
  18. uint64_t seed() override;
  19. void set_state(const c10::TensorImpl& new_state) override;
  20. c10::intrusive_ptr<c10::TensorImpl> get_state() const override;
  21. static c10::DeviceType device_type();
  22. uint32_t random();
  23. uint64_t random64();
  24. std::optional<float> next_float_normal_sample();
  25. std::optional<double> next_double_normal_sample();
  26. void set_next_float_normal_sample(std::optional<float> randn);
  27. void set_next_double_normal_sample(std::optional<double> randn);
  28. at::mt19937 engine();
  29. void set_engine(at::mt19937 engine);
  30. private:
  31. CPUGeneratorImpl* clone_impl() const override;
  32. at::mt19937 engine_;
  33. std::optional<float> next_float_normal_sample_;
  34. std::optional<double> next_double_normal_sample_;
  35. };
  36. namespace detail {
  37. TORCH_API const Generator& getDefaultCPUGenerator();
  38. TORCH_API Generator
  39. createCPUGenerator(uint64_t seed_val = default_rng_seed_val);
  40. } // namespace detail
  41. } // namespace at
  42. #else
  43. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  44. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)