[Openmp-commits] [PATCH] D149557: [OpenMP] Handle function calls from `libomp` to `libomptarget` correctly
Shilei Tian via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Sun Apr 30 14:07:23 PDT 2023
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, AndreyChurbanov, tlwilmar, jlpeyton, natgla.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added subscribers: openmp-commits, jplehr, sstefan1.
Herald added a project: OpenMP.
D132005 <https://reviews.llvm.org/D132005> introduced function calls from `libomp` to `libomptarget` if offloading
is enabled. However, the external function declaration may not always work. For
example, it causes a link error on macOS. Currently it is guarded properly by
a macro, but in order to get OpenMP target offloading working on macOS, it has
to be handled correctly. This patch applies the same idea of how we support
target memory extension by using function pointer indirect call for that function.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149557
Files:
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_runtime.cpp
openmp/runtime/src/kmp_tasking.cpp
Index: openmp/runtime/src/kmp_tasking.cpp
===================================================================
--- openmp/runtime/src/kmp_tasking.cpp
+++ openmp/runtime/src/kmp_tasking.cpp
@@ -22,8 +22,11 @@
#endif
#if ENABLE_LIBOMPTARGET
-// Declaration of synchronization function from libomptarget.
-extern "C" void __tgt_target_nowait_query(void **) KMP_WEAK_ATTRIBUTE_INTERNAL;
+static void (*tgt_target_nowait_query)(void **);
+
+void __kmp_init_target_task() {
+ *(void **)(&tgt_target_nowait_query) = KMP_DLSYM("__tgt_target_nowait_query");
+}
#endif
/* forward declaration */
@@ -1805,7 +1808,7 @@
// If we have a valid target async handle, that means that we have already
// executed the task routine once. We must query for the handle completion
// instead of re-executing the routine.
- __tgt_target_nowait_query(&taskdata->td_target_data.async_handle);
+ tgt_target_nowait_query(&taskdata->td_target_data.async_handle);
} else
#endif
if (task->routine != NULL) {
Index: openmp/runtime/src/kmp_runtime.cpp
===================================================================
--- openmp/runtime/src/kmp_runtime.cpp
+++ openmp/runtime/src/kmp_runtime.cpp
@@ -553,6 +553,14 @@
/* ------------------------------------------------------------------------ */
+#if ENABLE_LIBOMPTARGET
+static void __kmp_init_omptarget() {
+ __kmp_init_target_task();
+}
+#endif
+
+/* ------------------------------------------------------------------------ */
+
#if KMP_DYNAMIC_LIB
#if KMP_OS_WINDOWS
@@ -7041,6 +7049,11 @@
__kmp_validate_locks();
+#if ENABLE_LIBOMPTARGET
+ /* Initialize functions from libomptarget */
+ __kmp_init_omptarget();
+#endif
+
/* Initialize internal memory allocator */
__kmp_init_allocator();
Index: openmp/runtime/src/kmp.h
===================================================================
--- openmp/runtime/src/kmp.h
+++ openmp/runtime/src/kmp.h
@@ -1100,6 +1100,12 @@
/* ------------------------------------------------------------------------ */
+#if ENABLE_LIBOMPTARGET
+extern void __kmp_init_target_task();
+#endif
+
+/* ------------------------------------------------------------------------ */
+
#define KMP_UINT64_MAX \
(~((kmp_uint64)1 << ((sizeof(kmp_uint64) * (1 << 3)) - 1)))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149557.518355.patch
Type: text/x-patch
Size: 2356 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230430/73e47479/attachment-0001.bin>
More information about the Openmp-commits
mailing list