diff --git a/c10/core/StorageImpl.cpp b/c10/core/StorageImpl.cpp index fd1603ba011983..df43a796acce0a 100644 --- a/c10/core/StorageImpl.cpp +++ b/c10/core/StorageImpl.cpp @@ -7,9 +7,12 @@ namespace c10 { C10_API std::array StorageImplCreate; -// A allowlist of device type, currently available is PrivateUse1. -static ska::flat_hash_set DeviceTypeAllowList{ - DeviceType::PrivateUse1}; +// A allowlist of device type, currently available is PrivateUse1 +inline ska::flat_hash_set& GetBackendMetaAllowlist() { + static ska::flat_hash_set DeviceTypeAllowList{ + DeviceType::PrivateUse1}; + return DeviceTypeAllowList; +} void throwNullDataPtrError() { TORCH_CHECK( @@ -41,8 +44,9 @@ void SetStorageImplCreate(DeviceType t, StorageImplCreateHelper fptr) { // Allowlist verification. // Only if the devicetype is in the allowlist, // we allow the extension to be registered for storageImpl create. + const auto& DeviceTypeAllowlist = GetBackendMetaAllowlist(); TORCH_CHECK( - DeviceTypeAllowList.find(t) != DeviceTypeAllowList.end(), + DeviceTypeAllowlist.find(t) != DeviceTypeAllowlist.end(), "It is only allowed to register the storageImpl create method ", "for PrivateUse1. ", "If you have related storageImpl requirements, ",