@@ -1477,7 +1477,7 @@ static int detectPtrTypeAndMaybeCacheIpc(void *ptr, char *ipcHandleBuf,
14771477 deviceAdaptor->ipcMemHandleFree (handle);
14781478 return FLAGCX_PTR_CUDA ;
14791479 }
1480-
1480+ if (deviceAdaptor-> getLastError ) deviceAdaptor-> getLastError ();
14811481 deviceAdaptor->ipcMemHandleFree (handle);
14821482 return FLAGCX_PTR_HOST ;
14831483}
@@ -2632,11 +2632,22 @@ bool flagcxP2pEngineConnIsLocal(FlagcxP2pConn *conn) {
26322632 return conn != NULL && conn->isLocal ;
26332633}
26342634
2635- int flagcxP2pEngineReg (FlagcxP2pEngine *engine, uintptr_t data, size_t size,
2636- FlagcxP2pMr &mrId) {
2635+ int flagcxP2pEngineRegEx (FlagcxP2pEngine *engine, uintptr_t data, size_t size,
2636+ int hintType, FlagcxP2pMr &mrId) {
26372637 if (engine == NULL || data == 0 )
26382638 return -1 ;
26392639
2640+ auto resolvePtrType = [&](char *ipcHandleBuf,
2641+ uint32_t *ipcHandleSize) -> int {
2642+ if (hintType == FLAGCX_PTR_HOST || hintType == FLAGCX_PTR_CUDA ) {
2643+ if (ipcHandleSize)
2644+ *ipcHandleSize = 0 ;
2645+ return hintType;
2646+ }
2647+ return detectPtrTypeAndMaybeCacheIpc (reinterpret_cast <void *>(data),
2648+ ipcHandleBuf, ipcHandleSize);
2649+ };
2650+
26402651 if (!flagcxParamMrSortedLookup ()) {
26412652 /* Legacy: mutex + hash maps */
26422653 std::lock_guard<std::mutex> lock (gMemMutex );
@@ -2666,8 +2677,7 @@ int flagcxP2pEngineReg(FlagcxP2pEngine *engine, uintptr_t data, size_t size,
26662677 entry.ibDevN = ibDevN;
26672678
26682679 setEngineDevice (engine);
2669- entry.ptrType = detectPtrTypeAndMaybeCacheIpc (
2670- reinterpret_cast <void *>(data), entry.ipcHandle , &entry.ipcHandleSize );
2680+ entry.ptrType = resolvePtrType (entry.ipcHandle , &entry.ipcHandleSize );
26712681 entry.hasIpc = entry.ptrType == FLAGCX_PTR_CUDA && entry.ipcHandleSize > 0 ;
26722682
26732683 if (engine->adaptor ->regMr (&devCtx, reinterpret_cast <void *>(data), size,
@@ -2721,8 +2731,7 @@ int flagcxP2pEngineReg(FlagcxP2pEngine *engine, uintptr_t data, size_t size,
27212731 memset (ipcHandle, 0 , sizeof (ipcHandle));
27222732
27232733 setEngineDevice (engine);
2724- int ptrType = detectPtrTypeAndMaybeCacheIpc (reinterpret_cast <void *>(data),
2725- ipcHandle, &ipcHandleSize);
2734+ int ptrType = resolvePtrType (ipcHandle, &ipcHandleSize);
27262735 bool hasIpc = ptrType == FLAGCX_PTR_CUDA && ipcHandleSize > 0 ;
27272736
27282737 /* Register with adaptor */
@@ -2766,6 +2775,11 @@ int flagcxP2pEngineReg(FlagcxP2pEngine *engine, uintptr_t data, size_t size,
27662775 return 0 ;
27672776}
27682777
2778+ int flagcxP2pEngineReg (FlagcxP2pEngine *engine, uintptr_t data, size_t size,
2779+ FlagcxP2pMr &mrId) {
2780+ return flagcxP2pEngineRegEx (engine, data, size, 0 , mrId);
2781+ }
2782+
27692783void flagcxP2pEngineMrDestroy (FlagcxP2pEngine *engine, FlagcxP2pMr mr) {
27702784 if (engine == NULL )
27712785 return ;
@@ -3480,6 +3494,21 @@ int flagcxP2pRpcRegister(void *engine, uint64_t addr, uint64_t size,
34803494 return 0 ;
34813495}
34823496
3497+ int flagcxP2pRpcRegisterHost (void *engine, uint64_t addr, uint64_t size,
3498+ uint64_t *mrIdOut) {
3499+ if (mrIdOut == NULL )
3500+ return -1 ;
3501+ FlagcxP2pMr mrId = 0 ;
3502+ const int rc = flagcxP2pEngineRegEx (
3503+ reinterpret_cast <FlagcxP2pEngine *>(engine),
3504+ static_cast <uintptr_t >(addr), static_cast <size_t >(size),
3505+ FLAGCX_PTR_HOST , mrId);
3506+ if (rc != 0 )
3507+ return rc;
3508+ *mrIdOut = mrId;
3509+ return 0 ;
3510+ }
3511+
34833512void *flagcxP2pRpcGetConn (void *engine, const char *session) {
34843513 return reinterpret_cast <void *>(flagcxP2pEngineGetConn (
34853514 reinterpret_cast <FlagcxP2pEngine *>(engine), session));
0 commit comments