xref: /aosp_15_r20/external/pytorch/aten/src/ATen/detail/HIPHooksInterface.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #include <ATen/detail/HIPHooksInterface.h>
2 
3 #include <c10/util/CallOnce.h>
4 #include <c10/util/Registry.h>
5 
6 #include <memory>
7 
8 namespace at {
9 namespace detail {
10 
11 // See getCUDAHooks for some more commentary
getHIPHooks()12 const HIPHooksInterface& getHIPHooks() {
13   static std::unique_ptr<HIPHooksInterface> hip_hooks;
14 #if !defined C10_MOBILE
15   static c10::once_flag once;
16   c10::call_once(once, [] {
17     hip_hooks = HIPHooksRegistry()->Create("HIPHooks", HIPHooksArgs{});
18     if (!hip_hooks) {
19       hip_hooks = std::make_unique<HIPHooksInterface>();
20     }
21   });
22 #else
23   if (hip_hooks == nullptr) {
24     hip_hooks = std::make_unique<HIPHooksInterface>();
25   }
26 #endif
27   return *hip_hooks;
28 }
29 } // namespace detail
30 
31 C10_DEFINE_REGISTRY(HIPHooksRegistry, HIPHooksInterface, HIPHooksArgs)
32 
33 } // namespace at
34