Skip to content

Commit 5cd1ad9

Browse files
authored
Implement unified network adaptor system and refactor network adaptor (#239)
1 parent 3a2b541 commit 5cd1ad9

12 files changed

Lines changed: 225 additions & 708 deletions

File tree

flagcx/adaptor/adaptor.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
************************************************************************/
55

66
#include "adaptor.h"
7+
#include "core.h"
8+
#include "net.h"
9+
#include <string.h>
710

811
#ifdef USE_NVIDIA_ADAPTOR
912
#ifdef USE_BOOTSTRAP_ADAPTOR
@@ -104,3 +107,19 @@ struct flagcxCCLAdaptor *cclAdaptors[NCCLADAPTORS] = {&mpiAdaptor,
104107
#endif
105108
struct flagcxDeviceAdaptor *deviceAdaptor = &ducudaAdaptor;
106109
#endif
110+
111+
// External adaptor declarations
112+
extern struct flagcxNetAdaptor flagcxNetSocket;
113+
extern struct flagcxNetAdaptor flagcxNetIb;
114+
115+
// Unified network adaptor entry point
116+
struct flagcxNetAdaptor *getUnifiedNetAdaptor(int netType) {
117+
switch (netType) {
118+
case IBRC:
119+
return &flagcxNetIb;
120+
case SOCKET:
121+
return &flagcxNetSocket;
122+
default:
123+
return NULL;
124+
}
125+
}

flagcx/adaptor/include/adaptor.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ extern struct flagcxDeviceAdaptor kunlunAdaptor;
4343
extern struct flagcxDeviceAdaptor ducudaAdaptor;
4444
extern struct flagcxDeviceAdaptor *deviceAdaptor;
4545

46+
extern struct flagcxNetAdaptor *netAdaptor;
47+
48+
// Network type enumeration
49+
enum NetType {
50+
IBRC = 1, // InfiniBand RC
51+
SOCKET = 2 // Socket
52+
};
53+
54+
// Unified network adaptor function declarations
55+
struct flagcxNetAdaptor *getUnifiedNetAdaptor(int netType);
56+
4657
inline bool flagcxCCLAdaptorNeedSendrecv(size_t value) { return value != 0; }
4758

4859
struct flagcxCCLAdaptor {
@@ -218,7 +229,8 @@ struct flagcxNetAdaptor {
218229
flagcxResult_t (*accept)(
219230
void *listenComm,
220231
void **recvComm); // TODO: add flagcxNetDeviceHandle_t** recvDevComm
221-
flagcxResult_t (*close)(void *comm);
232+
flagcxResult_t (*closeSend)(void *sendComm);
233+
flagcxResult_t (*closeRecv)(void *recvComm);
222234
flagcxResult_t (*closeListen)(void *listenComm);
223235

224236
// Memory region functions
@@ -246,6 +258,9 @@ struct flagcxNetAdaptor {
246258
flagcxResult_t (*signal)(void *sendComm, void *data, size_t size, int tag,
247259
void *mhandle, void *phandle, void **request);
248260

261+
// Device name lookup
262+
flagcxResult_t (*getDevFromName)(char *name, int *dev);
263+
249264
// TODO: add switch functions such as
250265
// iallreduce, iallgather, ireducescatter,
251266
// ireduce, ibroadcast, iflush, etc.
Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "param.h"
1313
#include "socket.h"
1414
#include "utils.h"
15-
1615
#include <assert.h>
1716
#include <poll.h>
1817
#include <pthread.h>
@@ -432,7 +431,7 @@ int flagcxIbFindMatchingDev(int dev) {
432431
return flagcxNMergedIbDevs;
433432
}
434433

435-
flagcxResult_t flagcxIbInit(flagcxDebugLogger_t logFunction) {
434+
flagcxResult_t flagcxIbInit() {
436435
flagcxResult_t ret;
437436
if (flagcxParamIbDisable())
438437
return flagcxInternalError;
@@ -802,7 +801,7 @@ struct flagcxIbListenComm {
802801

803802
struct flagcxIbSendFifo {
804803
uint64_t addr;
805-
int size;
804+
size_t size;
806805
uint32_t rkeys[FLAGCX_IB_MAX_DEVS_PER_NIC];
807806
uint32_t nreqs;
808807
uint32_t tag;
@@ -1056,8 +1055,7 @@ flagcxResult_t flagcxIbListen(int dev, void *opaqueHandle, void **listenComm) {
10561055
return flagcxSuccess;
10571056
}
10581057

1059-
flagcxResult_t flagcxIbConnect(int dev, void *opaqueHandle, void **sendComm,
1060-
flagcxNetDeviceHandle_t ** /*sendDevComm*/) {
1058+
flagcxResult_t flagcxIbConnect(int dev, void *opaqueHandle, void **sendComm) {
10611059
struct flagcxIbHandle *handle = (struct flagcxIbHandle *)opaqueHandle;
10621060
struct flagcxIbCommStage *stage = &handle->stage;
10631061
struct flagcxIbSendComm *comm = (struct flagcxIbSendComm *)stage->comm;
@@ -1320,8 +1318,7 @@ flagcxResult_t flagcxIbConnect(int dev, void *opaqueHandle, void **sendComm,
13201318

13211319
FLAGCX_PARAM(IbGdrFlushDisable, "GDR_FLUSH_DISABLE", 0);
13221320

1323-
flagcxResult_t flagcxIbAccept(void *listenComm, void **recvComm,
1324-
flagcxNetDeviceHandle_t ** /*recvDevComm*/) {
1321+
flagcxResult_t flagcxIbAccept(void *listenComm, void **recvComm) {
13251322
struct flagcxIbListenComm *lComm = (struct flagcxIbListenComm *)listenComm;
13261323
struct flagcxIbCommStage *stage = &lComm->stage;
13271324
struct flagcxIbRecvComm *rComm = (struct flagcxIbRecvComm *)stage->comm;
@@ -1878,8 +1875,8 @@ flagcxResult_t flagcxIbMultiSend(struct flagcxIbSendComm *comm, int slot) {
18781875
return flagcxSuccess;
18791876
}
18801877

1881-
flagcxResult_t flagcxIbIsend(void *sendComm, void *data, int size, int tag,
1882-
void *mhandle, void **request) {
1878+
flagcxResult_t flagcxIbIsend(void *sendComm, void *data, size_t size, int tag,
1879+
void *mhandle, void *phandle, void **request) {
18831880
struct flagcxIbSendComm *comm = (struct flagcxIbSendComm *)sendComm;
18841881
if (comm->base.ready == 0) {
18851882
WARN("NET/IB: flagcxIbIsend() called when comm->base.ready == 0");
@@ -1986,7 +1983,7 @@ flagcxResult_t flagcxIbIsend(void *sendComm, void *data, int size, int tag,
19861983
}
19871984

19881985
flagcxResult_t flagcxIbPostFifo(struct flagcxIbRecvComm *comm, int n,
1989-
void **data, int *sizes, int *tags,
1986+
void **data, size_t *sizes, int *tags,
19901987
void **mhandles, struct flagcxIbRequest *req) {
19911988
struct ibv_send_wr wr;
19921989
memset(&wr, 0, sizeof(wr));
@@ -2011,9 +2008,8 @@ flagcxResult_t flagcxIbPostFifo(struct flagcxIbRecvComm *comm, int n,
20112008
// Send all applicable rkeys
20122009
for (int j = 0; j < comm->base.ndevs; j++)
20132010
localElem[i].rkeys[j] = mhandleWrapper->mrs[j]->rkey;
2014-
20152011
localElem[i].nreqs = n;
2016-
localElem[i].size = sizes[i]; // Sanity/Debugging
2012+
localElem[i].size = sizes[i];
20172013
localElem[i].tag = tags[i];
20182014
localElem[i].idx = comm->remFifo.fifoTail + 1;
20192015
}
@@ -2073,8 +2069,9 @@ flagcxResult_t flagcxIbPostFifo(struct flagcxIbRecvComm *comm, int n,
20732069
return flagcxSuccess;
20742070
}
20752071

2076-
flagcxResult_t flagcxIbIrecv(void *recvComm, int n, void **data, int *sizes,
2077-
int *tags, void **mhandles, void **request) {
2072+
flagcxResult_t flagcxIbIrecv(void *recvComm, int n, void **data, size_t *sizes,
2073+
int *tags, void **mhandles, void **phandles,
2074+
void **request) {
20782075
struct flagcxIbRecvComm *comm = (struct flagcxIbRecvComm *)recvComm;
20792076
if (comm->base.ready == 0) {
20802077
WARN("NET/IB: flagcxIbIrecv() called when comm->base.ready == 0");
@@ -2351,51 +2348,59 @@ flagcxResult_t flagcxIbGetDevFromName(char *name, int *dev) {
23512348
return flagcxSystemError;
23522349
}
23532350

2354-
flagcxResult_t flagcxIbGetProperties(int dev, flagcxNetProperties_t *props) {
2351+
flagcxResult_t flagcxIbGetProperties(int dev, void *props) {
23552352
struct flagcxIbMergedDev *mergedDev = flagcxIbMergedDevs + dev;
2356-
props->name = mergedDev->devName;
2357-
props->speed = mergedDev->speed;
2353+
flagcxNetProperties_t *properties = (flagcxNetProperties_t *)props;
2354+
2355+
properties->name = mergedDev->devName;
2356+
properties->speed = mergedDev->speed;
23582357

23592358
// Take the rest of the properties from an arbitrary sub-device (should be the
23602359
// same)
23612360
struct flagcxIbDev *ibDev = flagcxIbDevs + mergedDev->devs[0];
2362-
props->pciPath = ibDev->pciPath;
2363-
props->guid = ibDev->guid;
2364-
props->ptrSupport = FLAGCX_PTR_HOST;
2361+
properties->pciPath = ibDev->pciPath;
2362+
properties->guid = ibDev->guid;
2363+
properties->ptrSupport = FLAGCX_PTR_HOST;
23652364

23662365
if (flagcxIbGdrSupport() == flagcxSuccess) {
2367-
props->ptrSupport |= FLAGCX_PTR_CUDA; // GDR support via nv_peermem
2366+
properties->ptrSupport |= FLAGCX_PTR_CUDA; // GDR support via nv_peermem
23682367
}
2369-
props->regIsGlobal = 1;
2368+
properties->regIsGlobal = 1;
23702369
if (flagcxIbDmaBufSupport(dev) == flagcxSuccess) {
2371-
props->ptrSupport |= FLAGCX_PTR_DMABUF;
2372-
}
2373-
props->latency = 0; // Not set
2374-
props->port = ibDev->portNum + ibDev->realPort;
2375-
props->maxComms = ibDev->maxQp;
2376-
props->maxRecvs = FLAGCX_NET_IB_MAX_RECVS;
2377-
props->netDeviceType = FLAGCX_NET_DEVICE_HOST;
2378-
props->netDeviceVersion = FLAGCX_NET_DEVICE_INVALID_VERSION;
2370+
properties->ptrSupport |= FLAGCX_PTR_DMABUF;
2371+
}
2372+
properties->latency = 0; // Not set
2373+
properties->port = ibDev->portNum + ibDev->realPort;
2374+
properties->maxComms = ibDev->maxQp;
2375+
properties->maxRecvs = FLAGCX_NET_IB_MAX_RECVS;
2376+
properties->netDeviceType = FLAGCX_NET_DEVICE_HOST;
2377+
properties->netDeviceVersion = FLAGCX_NET_DEVICE_INVALID_VERSION;
23792378
return flagcxSuccess;
23802379
}
23812380

2382-
flagcxNet_t flagcxNetIb = {"IB",
2383-
flagcxIbInit,
2384-
flagcxIbDevices,
2385-
flagcxIbGetProperties,
2386-
flagcxIbListen,
2387-
flagcxIbConnect,
2388-
flagcxIbAccept,
2389-
flagcxIbRegMr,
2390-
flagcxIbRegMrDmaBuf,
2391-
flagcxIbDeregMr,
2392-
flagcxIbIsend,
2393-
flagcxIbIrecv,
2394-
flagcxIbIflush,
2395-
flagcxIbTest,
2396-
flagcxIbCloseSend,
2397-
flagcxIbCloseRecv,
2398-
flagcxIbCloseListen,
2399-
NULL /* getDeviceMr */,
2400-
NULL /* irecvConsumed */,
2401-
flagcxIbGetDevFromName};
2381+
// Adapter wrapper functions
2382+
2383+
struct flagcxNetAdaptor flagcxNetIb = {
2384+
// Basic functions
2385+
"IB", flagcxIbInit, flagcxIbDevices, flagcxIbGetProperties,
2386+
NULL, // reduceSupport
2387+
NULL, // getDeviceMr
2388+
NULL, // irecvConsumed
2389+
2390+
// Setup functions
2391+
flagcxIbListen, flagcxIbConnect, flagcxIbAccept, flagcxIbCloseSend,
2392+
flagcxIbCloseRecv, flagcxIbCloseListen,
2393+
2394+
// Memory region functions
2395+
flagcxIbRegMr, flagcxIbRegMrDmaBuf, flagcxIbDeregMr,
2396+
2397+
// Two-sided functions
2398+
flagcxIbIsend, flagcxIbIrecv, flagcxIbIflush, flagcxIbTest,
2399+
2400+
// One-sided functions
2401+
NULL, // write
2402+
NULL, // read
2403+
NULL, // signal
2404+
2405+
// Device name lookup
2406+
flagcxIbGetDevFromName};

0 commit comments

Comments
 (0)