Skip to content

Commit 8edfb10

Browse files
GirasoleYmeta-codesync[bot]
authored andcommitted
rename CtranVcImpl to CtranIbQpUtils to be reused by ibgda init process
Summary: The functions in CtranIbVcImpl can be reused for any QP initialization, move them to a standalone library and rename to `CtranIbQpUtils` to be reused ``` folly::Expected<ibverbx::IbvQp, ibverbx::Error> ctranIbQpCreate( const ibverbx::IbvPd* ibvPd, ibverbx::ibv_cq* cq); folly::Expected<folly::Unit, ibverbx::Error> ctranIbQpInit(ibverbx::IbvQp& ibvQp, int port, int qp_access_flags); folly::Expected<folly::Unit, ibverbx::Error> ctranIbQpRTR( const CtranIbRemoteQpInfo& remoteQpInfo, ibverbx::IbvQp& ibvQp, uint8_t trafficClass); folly::Expected<folly::Unit, ibverbx::Error> ctranIbQpRTS( ibverbx::IbvQp& ibvQp); ``` Reviewed By: dmwu Differential Revision: D83687865 fbshipit-source-id: 48c5a03e4be690d82a83acebf906db3e52f0c58b
1 parent 5c523a7 commit 8edfb10

File tree

6 files changed

+122
-108
lines changed

6 files changed

+122
-108
lines changed

comms/ctran/backends/ib/CtranIbLocalVc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "comms/ctran/backends/ib/CtranIbLocalVc.h"
44
#include "comms/ctran/backends/ib/CtranIb.h"
5-
#include "comms/ctran/backends/ib/CtranIbVcImpl.h"
5+
#include "comms/ctran/backends/ib/CtranIbQpUtils.h"
66
#include "comms/ctran/backends/ib/IbvWrap.h"
77
#include "comms/ctran/utils/Checks.h"
88
#include "comms/utils/logger/LogUtils.h"

comms/ctran/backends/ib/CtranIbVcImpl.cc renamed to comms/ctran/backends/ib/CtranIbQpUtils.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (c) Meta Platforms, Inc. and affiliates.
2-
#include "comms/ctran/backends/ib/CtranIbVcImpl.h"
3-
#include "comms/ctran/utils/Checks.h"
2+
43
#include "comms/utils/cvars/nccl_cvars.h"
54

