feat: introduce memory space detection and apply for MPI Broadcast#39
Merged
Conversation
…y of the given pointer - add `MemorySpace` and template `GetMemorySpace` in `src/device.h` - add the NVIDIA implementation of `GetMemorySpace` in `nvidia/device_.h` - add NVIDIA check function `CheckCudaImpl()` and the convenience macro `INFINI_CHECK_CUDA` in `nvidia/checks.h` - apply `MemorySpace` to the MPI implementation of `Broadcast` to handle host and device cases, respectively
- add MetaX's `GetMemorySpace` specialization in `src/metax/device_.h` - add MetaX's check function and macro in `src/metax/checks.h`
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.
Summary
This PR introduces a
MemorySpaceabstraction for identifying the memory properties of a given pointer and provides a platform-specific implementation for NVIDIA and MetaX. The new mechanism enables backends to distinguish between host and device memory at runtime and select the appropriate communication path.As an initial application, the MPI implementation of
Broadcastis updated to handle host and device buffers separately, allowing correct operation on both memory types.Changes
Memory Space Abstraction
MemorySpaceinsrc/device.hto represent the memory properties of a pointer;GetMemorySpace()for platform-specific memory space detection;GetMemorySpace()for NVIDIA and MetaX in their corresponding "device_.h".Error Checking Utilities
CheckCudaImpl()and the convenience macroINFINI_CHECK_CUDAfor CUDA API error checking insrc/nvidia/checks.h;CheckMacaImpl()and the convenience macroINFINI_CHECK_MACAfor MACA API error checking insrc/metax/checks.h.MPI Broadcast Enhancement
Broadcastto query the memory space of the communication buffer;Platform and Backend Affected
Platform
Backend
Performance Impact
Performance impact is nuanced. In practice, no significant performance change is expected or observed.
For host-resident buffers, performance can improve substantially. Previously, users had to copy data to device memory before invoking
Broadcast, after which the MPI implementation would internally transfer the data back to host memory. This introduced redundant data movement and unnecessary overhead. With memory-space awareness, host buffers can now be handled directly.For device-resident buffers, the new logic introduces a small amount of additional processing to determine the memory space and select the appropriate execution path. However, this overhead is negligible compared to the communication cost and is not expected to have a measurable impact on performance.
Known Issues & Future Work
MemorySpacein future work;Test Results
Test Involved Platform
Test Involved Backend
NV + MetaX:
all_gather.log
all_reduce.log
all_to_all.log
broadcast.log
gather.log
reduce.log
reduce_scatter.log
scatter.log
send_recv.log
Checklist
Title, Branch, and Commits
feat: …,fix(nccl): …).<type>/xxx-yyyy-zzzzwhere<type>matches the PR title's Conventional Commits type and words are joined with hyphens (seeCONTRIBUTING.md§Branches).CONTRIBUTING.md§Pull Requests).master— the branch is rebased cleanly on top of the currentmaster.fixup!/squash!/wipcommits remain.Scope and Design
CONTRIBUTING.md§Code/General).printf/std::cout/print(...)left behind, orTODOwithout an owner and issue link.General Code Hygiene
CONTRIBUTING.md§Code/General).CONTRIBUTING.md§Code/General).the `AllReduce` implementation) (CONTRIBUTING.md§Code/General).CONTRIBUTING.md§Code/General).CONTRIBUTING.md§Code/General; §Python).C++ Specific (if C++ files changed)
clang-format(version 16, per.github/workflows/clang-format.yml) has been run against all modified applicable files; the diff is clean.assertwith messages that include at least__FILE__,__LINE__, and__func__(CONTRIBUTING.md§C++).CONTRIBUTING.md§C++).CONTRIBUTING.md§C++).CONTRIBUTING.md§C++).CONTRIBUTING.md§C++).CONTRIBUTING.md§C++).Python Specific (if Python files changed)
ruff checkpasses cleanly on CI (see.github/workflows/ruff.yml).ruff format --checkpasses cleanly — if not, runruff formatand commit the result.CONTRIBUTING.md§Python).pytest.skipmessages without terminal period) are honored where applicable (CONTRIBUTING.md§Python).CONTRIBUTING.md§Python).if,for, and similar control-flow statements (CONTRIBUTING.md§Python).return, except when it directly follows a control-flow statement (CONTRIBUTING.md§Python).CONTRIBUTING.md§Python).Testing
Build, CI, and Tooling
CMakeLists.txtunderif(AUTO_DETECT_DEVICES)or toif(AUTO_DETECT_BACKENDS)if applicable.clang-format.yml,ruff.yml) are green locally (or expected to be green on CI).Documentation
README.md,CONTRIBUTING.md, or inline docs updated when behavior, build flags, or developer workflow changed.!orBREAKING CHANGE:footer.Security and Safety