|
13 | 13 | #ifndef _OMPTARGET_RTL_H
|
14 | 14 | #define _OMPTARGET_RTL_H
|
15 | 15 |
|
16 |
| -#include "llvm/ADT/SmallVector.h" |
17 |
| - |
18 | 16 | #include "omptarget.h"
|
| 17 | +#include <llvm/ADT/DenseSet.h> |
| 18 | +#include "llvm/ADT/SmallVector.h" |
| 19 | +#include "llvm/Support/DynamicLibrary.h" |
19 | 20 |
|
20 | 21 | #include <cstdint>
|
| 22 | +#include <list> |
| 23 | +#include <map> |
| 24 | +#include <mutex> |
| 25 | +#include <string> |
| 26 | +#include <vector> |
21 | 27 | #include <map>
|
22 | 28 |
|
| 29 | +// Forward declarations. |
| 30 | +struct DeviceTy; |
| 31 | +struct __tgt_bin_desc; |
| 32 | + |
| 33 | +struct RTLInfoTy { |
| 34 | + typedef int32_t(init_plugin_ty)(); |
| 35 | + typedef int32_t(deinit_plugin_ty)(); |
| 36 | + typedef int32_t(is_valid_binary_ty)(void *); |
| 37 | + typedef int32_t(is_valid_binary_info_ty)(void *, void *); |
| 38 | + typedef int32_t(is_data_exchangable_ty)(int32_t, int32_t); |
| 39 | + typedef int32_t(number_of_devices_ty)(); |
| 40 | + typedef bool(has_apu_device_ty)(); |
| 41 | + typedef bool(has_USM_capable_dGPU_ty)(); |
| 42 | + typedef bool(are_allocations_for_maps_on_apus_disabled_ty)(); |
| 43 | + typedef bool(requested_prepopulate_gpu_page_table_ty)(); |
| 44 | + typedef bool(is_no_maps_check_ty)(); |
| 45 | + typedef bool(is_fine_grained_memory_enabled_ty)(); |
| 46 | + typedef bool(is_system_supporting_managed_memory_ty)(); |
| 47 | + typedef int32_t(init_device_ty)(int32_t); |
| 48 | + typedef int32_t(deinit_device_ty)(int32_t); |
| 49 | + typedef int32_t(number_of_team_procs_ty)(int32_t); |
| 50 | + typedef __tgt_target_table *(load_binary_ty)(int32_t, void *); |
| 51 | + typedef void *(data_alloc_ty)(int32_t, int64_t, void *, int32_t); |
| 52 | + |
| 53 | + typedef int32_t(data_submit_ty)(int32_t, void *, void *, int64_t); |
| 54 | + typedef int32_t(data_submit_async_ty)(int32_t, void *, void *, int64_t, |
| 55 | + __tgt_async_info *); |
| 56 | + typedef int32_t(data_retrieve_ty)(int32_t, void *, void *, int64_t); |
| 57 | + typedef int32_t(data_retrieve_async_ty)(int32_t, void *, void *, int64_t, |
| 58 | + __tgt_async_info *); |
| 59 | + typedef int32_t(data_exchange_ty)(int32_t, void *, int32_t, void *, int64_t); |
| 60 | + typedef int32_t(data_exchange_async_ty)(int32_t, void *, int32_t, void *, |
| 61 | + int64_t, __tgt_async_info *); |
| 62 | + typedef int32_t(data_delete_ty)(int32_t, void *, int32_t); |
| 63 | + typedef int32_t(launch_kernel_sync_ty)(int32_t, void *, void **, ptrdiff_t *, |
| 64 | + const KernelArgsTy *); |
| 65 | + typedef int32_t(launch_kernel_ty)(int32_t, void *, void **, ptrdiff_t *, |
| 66 | + const KernelArgsTy *, __tgt_async_info *); |
| 67 | + typedef int64_t(init_requires_ty)(int64_t); |
| 68 | + typedef int32_t(synchronize_ty)(int32_t, __tgt_async_info *); |
| 69 | + typedef int32_t(query_async_ty)(int32_t, __tgt_async_info *); |
| 70 | + typedef int32_t (*register_lib_ty)(__tgt_bin_desc *); |
| 71 | + typedef int32_t(supports_empty_images_ty)(); |
| 72 | + typedef void(print_device_info_ty)(int32_t); |
| 73 | + typedef void(set_info_flag_ty)(uint32_t); |
| 74 | + typedef int32_t(create_event_ty)(int32_t, void **); |
| 75 | + typedef int32_t(record_event_ty)(int32_t, void *, __tgt_async_info *); |
| 76 | + typedef int32_t(wait_event_ty)(int32_t, void *, __tgt_async_info *); |
| 77 | + typedef int32_t(sync_event_ty)(int32_t, void *); |
| 78 | + typedef int32_t(destroy_event_ty)(int32_t, void *); |
| 79 | + typedef int(set_coarse_grain_mem_region_ty)(int32_t, void *, int64_t); |
| 80 | + typedef int(prepopulate_page_table_ty)(int32_t, void *, int64_t); |
| 81 | + typedef int32_t(query_coarse_grain_mem_region_ty)(int32_t, void *, int64_t); |
| 82 | + typedef int32_t(enable_access_to_all_agents_ty)(void *, int32_t); |
| 83 | + typedef int32_t(release_async_info_ty)(int32_t, __tgt_async_info *); |
| 84 | + typedef int32_t(init_async_info_ty)(int32_t, __tgt_async_info **); |
| 85 | + typedef int64_t(init_device_into_ty)(int64_t, __tgt_device_info *, |
| 86 | + const char **); |
| 87 | + typedef int32_t(data_lock_ty)(int32_t, void *, int64_t, void **); |
| 88 | + typedef int32_t(data_unlock_ty)(int32_t, void *); |
| 89 | + typedef int32_t(data_notify_mapped_ty)(int32_t, void *, int64_t); |
| 90 | + typedef int32_t(data_notify_unmapped_ty)(int32_t, void *); |
| 91 | + typedef int32_t(set_device_offset_ty)(int32_t); |
| 92 | + typedef int32_t(activate_record_replay_ty)(int32_t, uint64_t, void *, bool, |
| 93 | + bool); |
| 94 | + typedef void(set_up_env_ty)(void); |
| 95 | + |
| 96 | + int32_t Idx = -1; // RTL index, index is the number of devices |
| 97 | + // of other RTLs that were registered before, |
| 98 | + // i.e. the OpenMP index of the first device |
| 99 | + // to be registered with this RTL. |
| 100 | + int32_t NumberOfDevices = -1; // Number of devices this RTL deals with. |
| 101 | + |
| 102 | + std::unique_ptr<llvm::sys::DynamicLibrary> LibraryHandler; |
| 103 | + |
| 104 | +#ifdef OMPTARGET_DEBUG |
| 105 | + std::string RTLName; |
| 106 | +#endif |
| 107 | + |
| 108 | + // Functions implemented in the RTL. |
| 109 | + init_plugin_ty *init_plugin = nullptr; |
| 110 | + deinit_plugin_ty *deinit_plugin = nullptr; |
| 111 | + is_valid_binary_ty *is_valid_binary = nullptr; |
| 112 | + is_valid_binary_info_ty *is_valid_binary_info = nullptr; |
| 113 | + is_data_exchangable_ty *is_data_exchangable = nullptr; |
| 114 | + number_of_devices_ty *number_of_devices = nullptr; |
| 115 | + has_apu_device_ty *has_apu_device = nullptr; |
| 116 | + has_USM_capable_dGPU_ty *has_USM_capable_dGPU = nullptr; |
| 117 | + are_allocations_for_maps_on_apus_disabled_ty |
| 118 | + *are_allocations_for_maps_on_apus_disabled = nullptr; |
| 119 | + requested_prepopulate_gpu_page_table_ty |
| 120 | + *requested_prepopulate_gpu_page_table = nullptr; |
| 121 | + is_no_maps_check_ty *is_no_maps_check = nullptr; |
| 122 | + is_fine_grained_memory_enabled_ty *is_fine_grained_memory_enabled = nullptr; |
| 123 | + is_system_supporting_managed_memory_ty *is_system_supporting_managed_memory = |
| 124 | + nullptr; |
| 125 | + init_device_ty *init_device = nullptr; |
| 126 | + deinit_device_ty *deinit_device = nullptr; |
| 127 | + number_of_team_procs_ty *number_of_team_procs = nullptr; |
| 128 | + load_binary_ty *load_binary = nullptr; |
| 129 | + data_alloc_ty *data_alloc = nullptr; |
| 130 | + data_submit_ty *data_submit = nullptr; |
| 131 | + data_submit_async_ty *data_submit_async = nullptr; |
| 132 | + data_retrieve_ty *data_retrieve = nullptr; |
| 133 | + data_retrieve_async_ty *data_retrieve_async = nullptr; |
| 134 | + data_exchange_ty *data_exchange = nullptr; |
| 135 | + data_exchange_async_ty *data_exchange_async = nullptr; |
| 136 | + data_delete_ty *data_delete = nullptr; |
| 137 | + launch_kernel_sync_ty *launch_kernel_sync = nullptr; |
| 138 | + launch_kernel_ty *launch_kernel = nullptr; |
| 139 | + init_requires_ty *init_requires = nullptr; |
| 140 | + synchronize_ty *synchronize = nullptr; |
| 141 | + query_async_ty *query_async = nullptr; |
| 142 | + register_lib_ty register_lib = nullptr; |
| 143 | + register_lib_ty unregister_lib = nullptr; |
| 144 | + supports_empty_images_ty *supports_empty_images = nullptr; |
| 145 | + set_info_flag_ty *set_info_flag = nullptr; |
| 146 | + print_device_info_ty *print_device_info = nullptr; |
| 147 | + create_event_ty *create_event = nullptr; |
| 148 | + record_event_ty *record_event = nullptr; |
| 149 | + wait_event_ty *wait_event = nullptr; |
| 150 | + sync_event_ty *sync_event = nullptr; |
| 151 | + destroy_event_ty *destroy_event = nullptr; |
| 152 | + init_async_info_ty *init_async_info = nullptr; |
| 153 | + init_device_into_ty *init_device_info = nullptr; |
| 154 | + release_async_info_ty *release_async_info = nullptr; |
| 155 | + data_lock_ty *data_lock = nullptr; |
| 156 | + data_unlock_ty *data_unlock = nullptr; |
| 157 | + set_coarse_grain_mem_region_ty *set_coarse_grain_mem_region = nullptr; |
| 158 | + prepopulate_page_table_ty *prepopulate_page_table = nullptr; |
| 159 | + query_coarse_grain_mem_region_ty *query_coarse_grain_mem_region = nullptr; |
| 160 | + enable_access_to_all_agents_ty *enable_access_to_all_agents = nullptr; |
| 161 | + data_notify_mapped_ty *data_notify_mapped = nullptr; |
| 162 | + data_notify_unmapped_ty *data_notify_unmapped = nullptr; |
| 163 | + set_device_offset_ty *set_device_offset = nullptr; |
| 164 | + activate_record_replay_ty *activate_record_replay = nullptr; |
| 165 | + set_up_env_ty *set_up_env = nullptr; |
| 166 | + |
| 167 | + // Are there images associated with this RTL. |
| 168 | + bool IsUsed = false; |
| 169 | + |
| 170 | + llvm::DenseSet<const __tgt_device_image *> UsedImages; |
| 171 | + |
| 172 | + // Mutex for thread-safety when calling RTL interface functions. |
| 173 | + // It is easier to enforce thread-safety at the libomptarget level, |
| 174 | + // so that developers of new RTLs do not have to worry about it. |
| 175 | + std::mutex Mtx; |
| 176 | +}; |
| 177 | + |
| 178 | +/// RTLs identified in the system. |
| 179 | +struct RTLsTy { |
| 180 | + // List of the detected runtime libraries. |
| 181 | + std::list<RTLInfoTy> AllRTLs; |
| 182 | + |
| 183 | + // Array of pointers to the detected runtime libraries that have compatible |
| 184 | + // binaries. |
| 185 | + llvm::SmallVector<RTLInfoTy *> UsedRTLs; |
| 186 | + |
| 187 | + explicit RTLsTy() = default; |
| 188 | + |
| 189 | + // Register the clauses of the requires directive. |
| 190 | + void registerRequires(int64_t Flags); |
| 191 | + |
| 192 | + // Initialize RTL if it has not been initialized |
| 193 | + void initRTLonce(RTLInfoTy &RTL); |
| 194 | + |
| 195 | + // Initialize all RTLs |
| 196 | + void initAllRTLs(); |
| 197 | + |
| 198 | + // Register a shared library with all (compatible) RTLs. |
| 199 | + void registerLib(__tgt_bin_desc *Desc); |
| 200 | + |
| 201 | + // Unregister a shared library from all RTLs. |
| 202 | + void unregisterLib(__tgt_bin_desc *Desc); |
| 203 | + |
| 204 | + // not thread-safe, called from global constructor (i.e. once) |
| 205 | + void loadRTLs(); |
| 206 | +}; |
| 207 | + |
23 | 208 | /// Map between the host entry begin and the translation table. Each
|
24 | 209 | /// registered library gets one TranslationTable. Use the map from
|
25 | 210 | /// __tgt_offload_entry so that we may quickly determine whether we
|
|
0 commit comments