5+
#include "comms/ctran/backends/ib/CtranIbQpUtils.h"
6+
67
namespace ctran::ib {
78
folly::Expected<ibverbx::IbvQp, ibverbx::Error> ctranIbQpCreate(
89
const ibverbx::IbvPd* ibvPd,
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
#pragma once
4+
5+
#include "comms/ctran/ibverbx/Ibverbx.h"
6+
7+
namespace ctran::ib {
8+
9+
/**
10+
* Common utility functions for InfiniBand Queue Pair (QP) management.
11+
*
12+
* These functions provide a reusable interface for QP creation and state
13+
* transitions that can be used across different components of the Ctran IB
14+
* backend. They were extracted from CtranIbVcImpl to enable reuse in other QP
15+
* initialization scenarios.
16+
*/
17+
18+
constexpr int MAX_CONTROL_MSGS{128};
19+
constexpr int MAX_SEND_WR{256};
20+
21+
struct CtranIbRemoteQpInfo {
22+
enum ibverbx::ibv_mtu mtu;
23+
uint32_t qpn;
24+
uint8_t port;
25+
int linkLayer;
26+
union {
27+
struct {
28+
uint64_t spn;
29+
uint64_t iid;
30+
} eth;
31+
struct {
32+
uint16_t lid;
33+
} ib;
34+
} u;
35+
};
36+
37+
// ctranIbQpCreate - Creates a new Reliable Connection (RC) QP
38+
folly::Expected<ibverbx::IbvQp, ibverbx::Error> ctranIbQpCreate(
39+
const ibverbx::IbvPd* ibvPd,
40+
ibverbx::ibv_cq* cq);
41+
42+
// ctranIbQpInit - Transitions QP to INIT state with port and access
43+
// configuration
44+
folly::Expected<folly::Unit, ibverbx::Error>
45+
ctranIbQpInit(ibverbx::IbvQp& ibvQp, int port, int qp_access_flags);
46+
47+
// ctranIbQpRTR - Transitions QP to Ready To Receive (RTR) state with remote
48+
// endpoint info
49+
folly::Expected<folly::Unit, ibverbx::Error> ctranIbQpRTR(
50+
const CtranIbRemoteQpInfo& remoteQpInfo,
51+
ibverbx::IbvQp& ibvQp,
52+
uint8_t trafficClass);
53+
54+
// ctranIbQpRTS - Transitions QP to Ready To Send (RTS) state for active
55+
// communication
56+
folly::Expected<folly::Unit, ibverbx::Error> ctranIbQpRTS(
57+
ibverbx::IbvQp& ibvQp);
58+
59+
} // namespace ctran::ib

comms/ctran/backends/ib/CtranIbVc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include "comms/ctran/backends/CtranCtrl.h"
99
#include "comms/ctran/backends/ib/CtranIb.h"
1010
#include "comms/ctran/backends/ib/CtranIbBase.h"
11+
#include "comms/ctran/backends/ib/CtranIbQpUtils.h"
1112
#include "comms/ctran/backends/ib/CtranIbVc.h"
12-
#include "comms/ctran/backends/ib/CtranIbVcImpl.h"
1313
#include "comms/ctran/utils/Checks.h"
1414

1515
#include "comms/utils/cvars/nccl_cvars.h"

comms/ctran/backends/ib/CtranIbVc.h

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <vector>
1010
#include "comms/ctran/CtranComm.h"
1111
#include "comms/ctran/backends/ib/CtranIbBase.h"
12+
#include "comms/ctran/backends/ib/CtranIbQpUtils.h"
1213
#include "comms/ctran/backends/ib/CtranIbSingleton.h"
13-
#include "comms/ctran/backends/ib/CtranIbVcImpl.h"
1414
#include "comms/ctran/backends/ib/IbvWrap.h"
1515
#include "comms/ctran/mapper/CtranMapperTypes.h"
1616
#include "comms/ctran/utils/Checks.h"
@@ -24,7 +24,63 @@
2424
// a QpUniqueId is defined by a pair of <qpnum, ibDeviceId>
2525
typedef std::pair<int, int> QpUniqueId;
2626

27-
using ctran::ib::CtrlPacket;
27+
// Fix-sized payload buffer for IB transport to prepare and register the
28+
// temporary buffers for control messages
29+
constexpr int MAX_PAYLOAD_SIZE{4096};
30+
struct CtrlPacket {
31+
int type{0}; // for callback check
32+
size_t size{0}; // size of actual data in payload
33+
char payload[MAX_PAYLOAD_SIZE];
34+
35+
inline void
36+
copyFrom(const int srcType, const void* srcPayload, const size_t srcSize) {
37+
FB_CHECKABORT(
38+
srcSize <= sizeof(payload),
39+
"Unexpected payload size {} > packet max payload size {}",
40+
srcSize,
41+
sizeof(payload));
42+
43+
memcpy(payload, srcPayload, srcSize);
44+
size = srcSize;
45+
type = srcType;
46+
}
47+
48+
inline void copyTo(void* dstPayload, const size_t dstSize) {
49+
FB_CHECKABORT(
50+
size == dstSize,
51+
"Unexpected packet payload size {} != input payload size {}",
52+
size,
53+
dstSize);
54+
55+
memcpy(dstPayload, payload, dstSize);
56+
}
57+
58+
inline void copyFrom(const CtrlPacket& src) {
59+
type = src.type;
60+
size = src.size;
61+
memcpy(payload, src.payload, src.size);
62+
}
63+
64+
inline void copyTo(CtrlPacket& dst) {
65+
dst.type = type;
66+
dst.size = size;
67+
memcpy(dst.payload, payload, size);
68+
}
69+
70+
inline size_t getPacketSize() const {
71+
return offsetof(CtrlPacket, payload) +
72+
size; // transfer header + actual size of payload
73+
}
74+
75+
std::string toString() const {
76+
return fmt::format(
77+
"addr {} type {} payloadSize {} packetSize {}",
78+
(void*)this,
79+
type,
80+
size,
81+
getPacketSize());
82+
}
83+
};
2884

2985
/**
3086
* Virtual connection internal work request (WR) structure holding a pending

comms/ctran/backends/ib/CtranIbVcImpl.h

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)