HPUHooksInterface.h 1.4 KB

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