From 05e2bc25e85a904e45663584167d575580834396 Mon Sep 17 00:00:00 2001 From: Jonathan Peyton Date: Thu, 6 Jul 2023 12:31:47 -0500 Subject: [PATCH] [OpenMP] Ensure socket layer is not first in CPUID topology detection * Return 0 length topology if socket layer is detected first * Fix DEBUG ASSERT --- openmp/runtime/src/kmp_affinity.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openmp/runtime/src/kmp_affinity.cpp b/openmp/runtime/src/kmp_affinity.cpp index 31e9a19c47fcd..eead5bdfb9e4f 100644 --- a/openmp/runtime/src/kmp_affinity.cpp +++ b/openmp/runtime/src/kmp_affinity.cpp @@ -2509,6 +2509,10 @@ __kmp_x2apicid_get_levels(int leaf, level++; } while (level_type != INTEL_LEVEL_TYPE_INVALID); + // Ensure the INTEL_LEVEL_TYPE_INVALID (Socket) layer isn't first + if (levels_index == 0 || levels[0].level_type == INTEL_LEVEL_TYPE_INVALID) + return 0; + // Set the masks to & with apicid for (unsigned i = 0; i < levels_index; ++i) { if (levels[i].level_type != INTEL_LEVEL_TYPE_INVALID) { @@ -2517,7 +2521,7 @@ __kmp_x2apicid_get_levels(int leaf, for (unsigned j = 0; j < i; ++j) levels[i].mask ^= levels[j].mask; } else { - KMP_DEBUG_ASSERT(levels_index > 0); + KMP_DEBUG_ASSERT(i > 0); levels[i].mask = (-1) << levels[i - 1].mask_width; levels[i].cache_mask = 0; }