@@ -32,7 +32,10 @@ struct offload_platform_handle_t_ {
3232 std::vector<offload_device_handle_t_> Devices;
3333};
3434
35- static std::vector<offload_platform_handle_t_> Platforms;
35+ std::vector<offload_platform_handle_t_> &Platforms () {
36+ static std::vector<offload_platform_handle_t_> Platforms;
37+ return Platforms;
38+ }
3639
3740// Every plugin exports this method to create an instance of the plugin type.
3841#define PLUGIN_TARGET (Name ) extern " C" GenericPluginTy *createPlugin_##Name();
@@ -42,14 +45,14 @@ void initPlugins() {
4245 // Attempt to create an instance of each supported plugin.
4346#define PLUGIN_TARGET (Name ) \
4447 do { \
45- Platforms.emplace_back (offload_platform_handle_t_{ \
48+ Platforms () .emplace_back (offload_platform_handle_t_{ \
4649 std::unique_ptr<GenericPluginTy>(createPlugin_##Name ()), {}}); \
4750 } while (false );
4851#include " Shared/Targets.def"
4952
5053 // Preemptively initialize all devices in the plugin so we can just return
5154 // them from deviceGet
52- for (auto &Platform : Platforms) {
55+ for (auto &Platform : Platforms () ) {
5356 auto Err = Platform.Plugin ->init ();
5457 [[maybe_unused]] std::string InfoMsg = toString (std::move (Err));
5558 for (auto DevNum = 0 ; DevNum < Platform.Plugin ->number_of_devices ();
@@ -71,19 +74,19 @@ offload_result_t offloadPlatformGet_impl(uint32_t NumEntries,
7174 static std::once_flag InitFlag;
7275 std::call_once (InitFlag, initPlugins);
7376
74- if (NumEntries > Platforms.size ()) {
77+ if (NumEntries > Platforms () .size ()) {
7578 return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
7679 }
7780
7881 if (phPlatforms) {
7982 for (uint32_t PlatformIndex = 0 ; PlatformIndex < NumEntries;
8083 PlatformIndex++) {
81- phPlatforms[PlatformIndex] = &Platforms[PlatformIndex];
84+ phPlatforms[PlatformIndex] = &( Platforms ()) [PlatformIndex];
8285 }
8386 }
8487
8588 if (pNumPlatforms) {
86- *pNumPlatforms = Platforms.size ();
89+ *pNumPlatforms = Platforms () .size ();
8790 }
8891
8992 return OFFLOAD_RESULT_SUCCESS;
0 commit comments