[BE] Use static local variable instead of call_once (#112994)

See https://en.cppreference.com/w/cpp/language/storage_duration#Static_local_variables

And also, it's weird to mix two paradigms together, as static local variable is used to initialize `DriverAPI::get()` singleton mere 3 lines below
Pull Request resolved: https://github.com/pytorch/pytorch/pull/112994
Approved by: https://github.com/Skylion007
This commit is contained in:
Nikita Shulga
2023-11-05 11:47:30 -08:00
committed by PyTorch MergeBot
parent 9c1fb2cbb3
commit 57191172f8

View File

@@ -33,11 +33,8 @@ DriverAPI create_driver_api() {
} // namespace
void* DriverAPI::get_nvml_handle() {
static c10::once_flag once;
static void* handle_1;
c10::call_once(
once, [] { handle_1 = dlopen("libnvidia-ml.so.1", RTLD_LAZY); });
return handle_1;
static void* nvml_hanle = dlopen("libnvidia-ml.so.1", RTLD_LAZY);
return nvml_hanle;
}
DriverAPI* DriverAPI::get() {