Skip to content

Commit

Permalink
Ensure memory copy integrity during transport setup (#731)
Browse files Browse the repository at this point in the history
(cherry picked from commit 36e453c)
  • Loading branch information
wenkaidu committed Apr 26, 2023
1 parent f2cdb65 commit 147fe93
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "bootstrap.h"
#define ENABLE_TIMER 0
#include "timer.h"
#include <cstring>

struct ncclTransport* ncclTransports[NTRANSPORTS] = {
&p2pTransport,
Expand Down Expand Up @@ -131,8 +132,13 @@ ncclResult_t ncclTransportP2pSetup(struct ncclComm* comm, struct ncclTopoGraph*
struct ncclConnector* conn = comm->channels[c].peers[sendPeer].send + connIndex;
NCCLCHECK(conn->transportComm->connect(comm, sendData++, 1, comm->rank, conn));
conn->connected = 1;
CUDACHECK(cudaMemcpyAsync(&comm->channels[c].devPeers[sendPeer].send[connIndex], &conn->conn, sizeof(struct ncclConnInfo), cudaMemcpyHostToDevice, comm->sideStream));
CUDACHECK(cudaMemcpyAsync(&comm->channels[c].devPeers[sendPeer].send[connIndex], &conn->conn, sizeof(struct ncclConnInfo), cudaMemcpyHostToDevice, comm->sideStream));
do {
struct ncclConnInfo connInfo;
CUDACHECK(cudaMemcpyAsync(&comm->channels[c].devPeers[sendPeer].send[connIndex], &conn->conn, sizeof(struct ncclConnInfo), cudaMemcpyHostToDevice, comm->sideStream));
CUDACHECK(cudaMemcpyAsync(&connInfo, &comm->channels[c].devPeers[sendPeer].send[connIndex], sizeof(struct ncclConnInfo), cudaMemcpyDeviceToHost, comm->sideStream));
CUDACHECK(hipStreamSynchronize(comm->sideStream));
if (memcmp(&connInfo, &conn->conn, sizeof(struct ncclConnInfo)) == 0) break;
} while (true);
}
}
TIME_STOP(3);
Expand All @@ -142,7 +148,13 @@ ncclResult_t ncclTransportP2pSetup(struct ncclComm* comm, struct ncclTopoGraph*
struct ncclConnector* conn = comm->channels[c].peers[recvPeer].recv + connIndex;
NCCLCHECK(conn->transportComm->connect(comm, recvData++, 1, comm->rank, conn));
conn->connected = 1;
CUDACHECK(cudaMemcpyAsync(&comm->channels[c].devPeers[recvPeer].recv[connIndex], &conn->conn, sizeof(struct ncclConnInfo), cudaMemcpyHostToDevice, comm->sideStream));
do {
struct ncclConnInfo connInfo;
CUDACHECK(cudaMemcpyAsync(&comm->channels[c].devPeers[recvPeer].recv[connIndex], &conn->conn, sizeof(struct ncclConnInfo), cudaMemcpyHostToDevice, comm->sideStream));
CUDACHECK(cudaMemcpyAsync(&connInfo, &comm->channels[c].devPeers[recvPeer].recv[connIndex], sizeof(struct ncclConnInfo), cudaMemcpyDeviceToHost, comm->sideStream));
CUDACHECK(hipStreamSynchronize(comm->sideStream));
if (memcmp(&connInfo, &conn->conn, sizeof(struct ncclConnInfo)) == 0) break;
} while (true);
}
}
TIME_STOP(4);
Expand Down

0 comments on commit 147fe93

Please sign in to comment.