1 #pragma once 2 3 #include <c10/core/Device.h> 4 #include <c10/core/Stream.h> 5 #include <c10/core/Allocator.h> 6 C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wunused-parameter") 7 namespace at { 8 9 // AcceleratorHooksInterface is a shared interface provided by all 10 // accelerators to allow generic code. 11 // This inferface is hook-based as it corresponds to all the functions 12 // that are going to be called in a generic way from the CPU code. 13 14 struct TORCH_API AcceleratorHooksInterface { 15 // This should never actually be implemented, but it is used to 16 // squelch -Werror=non-virtual-dtor 17 virtual ~AcceleratorHooksInterface() = default; 18 19 // Whether the device at device_index is fully initialized or not. 20 virtual bool hasPrimaryContext(DeviceIndex device_index) const = 0; 21 deviceCountAcceleratorHooksInterface22 virtual DeviceIndex deviceCount() const { 23 return 0; 24 } 25 setCurrentDeviceAcceleratorHooksInterface26 virtual void setCurrentDevice(DeviceIndex device) const { 27 TORCH_CHECK(false, "Backend doesn't support setCurrentDevice()"); 28 } 29 getCurrentDeviceAcceleratorHooksInterface30 virtual DeviceIndex getCurrentDevice() const { 31 TORCH_CHECK(false, "Backend doesn't support getCurrentDevice()"); 32 return -1; 33 } 34 exchangeDeviceAcceleratorHooksInterface35 virtual DeviceIndex exchangeDevice(DeviceIndex device) const { 36 TORCH_CHECK(false, "Backend doesn't support exchangeDevice()"); 37 return -1; 38 } 39 maybeExchangeDeviceAcceleratorHooksInterface40 virtual DeviceIndex maybeExchangeDevice(DeviceIndex device) const { 41 TORCH_CHECK(false, "Backend doesn't support maybeExchangeDevice()"); 42 return -1; 43 } 44 isPinnedPtrAcceleratorHooksInterface45 virtual bool isPinnedPtr(const void* data) const { 46 return false; 47 } 48 getPinnedMemoryAllocatorAcceleratorHooksInterface49 virtual Allocator* getPinnedMemoryAllocator() const { 50 TORCH_CHECK(false, "Backend doesn't support getPinnedMemoryAllocator()"); 51 return nullptr; 52 } 53 }; 54 55 } // namespace at 56 C10_DIAGNOSTIC_POP() 57