HPUHooksInterface.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. #pragma once
  3. #include <ATen/core/Generator.h>
  4. #include <ATen/detail/AcceleratorHooksInterface.h>
  5. #include <c10/core/Allocator.h>
  6. #include <c10/core/Device.h>
  7. #include <c10/util/Registry.h>
  8. namespace at {
  9. struct TORCH_API HPUHooksInterface : AcceleratorHooksInterface {
  10. ~HPUHooksInterface() override = default;
  11. void init() const override {
  12. TORCH_CHECK(false, "Cannot initialize HPU without HPU backend");
  13. }
  14. virtual bool hasHPU() const {
  15. return false;
  16. }
  17. Device getDeviceFromPtr(void* /*data*/) const override {
  18. TORCH_CHECK(
  19. false, "Cannot get device of pointer on HPU without HPU backend");
  20. }
  21. bool isPinnedPtr(const void* /*data*/) const override {
  22. return false;
  23. }
  24. Allocator* getPinnedMemoryAllocator() const override {
  25. TORCH_CHECK(
  26. false,
  27. "You should register `HPUHooksInterface` for HPU before call `getPinnedMemoryAllocator`.");
  28. }
  29. bool hasPrimaryContext(
  30. [[maybe_unused]] DeviceIndex device_index) const override {
  31. TORCH_CHECK(
  32. false,
  33. "You should register `HPUHooksInterface` for HPU before call `hasPrimaryContext`.");
  34. }
  35. };
  36. struct TORCH_API HPUHooksArgs {};
  37. TORCH_DECLARE_REGISTRY(HPUHooksRegistry, HPUHooksInterface, HPUHooksArgs);
  38. #define REGISTER_HPU_HOOKS(clsname) \
  39. C10_REGISTER_CLASS(HPUHooksRegistry, clsname, clsname)
  40. namespace detail {
  41. TORCH_API const at::HPUHooksInterface& getHPUHooks();
  42. } // namespace detail
  43. } // namespace at
  44. #else
  45. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  46. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)