xref: /aosp_15_r20/external/pytorch/aten/src/ATen/detail/XPUHooksInterface.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #pragma once
2 
3 #include <c10/core/Device.h>
4 #include <c10/util/Exception.h>
5 #include <c10/util/Registry.h>
6 
7 #include <ATen/core/Generator.h>
8 #include <ATen/detail/AcceleratorHooksInterface.h>
9 
10 C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wunused-parameter")
11 
12 namespace at {
13 
14 struct TORCH_API XPUHooksInterface : AcceleratorHooksInterface{
15   ~XPUHooksInterface() override = default;
16 
initXPUXPUHooksInterface17   virtual void initXPU() const {
18     TORCH_CHECK(
19         false,
20         "Cannot initialize XPU without ATen_xpu library.");
21   }
22 
hasXPUXPUHooksInterface23   virtual bool hasXPU() const {
24     return false;
25   }
26 
showConfigXPUHooksInterface27   virtual std::string showConfig() const {
28     TORCH_CHECK(
29         false,
30         "Cannot query detailed XPU version without ATen_xpu library.");
31   }
32 
getGlobalIdxFromDeviceXPUHooksInterface33   virtual int32_t getGlobalIdxFromDevice(const Device& device) const {
34     TORCH_CHECK(false, "Cannot get XPU global device index without ATen_xpu library.");
35   }
36 
37   virtual Generator getXPUGenerator(C10_UNUSED DeviceIndex device_index = -1) const {
38     TORCH_CHECK(false, "Cannot get XPU generator without ATen_xpu library.");
39   }
40 
41   virtual const Generator& getDefaultXPUGenerator(C10_UNUSED DeviceIndex device_index = -1) const {
42     TORCH_CHECK(false, "Cannot get default XPU generator without ATen_xpu library.");
43   }
44 
getNumGPUsXPUHooksInterface45   virtual DeviceIndex getNumGPUs() const {
46     return 0;
47   }
48 
current_deviceXPUHooksInterface49   virtual DeviceIndex current_device() const {
50     TORCH_CHECK(false, "Cannot get current device on XPU without ATen_xpu library.");
51   }
52 
getDeviceFromPtrXPUHooksInterface53   virtual Device getDeviceFromPtr(void* /*data*/) const {
54     TORCH_CHECK(false, "Cannot get device of pointer on XPU without ATen_xpu library.");
55   }
56 
deviceSynchronizeXPUHooksInterface57   virtual void deviceSynchronize(DeviceIndex /*device_index*/) const {
58     TORCH_CHECK(false, "Cannot synchronize XPU device without ATen_xpu library.");
59   }
60 
getPinnedMemoryAllocatorXPUHooksInterface61   Allocator* getPinnedMemoryAllocator() const override {
62     TORCH_CHECK(false, "Cannot get XPU pinned memory allocator without ATen_xpu library.");
63   }
64 
isPinnedPtrXPUHooksInterface65   bool isPinnedPtr(const void* data) const override {
66     return false;
67   }
68 
hasPrimaryContextXPUHooksInterface69   bool hasPrimaryContext(DeviceIndex device_index) const override {
70     TORCH_CHECK(false, "Cannot query primary context without ATen_xpu library.");
71   }
72 };
73 
74 struct TORCH_API XPUHooksArgs {};
75 
76 C10_DECLARE_REGISTRY(XPUHooksRegistry, XPUHooksInterface, XPUHooksArgs);
77 #define REGISTER_XPU_HOOKS(clsname) \
78   C10_REGISTER_CLASS(XPUHooksRegistry, clsname, clsname)
79 
80 namespace detail {
81 TORCH_API const XPUHooksInterface& getXPUHooks();
82 } // namespace detail
83 } // namespace at
84 C10_DIAGNOSTIC_POP()
85