Skip to content

Commit ed68aac

Browse files
authored
[Libomptarget] Move API implementations into GenericPluginTy (#86683)
Summary: The plan is to remove the entire plugin interface and simply use the `GenericPluginTy` inside of `libomptarget` by statically linking against it. This means that inside of `libomptarget` we will simply do `Plugin.data_alloc` without the dynamically loaded interface. To reduce the amount of code required, this patch simply moves all of the RTL implementation functions inside of the Generic device. Now the `__tgt_rtl_` interface is simply a shallow wrapper that will soon go away. There is some redundancy here, this will be improved later. For now what is important is minimizing the changes to the API.
1 parent 421085f commit ed68aac

File tree

2 files changed

+444
-147
lines changed

2 files changed

+444
-147
lines changed

openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,132 @@ struct GenericPluginTy {
10651065
return (DeviceId >= 0 && DeviceId < getNumDevices());
10661066
}
10671067

1068+
public:
1069+
// TODO: This plugin interface needs to be cleaned up.
1070+
1071+
/// Returns non-zero if the provided \p Image can be executed by the runtime.
1072+
int32_t is_valid_binary(__tgt_device_image *Image);
1073+
1074+
/// Initialize the device inside of the plugin.
1075+
int32_t init_device(int32_t DeviceId);
1076+
1077+
/// Return the number of devices this plugin can support.
1078+
int32_t number_of_devices();
1079+
1080+
/// Initializes the OpenMP register requires information.
1081+
int64_t init_requires(int64_t RequiresFlags);
1082+
1083+
/// Returns non-zero if the data can be exchanged between the two devices.
1084+
int32_t is_data_exchangable(int32_t SrcDeviceId, int32_t DstDeviceId);
1085+
1086+
/// Initializes the record and replay mechanism inside the plugin.
1087+
int32_t initialize_record_replay(int32_t DeviceId, int64_t MemorySize,
1088+
void *VAddr, bool isRecord, bool SaveOutput,
1089+
uint64_t &ReqPtrArgOffset);
1090+
1091+
/// Loads the associated binary into the plugin and returns a handle to it.
1092+
int32_t load_binary(int32_t DeviceId, __tgt_device_image *TgtImage,
1093+
__tgt_device_binary *Binary);
1094+
1095+
/// Allocates memory that is accessively to the given device.
1096+
void *data_alloc(int32_t DeviceId, int64_t Size, void *HostPtr, int32_t Kind);
1097+
1098+
/// Deallocates memory on the given device.
1099+
int32_t data_delete(int32_t DeviceId, void *TgtPtr, int32_t Kind);
1100+
1101+
/// Locks / pins host memory using the plugin runtime.
1102+
int32_t data_lock(int32_t DeviceId, void *Ptr, int64_t Size,
1103+
void **LockedPtr);
1104+
1105+
/// Unlocks / unpins host memory using the plugin runtime.
1106+
int32_t data_unlock(int32_t DeviceId, void *Ptr);
1107+
1108+
/// Notify the runtime about a new mapping that has been created outside.
1109+
int32_t data_notify_mapped(int32_t DeviceId, void *HstPtr, int64_t Size);
1110+
1111+
/// Notify t he runtime about a mapping that has been deleted.
1112+
int32_t data_notify_unmapped(int32_t DeviceId, void *HstPtr);
1113+
1114+
/// Copy data to the given device.
1115+
int32_t data_submit(int32_t DeviceId, void *TgtPtr, void *HstPtr,
1116+
int64_t Size);
1117+
1118+
/// Copy data to the given device asynchronously.
1119+
int32_t data_submit_async(int32_t DeviceId, void *TgtPtr, void *HstPtr,
1120+
int64_t Size, __tgt_async_info *AsyncInfoPtr);
1121+
1122+
/// Copy data from the given device.
1123+
int32_t data_retrieve(int32_t DeviceId, void *HstPtr, void *TgtPtr,
1124+
int64_t Size);
1125+
1126+
/// Copy data from the given device asynchornously.
1127+
int32_t data_retrieve_async(int32_t DeviceId, void *HstPtr, void *TgtPtr,
1128+
int64_t Size, __tgt_async_info *AsyncInfoPtr);
1129+
1130+
/// Exchange memory addresses between two devices.
1131+
int32_t data_exchange(int32_t SrcDeviceId, void *SrcPtr, int32_t DstDeviceId,
1132+
void *DstPtr, int64_t Size);
1133+
1134+
/// Exchange memory addresses between two devices asynchronously.
1135+
int32_t data_exchange_async(int32_t SrcDeviceId, void *SrcPtr,
1136+
int DstDeviceId, void *DstPtr, int64_t Size,
1137+
__tgt_async_info *AsyncInfo);
1138+
1139+
/// Begin executing a kernel on the given device.
1140+
int32_t launch_kernel(int32_t DeviceId, void *TgtEntryPtr, void **TgtArgs,
1141+
ptrdiff_t *TgtOffsets, KernelArgsTy *KernelArgs,
1142+
__tgt_async_info *AsyncInfoPtr);
1143+
1144+
/// Synchronize an asyncrhonous queue with the plugin runtime.
1145+
int32_t synchronize(int32_t DeviceId, __tgt_async_info *AsyncInfoPtr);
1146+
1147+
/// Query the current state of an asynchronous queue.
1148+
int32_t query_async(int32_t DeviceId, __tgt_async_info *AsyncInfoPtr);
1149+
1150+
/// Prints information about the given devices supported by the plugin.
1151+
void print_device_info(int32_t DeviceId);
1152+
1153+
/// Creates an event in the given plugin if supported.
1154+
int32_t create_event(int32_t DeviceId, void **EventPtr);
1155+
1156+
/// Records an event that has occurred.
1157+
int32_t record_event(int32_t DeviceId, void *EventPtr,
1158+
__tgt_async_info *AsyncInfoPtr);
1159+
1160+
/// Wait until an event has occurred.
1161+
int32_t wait_event(int32_t DeviceId, void *EventPtr,
1162+
__tgt_async_info *AsyncInfoPtr);
1163+
1164+
/// Syncrhonize execution until an event is done.
1165+
int32_t sync_event(int32_t DeviceId, void *EventPtr);
1166+
1167+
/// Remove the event from the plugin.
1168+
int32_t destroy_event(int32_t DeviceId, void *EventPtr);
1169+
1170+
/// Remove the event from the plugin.
1171+
void set_info_flag(uint32_t NewInfoLevel);
1172+
1173+
/// Creates an asynchronous queue for the given plugin.
1174+
int32_t init_async_info(int32_t DeviceId, __tgt_async_info **AsyncInfoPtr);
1175+
1176+
/// Creates device information to be used for diagnostics.
1177+
int32_t init_device_info(int32_t DeviceId, __tgt_device_info *DeviceInfo,
1178+
const char **ErrStr);
1179+
1180+
/// Sets the offset into the devices for use by OMPT.
1181+
int32_t set_device_offset(int32_t DeviceIdOffset);
1182+
1183+
/// Returns if the plugin can support auotmatic copy.
1184+
int32_t use_auto_zero_copy(int32_t DeviceId);
1185+
1186+
/// Look up a global symbol in the given binary.
1187+
int32_t get_global(__tgt_device_binary Binary, uint64_t Size,
1188+
const char *Name, void **DevicePtr);
1189+
1190+
/// Look up a kernel function in the given binary.
1191+
int32_t get_function(__tgt_device_binary Binary, const char *Name,
1192+
void **KernelPtr);
1193+
10681194
private:
10691195
/// Number of devices available for the plugin.
10701196
int32_t NumDevices = 0;

0 commit comments

Comments
 (0)