ParallelGuard.h 627 B

12345678910111213141516171819202122232425
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. #pragma once
  3. #include <c10/macros/Macros.h>
  4. namespace c10 {
  5. // RAII thread local guard that tracks whether code is being executed in
  6. // `at::parallel_for` or `at::parallel_reduce` loop function.
  7. class C10_API ParallelGuard {
  8. public:
  9. static bool is_enabled();
  10. ParallelGuard(bool state);
  11. ~ParallelGuard();
  12. private:
  13. bool previous_state_;
  14. };
  15. } // namespace c10
  16. #else
  17. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  18. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)