mirror of
https://github.com/NVIDIA/TensorRT-LLM.git
synced 2026-01-14 06:27:45 +08:00
* Adding two-shot allreduce kernel and mnnvl multicasting buffergit gffe Signed-off-by: Shiyu Li <shili@nvidia.com> Adding comments Signed-off-by: Shiyu Li <shili@nvidia.com> Add unittest of the twoshot kernel. Signed-off-by: Shiyu Li <shili@nvidia.com> Update dispatch logic Signed-off-by: Shiyu Li <shili@nvidia.com> Use cpu barrier instead of GPU at init Signed-off-by: Shiyu Li <shili@nvidia.com> Merge dispatch logic fix Signed-off-by: Shiyu Li <shili@nvidia.com> Update the kernel to use GPU-managed buffer Signed-off-by: Shiyu Li <shili@nvidia.com> * Refine Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Clean code Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Fix compile error Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Fix issue Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Clean up Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Simplify AllReduce interface Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Rename Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Fix warning Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Tidy code Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Rename Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Fix compile error Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Refine Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Skip ut for no_fusion Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> * Refine Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> --------- Signed-off-by: Shiyu Li <shili@nvidia.com> Signed-off-by: Zongfei Jing <20381269+zongfeijing@users.noreply.github.com> Co-authored-by: Shiyu Li <shili@nvidia.com>
111 lines
3.4 KiB
C++
111 lines
3.4 KiB
C++
/*
|
|
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
#pragma once
|
|
|
|
#include "tensorrt_llm/common/mcastDevMemUtils.h"
|
|
#include "tensorrt_llm/runtime/ipcNvlsMemory.h"
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <cuda.h>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace tensorrt_llm::runtime
|
|
{
|
|
|
|
//! \brief A class that manages multicast device memory for efficient communication between GPUs.
|
|
//!
|
|
//! This class uses IPC-based allocation if mnNvlink is true, otherwise it uses fabric allocation.
|
|
//! The fabric allocation can also be used for single-node/intra-node-only communication, but the machine
|
|
//! must properly configure IMEX services. See:
|
|
//! https://docs.nvidia.com/multi-node-nvlink-systems/imex-guide/gettingstarted.html
|
|
//!
|
|
//! The class manages both unicast pointers (one per rank) and a single multicast pointer,
|
|
//! along with signal pads used for synchronization between devices.
|
|
class McastDeviceMemory
|
|
{
|
|
public:
|
|
// Disallow copy construction
|
|
McastDeviceMemory(McastDeviceMemory const&) = delete;
|
|
McastDeviceMemory& operator=(McastDeviceMemory const&) = delete;
|
|
|
|
McastDeviceMemory(size_t bufSize, uint32_t groupSize, uint32_t groupRank, int deviceIdx, bool mnNvlink);
|
|
|
|
//! Get the raw array of signal pad pointers to all ranks (including self)
|
|
void** getSignalPadPtrsDev()
|
|
{
|
|
return reinterpret_cast<void**>(mSignalPadsDev.data());
|
|
}
|
|
|
|
//! Get the raw array of unicast pointers to all ranks (including self)
|
|
void** getBufferPtrsDev()
|
|
{
|
|
return reinterpret_cast<void**>(mUcPtrs.data());
|
|
}
|
|
|
|
//! Get the raw unicast pointer to a given rank
|
|
void* getUnicastPtr(uint32_t rank)
|
|
{
|
|
auto* data_ptr = reinterpret_cast<void*>(mUcPtrs[rank]);
|
|
tensorrt_llm::common::registerMcastDevMemBuffer(data_ptr, this);
|
|
return data_ptr;
|
|
}
|
|
|
|
//! Get the raw multicast pointer
|
|
void* getMulticastPtr()
|
|
{
|
|
auto* data_ptr = reinterpret_cast<void*>(mMcPtr);
|
|
tensorrt_llm::common::registerMcastDevMemBuffer(data_ptr, this);
|
|
return data_ptr;
|
|
}
|
|
|
|
[[nodiscard]] size_t getRank() const
|
|
{
|
|
return mGroupRank;
|
|
}
|
|
|
|
[[nodiscard]] size_t getWorldSize() const
|
|
{
|
|
return mGroupSize;
|
|
}
|
|
|
|
~McastDeviceMemory();
|
|
|
|
private:
|
|
bool mIsMNNvlink;
|
|
int mDeviceIdx;
|
|
uint32_t mGroupSize, mGroupRank;
|
|
size_t mBufSize;
|
|
size_t mSignalPadOffset;
|
|
size_t mAllocationSize;
|
|
|
|
CUdeviceptr mMcPtr;
|
|
std::vector<CUdeviceptr> mUcPtrs;
|
|
std::vector<CUdeviceptr> mSignalPadsDev;
|
|
CUmemGenericAllocationHandle mMcHandle;
|
|
std::vector<CUmemGenericAllocationHandle> mUcHandles;
|
|
|
|
// For intra-node mcast
|
|
tensorrt_llm::runtime::IpcNvlsHandle* mNvlsHandle;
|
|
|
|
void allocMnMcastMem(size_t bufSize);
|
|
void allocNvlsMcastMem(size_t bufSize);
|
|
};
|
|
|
|
constexpr size_t kSIGNAL_PAD_SIZE = 2048;
|
|
|
|
} // namespace tensorrt_llm::runtime
|