Fix memory allocation bug to use the correct hipDevice#308
Open
nileshnegi wants to merge 3 commits into
Open
Conversation
Not using hipSetDevice before allocating memory can use unintended deviceIdx when executing fabric-handle based transfers
gilbertlee-amd
approved these changes
May 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses incorrect device selection during memory allocation for fabric-handle-based transfers by ensuring the appropriate HIP device (or NUMA policy) is selected before allocation occurs.
Changes:
- Set NUMA preference before CPU allocations and call
hipSetDevice()before GPU allocations insideAllocateMemory(). - Reset NUMA preference after shared (fabric-handle) CPU memory initialization/checking.
- Remove now-redundant per-branch
numa_set_preferred/hipSetDevicecalls later in the function.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Reset numa_set_preferred(-1) before ERR_FATAL early return in the non-POD_COMM_ENABLED path; without this the NUMA policy stays dirty for subsequent CPU allocations in the same process - Use memDevice.memIndex directly in the top-level hipSetDevice call instead of deviceIdx, which is NUMA-remapped for CPU types only; documents that the MEM_CPU_CLOSEST remapping does not apply to GPU - Remove now-redundant hipSetDevice inside the POD_COMM GPU memHandle branch; device was already set at the top of AllocateMemory - Guard CollectTopology GPU agent probe loop with hipSetDevice(i) so each AllocateMemory call targets the correct device Co-authored-by: Claude <claude@anthropic.com>
Comment on lines
+1498
to
+1505
| if (IsCpuMemType(memType)) { | ||
| // Set NUMA policy prior to call to hipHostMalloc | ||
| numa_set_preferred(deviceIdx); | ||
| } else if (IsGpuMemType(memType)) { | ||
| // Switch to the appropriate GPU | ||
| // IMP: if the remapping above changes, remember to modify this! | ||
| ERR_CHECK(hipSetDevice(deviceIdx)); | ||
| } |
Comment on lines
+1498
to
+1501
| if (IsCpuMemType(memType)) { | ||
| // Set NUMA policy prior to call to hipHostMalloc | ||
| numa_set_preferred(deviceIdx); | ||
| } else if (IsGpuMemType(memType)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Not using hipSetDevice before allocating memory can use an unintended deviceIdx when executing fabric-handle-based transfers
Technical Details
Test Plan
Test Result
Submission Checklist