[Openmp-commits] [openmp] a60bc55 - [OpenMP] libomp: cleanup parsing of OMP_ALLOCATOR env variable.
via Openmp-commits
openmp-commits at lists.llvm.org
Tue Jan 19 05:23:55 PST 2021
Author: AndreyChurbanov
Date: 2021-01-19T16:21:22+03:00
New Revision: a60bc55c693609e9417419b72754b9984f52acbe
URL: https://github.com/llvm/llvm-project/commit/a60bc55c693609e9417419b72754b9984f52acbe
DIFF: https://github.com/llvm/llvm-project/commit/a60bc55c693609e9417419b72754b9984f52acbe.diff
LOG: [OpenMP] libomp: cleanup parsing of OMP_ALLOCATOR env variable.
Differential Revision: https://reviews.llvm.org/D94932
Added:
openmp/runtime/test/env/omp_alloc_env_invalid.c
Modified:
openmp/runtime/src/kmp_settings.cpp
Removed:
################################################################################
diff --git a/openmp/runtime/src/kmp_settings.cpp b/openmp/runtime/src/kmp_settings.cpp
index bfcd1faecdc0..e3270c79a702 100644
--- a/openmp/runtime/src/kmp_settings.cpp
+++ b/openmp/runtime/src/kmp_settings.cpp
@@ -3272,6 +3272,7 @@ static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer,
}
__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) {
@@ -3289,104 +3290,65 @@ static void __kmp_stg_parse_allocator(char const *name, char const *value,
*/
const char *buf = value;
const char *next;
- int num;
SKIP_WS(buf);
- if ((*buf > '0') && (*buf < '9')) {
- next = buf;
- SKIP_DIGITS(next);
- num = __kmp_str_to_int(buf, *next);
- KMP_ASSERT(num > 0);
- switch (num) {
- case 4:
+ next = buf;
+ // check HBW first as the only non-default supported
+ if (__kmp_match_str("omp_high_bw_mem_alloc", buf, &next) ||
+ __kmp_match_str("4", buf, &next)) {
+ SKIP_WS(next);
+ if (*next == '\0') {
if (__kmp_memkind_available) {
__kmp_def_allocator = omp_high_bw_mem_alloc;
+ return;
} else {
- __kmp_msg(kmp_ms_warning,
- KMP_MSG(OmpNoAllocator, "omp_high_bw_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
+ KMP_WARNING(OmpNoAllocator, "omp_high_bw_mem_alloc");
}
- break;
- case 1:
- __kmp_def_allocator = omp_default_mem_alloc;
- break;
- case 2:
- __kmp_msg(kmp_ms_warning,
- KMP_MSG(OmpNoAllocator, "omp_large_cap_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- break;
- case 3:
- __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_const_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- break;
- case 5:
- __kmp_msg(kmp_ms_warning,
- KMP_MSG(OmpNoAllocator, "omp_low_lat_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- break;
- case 6:
- __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_cgroup_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- break;
- case 7:
- __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_pteam_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- break;
- case 8:
- __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_thread_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- break;
}
- return;
- }
- next = buf;
- if (__kmp_match_str("omp_high_bw_mem_alloc", buf, &next)) {
- if (__kmp_memkind_available) {
- __kmp_def_allocator = omp_high_bw_mem_alloc;
- } else {
- __kmp_msg(kmp_ms_warning,
- KMP_MSG(OmpNoAllocator, "omp_high_bw_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
+ } else if (__kmp_match_str("omp_default_mem_alloc", buf, &next) ||
+ __kmp_match_str("1", buf, &next)) {
+ // default requested
+ SKIP_WS(next);
+ } else if (__kmp_match_str("omp_large_cap_mem_alloc", buf, &next) ||
+ __kmp_match_str("2", buf, &next)) {
+ SKIP_WS(next);
+ if (*next == '\0') {
+ KMP_WARNING(OmpNoAllocator, "omp_large_cap_mem_alloc");
+ }
+ } else if (__kmp_match_str("omp_const_mem_alloc", buf, &next) ||
+ __kmp_match_str("3", buf, &next)) {
+ SKIP_WS(next);
+ if (*next == '\0') {
+ KMP_WARNING(OmpNoAllocator, "omp_const_mem_alloc");
+ }
+ } else if (__kmp_match_str("omp_low_lat_mem_alloc", buf, &next) ||
+ __kmp_match_str("5", buf, &next)) {
+ SKIP_WS(next);
+ if (*next == '\0') {
+ KMP_WARNING(OmpNoAllocator, "omp_low_lat_mem_alloc");
+ }
+ } else if (__kmp_match_str("omp_cgroup_mem_alloc", buf, &next) ||
+ __kmp_match_str("6", buf, &next)) {
+ SKIP_WS(next);
+ if (*next == '\0') {
+ KMP_WARNING(OmpNoAllocator, "omp_cgroup_mem_alloc");
+ }
+ } else if (__kmp_match_str("omp_pteam_mem_alloc", buf, &next) ||
+ __kmp_match_str("7", buf, &next)) {
+ SKIP_WS(next);
+ if (*next == '\0') {
+ KMP_WARNING(OmpNoAllocator, "omp_pteam_mem_alloc");
+ }
+ } else if (__kmp_match_str("omp_thread_mem_alloc", buf, &next) ||
+ __kmp_match_str("8", buf, &next)) {
+ SKIP_WS(next);
+ if (*next == '\0') {
+ KMP_WARNING(OmpNoAllocator, "omp_thread_mem_alloc");
}
- } else if (__kmp_match_str("omp_default_mem_alloc", buf, &next)) {
- __kmp_def_allocator = omp_default_mem_alloc;
- } else if (__kmp_match_str("omp_large_cap_mem_alloc", buf, &next)) {
- __kmp_msg(kmp_ms_warning,
- KMP_MSG(OmpNoAllocator, "omp_large_cap_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- } else if (__kmp_match_str("omp_const_mem_alloc", buf, &next)) {
- __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_const_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- } else if (__kmp_match_str("omp_low_lat_mem_alloc", buf, &next)) {
- __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_low_lat_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- } else if (__kmp_match_str("omp_cgroup_mem_alloc", buf, &next)) {
- __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_cgroup_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- } else if (__kmp_match_str("omp_pteam_mem_alloc", buf, &next)) {
- __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_pteam_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
- } else if (__kmp_match_str("omp_thread_mem_alloc", buf, &next)) {
- __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_thread_mem_alloc"),
- __kmp_msg_null);
- __kmp_def_allocator = omp_default_mem_alloc;
}
- buf = next;
- SKIP_WS(buf);
- if (*buf != '\0') {
- KMP_WARNING(ParseExtraCharsWarn, name, buf);
+ __kmp_def_allocator = omp_default_mem_alloc;
+ if (next == buf || *next != '\0') {
+ // either no match or extra symbols present after the matched token
+ KMP_WARNING(StgInvalidValue, name, value);
}
}
diff --git a/openmp/runtime/test/env/omp_alloc_env_invalid.c b/openmp/runtime/test/env/omp_alloc_env_invalid.c
new file mode 100644
index 000000000000..6b2e9d8213df
--- /dev/null
+++ b/openmp/runtime/test/env/omp_alloc_env_invalid.c
@@ -0,0 +1,16 @@
+// RUN: %libomp-compile
+// RUN: env OMP_ALLOCATOR=111 %libomp-run 2>&1 | FileCheck %s
+// RUN: env OMP_ALLOCATOR=omp_default_mem_alloc_xyz %libomp-run 2>&1 | FileCheck %s
+// UNSUPPORTED: gcc
+
+// Both invocations of the test should produce (
diff erent) warnings:
+// OMP: Warning #42: OMP_ALLOCATOR: "111" is an invalid value; ignored.
+// OMP: Warning #189: Allocator omp_const_mem_alloc is not available, will use default allocator.
+#include <stdio.h>
+#include <omp.h>
+int main() {
+ volatile int n = omp_get_max_threads(); // causes library initialization
+ return 0;
+}
+
+// CHECK: {{^OMP: Warning #[0-9]+}}: {{.*$}}
More information about the Openmp-commits
mailing list