Skip to content

Commit f1e4bba

Browse files
committed
p2p: register whole record for IPC to fix multi-segment reuse
Signed-off-by: Yasser Shalabi <[email protected]> Mirrored-from: 2fb9caa8b273772c7e61860cae6d05ec8ea0e0fc
1 parent a417486 commit f1e4bba

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎src/transport/p2p.cc‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,14 +1076,19 @@ static ncclResult_t ipcRegisterBuffer(ncclComm* comm, const void* userbuff, size
10761076
int numSegments = 1;
10771077
bool multiSegment = false;
10781078

1079+
// Register the whole record, not just the segment under userbuff, so a
1080+
// later reuse of this import for a different segment stays in bounds.
1081+
void* regBeg = (void*)regRecord->begAddr;
1082+
size_t regSize = (size_t)(regRecord->endAddr - regRecord->begAddr);
1083+
10791084
if (baseAddr == NULL) {
1080-
CUCHECKGOTO(cuMemGetAddressRange((CUdeviceptr*)&baseAddr, &baseSize, (CUdeviceptr)userbuff), ret, fail);
1085+
CUCHECKGOTO(cuMemGetAddressRange((CUdeviceptr*)&baseAddr, &baseSize, (CUdeviceptr)regBeg), ret, fail);
10811086
CUCHECKGOTO(cuPointerGetAttribute((void*)&legacyIpcCap, CU_POINTER_ATTRIBUTE_IS_LEGACY_CUDA_IPC_CAPABLE,
10821087
(CUdeviceptr)baseAddr),
10831088
ret, fail);
10841089
}
10851090

1086-
if ((uint64_t)baseAddr + baseSize < (uint64_t)userbuff + buffSize) multiSegment = true;
1091+
if ((uint64_t)baseAddr + baseSize < (uint64_t)regBeg + regSize) multiSegment = true;
10871092
if (multiSegment && (!ncclCuMemEnable() || !ncclParamMultiSegmentRegister())) goto exit;
10881093

10891094
if (!multiSegment) {
@@ -1100,7 +1105,7 @@ static ncclResult_t ipcRegisterBuffer(ncclComm* comm, const void* userbuff, size
11001105
// get the CUDA legacy mem handle, or through cuMem*.
11011106
if (ncclCuMemEnable()) {
11021107
if (multiSegment) {
1103-
NCCLCHECKGOTO(ipcHandleMultiSegmentRegistration((CUdeviceptr)userbuff, buffSize, comm, proxyConn,
1108+
NCCLCHECKGOTO(ipcHandleMultiSegmentRegistration((CUdeviceptr)regBeg, regSize, comm, proxyConn,
11041109
&totalMappedSize, &numSegments, &ipcInfo),
11051110
ret, fail);
11061111
} else {

0 commit comments

Comments
 (0)