[Openmp-commits] [openmp] Add openmp support to System z (PR #66081)
Ilya Leoshkevich via Openmp-commits
openmp-commits at lists.llvm.org
Wed Oct 18 16:20:39 PDT 2023
iii-i wrote:
The backchain PR was merged: https://github.com/llvm/llvm-project/pull/69405
One more fixup, which gets the number of failures down to 20:
```
diff --git a/openmp/runtime/src/kmp_affinity.cpp b/openmp/runtime/src/kmp_affinity.cpp
index 20c1c610b915..1686de7eaafd 100644
--- a/openmp/runtime/src/kmp_affinity.cpp
+++ b/openmp/runtime/src/kmp_affinity.cpp
@@ -2990,6 +2990,9 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
unsigned num_avail = 0;
*line = 0;
+#if KMP_ARCH_S390X
+ bool reading_s390x_sys_info = true;
+#endif
while (!feof(f)) {
// Create an inner scoping level, so that all the goto targets at the end of
// the loop appear in an outer scoping level. This avoids warnings about
@@ -3036,7 +3039,21 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
continue;
#endif
+#if KMP_ARCH_S390X
+ // s390x /proc/cpuinfo starts with a variable number of lines containing
+ // the overall system information. Skip them.
+ if (reading_s390x_sys_info) {
+ if (*buf == '\n')
+ reading_s390x_sys_info = false;
+ continue;
+ }
+#endif
+
+#if KMP_ARCH_S390X
+ char s1[] = "cpu number";
+#else
char s1[] = "processor";
+#endif
if (strncmp(buf, s1, sizeof(s1) - 1) == 0) {
CHECK_LINE;
char *p = strchr(buf + sizeof(s1) - 1, ':');
@@ -3062,6 +3079,23 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
threadInfo[num_avail][osIdIndex]);
__kmp_read_from_file(path, "%u", &threadInfo[num_avail][pkgIdIndex]);
+#if KMP_ARCH_S390X
+ // Disambiguate physical_package_id.
+ unsigned book_id;
+ KMP_SNPRINTF(path, sizeof(path),
+ "/sys/devices/system/cpu/cpu%u/topology/book_id",
+ threadInfo[num_avail][osIdIndex]);
+ __kmp_read_from_file(path, "%u", &book_id);
+ threadInfo[num_avail][pkgIdIndex] |= (book_id << 8);
+
+ unsigned drawer_id;
+ KMP_SNPRINTF(path, sizeof(path),
+ "/sys/devices/system/cpu/cpu%u/topology/drawer_id",
+ threadInfo[num_avail][osIdIndex]);
+ __kmp_read_from_file(path, "%u", &drawer_id);
+ threadInfo[num_avail][pkgIdIndex] |= (drawer_id << 16);
+#endif
+
KMP_SNPRINTF(path, sizeof(path),
"/sys/devices/system/cpu/cpu%u/topology/core_id",
threadInfo[num_avail][osIdIndex]);
```
It's somewhat hacky, so I'm open to suggestions on how to improve this. This diff adds /proc/cpuinfo parsing support. The problem is that openmp thinks that topology has 3 levels: threads, cores and sockets (https://www.openmp.org/spec-html/5.0/openmpse53.html). On IBM Z we have two more levels: books and drawers. This change works around this mismatch by combining socket, book and drawer into one value.
In theory this all can be skipped altogether, so that `__kmp_affinity_create_flat_map()` would create a simplistic view of the system topology based on the number of CPUs alone. The problem with that approach is that the testcases expect that it should be consistent with `/sys/devices/system/cpu`, which it isn't.
https://github.com/llvm/llvm-project/pull/66081
More information about the Openmp-commits
mailing list