MAIAHooksInterface.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. #pragma once
  3. #include <c10/util/Exception.h>
  4. #include <c10/util/Registry.h>
  5. #include <ATen/detail/AcceleratorHooksInterface.h>
  6. // NB: Class must live in `at` due to limitations of Registry.h.
  7. namespace at {
  8. struct TORCH_API MAIAHooksInterface : AcceleratorHooksInterface {
  9. // This should never actually be implemented, but it is used to
  10. // squelch -Werror=non-virtual-dtor
  11. ~MAIAHooksInterface() override = default;
  12. void init() const override {
  13. TORCH_CHECK(false, "Cannot initialize MAIA without ATen_maia library.");
  14. }
  15. bool hasPrimaryContext(DeviceIndex /*device_index*/) const override {
  16. TORCH_CHECK(false, "Cannot initialize MAIA without ATen_maia library.");
  17. return false;
  18. }
  19. virtual std::string showConfig() const {
  20. TORCH_CHECK(false, "Cannot query detailed MAIA version information.");
  21. }
  22. };
  23. // NB: dummy argument to suppress "ISO C++11 requires at least one argument
  24. // for the "..." in a variadic macro"
  25. struct TORCH_API MAIAHooksArgs {};
  26. TORCH_DECLARE_REGISTRY(MAIAHooksRegistry, MAIAHooksInterface, MAIAHooksArgs);
  27. #define REGISTER_MAIA_HOOKS(clsname) \
  28. C10_REGISTER_CLASS(MAIAHooksRegistry, clsname, clsname)
  29. namespace detail {
  30. TORCH_API const MAIAHooksInterface& getMAIAHooks();
  31. } // namespace detail
  32. } // namespace at
  33. #else
  34. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  35. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)