[Openmp-commits] [PATCH] D103058: [libomptarget][nfc] Move hostcall required test to rtl
Jon Chesterfield via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Mon May 24 17:17:12 PDT 2021
JonChesterfield created this revision.
JonChesterfield added reviewers: ronlieb, pdhaliwal.
Herald added subscribers: foad, kerbowa, jfb, nhaehnle, jvesely.
JonChesterfield requested review of this revision.
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.
[libomptarget][nfc] Move hostcall required test to rtl
Remove a global, fix minor race. First of N patches to bring up hostcall.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103058
Files:
openmp/libomptarget/plugins/amdgpu/impl/system.cpp
openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
Index: openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -335,6 +335,8 @@
// Resource pools
SignalPoolT FreeSignalPool;
+ bool hostcall_required = false;
+
std::vector<hsa_executable_t> HSAExecutables;
struct atmiFreePtrDeletor {
@@ -1158,6 +1160,12 @@
return ATMI_STATUS_SUCCESS;
}
+static bool image_contains_symbol(void *data, size_t size, const char *sym) {
+ symbol_info si;
+ int rc = get_symbol_info_without_loading((char *)data, size, sym, &si);
+ return (rc == 0) && (si.addr != nullptr);
+}
+
__tgt_target_table *__tgt_rtl_load_binary_locked(int32_t device_id,
__tgt_device_image *image) {
// This function loads the device image onto gpu[device_id] and does other
@@ -1199,7 +1207,13 @@
atmi_status_t err = module_register_from_memory_to_place(
(void *)image->ImageStart, img_size, get_gpu_place(device_id),
- [&](void *data, size_t size) { return env.before_loading(data, size); },
+ [&](void *data, size_t size) {
+ if (image_contains_symbol(data, size, "needs_hostcall_buffer")) {
+ __atomic_store_n(&DeviceInfo.hostcall_required, true,
+ __ATOMIC_RELEASE);
+ }
+ return env.before_loading(data, size);
+ },
DeviceInfo.HSAExecutables);
check("Module registering", err);
@@ -1735,8 +1749,6 @@
return packet_id;
}
-extern bool g_atmi_hostcall_required; // declared without header by atmi
-
static int32_t __tgt_rtl_run_target_team_region_locked(
int32_t device_id, void *tgt_entry_ptr, void **tgt_args,
ptrdiff_t *tgt_offsets, int32_t arg_num, int32_t num_teams,
@@ -1903,7 +1915,7 @@
impl_args->offset_z = 0;
// assign a hostcall buffer for the selected Q
- if (g_atmi_hostcall_required) {
+ if (__atomic_load_n(&DeviceInfo.hostcall_required, __ATOMIC_ACQUIRE)) {
// hostrpc_assign_buffer is not thread safe, and this function is
// under a multiple reader lock, not a writer lock.
static pthread_mutex_t hostcall_init_lock = PTHREAD_MUTEX_INITIALIZER;
Index: openmp/libomptarget/plugins/amdgpu/impl/system.cpp
===================================================================
--- openmp/libomptarget/plugins/amdgpu/impl/system.cpp
+++ openmp/libomptarget/plugins/amdgpu/impl/system.cpp
@@ -136,7 +136,6 @@
std::vector<std::map<std::string, atl_symbol_info_t>> SymbolInfoTable;
bool g_atmi_initialized = false;
-bool g_atmi_hostcall_required = false;
/*
atlc is all internal global values.
@@ -1125,8 +1124,6 @@
return err;
}
SymbolInfoTable[gpu][std::string(name)] = info;
- if (strcmp(name, "needs_hostcall_buffer") == 0)
- g_atmi_hostcall_required = true;
free(name);
} else {
DEBUG_PRINT("Symbol is an indirect function\n");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103058.347533.patch
Type: text/x-patch
Size: 3032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210525/730ab848/attachment.bin>
More information about the Openmp-commits
mailing list