Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect against ancient hwloc versions #1718

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/hwloc/hwloc_base_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,54 @@ void prte_hwloc_build_map(hwloc_topology_t topo,
}
}

#if HWLOC_API_VERSION < 0x20000
#define HWLOC_BITMAP_MAGIC 0x20091007
#ifdef HWLOC_DEBUG
#define HWLOC__BITMAP_CHECK(set) do { \
assert((set)->magic == HWLOC_BITMAP_MAGIC); \
assert((set)->ulongs_count >= 1); \
assert((set)->ulongs_allocated >= (set)->ulongs_count); \
} while (0)
#else
#define HWLOC__BITMAP_CHECK(set)
#endif
#define HWLOC_SUBBITMAP_INDEX(cpu) ((cpu)/(HWLOC_BITS_PER_LONG))
#define HWLOC_SUBBITMAP_CPU_ULBIT(cpu) ((cpu)%(HWLOC_BITS_PER_LONG))
#define HWLOC_SUBBITMAP_ULBIT_TO(bit) (HWLOC_SUBBITMAP_FULL>>(HWLOC_BITS_PER_LONG-1-(bit)))

static int hwloc_bitmap_next_unset(const struct hwloc_bitmap_s * set, int prev_cpu)
{
unsigned i = HWLOC_SUBBITMAP_INDEX(prev_cpu + 1);

HWLOC__BITMAP_CHECK(set);

if (i >= set->ulongs_count) {
if (!set->infinite)
return prev_cpu + 1;
else
return -1;
}

for(; i<set->ulongs_count; i++) {
/* subsets are unsigned longs, use ffsl */
unsigned long w = ~set->ulongs[i];

/* if the prev cpu is in the same word as the possible next one,
we need to mask out previous cpus */
if (prev_cpu >= 0 && HWLOC_SUBBITMAP_INDEX((unsigned) prev_cpu) == i)
w &= ~HWLOC_SUBBITMAP_ULBIT_TO(HWLOC_SUBBITMAP_CPU_ULBIT(prev_cpu));

if (w)
return hwloc_ffsl(w) - 1 + HWLOC_BITS_PER_LONG*i;
}

if (!set->infinite)
return set->ulongs_count * HWLOC_BITS_PER_LONG;

return -1;
}
#endif

/* formatting core/hwt binding information as xml elements */
int hwloc_bitmap_list_snprintf_exp(char *__hwloc_restrict buf, size_t buflen,
const struct hwloc_bitmap_s *__hwloc_restrict set,
Expand Down