@@ -196,13 +196,14 @@ static flagcxResult_t groupLaunch(struct flagcxAsyncJob *job_) {
196196 peer, comm->rank , op->args .p2pPeerSlotIdx ,
197197 op->args .p2pPeerOpHash );
198198 }
199-
200199 // launch proxyRegister op if not yet registered
201- flagcxConnector *peerConns[] = {
202- comm->channels [op->channelId ].peers [peer]->send };
203- FLAGCXCHECK (flagcxNetRegisterBuffer (
204- comm, p2p->buff , p2p->bytes , peerConns, 1 , &op->args .regBufFlag ,
205- &op->args .regHandle ));
200+ if (op->connection ->transport == TRANSPORT_NET ) {
201+ flagcxConnector *peerConns[] = {
202+ comm->channels [op->channelId ].peers [peer]->send };
203+ FLAGCXCHECK (flagcxNetRegisterBuffer (
204+ comm, p2p->buff , p2p->bytes , peerConns, 1 ,
205+ &op->args .regBufFlag , &op->args .regHandle ));
206+ }
206207 // we don't use semaphore tracking for device func for the moment
207208 if (deviceAsyncLoad && deviceAsyncStore) {
208209 FLAGCXCHECK (deviceAdaptor->eventCreate (&op->event ,
@@ -227,10 +228,10 @@ static flagcxResult_t groupLaunch(struct flagcxAsyncJob *job_) {
227228 } else {
228229 op->args .semaphore = semaphore;
229230 op->event = semaphore->getEvent ();
231+ semaphore->counter ++;
230232 FLAGCXCHECK (deviceAdaptor->eventRecord (op->event , op->stream ));
231233 if (launchStream == nullptr ) {
232234 launchStream = op->stream ;
233- semaphore->counter ++;
234235 } else {
235236 FLAGCXCHECK (
236237 deviceAdaptor->streamWaitEvent (launchStream, op->event ));
@@ -273,13 +274,14 @@ static flagcxResult_t groupLaunch(struct flagcxAsyncJob *job_) {
273274 peer, comm->rank , op->args .p2pPeerSlotIdx ,
274275 op->args .p2pPeerOpHash );
275276 }
276-
277277 // launch proxyRegister op if not yet registered
278- flagcxConnector *peerConns[] = {
279- comm->channels [op->channelId ].peers [peer]->recv };
280- FLAGCXCHECK (flagcxNetRegisterBuffer (
281- comm, p2p->buff , p2p->bytes , peerConns, 1 , &op->args .regBufFlag ,
282- &op->args .regHandle ));
278+ if (op->connection ->transport == TRANSPORT_NET ) {
279+ flagcxConnector *peerConns[] = {
280+ comm->channels [op->channelId ].peers [peer]->recv };
281+ FLAGCXCHECK (flagcxNetRegisterBuffer (
282+ comm, p2p->buff , p2p->bytes , peerConns, 1 ,
283+ &op->args .regBufFlag , &op->args .regHandle ));
284+ }
283285 // we don't use semaphore tracking for device func for the moment
284286 if (deviceAsyncLoad && deviceAsyncStore) {
285287 std::vector<void *> argList;
@@ -304,10 +306,10 @@ static flagcxResult_t groupLaunch(struct flagcxAsyncJob *job_) {
304306 } else {
305307 op->args .semaphore = semaphore;
306308 op->event = semaphore->getEvent ();
309+ semaphore->counter ++;
307310 FLAGCXCHECK (deviceAdaptor->eventRecord (op->event , op->stream ));
308311 if (launchStream == nullptr ) {
309312 launchStream = op->stream ;
310- semaphore->counter ++;
311313 } else {
312314 FLAGCXCHECK (
313315 deviceAdaptor->streamWaitEvent (launchStream, op->event ));
@@ -332,24 +334,35 @@ static flagcxResult_t groupLaunch(struct flagcxAsyncJob *job_) {
332334 if (sendTasks[i]->bytes == recvTasks[j]->bytes &&
333335 sendTasks[i]->dtype == recvTasks[j]->dtype ) {
334336 if (sendTasks[i]->buff != recvTasks[j]->buff ) {
335- flagcxEvent_t selfEvent = semaphore->getEvent ();
336- FLAGCXCHECK (deviceAdaptor->eventRecord (selfEvent,
337- sendTasks[i]->stream ));
337+ flagcxProxyOp *op;
338+ FLAGCXCHECK (flagcxCalloc (&op, 1 ));
339+ op->pattern = flagcxPatternSend;
340+ op->nbytes = sendTasks[i]->bytes ;
341+ op->sendbuff = (uint8_t *)sendTasks[i]->buff ;
342+ op->recvbuff = (uint8_t *)recvTasks[j]->buff ;
343+ op->channelId = 0 ;
344+ op->root = peer;
345+ op->connection = comm->channels [op->channelId ]
346+ .peers [peer]
347+ ->send [0 ]
348+ .proxyConn .connection ;
349+ op->stream = sendTasks[i]->stream ;
350+ op->event = semaphore->getEvent ();
351+ op->args .chunkSteps = 1 ; // single step
352+ op->args .semaphore = semaphore;
353+ semaphore->counter ++;
354+ FLAGCXCHECK (
355+ deviceAdaptor->eventRecord (op->event , op->stream ));
338356 if (launchStream == nullptr ) {
339- launchStream = sendTasks[i] ->stream ;
357+ launchStream = op ->stream ;
340358 } else {
341359 FLAGCXCHECK (deviceAdaptor->streamWaitEvent (launchStream,
342- selfEvent ));
360+ op-> event ));
343361 }
344-
345- FLAGCXCHECK (deviceAdaptor->deviceMemcpy (
346- recvTasks[j]->buff , sendTasks[i]->buff ,
347- sendTasks[i]->bytes , flagcxMemcpyDeviceToDevice,
348- sendTasks[i]->stream , NULL ));
362+ FLAGCXCHECK (flagcxProxySaveOp (comm, op));
349363 }
350364 free (sendTasks[i]);
351365 free (recvTasks[j]);
352-
353366 sendTasks.erase (sendTasks.begin () + i);
354367 recvTasks.erase (recvTasks.begin () + j);
355368 matched = true ;
@@ -377,7 +390,6 @@ static flagcxResult_t groupLaunch(struct flagcxAsyncJob *job_) {
377390 }
378391 }
379392 tasks->p2pOrderSteps = newOrderSteps;
380-
381393 comm = comm->groupNext ;
382394 } while (comm != nullptr );
383395 }
@@ -409,8 +421,10 @@ static flagcxResult_t groupLaunch(struct flagcxAsyncJob *job_) {
409421 argsQueue.pop ();
410422 }
411423 } else {
412- FLAGCXCHECK (deviceAdaptor->launchHostFunc (launchStream, cpuAsyncKernel,
413- (void *)semaphore.get ()));
424+ if (launchStream != nullptr ) {
425+ FLAGCXCHECK (deviceAdaptor->launchHostFunc (launchStream, cpuAsyncKernel,
426+ (void *)semaphore.get ()));
427+ }
414428 }
415429 // deprecated code path for host func, since the previous
416430 // hang issue may be walked around by using zero copy
0 commit comments