[Openmp-commits] [PATCH] D99447: [OpenMP] Define omp_is_initial_device() variants in omp.h

Hansang Bae via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Mar 26 15:34:36 PDT 2021


hbae created this revision.
hbae added reviewers: RaviNarayanaswamy, mikerice.
hbae added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
hbae requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

omp_is_initial_device() is marked as a built-in function in the current
 compiler, and user code guarded by this call may be optimized away,
 resulting in undesired behavior in some cases. This patch provides a
 possible fix for such cases by defining the routine as a variant
 function. Full fix also requires removal of the routine from the
 built-in function list in the compiler.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99447

Files:
  openmp/runtime/src/include/omp.h.var


Index: openmp/runtime/src/include/omp.h.var
===================================================================
--- openmp/runtime/src/include/omp.h.var
+++ openmp/runtime/src/include/omp.h.var
@@ -468,6 +468,15 @@
     /* OpenMP 5.1 Display Environment */
     extern void omp_display_env(int verbose);
 
+#   if defined(_OPENMP) && _OPENMP >= 201811
+    #pragma omp begin declare variant match(device={kind(host)})
+    static int omp_is_initial_device(void) { return 1; }
+    #pragma omp end declare variant
+    #pragma omp begin declare variant match(device={kind(nohost)})
+    static int omp_is_initial_device(void) { return 0; }
+    #pragma omp end declare variant
+#   endif
+
 #   undef __KAI_KMPC_CONVENTION
 #   undef __KMP_IMP
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99447.333646.patch
Type: text/x-patch
Size: 745 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210326/6920ad12/attachment.bin>


More information about the Openmp-commits mailing list