Skip to content

Commit 8a2ef11

Browse files
committed
Plugin version v7
removed old v4 version
1 parent 8daeea9 commit 8a2ef11

9 files changed

Lines changed: 303 additions & 246 deletions

File tree

include/net.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ typedef enum {NCCL_INIT=1, NCCL_COLL=2, NCCL_P2P=4, NCCL_SHM=8, NCCL_NET=16, NCC
2222

2323
typedef void (*ncclDebugLogger_t)(ncclDebugLogLevel level, unsigned long flags, const char *file, int line, const char *fmt, ...);
2424

25+
#include "net_v7.h"
2526
#include "net_v6.h"
2627
#include "net_v5.h"
27-
#include "net_v4.h"
28-
29-
#define NCCL_PLUGIN_SYMBOL ncclNetPlugin_v6
3028

3129
#endif // end include guard

include/net_device.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*************************************************************************
2+
* Copyright (c) 2023-2023, NVIDIA CORPORATION. All rights reserved.
3+
*
4+
* See LICENSE.txt for license information
5+
************************************************************************/
6+
7+
#ifndef NET_DEVICE_H_
8+
#define NET_DEVICE_H_
9+
10+
#include "net_device.h"
11+
12+
#define NCCL_NET_DEVICE_INVALID_VERSION 0x0
13+
#define NCCL_NET_MTU_SIZE 4096
14+
15+
// Arbitrary version number - A given NCCL build will only be compatible with a single device networking plugin
16+
// version. NCCL will check the supplied version number from net->getProperties() and compare to its internal version.
17+
#define NCCL_NET_DEVICE_UNPACK_VERSION 0x7
18+
19+
typedef enum {NCCL_NET_DEVICE_HOST=0, NCCL_NET_DEVICE_UNPACK=1} ncclNetDeviceType;
20+
21+
typedef struct {
22+
ncclNetDeviceType netDeviceType; // Network offload type
23+
int netDeviceVersion; // Version number for network offload
24+
void* handle;
25+
size_t size;
26+
int needsProxyProgress;
27+
} ncclNetDeviceHandle_v7_t;
28+
29+
typedef ncclNetDeviceHandle_v7_t ncclNetDeviceHandle_t;
30+
31+
#endif

include/net_v6.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ typedef struct {
1818
int maxRecvs; // Maximum number of grouped receives.
1919
}ncclNetProperties_v6_t;
2020

21-
typedef ncclNetProperties_v6_t ncclNetProperties_t;
22-
2321
typedef struct {
2422
// Name of the network (mainly for logs)
2523
const char* name;
Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
/*
2-
* Copyright (c) 2017-2022, NVIDIA CORPORATION. All rights reserved.
2+
* Copyright (c) 2017-2023, NVIDIA CORPORATION. All rights reserved.
33
*/
44

5-
#ifndef NCCL_NET_V4_H_
6-
#define NCCL_NET_V4_H_
5+
#ifndef NCCL_NET_V7_H_
6+
#define NCCL_NET_V7_H_
7+
8+
#include "net_device.h"
79

810
typedef struct {
9-
char* name; // Used mostly for logging.
10-
char* pciPath; // Path to the PCI device in /sys.
11-
uint64_t guid; // Unique identifier for the NIC chip. Important for
12-
// cards with multiple PCI functions (Physical or virtual).
13-
int ptrSupport; // NCCL_PTR_HOST or NCCL_PTR_HOST|NCCL_PTR_CUDA
14-
int speed; // Port speed in Mbps.
15-
int port; // Port number.
16-
int maxComms; // Maximum number of comms we can create
17-
} ncclNetProperties_v4_t;
11+
char* name; // Used mostly for logging.
12+
char* pciPath; // Path to the PCI device in /sys.
13+
uint64_t guid; // Unique identifier for the NIC chip. Important for
14+
// cards with multiple PCI functions (Physical or virtual).
15+
int ptrSupport; // [NCCL_PTR_HOST|NCCL_PTR_CUDA|NCCL_PTR_DMABUF]
16+
int speed; // Port speed in Mbps.
17+
int port; // Port number.
18+
float latency; // Network latency
19+
int maxComms; // Maximum number of comms we can create
20+
int maxRecvs; // Maximum number of grouped receives.
21+
ncclNetDeviceType netDeviceType; // Network offload type
22+
int netDeviceVersion; // Version number for network offload
23+
} ncclNetProperties_v7_t;
24+
25+
typedef ncclNetProperties_v7_t ncclNetProperties_t;
1826

19-
// v4 struct for backwards compatibility
2027
typedef struct {
2128
// Name of the network (mainly for logs)
2229
const char* name;
@@ -25,37 +32,54 @@ typedef struct {
2532
// Return the number of adapters.
2633
ncclResult_t (*devices)(int* ndev);
2734
// Get various device properties.
28-
ncclResult_t (*getProperties)(int dev, ncclNetProperties_v4_t* props);
35+
ncclResult_t (*getProperties)(int dev, ncclNetProperties_v7_t* props);
2936
// Create a receiving object and provide a handle to connect to it. The
3037
// handle can be up to NCCL_NET_HANDLE_MAXSIZE bytes and will be exchanged
3138
// between ranks to create a connection.
3239
ncclResult_t (*listen)(int dev, void* handle, void** listenComm);
3340
// Connect to a handle and return a sending comm object for that peer.
34-
ncclResult_t (*connect)(int dev, void* handle, void** sendComm);
35-
// Finalize connection establishment after remote peer has called connectHandle
36-
ncclResult_t (*accept)(void* listenComm, void** recvComm);
41+
// This call must not block for the connection to be established, and instead
42+
// should return successfully with sendComm == NULL with the expectation that
43+
// it will be called again until sendComm != NULL.
44+
// If *sendDevComm points to a valid object, then NCCL is requesting device offload for this connection
45+
ncclResult_t (*connect)(int dev, void* handle, void** sendComm, ncclNetDeviceHandle_v7_t** sendDevComm);
46+
// Finalize connection establishment after remote peer has called connect.
47+
// This call must not block for the connection to be established, and instead
48+
// should return successfully with recvComm == NULL with the expectation that
49+
// it will be called again until recvComm != NULL.
50+
// If *recvDevComm points to a valid object, then NCCL is requesting device offload for this connection
51+
ncclResult_t (*accept)(void* listenComm, void** recvComm, ncclNetDeviceHandle_v7_t** recvDevComm);
3752
// Register/Deregister memory. Comm can be either a sendComm or a recvComm.
3853
// Type is either NCCL_PTR_HOST or NCCL_PTR_CUDA.
3954
ncclResult_t (*regMr)(void* comm, void* data, int size, int type, void** mhandle);
55+
/* DMA-BUF support */
56+
ncclResult_t (*regMrDmaBuf)(void* comm, void* data, size_t size, int type, uint64_t offset, int fd, void** mhandle);
4057
ncclResult_t (*deregMr)(void* comm, void* mhandle);
4158
// Asynchronous send to a peer.
4259
// May return request == NULL if the call cannot be performed (or would block)
43-
ncclResult_t (*isend)(void* sendComm, void* data, int size, void* mhandle, void** request);
60+
ncclResult_t (*isend)(void* sendComm, void* data, int size, int tag, void* mhandle, void** request);
4461
// Asynchronous recv from a peer.
4562
// May return request == NULL if the call cannot be performed (or would block)
46-
ncclResult_t (*irecv)(void* recvComm, void* data, int size, void* mhandle, void** request);
63+
ncclResult_t (*irecv)(void* recvComm, int n, void** data, int* sizes, int* tags, void** mhandles, void** request);
4764
// Perform a flush/fence to make sure all data received with NCCL_PTR_CUDA is
4865
// visible to the GPU
49-
ncclResult_t (*iflush)(void* recvComm, void* data, int size, void* mhandle, void** request);
66+
ncclResult_t (*iflush)(void* recvComm, int n, void** data, int* sizes, void** mhandles, void** request);
5067
// Test whether a request is complete. If size is not NULL, it returns the
5168
// number of bytes sent/received.
52-
ncclResult_t (*test)(void* request, int* done, int* size);
69+
ncclResult_t (*test)(void* request, int* done, int* sizes);
5370
// Close and free send/recv comm objects
5471
ncclResult_t (*closeSend)(void* sendComm);
5572
ncclResult_t (*closeRecv)(void* recvComm);
5673
ncclResult_t (*closeListen)(void* listenComm);
57-
} ncclNet_v4_t;
5874

75+
// Copy the given mhandle to a dptr in a format usable by this plugin's device code
76+
ncclResult_t (*getDeviceMr)(void* comm, void* mhandle, void** dptr_mhandle);
77+
78+
// Notify the plugin that a recv has completed by the device
79+
ncclResult_t (*irecvConsumed)(void* recvComm, int n, void* request);
80+
} ncclNet_v7_t;
81+
82+
// v7 struct for backwards compatibility
5983
typedef struct {
6084
// Name of the collective network (mainly for logs)
6185
const char* name;
@@ -65,7 +89,7 @@ typedef struct {
6589
// If ndev returns 0, all other functions might be set to NULL.
6690
ncclResult_t (*devices)(int* ndev);
6791
// Get various device properties.
68-
ncclResult_t (*getProperties)(int dev, ncclNetProperties_v4_t* props);
92+
ncclResult_t (*getProperties)(int dev, ncclNetProperties_v7_t* props);
6993
// Create a receiving object and provide a handle to connect to it. The
7094
// handle can be up to NCCL_NET_HANDLE_MAXSIZE bytes and will be exchanged
7195
// between ranks to create connections.
@@ -78,6 +102,8 @@ typedef struct {
78102
ncclResult_t (*reduceSupport)(ncclDataType_t dataType, ncclRedOp_t redOp, int* supported);
79103
// Register/Deregister memory. Type is either NCCL_PTR_HOST or NCCL_PTR_CUDA.
80104
ncclResult_t (*regMr)(void* collComm, void* data, int size, int type, void** mhandle);
105+
/* DMA-BUF support */
106+
ncclResult_t (*regMrDmaBuf)(void* collComm, void* data, size_t size, int type, uint64_t offset, int fd, void** mhandle);
81107
ncclResult_t (*deregMr)(void* collComm, void* mhandle);
82108
// Performs an asynchronous allreduce operation on the collective group.
83109
// May return request == NULL if the call cannot be performed (or would block).
@@ -92,6 +118,6 @@ typedef struct {
92118
// Close and free collective comm objects
93119
ncclResult_t (*closeColl)(void* collComm);
94120
ncclResult_t (*closeListen)(void* listenComm);
95-
} ncclCollNet_v4_t;
121+
} ncclCollNet_v7_t;
96122

97123
#endif // end include guard

src/ib_plugin.c

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ ncclResult_t ncclIbGetProperties(int dev, ncclNetProperties_t* props)
9292
return nccl_p2p_ib_get_properties(ncclIbDevs, dev, props);
9393
}
9494

95+
ncclResult_t ncclIbGetProperties_v6(int dev, ncclNetProperties_v6_t* props_v6)
96+
{
97+
ncclNetProperties_t props;
98+
ncclResult_t ret = nccl_p2p_ib_get_properties(ncclIbDevs, dev, &props);
99+
if (ret != ncclSuccess) return ret;
100+
props_v6->name = props.name;
101+
props_v6->pciPath = props.pciPath;
102+
props_v6->guid = props.guid;
103+
props_v6->ptrSupport = props.ptrSupport;
104+
props_v6->speed = props.speed;
105+
props_v6->latency = props.latency;
106+
props_v6->port = props.port;
107+
props_v6->maxComms = props.maxComms;
108+
props_v6->maxRecvs = props.maxRecvs;
109+
110+
return ncclSuccess;
111+
}
112+
95113
static ncclResult_t GetSocketAddr(union ncclSocketAddress* addr) {
96114
memcpy(addr, &ncclIbIfAddr, sizeof(*addr));
97115
return ncclSuccess;
@@ -345,7 +363,7 @@ ncclResult_t ncclIbListen(int dev, void* opaqueHandle, void** listenComm) {
345363
return ncclSuccess;
346364
}
347365

348-
ncclResult_t ncclIbConnect(int dev, void* opaqueHandle, void** sendComm) {
366+
ncclResult_t ncclIbConnect(int dev, void* opaqueHandle, void** sendComm, ncclNetDeviceHandle_t** sendDevComm) {
349367
struct ncclIbHandle* handle = (struct ncclIbHandle*) opaqueHandle;
350368
enum ncclSocketState conState;
351369
struct ncclIbCommStage* stage = &handle->stage;
@@ -461,9 +479,14 @@ ncclResult_t ncclIbConnect(int dev, void* opaqueHandle, void** sendComm) {
461479
return ncclSuccess;
462480
}
463481

482+
ncclResult_t ncclIbConnect_v6(int dev, void* opaqueHandle, void** sendComm) {
483+
ncclNetDeviceHandle_v7_t* handle = NULL;
484+
return ncclIbConnect(dev, opaqueHandle, sendComm, &handle);
485+
}
486+
464487
NCCL_PARAM(IbGdrFlushDisable, "GDR_FLUSH_DISABLE", 0);
465488

466-
ncclResult_t ncclIbAccept(void* listenComm, void** recvComm) {
489+
ncclResult_t ncclIbAccept(void* listenComm, void** recvComm, ncclNetDeviceHandle_t** recvDevComm) {
467490
struct ncclIbListenComm* lComm = (struct ncclIbListenComm*)listenComm;
468491
struct ncclIbCommStage* stage = &lComm->stage;
469492
struct ncclIbRecvComm* rComm = (struct ncclIbRecvComm*)stage->comm;
@@ -604,6 +627,10 @@ ncclResult_t ncclIbAccept(void* listenComm, void** recvComm) {
604627
stage->buffer = NULL;
605628
return ncclSuccess;
606629
}
630+
ncclResult_t ncclIbAccept_v6(void* listenComm, void** recvComm) {
631+
ncclNetDeviceHandle_v7_t* handle = NULL;
632+
return ncclIbAccept(listenComm, recvComm, &handle);
633+
}
607634

608635
ncclResult_t ncclIbGetRequest(struct ncclIbVerbs* verbs, struct ncclIbRequest** req) {
609636
for (int i=0; i<MAX_REQUESTS; i++) {
@@ -1117,8 +1144,8 @@ ncclResult_t ncclIbCloseListen(void* listenComm) {
11171144
return ncclSuccess;
11181145
}
11191146

1120-
const ncclNet_v6_t ibPlugin_v6 = {
1121-
.name = "IBext",
1147+
const ncclNet_v7_t ibPlugin_v7 = {
1148+
.name = "IBext_v7",
11221149
.init = ncclIbInit,
11231150
.devices = ncclIbDevices,
11241151
.getProperties = ncclIbGetProperties,
@@ -1135,17 +1162,20 @@ const ncclNet_v6_t ibPlugin_v6 = {
11351162
.closeSend = ncclIbCloseSend,
11361163
.closeRecv = ncclIbCloseRecv,
11371164
.closeListen = ncclIbCloseListen,
1165+
NULL /* getDeviceMr */,
1166+
NULL /* irecvConsumed */
11381167
};
11391168

1140-
const ncclNet_v5_t ibPlugin_v5 = {
1141-
.name = "IBext",
1169+
const ncclNet_v6_t ibPlugin_v6 = {
1170+
.name = "IBext_v6",
11421171
.init = ncclIbInit,
11431172
.devices = ncclIbDevices,
1144-
.getProperties = ncclIbGetProperties,
1173+
.getProperties = ncclIbGetProperties_v6,
11451174
.listen = ncclIbListen,
1146-
.connect = ncclIbConnect,
1147-
.accept = ncclIbAccept,
1175+
.connect = ncclIbConnect_v6,
1176+
.accept = ncclIbAccept_v6,
11481177
.regMr = ncclIbRegMr,
1178+
.regMrDmaBuf = ncclIbRegMrDmaBuf,
11491179
.deregMr = ncclIbDeregMr,
11501180
.isend = ncclIbIsend,
11511181
.irecv = ncclIbIrecv,
@@ -1156,58 +1186,19 @@ const ncclNet_v5_t ibPlugin_v5 = {
11561186
.closeListen = ncclIbCloseListen,
11571187
};
11581188

1159-
static ncclResult_t ncclIbGetProperties_v4(int dev, ncclNetProperties_v4_t* props) {
1160-
ncclNetProperties_v6_t props_v6;
1161-
ncclResult_t ret = ncclIbGetProperties(dev, &props_v6);
1162-
if (ret != ncclSuccess) return ret;
1163-
props->name = props_v6.name;
1164-
props->pciPath = props_v6.pciPath;
1165-
props->guid = props_v6.guid;
1166-
props->ptrSupport = props_v6.ptrSupport;
1167-
props->speed = props_v6.speed;
1168-
props->port = props_v6.port;
1169-
props->maxComms = props_v6.maxComms;
1170-
return ncclSuccess;
1171-
}
1172-
static ncclResult_t ncclIbIsend_v4(void *sendComm, void* data, int size, void *mhandle, void** request) {
1173-
return ncclIbIsend(sendComm, data, size, 0, mhandle, request);
1174-
}
1175-
static ncclResult_t ncclIbIrecv_v4(void* recvComm, void* data, int size, void* mhandle, void** request) {
1176-
int tag = 0;
1177-
return ncclIbIrecv(recvComm, 1, &data, &size, &tag, &mhandle, request);
1178-
}
1179-
static ncclResult_t ncclIbIflush_v4(void* recvComm, void* data, int size, void* mhandle, void** request) {
1180-
return ncclIbIflush(recvComm, 1, &data, &size, &mhandle, request);
1181-
}
1182-
static ncclResult_t ncclIbConnect_v4(int dev, void* handle, void** sendComm) {
1183-
ncclResult_t ret;
1184-
do {
1185-
ret = ncclIbConnect(dev, handle, sendComm);
1186-
} while (ret == ncclSuccess && *sendComm == NULL);
1187-
return ret;
1188-
}
1189-
static ncclResult_t ncclIbAccept_v4(void* listenComm, void** recvComm) {
1190-
ncclResult_t ret;
1191-
do {
1192-
ret = ncclIbAccept(listenComm, recvComm);
1193-
} while (ret == ncclSuccess && *recvComm == NULL);
1194-
return ret;
1195-
}
1196-
1197-
1198-
const ncclNet_v4_t ibPlugin_v4 = {
1199-
.name = "IBext",
1189+
const ncclNet_v5_t ibPlugin_v5 = {
1190+
.name = "IBext_v5",
12001191
.init = ncclIbInit,
12011192
.devices = ncclIbDevices,
1202-
.getProperties = ncclIbGetProperties_v4,
1193+
.getProperties = ncclIbGetProperties_v6,
12031194
.listen = ncclIbListen,
1204-
.connect = ncclIbConnect_v4,
1205-
.accept = ncclIbAccept_v4,
1195+
.connect = ncclIbConnect_v6,
1196+
.accept = ncclIbAccept_v6,
12061197
.regMr = ncclIbRegMr,
12071198
.deregMr = ncclIbDeregMr,
1208-
.isend = ncclIbIsend_v4,
1209-
.irecv = ncclIbIrecv_v4,
1210-
.iflush = ncclIbIflush_v4,
1199+
.isend = ncclIbIsend,
1200+
.irecv = ncclIbIrecv,
1201+
.iflush = ncclIbIflush,
12111202
.test = ncclIbTest,
12121203
.closeSend = ncclIbCloseSend,
12131204
.closeRecv = ncclIbCloseRecv,

0 commit comments

Comments
 (0)