88#include < map>
99#include < string.h> // for memcpy
1010
11+ int64_t flagcxP2PBufferSize;
12+ int64_t flagcxP2PChunkSize;
13+
1114struct p2pIpcExpInfo {
1215 flagcxP2pIpcDesc ipcDesc;
1316 bool legacyIpcCap;
@@ -72,7 +75,7 @@ flagcxResult_t flagcxP2pProxySend(struct flagcxP2pResources *resources,
7275 slotPtr->done = 0 ;
7376 slotPtr->peerDone = 0 ;
7477 slotPtr->sendHead = 0 ;
75- slotPtr->recvTail = FLAGCX_P2P_STEPS ;
78+ slotPtr->recvTail = FLAGCX_P2P_MAX_STEPS ;
7679 // Reset reg info for new operation
7780 regInfoPtr->copyStarted = 0 ;
7881 regInfoPtr->copyDone = 0 ;
@@ -140,7 +143,7 @@ flagcxResult_t flagcxP2pProxySend(struct flagcxP2pResources *resources,
140143 // Non-zero-copy mode: use FIFO buffer
141144 if (args->transmitted < args->chunkSteps ) {
142145 if (args->copied < args->chunkSteps &&
143- args->copied - args->transmitted < FLAGCX_P2P_STEPS ) {
146+ args->copied - args->transmitted < FLAGCX_P2P_MAX_STEPS ) {
144147 int step = args->copied & args->sendStepMask ;
145148
146149 volatile uint64_t *recvTail = &peerSlotPtr->recvTail ;
@@ -149,7 +152,7 @@ flagcxResult_t flagcxP2pProxySend(struct flagcxP2pResources *resources,
149152 args->subs [step].stepSize =
150153 std::min (args->chunkSize , size - args->totalCopySize );
151154 args->subs [step].stepBuff =
152- resources->proxyInfo .recvFifo + (FLAGCX_P2P_CHUNKSIZE * step);
155+ resources->proxyInfo .recvFifo + (flagcxP2PChunkSize * step);
153156
154157 FLAGCXCHECK (deviceAdaptor->deviceMemcpy (
155158 args->subs [step].stepBuff , (char *)data + args->totalCopySize ,
@@ -227,7 +230,7 @@ flagcxResult_t flagcxP2pProxyRecv(struct flagcxP2pResources *resources,
227230 slotPtr->done = 0 ;
228231 slotPtr->peerDone = 0 ;
229232 slotPtr->sendHead = 0 ;
230- slotPtr->recvTail = FLAGCX_P2P_STEPS ;
233+ slotPtr->recvTail = FLAGCX_P2P_MAX_STEPS ;
231234 }
232235
233236 // Return and retry later since the slot is still in use
@@ -277,15 +280,15 @@ flagcxResult_t flagcxP2pProxyRecv(struct flagcxP2pResources *resources,
277280 // Non-zero-copy mode: use FIFO buffer
278281 if (args->transmitted < args->chunkSteps ) {
279282 if (args->copied < args->chunkSteps &&
280- args->copied - args->transmitted < FLAGCX_P2P_STEPS ) {
283+ args->copied - args->transmitted < FLAGCX_P2P_MAX_STEPS ) {
281284 int step = args->copied & args->sendStepMask ;
282285 volatile uint64_t *sendHead = &peerSlotPtr->sendHead ;
283286
284287 if (*sendHead > args->copied ) {
285288 args->subs [step].stepSize =
286289 std::min (args->chunkSize , size - args->totalCopySize );
287290 args->subs [step].stepBuff =
288- resources->proxyInfo .recvFifo + (FLAGCX_P2P_CHUNKSIZE * step);
291+ resources->proxyInfo .recvFifo + (flagcxP2PChunkSize * step);
289292
290293 FLAGCXCHECK (deviceAdaptor->deviceMemcpy (
291294 (char *)data + args->totalCopySize , args->subs [step].stepBuff ,
@@ -308,7 +311,7 @@ flagcxResult_t flagcxP2pProxyRecv(struct flagcxP2pResources *resources,
308311 args->transmitted ++;
309312 // Update recvTail in the shared slot
310313 volatile uint64_t *recvTail = &slotPtr->recvTail ;
311- *recvTail = args->transmitted + FLAGCX_P2P_STEPS ;
314+ *recvTail = args->transmitted + FLAGCX_P2P_MAX_STEPS ;
312315 }
313316 }
314317 } else {
@@ -411,7 +414,7 @@ flagcxResult_t flagcxP2pSendProxySetup(struct flagcxProxyConnection *connection,
411414 // Initialize all synchronization slots
412415 for (int i = 0 ; i < FLAGCX_P2P_MAX_OPS ; i++) {
413416 resources->proxyInfo .shm ->slots [i].sendHead = 0 ;
414- resources->proxyInfo .shm ->slots [i].recvTail = FLAGCX_P2P_STEPS ;
417+ resources->proxyInfo .shm ->slots [i].recvTail = FLAGCX_P2P_MAX_STEPS ;
415418 resources->proxyInfo .shm ->slots [i].opHash = -1 ;
416419 resources->proxyInfo .shm ->slots [i].done = 1 ; // 1 = slot is free
417420 resources->proxyInfo .shm ->slots [i].peerDone = 1 ; // 1 = slot is free
@@ -481,7 +484,7 @@ flagcxP2pSendProxyConnect(struct flagcxProxyConnection *connection,
481484
482485 // Create stream and events for data transfers
483486 FLAGCXCHECK (deviceAdaptor->streamCreate (&resources->proxyInfo .stream ));
484- for (int i = 0 ; i < FLAGCX_P2P_STEPS ; i++) {
487+ for (int i = 0 ; i < FLAGCX_P2P_MAX_STEPS ; i++) {
485488 FLAGCXCHECK (deviceAdaptor->eventCreate (&resources->proxyInfo .events [i],
486489 flagcxEventDisableTiming));
487490 }
@@ -508,7 +511,7 @@ flagcxP2pRecvProxyConnect(struct flagcxProxyConnection *connection,
508511
509512 // Create stream and events for data transfers
510513 FLAGCXCHECK (deviceAdaptor->streamCreate (&resources->proxyInfo .stream ));
511- for (int i = 0 ; i < FLAGCX_P2P_STEPS ; i++) {
514+ for (int i = 0 ; i < FLAGCX_P2P_MAX_STEPS ; i++) {
512515 FLAGCXCHECK (deviceAdaptor->eventCreate (&resources->proxyInfo .events [i],
513516 flagcxEventDisableTiming));
514517 }
@@ -1047,7 +1050,7 @@ flagcxResult_t flagcxP2pSendProxyFree(struct flagcxP2pResources *resources) {
10471050 if (resources == NULL )
10481051 return flagcxSuccess;
10491052
1050- for (int s = 0 ; s < FLAGCX_P2P_STEPS ; s++) {
1053+ for (int s = 0 ; s < FLAGCX_P2P_MAX_STEPS ; s++) {
10511054 if (resources->proxyInfo .events [s] != NULL ) {
10521055 FLAGCXCHECK (deviceAdaptor->eventDestroy (resources->proxyInfo .events [s]));
10531056 }
@@ -1068,7 +1071,7 @@ flagcxResult_t flagcxP2pRecvProxyFree(struct flagcxP2pResources *resources) {
10681071 return flagcxSuccess;
10691072
10701073 // Destroy events
1071- for (int s = 0 ; s < FLAGCX_P2P_STEPS ; s++) {
1074+ for (int s = 0 ; s < FLAGCX_P2P_MAX_STEPS ; s++) {
10721075 if (resources->proxyInfo .events [s] != NULL ) {
10731076 FLAGCXCHECK (deviceAdaptor->eventDestroy (resources->proxyInfo .events [s]));
10741077 }
0 commit comments