env.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. #pragma once
  3. #include <c10/macros/Export.h>
  4. #include <optional>
  5. #include <string>
  6. namespace c10::utils {
  7. // Set an environment variable.
  8. C10_API void set_env(
  9. const char* name,
  10. const char* value,
  11. bool overwrite = true);
  12. // Checks an environment variable is set.
  13. C10_API bool has_env(const char* name) noexcept;
  14. // Reads an environment variable and returns
  15. // - std::optional<true>, if set equal to "1"
  16. // - std::optional<false>, if set equal to "0"
  17. // - nullopt, otherwise
  18. //
  19. // NB:
  20. // Issues a warning if the value of the environment variable is not 0 or 1.
  21. C10_API std::optional<bool> check_env(const char* name);
  22. // Reads the value of an environment variable if it is set.
  23. // However, check_env should be used if the value is assumed to be a flag.
  24. C10_API std::optional<std::string> get_env(const char* name) noexcept;
  25. } // namespace c10::utils
  26. #else
  27. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  28. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)