Remove redundant code (#134955)

Remove GetPrivateUse1HooksInterface
Pull Request resolved: https://github.com/pytorch/pytorch/pull/134955
Approved by: https://github.com/Skylion007
This commit is contained in:
FFFrog
2024-09-04 14:47:24 +00:00
committed by PyTorch MergeBot
parent 32f45f01a9
commit 27d86f93fe
6 changed files with 13 additions and 20 deletions

View File

@ -52,7 +52,7 @@ class TORCH_API Context {
} else if (device_type == at::kIPU) {
return at::detail::getIPUHooks().getDefaultIPUGenerator(device.index());
} else if (device_type == at::kPrivateUse1) {
return at::GetPrivateUse1HooksInterface()->getDefaultGenerator(
return at::detail::getPrivateUse1Hooks().getDefaultGenerator(
device.index());
} else {
AT_ERROR(c10::DeviceTypeName(device_type), " device type not enabled.");
@ -91,7 +91,7 @@ class TORCH_API Context {
} else if (device_type == at::kXPU) {
return at::detail::getXPUHooks().getDeviceFromPtr(data);
} else if (device_type == at::kPrivateUse1) {
return at::GetPrivateUse1HooksInterface()->getDeviceFromPtr(data);
return at::detail::getPrivateUse1Hooks().getDeviceFromPtr(data);
} else {
AT_ERROR(c10::DeviceTypeName(device_type), " device type not enabled.");
}
@ -182,7 +182,7 @@ class TORCH_API Context {
void lazyInitPrivateUse1() {
c10::call_once(thp_init, [&] {
if (isPrivateUse1HooksRegistered()) {
at::GetPrivateUse1HooksInterface()->initPrivateUse1();
at::detail::getPrivateUse1Hooks().initPrivateUse1();
}
});
}

View File

@ -21,7 +21,7 @@ c10::Allocator* GetCPUAllocatorMaybePinned(bool pin_memory) {
} else if (at::globalContext().hasXPU()) {
return at::detail::getXPUHooks().getPinnedMemoryAllocator();
} else if(at::isPrivateUse1HooksRegistered()) {
return at::GetPrivateUse1HooksInterface()->getPinnedMemoryAllocator();
return at::detail::getPrivateUse1Hooks().getPinnedMemoryAllocator();
} else {
TORCH_CHECK(false, "Need to provide pin_memory allocator to use pin memory.")
}

View File

@ -11,13 +11,6 @@ TORCH_API void RegisterPrivateUse1HooksInterface(at::PrivateUse1HooksInterface*
privateuse1_hooks = hook_;
}
TORCH_API at::PrivateUse1HooksInterface* GetPrivateUse1HooksInterface() {
TORCH_CHECK(
privateuse1_hooks != nullptr,
"Please register PrivateUse1HooksInterface by `RegisterPrivateUse1HooksInterface` first.");
return privateuse1_hooks;
}
TORCH_API bool isPrivateUse1HooksRegistered() {
return privateuse1_hooks != nullptr;
}

View File

@ -12,7 +12,7 @@ namespace at {
struct TORCH_API PrivateUse1HooksInterface : AcceleratorHooksInterface {
~PrivateUse1HooksInterface() override = default;
virtual const at::Generator& getDefaultGenerator(
c10::DeviceIndex device_index) {
c10::DeviceIndex device_index) const {
TORCH_CHECK_NOT_IMPLEMENTED(
false,
"You should register `PrivateUse1HooksInterface` for PrivateUse1 before call `getDefaultGenerator`.");
@ -24,24 +24,26 @@ struct TORCH_API PrivateUse1HooksInterface : AcceleratorHooksInterface {
"You should register `PrivateUse1HooksInterface` for PrivateUse1 before call `getDeviceFromPtr`.");
}
bool isPinnedPtr(const void* data) const override {
virtual bool isPinnedPtr(const void* data) const override {
return false;
}
Allocator* getPinnedMemoryAllocator() const override {
virtual Allocator* getPinnedMemoryAllocator() const override {
TORCH_CHECK(
false,
"You should register `PrivateUse1HooksInterface` for PrivateUse1 before call `getPinnedMemoryAllocator`.");
}
bool hasPrimaryContext(DeviceIndex device_index) const override {
virtual bool hasPrimaryContext(DeviceIndex device_index) const override {
TORCH_CHECK_NOT_IMPLEMENTED(
false,
"You should register `PrivateUse1HooksInterface` for PrivateUse1 before call `hasPrimaryContext`.");
}
virtual void initPrivateUse1() const {}
virtual void resizePrivateUse1Bytes(const c10::Storage &storage, size_t newsize) const {
virtual void resizePrivateUse1Bytes(
const c10::Storage& storage,
size_t newsize) const {
TORCH_CHECK_NOT_IMPLEMENTED(
false,
"You should register `PrivateUse1HooksInterface` for PrivateUse1 before call `resizePrivateUse1Bytes`.");
@ -53,8 +55,6 @@ struct TORCH_API PrivateUse1HooksArgs {};
TORCH_API void RegisterPrivateUse1HooksInterface(
at::PrivateUse1HooksInterface* hook_);
TORCH_API at::PrivateUse1HooksInterface* GetPrivateUse1HooksInterface();
TORCH_API bool isPrivateUse1HooksRegistered();
namespace detail {

View File

@ -282,7 +282,7 @@ void resize_bytes_nocuda(const Storage& storage, const c10::SymInt& newsize) {
} else if (device_type == at::kMeta) {
at::native::resize_bytes_meta(storage.unsafeGetStorageImpl(), newsize);
} else if (device_type == at::kPrivateUse1) {
at::GetPrivateUse1HooksInterface()->resizePrivateUse1Bytes(
at::detail::getPrivateUse1Hooks().resizePrivateUse1Bytes(
storage, newsize.expect_int());
} else if (device_type == at::kXPU || device_type == at::kHPU) {
ptrdiff_t size_bytes_i = newsize.expect_int();

View File

@ -586,7 +586,7 @@ struct FooHooksArgs : public at::PrivateUse1HooksArgs {};
struct FooHooksInterface : public at::PrivateUse1HooksInterface {
FooHooksInterface(FooHooksArgs) {}
~FooHooksInterface() override = default;
const at::Generator& getDefaultGenerator(c10::DeviceIndex device_index) override {
const at::Generator& getDefaultGenerator(c10::DeviceIndex device_index) const override {
static auto device_gen = make_generator_privateuse1(device_index);
return device_gen;
}