diff options
author | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2018-12-13 23:14:24 +0000 |
---|---|---|
committer | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2018-12-13 23:14:24 +0000 |
commit | 6d88e049dc51be8a9ba2e853e17fdf8c4fa6026b (patch) | |
tree | 5791e2d26aeb82d58420cb0d8c23811fe7fc5951 /openmp/runtime/src/kmp_settings.cpp | |
parent | 66c6c5abea94e3fcaef169f54b0c91e087ec15dc (diff) | |
download | bcm5719-llvm-6d88e049dc51be8a9ba2e853e17fdf8c4fa6026b.tar.gz bcm5719-llvm-6d88e049dc51be8a9ba2e853e17fdf8c4fa6026b.zip |
[OpenMP] Implement OpenMP 5.0 affinity format functionality
This patch adds the affinity format functionality introduced in OpenMP 5.0.
This patch adds: Two new environment variables:
OMP_DISPLAY_AFFINITY=TRUE|FALSE
OMP_AFFINITY_FORMAT=<string>
and Four new API:
1) omp_set_affinity_format()
2) omp_get_affinity_format()
3) omp_display_affinity()
4) omp_capture_affinity()
The affinity format functionality has two ICV's associated with it:
affinity-display-var (bool) and affinity-format-var (string).
The affinity-display-var enables/disables the functionality through the
envirable OMP_DISPLAY_AFFINITY. The affinity-format-var is a formatted
string with the special field types beginning with a '%' character
similar to printf
For example, the affinity-format-var could be:
"OMP: host:%H pid:%P OStid:%i num_threads:%N thread_num:%n affinity:{%A}"
The affinity-format-var is displayed by every thread implicitly at the beginning
of a parallel region when any thread's affinity has changed (including a brand
new thread being spawned), or explicitly using the omp_display_affinity() API.
The omp_capture_affinity() function can capture the affinity-format-var in a
char buffer. And omp_set|get_affinity_format() allow the user to set|get the
affinity-format-var explicitly at runtime. omp_capture_affinity() and
omp_get_affinity_format() both return the number of characters needed to hold
the entire string it tried to make (not including NULL character). If not
enough buffer space is available,
both these functions truncate their output.
Differential Revision: https://reviews.llvm.org/D55148
llvm-svn: 349089
Diffstat (limited to 'openmp/runtime/src/kmp_settings.cpp')
-rw-r--r-- | openmp/runtime/src/kmp_settings.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/openmp/runtime/src/kmp_settings.cpp b/openmp/runtime/src/kmp_settings.cpp index 37690a2c9e3..6d049e4b923 100644 --- a/openmp/runtime/src/kmp_settings.cpp +++ b/openmp/runtime/src/kmp_settings.cpp @@ -3252,7 +3252,29 @@ static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name, #endif /* OMP_40_ENABLED */ #if OMP_50_ENABLED - +static void __kmp_stg_parse_display_affinity(char const *name, + char const *value, void *data) { + __kmp_stg_parse_bool(name, value, &__kmp_display_affinity); +} +static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer, + char const *name, void *data) { + __kmp_stg_print_bool(buffer, name, __kmp_display_affinity); +} +static void __kmp_stg_parse_affinity_format(char const *name, char const *value, + void *data) { + size_t length = KMP_STRLEN(value); + __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value, + length); +} +static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer, + char const *name, void *data) { + if (__kmp_env_format) { + KMP_STR_BUF_PRINT_NAME_EX(name); + } else { + __kmp_str_buf_print(buffer, " %s='", name); + } + __kmp_str_buf_print(buffer, "%s'\n", __kmp_affinity_format); +} // OMP_ALLOCATOR sets default allocator static void __kmp_stg_parse_allocator(char const *name, char const *value, void *data) { @@ -4879,7 +4901,12 @@ static kmp_setting_t __kmp_stg_table[] = { #endif #endif // KMP_AFFINITY_SUPPORTED - +#if OMP_50_ENABLED + {"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity, + __kmp_stg_print_display_affinity, NULL, 0, 0}, + {"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format, + __kmp_stg_print_affinity_format, NULL, 0, 0}, +#endif {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork, __kmp_stg_print_init_at_fork, NULL, 0, 0}, {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL, @@ -5409,6 +5436,21 @@ void __kmp_env_initialize(char const *string) { } #endif /* OMP_40_ENABLED */ +#if OMP_50_ENABLED + // Set up the affinity format ICV + // Grab the default affinity format string from the message catalog + kmp_msg_t m = + __kmp_msg_format(kmp_i18n_msg_AffFormatDefault, "%P", "%i", "%n", "%A"); + KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE); + + if (__kmp_affinity_format == NULL) { + __kmp_affinity_format = + (char *)KMP_INTERNAL_MALLOC(sizeof(char) * KMP_AFFINITY_FORMAT_SIZE); + } + KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str); + __kmp_str_free(&m.str); +#endif + // Now process all of the settings. for (i = 0; i < block.count; ++i) { __kmp_stg_parse(block.vars[i].name, block.vars[i].value); |