Feature/sm free normal kernel #347
Open
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.
1. Motivation
In MOE training and the prefilling phase of inference, the current ring-based RDMA buffer implementation for normal kernels significantly wastes SM resources. Due to the small size of the ring buffer and its frequent reuse for token transmission, SMs are often stalled, continuously polling for RDMA buffer availability instead of performing useful computation. This inefficient resource usage severely limits overall system throughput.
To address this issue, this PR implements a SM-friendly buffer design that frees SMs from buffer polling duties. This design is inspired by the large RDMA buffer approach discussed in #39. By allocating a larger RDMA buffer in HBM, tokens can be moved from SMs to the RDMA buffer in one go. While the NIC handles transmission asynchronously in the background, SMs can immediately resume computation tasks. Once data transfer completes, SMs can process the received tokens without blocking.
2. Design
2.1. Feature
The SM Free mode decouples the execution phases of the native mode: when the user first launches internode dispatch/combine, only the send phase is executed and a recv hook is returned. The user can wait for the network transmission to complete and then launch the receive phase of the internode dispatch/combine using the recv hook.
Implementation
2.2.1. Principles
2.2.2. Highlights
return_recv_hook
: Introduces a user-controllable argumentreturn_recv_hook
to switch between native mode and hook mode.get_normal_hook_rdma_size_hint()
to help users estimate the minimum required RDMA buffer size.3. Performance Evaluation
3.1. Experiment Setup
3.2. Effect
3.2.1. Estimated Performance (native mode → hook mode)
Dispatch Kernel Execution Time & Bandwidth
Kernel Execution Time
RDMA Bandwidth
Kernel Execution Time
RDMA Bandwidth
Combine Kernel Execution Time & Bandwidth
Kernel Execution Time
RDMA Bandwidth
3.3. Cost
3.3.1. HBM Cost
The main HBM cost in hook mode comes from two sides:
RDMA Buffer:
rdma_buffer_size = num_max_dispatch_tokens_per_rank × hidden_size × size_of(element) × num_nodes × 2
The HBM cost from using the large RDMA buffer increases with
num_max_dispatch_tokens_per_rank
andnum_nodes
; for our experiment setup, the HBM cost for the RDMA buffer on each rank is about 270 MB.NVLink Buffer:
nvl_buffer_size = num_max_nvl_chunked_recv_tokens × hidden_size × size_of(element) × num_nvl_peers × num_channels
HBM used for NVLink buffer increased with the number of SMs (channels) in the hook mode, but the number of tokens assigned to each channel is smaller, so the
nvl_recv_chunk
could be shrunk and the overall HBM cost for this part changed slightly.3.3.2. Bandwidth Cost
For SM Free mode, the data movement in the recv phase of dispatch and the send phase of combine are inter-GPU through NVLink. So the respective kernel execution time is also limited by the NVLink bandwidth.
4. RoadMap