DP("Successfully loaded library '%s'!\n", Name);
- // Retrieve the RTL information from the runtime library.
- RTLInfoTy R;
+ AllRTLs.emplace_back();
- R.LibraryHandler = dynlib_handle;
- R.isUsed = false;
+ // Retrieve the RTL information from the runtime library.
+ RTLInfoTy &R = AllRTLs.back();
-#ifdef OMPTARGET_DEBUG
- R.RTLName = Name;
-#endif
+ bool ValidPlugin = true;
if (!(*((void **)&R.is_valid_binary) =
dlsym(dynlib_handle, "__tgt_rtl_is_valid_binary")))
- continue;
+ ValidPlugin = false;
if (!(*((void **)&R.number_of_devices) =
dlsym(dynlib_handle, "__tgt_rtl_number_of_devices")))
- continue;
+ ValidPlugin = false;
if (!(*((void **)&R.init_device) =
dlsym(dynlib_handle, "__tgt_rtl_init_device")))
- continue;
+ ValidPlugin = false;
if (!(*((void **)&R.load_binary) =
dlsym(dynlib_handle, "__tgt_rtl_load_binary")))
- continue;
+ ValidPlugin = false;
if (!(*((void **)&R.data_alloc) =
dlsym(dynlib_handle, "__tgt_rtl_data_alloc")))
- continue;
+ ValidPlugin = false;
if (!(*((void **)&R.data_submit) =
dlsym(dynlib_handle, "__tgt_rtl_data_submit")))
- continue;
+ ValidPlugin = false;
if (!(*((void **)&R.data_retrieve) =
dlsym(dynlib_handle, "__tgt_rtl_data_retrieve")))
- continue;
+ ValidPlugin = false;
if (!(*((void **)&R.data_delete) =
dlsym(dynlib_handle, "__tgt_rtl_data_delete")))
- continue;
+ ValidPlugin = false;
if (!(*((void **)&R.run_region) =
dlsym(dynlib_handle, "__tgt_rtl_run_target_region")))
- continue;
+ ValidPlugin = false;
if (!(*((void **)&R.run_team_region) =
dlsym(dynlib_handle, "__tgt_rtl_run_target_team_region")))
+ ValidPlugin = false;
+
+ // Invalid plugin
+ if (!ValidPlugin) {
+ DP("Invalid plugin as necessary interface is not found.\n");
+ AllRTLs.pop_back();
+ continue;
+ }
+
+ // No devices are supported by this RTL?
+ if (!(R.NumberOfDevices = R.number_of_devices())) {
+ // The RTL is invalid! Will pop the object from the RTLs list.
+ DP("No devices supported in this RTL\n");
+ AllRTLs.pop_back();
continue;
+ }
+
+ R.LibraryHandler = dynlib_handle;
+
+#ifdef OMPTARGET_DEBUG
+ R.RTLName = Name;
+#endif
+
+ DP("Registering RTL %s supporting %d devices!\n", R.RTLName.c_str(),
+ R.NumberOfDevices);
// Optional functions
*((void **)&R.init_requires) =
dlsym(dynlib_handle, "__tgt_rtl_data_exchange_async");
*((void **)&R.is_data_exchangable) =
dlsym(dynlib_handle, "__tgt_rtl_is_data_exchangable");
-
- // No devices are supported by this RTL?
- if (!(R.NumberOfDevices = R.number_of_devices())) {
- DP("No devices supported in this RTL\n");
- continue;
- }
-
- DP("Registering RTL %s supporting %d devices!\n", R.RTLName.c_str(),
- R.NumberOfDevices);
-
- // The RTL is valid! Will save the information in the RTLs list.
- AllRTLs.push_back(R);
}
DP("RTLs loaded!\n");
// It is easier to enforce thread-safety at the libomptarget level,
// so that developers of new RTLs do not have to worry about it.
std::mutex Mtx;
-
- // The existence of the mutex above makes RTLInfoTy non-copyable.
- // We need to provide a copy constructor explicitly.
- RTLInfoTy() = default;
-
- RTLInfoTy(const RTLInfoTy &r) {
- Idx = r.Idx;
- NumberOfDevices = r.NumberOfDevices;
- LibraryHandler = r.LibraryHandler;
-#ifdef OMPTARGET_DEBUG
- RTLName = r.RTLName;
-#endif
- is_valid_binary = r.is_valid_binary;
- is_data_exchangable = r.is_data_exchangable;
- number_of_devices = r.number_of_devices;
- init_device = r.init_device;
- load_binary = r.load_binary;
- data_alloc = r.data_alloc;
- data_submit = r.data_submit;
- data_submit_async = r.data_submit_async;
- data_retrieve = r.data_retrieve;
- data_retrieve_async = r.data_retrieve_async;
- data_exchange = r.data_exchange;
- data_exchange_async = r.data_exchange_async;
- data_delete = r.data_delete;
- run_region = r.run_region;
- run_region_async = r.run_region_async;
- run_team_region = r.run_team_region;
- run_team_region_async = r.run_team_region_async;
- init_requires = r.init_requires;
- isUsed = r.isUsed;
- synchronize = r.synchronize;
- }
};
/// RTLs identified in the system.