Skip to content

[Libomptarget][NFC] Remove concept of optional plugin functions #82681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions openmp/libomptarget/include/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct PluginAdaptorTy {
/// Access to the shared object file representing the plugin.
std::unique_ptr<llvm::sys::DynamicLibrary> LibraryHandler;

#define PLUGIN_API_HANDLE(NAME, MANDATORY) \
#define PLUGIN_API_HANDLE(NAME) \
using NAME##_ty = decltype(__tgt_rtl_##NAME); \
NAME##_ty *NAME = nullptr;

Expand Down Expand Up @@ -114,8 +114,10 @@ struct PluginManager {
// Unregister a shared library from all RTLs.
void unregisterLib(__tgt_bin_desc *Desc);

void addDeviceImage(__tgt_bin_desc &TgtBinDesc, __tgt_device_image &TgtDeviceImage) {
DeviceImages.emplace_back(std::make_unique<DeviceImageTy>(TgtBinDesc, TgtDeviceImage));
void addDeviceImage(__tgt_bin_desc &TgtBinDesc,
__tgt_device_image &TgtDeviceImage) {
DeviceImages.emplace_back(
std::make_unique<DeviceImageTy>(TgtBinDesc, TgtDeviceImage));
}

/// Return the device presented to the user as device \p DeviceNo if it is
Expand Down
72 changes: 36 additions & 36 deletions openmp/libomptarget/include/Shared/PluginAPI.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@

// No include guards!

PLUGIN_API_HANDLE(init_plugin, true);
PLUGIN_API_HANDLE(is_valid_binary, true);
PLUGIN_API_HANDLE(is_data_exchangable, false);
PLUGIN_API_HANDLE(number_of_devices, true);
PLUGIN_API_HANDLE(init_device, true);
PLUGIN_API_HANDLE(load_binary, true);
PLUGIN_API_HANDLE(get_global, true);
PLUGIN_API_HANDLE(get_function, true);
PLUGIN_API_HANDLE(data_alloc, true);
PLUGIN_API_HANDLE(data_submit, true);
PLUGIN_API_HANDLE(data_submit_async, false);
PLUGIN_API_HANDLE(data_retrieve, true);
PLUGIN_API_HANDLE(data_retrieve_async, false);
PLUGIN_API_HANDLE(data_exchange, false);
PLUGIN_API_HANDLE(data_exchange_async, false);
PLUGIN_API_HANDLE(data_delete, true);
PLUGIN_API_HANDLE(launch_kernel, true);
PLUGIN_API_HANDLE(init_requires, false);
PLUGIN_API_HANDLE(synchronize, false);
PLUGIN_API_HANDLE(query_async, false);
PLUGIN_API_HANDLE(set_info_flag, false);
PLUGIN_API_HANDLE(print_device_info, false);
PLUGIN_API_HANDLE(create_event, false);
PLUGIN_API_HANDLE(record_event, false);
PLUGIN_API_HANDLE(wait_event, false);
PLUGIN_API_HANDLE(sync_event, false);
PLUGIN_API_HANDLE(destroy_event, false);
PLUGIN_API_HANDLE(init_async_info, false);
PLUGIN_API_HANDLE(init_device_info, false);
PLUGIN_API_HANDLE(data_lock, false);
PLUGIN_API_HANDLE(data_unlock, false);
PLUGIN_API_HANDLE(data_notify_mapped, false);
PLUGIN_API_HANDLE(data_notify_unmapped, false);
PLUGIN_API_HANDLE(set_device_offset, false);
PLUGIN_API_HANDLE(initialize_record_replay, false);
PLUGIN_API_HANDLE(use_auto_zero_copy, false);
PLUGIN_API_HANDLE(init_plugin);
PLUGIN_API_HANDLE(is_valid_binary);
PLUGIN_API_HANDLE(is_data_exchangable);
PLUGIN_API_HANDLE(number_of_devices);
PLUGIN_API_HANDLE(init_device);
PLUGIN_API_HANDLE(load_binary);
PLUGIN_API_HANDLE(get_global);
PLUGIN_API_HANDLE(get_function);
PLUGIN_API_HANDLE(data_alloc);
PLUGIN_API_HANDLE(data_submit);
PLUGIN_API_HANDLE(data_submit_async);
PLUGIN_API_HANDLE(data_retrieve);
PLUGIN_API_HANDLE(data_retrieve_async);
PLUGIN_API_HANDLE(data_exchange);
PLUGIN_API_HANDLE(data_exchange_async);
PLUGIN_API_HANDLE(data_delete);
PLUGIN_API_HANDLE(launch_kernel);
PLUGIN_API_HANDLE(init_requires);
PLUGIN_API_HANDLE(synchronize);
PLUGIN_API_HANDLE(query_async);
PLUGIN_API_HANDLE(set_info_flag);
PLUGIN_API_HANDLE(print_device_info);
PLUGIN_API_HANDLE(create_event);
PLUGIN_API_HANDLE(record_event);
PLUGIN_API_HANDLE(wait_event);
PLUGIN_API_HANDLE(sync_event);
PLUGIN_API_HANDLE(destroy_event);
PLUGIN_API_HANDLE(init_async_info);
PLUGIN_API_HANDLE(init_device_info);
PLUGIN_API_HANDLE(data_lock);
PLUGIN_API_HANDLE(data_unlock);
PLUGIN_API_HANDLE(data_notify_mapped);
PLUGIN_API_HANDLE(data_notify_unmapped);
PLUGIN_API_HANDLE(set_device_offset);
PLUGIN_API_HANDLE(initialize_record_replay);
PLUGIN_API_HANDLE(use_auto_zero_copy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what will happen on NVIDIA GPUs for use_auto_zero_copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch doesn't change what happens if it's called, but the fallback is to just return false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, for those APIs don't exist on a target, we will error out immediately with this change right? However, since they are optional, the program can and should still work even w/o them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we were never actually exercising this functionality. Every function is defined on every "plugin" with some returning default results, this change is NFC.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah now it's all virtual function and then have a unified implementation in PluginInterface.cpp. TBH I'm not sure if that's a good idea but that is out of the scope. For now it looks fine.

4 changes: 2 additions & 2 deletions openmp/libomptarget/src/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ PluginAdaptorTy::PluginAdaptorTy(const std::string &Name,

Error PluginAdaptorTy::init() {

#define PLUGIN_API_HANDLE(NAME, MANDATORY) \
#define PLUGIN_API_HANDLE(NAME) \
NAME = reinterpret_cast<decltype(NAME)>( \
LibraryHandler->getAddressOfSymbol(GETNAME(__tgt_rtl_##NAME))); \
if (MANDATORY && !NAME) { \
if (!NAME) { \
return createStringError(inconvertibleErrorCode(), \
"Invalid plugin as necessary interface function " \
"(%s) was not found.\n", \
Expand Down