XPUHooksInterface.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include <c10/core/Device.h>
  3. #include <c10/util/Exception.h>
  4. #include <c10/util/Registry.h>
  5. #include <ATen/detail/AcceleratorHooksInterface.h>
  6. C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wunused-parameter")
  7. namespace at {
  8. struct TORCH_API XPUHooksInterface : AcceleratorHooksInterface{
  9. ~XPUHooksInterface() override = default;
  10. void init() const override {
  11. TORCH_CHECK(false, "Cannot initialize XPU without ATen_xpu library.");
  12. }
  13. virtual bool hasXPU() const {
  14. return false;
  15. }
  16. virtual std::string showConfig() const {
  17. TORCH_CHECK(
  18. false,
  19. "Cannot query detailed XPU version without ATen_xpu library.");
  20. }
  21. virtual int32_t getGlobalIdxFromDevice(const Device& device) const {
  22. TORCH_CHECK(false, "Cannot get XPU global device index without ATen_xpu library.");
  23. }
  24. const Generator& getDefaultGenerator(
  25. [[maybe_unused]] DeviceIndex device_index = -1) const override {
  26. TORCH_CHECK(
  27. false, "Cannot get default XPU generator without ATen_xpu library.");
  28. }
  29. Generator getNewGenerator(
  30. [[maybe_unused]] DeviceIndex device_index = -1) const override {
  31. TORCH_CHECK(false, "Cannot get XPU generator without ATen_xpu library.");
  32. }
  33. virtual DeviceIndex getNumGPUs() const {
  34. return 0;
  35. }
  36. virtual DeviceIndex current_device() const {
  37. TORCH_CHECK(false, "Cannot get current device on XPU without ATen_xpu library.");
  38. }
  39. Device getDeviceFromPtr(void* /*data*/) const override {
  40. TORCH_CHECK(false, "Cannot get device of pointer on XPU without ATen_xpu library.");
  41. }
  42. virtual void deviceSynchronize(DeviceIndex /*device_index*/) const {
  43. TORCH_CHECK(false, "Cannot synchronize XPU device without ATen_xpu library.");
  44. }
  45. Allocator* getPinnedMemoryAllocator() const override {
  46. TORCH_CHECK(false, "Cannot get XPU pinned memory allocator without ATen_xpu library.");
  47. }
  48. bool isPinnedPtr(const void* data) const override {
  49. return false;
  50. }
  51. bool hasPrimaryContext(DeviceIndex device_index) const override {
  52. TORCH_CHECK(false, "Cannot query primary context without ATen_xpu library.");
  53. }
  54. };
  55. struct TORCH_API XPUHooksArgs {};
  56. TORCH_DECLARE_REGISTRY(XPUHooksRegistry, XPUHooksInterface, XPUHooksArgs);
  57. #define REGISTER_XPU_HOOKS(clsname) \
  58. C10_REGISTER_CLASS(XPUHooksRegistry, clsname, clsname)
  59. namespace detail {
  60. TORCH_API const XPUHooksInterface& getXPUHooks();
  61. } // namespace detail
  62. } // namespace at
  63. C10_DIAGNOSTIC_POP()