8000 fallback registration if HPU not loaded · pytorch/pytorch@1195682 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1195682

Browse files
tbohutynbsochack
authored andcommitted
fallback registration if HPU not loaded
1 parent cf259a8 commit 1195682

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

aten/src/ATen/detail/HPUHooksInterface.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#include <ATen/detail/HPUHooksInterface.h>
22
#include <c10/util/CallOnce.h>
3+
#include <memory>
34

45
namespace at {
56
namespace detail {
67

7-
static HPUHooksInterface* hpu_hooks = nullptr;
8-
98
TORCH_API const at::HPUHooksInterface& getHPUHooks() {
9+
static std::unique_ptr<HPUHooksInterface> hpu_hooks;
1010
static c10::once_flag once;
1111
c10::call_once(once, [] {
12-
hpu_hooks =
13-
HPUHooksRegistry()->Create("HPUHooks", HPUHooksArgs{}).release();
14-
TORCH_CHECK(
15-
hpu_hooks != nullptr,
16-
"Missing registration for HPUHooks in HPUHooksRegistry.")
12+
hpu_hooks = HPUHooksRegistry()->Create("HPUHooks", HPUHooksArgs{});
13+
if (!hpu_hooks) {
14+
hpu_hooks = std::make_unique<HPUHooksInterface>();
15+
}
1716
});
1817
return *hpu_hooks;
1918
}

aten/src/ATen/detail/HPUHooksInterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ struct TORCH_API HPUHooksInterface : AcceleratorHooksInterface {
3737
false,
3838
"You should register `HPUHooksInterface` for HPU before call `getPinnedMemoryAllocator`.");
3939
}
40+
bool hasPrimaryContext(C10_UNUSED DeviceIndex device_index) const override {
41+
TORCH_CHECK(
42+
false,
43+
"You should register `HPUHooksInterface` for HPU before call `hasPrimaryContext`.");
44+
}
4045
};
4146

4247
struct TORCH_API HPUHooksArgs {};

0 commit comments

Comments
 (0)
0