Skip to content

Update hwloc CPU Binding Implementation#1226

Draft
bcmIntc wants to merge 3 commits intoSandia-OpenSHMEM:mainfrom
bcmIntc:bcm_hwloc_fixes_updated
Draft

Update hwloc CPU Binding Implementation#1226
bcmIntc wants to merge 3 commits intoSandia-OpenSHMEM:mainfrom
bcmIntc:bcm_hwloc_fixes_updated

Conversation

@bcmIntc
Copy link
Copy Markdown
Collaborator

@bcmIntc bcmIntc commented Apr 2, 2026

Description:

This PR replaces the previous compile-time-gated hwloc CPU binding in shmem_internal_heap_postinit() with an always-on implementation (iff hwloc enabled) that respects user affinity.

New implementation

Replaced the HWLOC_ENFORCE_SINGLE_SOCKET / HWLOC_ENFORCE_SINGLE_NUMA_NODE compile-time guards with unconditional binding logic (when built with USE_HWLOC). The new code queries the PE's current CPU affinity, attempts to find a covering NUMA node first, and falls back to the covering socket if the affinity spans multiple NUMA nodes.

Bug fixes

  • Fixed hwloc_bitmap_copy being called with hwloc_obj_t instead of hwloc_obj_t->cpuset in both the NUMA and socket paths, which silently corrupted the destination bitmap and caused hwloc_set_proc_cpubind to set an invalid binding.
  • Added return value check on hwloc_get_proc_cpubind with goto hwloc_cleanup on failure, preventing subsequent hwloc operations from running on an uninitialized bitmap.
  • Removed unused variables and #if 0 blocks.

Preserve user affinity

  • CPU binding is now a no-op when the process affinity already fits within a single NUMA node — the launcher or user's binding is preserved as-is.
  • hwloc_set_proc_cpubind() is only called when the affinity spans multiple NUMA nodes and needs narrowing to the covering socket.
  • Adds SHMEM_DISABLE_CPU_BINDING environment variable to skip all hwloc CPU binding at init time.

Test coverage

@bcmIntc bcmIntc self-assigned this Apr 2, 2026
- Fix hwloc_bitmap_copy called with hwloc_obj_t instead of hwloc_bitmap_t
  (covering_obj -> covering_obj->cpuset) in both NUMA and socket paths
- Add return value check for hwloc_get_proc_cpubind with goto hwloc_cleanup
  on failure to avoid operating on uninitialized bitmap data
- Remove unused variables numa_node_id and socket_id
- Removed #if 0's used to maintain the original code
@bcmIntc bcmIntc force-pushed the bcm_hwloc_fixes_updated branch from a1feea1 to 4fe8faa Compare April 2, 2026 15:35
- Only call hwloc_set_proc_cpubind() when the process affinity spans
  multiple NUMA nodes. If the binding already fits within a single NUMA
  node (e.g. set by the job launcher), leave it untouched to avoid
  inadvertently broadening a tight affinity mask.
- Add SHMEM_DISABLE_CPU_BINDING env var to skip all hwloc CPU binding
  during shmem_init(), giving users full control over process affinity.
- Remove leftover debug print_bitmap_hex() function and printf calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant