Merge branch 'main' into copilot/remove-gtest-use-custom-framework

This commit is contained in:
Changho Hwang
2026-03-21 02:37:22 -07:00
committed by GitHub
2 changed files with 16 additions and 3 deletions

View File

@@ -140,6 +140,11 @@ void GpuIpcMemHandle::deleter(GpuIpcMemHandle* handle) {
UnixSocketServer::instance().unregisterFd(handle->posixFd.fd);
::close(handle->posixFd.fd);
}
if (handle->typeFlags & GpuIpcMemHandle::Type::Fabric) {
if (handle->fabric.allocHandle != 0) {
cuMemRelease(handle->fabric.allocHandle);
}
}
delete handle;
}
}
@@ -148,6 +153,7 @@ UniqueGpuIpcMemHandle GpuIpcMemHandle::create(const CUdeviceptr ptr) {
auto handle = UniqueGpuIpcMemHandle(new GpuIpcMemHandle(), &GpuIpcMemHandle::deleter);
handle->typeFlags = GpuIpcMemHandle::Type::None;
handle->posixFd.fd = -1;
handle->fabric.allocHandle = {};
CUdeviceptr basePtr;
size_t sz;
@@ -189,6 +195,7 @@ UniqueGpuIpcMemHandle GpuIpcMemHandle::create(const CUdeviceptr ptr) {
// FABRIC handle
if (cuMemExportToShareableHandle(&(handle->fabric.handle), allocHandle, CU_MEM_HANDLE_TYPE_FABRIC, 0) ==
CUDA_SUCCESS) {
MSCCLPP_CUTHROW(cuMemRetainAllocationHandle(&(handle->fabric.allocHandle), (void*)basePtr));
handle->typeFlags |= GpuIpcMemHandle::Type::Fabric;
}
@@ -232,6 +239,7 @@ UniqueGpuIpcMemHandle GpuIpcMemHandle::createMulticast([[maybe_unused]] size_t b
handle->offsetFromBase = 0;
handle->typeFlags = GpuIpcMemHandle::Type::None;
handle->posixFd.fd = -1;
handle->fabric.allocHandle = {};
// POSIX FD handle
int fileDesc;
@@ -246,6 +254,7 @@ UniqueGpuIpcMemHandle GpuIpcMemHandle::createMulticast([[maybe_unused]] size_t b
if (isFabricAvailable && (cuMemExportToShareableHandle(&(handle->fabric.handle), allocHandle,
CU_MEM_HANDLE_TYPE_FABRIC, 0) == CUDA_SUCCESS)) {
handle->typeFlags |= GpuIpcMemHandle::Type::Fabric;
handle->fabric.allocHandle = allocHandle;
}
if (handle->typeFlags == GpuIpcMemHandle::Type::None) {
@@ -253,9 +262,10 @@ UniqueGpuIpcMemHandle GpuIpcMemHandle::createMulticast([[maybe_unused]] size_t b
THROW(GPU, Error, ErrorCode::SystemError, "createMulticast failed: neither POSIX FD nor FABRIC handle was created");
}
// Release the local allocation handle. The exported POSIX FD / Fabric handle keeps the
// multicast object alive. Each importer will get its own handle via cuMemImportFromShareableHandle.
MSCCLPP_CUTHROW(cuMemRelease(allocHandle));
// Only release allocHandle if it is not stored in fabric.allocHandle.
if (!(handle->typeFlags & GpuIpcMemHandle::Type::Fabric)) {
MSCCLPP_CUTHROW(cuMemRelease(allocHandle));
}
return handle;
#else // !(CUDA_NVLS_API_AVAILABLE)
THROW(GPU, Error, ErrorCode::InvalidUsage,
@@ -275,6 +285,8 @@ GpuIpcMem::GpuIpcMem(const GpuIpcMemHandle& handle)
if ((type_ == GpuIpcMemHandle::Type::None) && (handle_.typeFlags & GpuIpcMemHandle::Type::Fabric)) {
if (cuMemImportFromShareableHandle(&allocHandle_, (void*)handle_.fabric.handle, CU_MEM_HANDLE_TYPE_FABRIC) ==
CUDA_SUCCESS) {
// Ignore allocHandle in the handle struct since it is process-local and not transferable across processes.
handle_.fabric.allocHandle = {};
type_ = GpuIpcMemHandle::Type::Fabric;
}
}

View File

@@ -44,6 +44,7 @@ struct GpuIpcMemHandle {
struct {
char handle[64];
CUmemGenericAllocationHandle allocHandle;
} fabric;
static void deleter(GpuIpcMemHandle* handle);