[Perf][Distributed] Add low-SM multimem reduce-scatter for SM100/SM103 (#55072)

Signed-off-by: Yongye Zhu <zyy1102000@gmail.com>
Signed-off-by: Summer Yang <girasoleyang@gmail.com>
Co-authored-by: Summer Yang <girasoleyang@gmail.com>
This commit is contained in:
Yongye Zhu
2026-09-25 03:27:21 +00:00
committed by GitHub
co-authored by Summer Yang
parent 8b365ff949
commit 442bd00d9f
10 changed files with 1243 additions and 31 deletions
@@ -191,6 +191,55 @@ void CustomAllreduce::mnnvl_lamport_reduce_scatter(cudaStream_t stream,
#undef MNNVL_LAMPORT_RS_LAUNCH
}
template <typename T>
void CustomAllreduce::mnnvl_multimem_reduce_scatter(
cudaStream_t stream, const T* multicast_input, T* output,
Signal* local_signal, Signal* multicast_signal, int size, int block_limit) {
#if defined(USE_ROCM)
throw std::runtime_error(
"MNNVL multimem reduce-scatter requires NVLS multicast and is not "
"supported on ROCm");
#else
if (size <= 0)
throw std::runtime_error(
"MNNVL multimem reduce-scatter requires a non-empty input");
int size_bytes = size * sizeof(T);
if (size_bytes % (kMnnvlMultimemRsVectorBytes * world_size_) != 0)
throw std::runtime_error(
"MNNVL multimem reduce-scatter requires each output shard byte size "
"to be a multiple of 16");
if (block_limit <= 0 || block_limit > kMnnvlMultimemRsBlockLimit)
throw std::runtime_error(
"MNNVL multimem reduce-scatter block limit is out of range");
int packs_per_rank = size_bytes / kMnnvlMultimemRsVectorBytes / world_size_;
int packs_per_block = kMnnvlMultimemRsThreads * kMnnvlMultimemRsUnroll;
int blocks = std::min(
block_limit, (packs_per_rank + packs_per_block - 1) / packs_per_block);
#define MNNVL_MULTIMEM_RS_CASE(ngpus) \
case ngpus: \
mnnvl_multimem_barrier_kernel<true, ngpus> \
<<<1, 1, 0, stream>>>(local_signal, multicast_signal, rank_); \
mnnvl_multimem_reduce_scatter_kernel<T, ngpus> \
<<<blocks, kMnnvlMultimemRsThreads, 0, stream>>>( \
multicast_input, output, rank_, packs_per_rank); \
mnnvl_multimem_barrier_kernel<false, ngpus> \
<<<1, 1, 0, stream>>>(local_signal, multicast_signal, rank_); \
break;
switch (world_size_) {
MNNVL_MULTIMEM_RS_CASE(2)
MNNVL_MULTIMEM_RS_CASE(4)
MNNVL_MULTIMEM_RS_CASE(8)
default:
throw std::runtime_error(
"MNNVL multimem reduce-scatter only supports num gpus in (2,4,8)");
}
#undef MNNVL_MULTIMEM_RS_CASE
#endif
}
} // namespace vllm
using fptr_t = int64_t;
@@ -360,3 +409,62 @@ void mnnvl_lamport_reduce_scatter(fptr_t _fa, torch::stable::Tensor& inp,
"bfloat16");
}
}
void mnnvl_multimem_reduce_scatter(fptr_t _fa, torch::stable::Tensor& inp,
torch::stable::Tensor& out,
fptr_t _local_buffer,
fptr_t _multicast_buffer,
int64_t stage_sz_bytes,
int64_t block_limit) {
auto fa = reinterpret_cast<vllm::CustomAllreduce*>(_fa);
const torch::stable::accelerator::DeviceGuard device_guard(
inp.get_device_index());
const cudaStream_t stream = get_current_cuda_stream(inp.get_device_index());
STD_TORCH_CHECK((inp.scalar_type()) == (out.scalar_type()));
STD_TORCH_CHECK((out.numel() * fa->world_size_) == (inp.numel()));
STD_TORCH_CHECK(inp.numel() > 0);
STD_TORCH_CHECK(_is_weak_contiguous(out));
STD_TORCH_CHECK(_is_weak_contiguous(inp));
auto input_size = inp.numel() * inp.element_size();
STD_TORCH_CHECK(input_size <= stage_sz_bytes);
auto local_buffer = reinterpret_cast<void*>(_local_buffer);
auto multicast_buffer = reinterpret_cast<void*>(_multicast_buffer);
STD_TORCH_CHECK(local_buffer != nullptr);
STD_TORCH_CHECK(multicast_buffer != nullptr);
auto* local_signal = reinterpret_cast<vllm::Signal*>(
static_cast<char*>(local_buffer) - sizeof(vllm::Signal));
auto* multicast_signal = reinterpret_cast<vllm::Signal*>(
static_cast<char*>(multicast_buffer) - sizeof(vllm::Signal));
STD_CUDA_CHECK(cudaMemcpyAsync(local_buffer, inp.const_data_ptr(), input_size,
cudaMemcpyDeviceToDevice, stream));
switch (out.scalar_type()) {
case torch::headeronly::ScalarType::Float: {
fa->mnnvl_multimem_reduce_scatter<float>(
stream, reinterpret_cast<float*>(multicast_buffer),
reinterpret_cast<float*>(out.mutable_data_ptr()), local_signal,
multicast_signal, inp.numel(), block_limit);
break;
}
case torch::headeronly::ScalarType::Half: {
fa->mnnvl_multimem_reduce_scatter<half>(
stream, reinterpret_cast<half*>(multicast_buffer),
reinterpret_cast<half*>(out.mutable_data_ptr()), local_signal,
multicast_signal, inp.numel(), block_limit);
break;
}
#if (__CUDA_ARCH__ >= 800 || !defined(__CUDA_ARCH__))
case torch::headeronly::ScalarType::BFloat16: {
fa->mnnvl_multimem_reduce_scatter<nv_bfloat16>(
stream, reinterpret_cast<nv_bfloat16*>(multicast_buffer),
reinterpret_cast<nv_bfloat16*>(out.mutable_data_ptr()), local_signal,
multicast_signal, inp.numel(), block_limit);
break;
}
#endif
default:
throw std::runtime_error(
"MNNVL multimem reduce-scatter only supports float32, float16 and "
"bfloat16");
}
}
@@ -17,6 +17,10 @@ STABLE_TORCH_LIBRARY_FRAGMENT(_C_custom_ar, custom_ag_rs) {
custom_ag_rs.def(
"mnnvl_lamport_reduce_scatter(int fa, Tensor inp, Tensor! out, int "
"local_buffer, int epoch_buffer, int stage_sz_bytes) -> ()");
custom_ag_rs.def(
"mnnvl_multimem_reduce_scatter(int fa, Tensor inp, Tensor! out, int "
"local_buffer, int multicast_buffer, int stage_sz_bytes, int "
"block_limit) -> ()");
}
STABLE_TORCH_LIBRARY_IMPL(_C_custom_ar, CUDA, custom_ag_rs) {
@@ -26,4 +30,6 @@ STABLE_TORCH_LIBRARY_IMPL(_C_custom_ar, CUDA, custom_ag_rs) {
custom_ag_rs.impl("custom_reduce_scatter", TORCH_BOX(&custom_reduce_scatter));
custom_ag_rs.impl("mnnvl_lamport_reduce_scatter",
TORCH_BOX(&mnnvl_lamport_reduce_scatter));
custom_ag_rs.impl("mnnvl_multimem_reduce_scatter",
TORCH_BOX(&mnnvl_multimem_reduce_scatter));
}
+4
View File
@@ -527,6 +527,10 @@ void mnnvl_lamport_reduce_scatter(fptr_t _fa, torch::stable::Tensor& inp,
torch::stable::Tensor& out,
fptr_t local_buffer, fptr_t epoch_buffer,
int64_t stage_sz_bytes);
void mnnvl_multimem_reduce_scatter(fptr_t _fa, torch::stable::Tensor& inp,
torch::stable::Tensor& out,
fptr_t local_buffer, fptr_t multicast_buffer,
int64_t stage_sz_bytes, int64_t block_limit);
void dispose(fptr_t _fa);
int64_t meta_size();
void register_buffer(fptr_t _fa, const std::vector<int64_t>& fake_ipc_ptrs);