[Openmp-commits] [openmp] 56da282 - [OpenMP] Add GOMP 5.0 version symbols to API
via Openmp-commits
openmp-commits at lists.llvm.org
Tue Jun 15 14:25:40 PDT 2021
Author: Peyton, Jonathan L
Date: 2021-06-15T16:25:00-05:00
New Revision: 56da28240f3c9d1c0b7152749bfd4777c67828e0
URL: https://github.com/llvm/llvm-project/commit/56da28240f3c9d1c0b7152749bfd4777c67828e0
DIFF: https://github.com/llvm/llvm-project/commit/56da28240f3c9d1c0b7152749bfd4777c67828e0.diff
LOG: [OpenMP] Add GOMP 5.0 version symbols to API
* Add GOMP versioned pause functions
* Add GOMP versioned affinity format functions
To do the affinity format functions, only attach versioned symbols
to the APPEND Fortran entries (e.g., omp_set_affinity_format_) since
GOMP only exports two symbols (one for Fortran, one for C). Our
affinity format functions have three symbols.
e.g., with omp_set_affinity_format:
1) omp_set_affinity_format (Fortran interface)
2) omp_set_affinity_format_ (Fortran interface)
3) ompc_set_affinity_format (C interface)
Have the GOMP version of the C symbol alias the ompc_* 3) version
instead of the Fortran unappended version 1).
Differential Revision: https://reviews.llvm.org/D103647
Added:
Modified:
openmp/runtime/src/exports_so.txt
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_csupport.cpp
openmp/runtime/src/kmp_ftn_entry.h
openmp/runtime/src/kmp_os.h
Removed:
################################################################################
diff --git a/openmp/runtime/src/exports_so.txt b/openmp/runtime/src/exports_so.txt
index 30222418163d..524bf117be0c 100644
--- a/openmp/runtime/src/exports_so.txt
+++ b/openmp/runtime/src/exports_so.txt
@@ -107,6 +107,8 @@ OMP_4.0 {
} OMP_3.1;
OMP_4.5 {
} OMP_4.0;
+OMP_5.0 {
+} OMP_4.5;
# sets up GCC GOMP_ version dependency chain
GOMP_1.0 {
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index d1f0da8ae356..479522427064 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -4012,6 +4012,11 @@ KMP_EXPORT void KMPC_CONVENTION kmpc_set_stacksize_s(size_t);
KMP_EXPORT void KMPC_CONVENTION kmpc_set_library(int);
KMP_EXPORT void KMPC_CONVENTION kmpc_set_defaults(char const *);
KMP_EXPORT void KMPC_CONVENTION kmpc_set_disp_num_buffers(int);
+void KMP_EXPAND_NAME(ompc_set_affinity_format)(char const *format);
+size_t KMP_EXPAND_NAME(ompc_get_affinity_format)(char *buffer, size_t size);
+void KMP_EXPAND_NAME(ompc_display_affinity)(char const *format);
+size_t KMP_EXPAND_NAME(ompc_capture_affinity)(char *buffer, size_t buf_size,
+ char const *format);
enum kmp_target_offload_kind {
tgt_disabled = 0,
diff --git a/openmp/runtime/src/kmp_csupport.cpp b/openmp/runtime/src/kmp_csupport.cpp
index 1189db1a70e5..cf63aa417b77 100644
--- a/openmp/runtime/src/kmp_csupport.cpp
+++ b/openmp/runtime/src/kmp_csupport.cpp
@@ -1997,8 +1997,7 @@ int ompc_get_team_size(int level) {
}
/* OpenMP 5.0 Affinity Format API */
-
-void ompc_set_affinity_format(char const *format) {
+void KMP_EXPAND_NAME(ompc_set_affinity_format)(char const *format) {
if (!__kmp_init_serial) {
__kmp_serial_initialize();
}
@@ -2006,7 +2005,7 @@ void ompc_set_affinity_format(char const *format) {
format, KMP_STRLEN(format) + 1);
}
-size_t ompc_get_affinity_format(char *buffer, size_t size) {
+size_t KMP_EXPAND_NAME(ompc_get_affinity_format)(char *buffer, size_t size) {
size_t format_size;
if (!__kmp_init_serial) {
__kmp_serial_initialize();
@@ -2019,7 +2018,7 @@ size_t ompc_get_affinity_format(char *buffer, size_t size) {
return format_size;
}
-void ompc_display_affinity(char const *format) {
+void KMP_EXPAND_NAME(ompc_display_affinity)(char const *format) {
int gtid;
if (!TCR_4(__kmp_init_middle)) {
__kmp_middle_initialize();
@@ -2029,8 +2028,8 @@ void ompc_display_affinity(char const *format) {
__kmp_aux_display_affinity(gtid, format);
}
-size_t ompc_capture_affinity(char *buffer, size_t buf_size,
- char const *format) {
+size_t KMP_EXPAND_NAME(ompc_capture_affinity)(char *buffer, size_t buf_size,
+ char const *format) {
int gtid;
size_t num_required;
kmp_str_buf_t capture_buf;
@@ -4401,3 +4400,35 @@ void __kmpc_error(ident_t *loc, int severity, const char *message) {
__kmp_str_free(&src_loc);
}
+
+#ifdef KMP_USE_VERSION_SYMBOLS
+// For GOMP compatibility there are two versions of each omp_* API.
+// One is the plain C symbol and one is the Fortran symbol with an appended
+// underscore. When we implement a specific ompc_* version of an omp_*
+// function, we want the plain GOMP versioned symbol to alias the ompc_* version
+// instead of the Fortran versions in kmp_ftn_entry.h
+extern "C" {
+// Have to undef these from omp.h so they aren't translated into
+// their ompc counterparts in the KMP_VERSION_OMPC_SYMBOL macros below
+#ifdef omp_set_affinity_format
+#undef omp_set_affinity_format
+#endif
+#ifdef omp_get_affinity_format
+#undef omp_get_affinity_format
+#endif
+#ifdef omp_display_affinity
+#undef omp_display_affinity
+#endif
+#ifdef omp_capture_affinity
+#undef omp_capture_affinity
+#endif
+KMP_VERSION_OMPC_SYMBOL(ompc_set_affinity_format, omp_set_affinity_format, 50,
+ "OMP_5.0");
+KMP_VERSION_OMPC_SYMBOL(ompc_get_affinity_format, omp_get_affinity_format, 50,
+ "OMP_5.0");
+KMP_VERSION_OMPC_SYMBOL(ompc_display_affinity, omp_display_affinity, 50,
+ "OMP_5.0");
+KMP_VERSION_OMPC_SYMBOL(ompc_capture_affinity, omp_capture_affinity, 50,
+ "OMP_5.0");
+} // extern "C"
+#endif
diff --git a/openmp/runtime/src/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h
index d88bf1e68aef..8f374c49fa10 100644
--- a/openmp/runtime/src/kmp_ftn_entry.h
+++ b/openmp/runtime/src/kmp_ftn_entry.h
@@ -58,6 +58,16 @@ extern "C" {
#define KMP_DEREF *
#endif
+// For API with specific C vs. Fortran interfaces (ompc_* exists in
+// kmp_csupport.cpp), only create GOMP versioned symbols of the API for the
+// APPEND Fortran entries in this file. The GOMP versioned symbols of the C API
+// will take place where the ompc_* functions are defined.
+#if KMP_FTN_ENTRIES == KMP_FTN_APPEND
+#define KMP_EXPAND_NAME_IF_APPEND(name) KMP_EXPAND_NAME(name)
+#else
+#define KMP_EXPAND_NAME_IF_APPEND(name) name
+#endif
+
void FTN_STDCALL FTN_SET_STACKSIZE(int KMP_DEREF arg) {
#ifdef KMP_STUB
__kmps_set_stacksize(KMP_DEREF arg);
@@ -445,7 +455,8 @@ class ConvertedString {
* Set the value of the affinity-format-var ICV on the current device to the
* format specified in the argument.
*/
-void FTN_STDCALL FTN_SET_AFFINITY_FORMAT(char const *format, size_t size) {
+void FTN_STDCALL KMP_EXPAND_NAME_IF_APPEND(FTN_SET_AFFINITY_FORMAT)(
+ char const *format, size_t size) {
#ifdef KMP_STUB
return;
#else
@@ -466,7 +477,8 @@ void FTN_STDCALL FTN_SET_AFFINITY_FORMAT(char const *format, size_t size) {
* affinity-format-var ICV on the current device to buffer. If the return value
* is larger than size, the affinity format specification is truncated.
*/
-size_t FTN_STDCALL FTN_GET_AFFINITY_FORMAT(char *buffer, size_t size) {
+size_t FTN_STDCALL KMP_EXPAND_NAME_IF_APPEND(FTN_GET_AFFINITY_FORMAT)(
+ char *buffer, size_t size) {
#ifdef KMP_STUB
return 0;
#else
@@ -488,7 +500,8 @@ size_t FTN_STDCALL FTN_GET_AFFINITY_FORMAT(char *buffer, size_t size) {
* specified by the format argument. If the format is NULL or a zero-length
* string, the value of the affinity-format-var ICV is used.
*/
-void FTN_STDCALL FTN_DISPLAY_AFFINITY(char const *format, size_t size) {
+void FTN_STDCALL KMP_EXPAND_NAME_IF_APPEND(FTN_DISPLAY_AFFINITY)(
+ char const *format, size_t size) {
#ifdef KMP_STUB
return;
#else
@@ -513,8 +526,8 @@ void FTN_STDCALL FTN_DISPLAY_AFFINITY(char const *format, size_t size) {
* return value is larger than size, the affinity format specification is
* truncated.
*/
-size_t FTN_STDCALL FTN_CAPTURE_AFFINITY(char *buffer, char const *format,
- size_t buf_size, size_t for_size) {
+size_t FTN_STDCALL KMP_EXPAND_NAME_IF_APPEND(FTN_CAPTURE_AFFINITY)(
+ char *buffer, char const *format, size_t buf_size, size_t for_size) {
#if defined(KMP_STUB)
return 0;
#else
@@ -1345,7 +1358,8 @@ int FTN_STDCALL FTN_GET_DEVICE_NUM(void) {
}
// Compiler will ensure that this is only called from host in sequential region
-int FTN_STDCALL FTN_PAUSE_RESOURCE(kmp_pause_status_t kind, int device_num) {
+int FTN_STDCALL KMP_EXPAND_NAME(FTN_PAUSE_RESOURCE)(kmp_pause_status_t kind,
+ int device_num) {
#ifdef KMP_STUB
return 1; // just fail
#else
@@ -1362,7 +1376,8 @@ int FTN_STDCALL FTN_PAUSE_RESOURCE(kmp_pause_status_t kind, int device_num) {
}
// Compiler will ensure that this is only called from host in sequential region
-int FTN_STDCALL FTN_PAUSE_RESOURCE_ALL(kmp_pause_status_t kind) {
+int FTN_STDCALL
+ KMP_EXPAND_NAME(FTN_PAUSE_RESOURCE_ALL)(kmp_pause_status_t kind) {
#ifdef KMP_STUB
return 1; // just fail
#else
@@ -1536,8 +1551,15 @@ KMP_VERSION_SYMBOL(FTN_GET_INITIAL_DEVICE, 45, "OMP_4.5");
// OMP_5.0 versioned symbols
// KMP_VERSION_SYMBOL(FTN_GET_DEVICE_NUM, 50, "OMP_5.0");
-// KMP_VERSION_SYMBOL(FTN_PAUSE_RESOURCE, 50, "OMP_5.0");
-// KMP_VERSION_SYMBOL(FTN_PAUSE_RESOURCE_ALL, 50, "OMP_5.0");
+KMP_VERSION_SYMBOL(FTN_PAUSE_RESOURCE, 50, "OMP_5.0");
+KMP_VERSION_SYMBOL(FTN_PAUSE_RESOURCE_ALL, 50, "OMP_5.0");
+// The C versions (KMP_FTN_PLAIN) of these symbols are in kmp_csupport.c
+#if KMP_FTN_ENTRIES == KMP_FTN_APPEND
+KMP_VERSION_SYMBOL(FTN_CAPTURE_AFFINITY, 50, "OMP_5.0");
+KMP_VERSION_SYMBOL(FTN_DISPLAY_AFFINITY, 50, "OMP_5.0");
+KMP_VERSION_SYMBOL(FTN_GET_AFFINITY_FORMAT, 50, "OMP_5.0");
+KMP_VERSION_SYMBOL(FTN_SET_AFFINITY_FORMAT, 50, "OMP_5.0");
+#endif
// KMP_VERSION_SYMBOL(FTN_GET_SUPPORTED_ACTIVE_LEVELS, 50, "OMP_5.0");
// KMP_VERSION_SYMBOL(FTN_FULFILL_EVENT, 50, "OMP_5.0");
diff --git a/openmp/runtime/src/kmp_os.h b/openmp/runtime/src/kmp_os.h
index 011c517f34b1..858acd9c1d7a 100644
--- a/openmp/runtime/src/kmp_os.h
+++ b/openmp/runtime/src/kmp_os.h
@@ -406,9 +406,24 @@ extern "C" {
api_name) "@" ver_str "\n\t"); \
__asm__(".symver " KMP_STR(__kmp_api_##api_name) "," KMP_STR( \
api_name) "@@" default_ver "\n\t")
+
+#define KMP_VERSION_OMPC_SYMBOL(apic_name, api_name, ver_num, ver_str) \
+ _KMP_VERSION_OMPC_SYMBOL(apic_name, api_name, ver_num, ver_str, "VERSION")
+#define _KMP_VERSION_OMPC_SYMBOL(apic_name, api_name, ver_num, ver_str, \
+ default_ver) \
+ __typeof__(__kmp_api_##apic_name) __kmp_api_##apic_name##_##ver_num##_alias \
+ __attribute__((alias(KMP_STR(__kmp_api_##apic_name)))); \
+ __asm__(".symver " KMP_STR(__kmp_api_##apic_name) "," KMP_STR( \
+ apic_name) "@@" default_ver "\n\t"); \
+ __asm__( \
+ ".symver " KMP_STR(__kmp_api_##apic_name##_##ver_num##_alias) "," KMP_STR( \
+ api_name) "@" ver_str "\n\t")
+
#else // KMP_USE_VERSION_SYMBOLS
#define KMP_EXPAND_NAME(api_name) api_name
#define KMP_VERSION_SYMBOL(api_name, ver_num, ver_str) /* Nothing */
+#define KMP_VERSION_OMPC_SYMBOL(apic_name, api_name, ver_num, \
+ ver_str) /* Nothing */
#endif // KMP_USE_VERSION_SYMBOLS
/* Temporary note: if performance testing of this passes, we can remove
More information about the Openmp-commits
mailing list