Files
rocm-systems/src/channel.cc
T

65 righe
2.4 KiB
C++

2018-12-13 15:56:12 -08:00
/*************************************************************************
2022-01-07 06:39:55 -08:00
* Copyright (c) 2015-2022, NVIDIA CORPORATION. All rights reserved.
2018-12-13 15:56:12 -08:00
*
* See LICENSE.txt for license information
************************************************************************/
#include "channel.h"
#include "param.h"
2021-04-12 16:00:11 -07:00
#include "gdrwrap.h"
2022-05-24 02:02:31 -07:00
ncclResult_t initChannel(struct ncclComm* comm, int channelId) {
struct ncclChannel* channel = &comm->channels[channelId];
2020-05-12 14:40:18 -07:00
if (channel->id != -1) return ncclSuccess;
2018-12-13 15:56:12 -08:00
2022-05-24 02:02:31 -07:00
int nRanks = comm->nRanks;
channel->id = channelId;
channel->workFifoSent = 0;
2018-12-13 15:56:12 -08:00
2022-05-24 02:02:31 -07:00
NCCLCHECK(ncclStrongStreamAcquireUncaptured(&comm->deviceStream));
// The extra on nRanks+1 is for collnet root (i.e. network)
channel->peers = ncclMemoryStackAlloc<struct ncclChannelPeer>(&comm->memPermanent, nRanks+1);
2022-10-25 00:55:55 -07:00
NCCLCHECK(ncclCudaCallocAsync(&channel->devPeers, nRanks+1, comm->deviceStream.cudaStream));
2022-05-24 02:02:31 -07:00
ncclCommPushCudaFree(comm, channel->devPeers);
channel->ring.userRanks = ncclMemoryStackAlloc<int>(&comm->memPermanent, nRanks);
2022-10-25 00:55:55 -07:00
NCCLCHECK(ncclCudaCallocAsync(&channel->devRingUserRanks, nRanks, comm->deviceStream.cudaStream));
2022-05-24 02:02:31 -07:00
ncclCommPushCudaFree(comm, channel->devRingUserRanks);
2018-12-13 15:56:12 -08:00
2022-09-27 02:31:13 -07:00
NCCLCHECK(ncclStrongStreamRelease(ncclCudaGraphNone(), &comm->deviceStream));
2022-05-24 02:02:31 -07:00
for (int r=0; r < nRanks+1; ++r) {
for (int b=0; b < NCCL_MAX_CONNS; b++) {
channel->peers[r].send[b].comm = comm;
channel->peers[r].recv[b].comm = comm;
}
2021-04-12 16:00:11 -07:00
}
2018-12-13 15:56:12 -08:00
return ncclSuccess;
}
ncclResult_t freeChannel(struct ncclChannel* channel, int nRanks) {
2022-08-18 02:53:17 -07:00
/* channel peers are only valid when async init thread completes commAlloc() and
* the channel is intialized with initChannel(); if either is not done, this channel
* should never be free. */
if (channel->id == -1 || channel->peers == NULL) return ncclSuccess;
2018-12-13 15:56:12 -08:00
// Free transport proxy resources
2020-01-16 16:02:42 -08:00
// Note: free all send resources first due to CollNet arrangement
for (int r=0; r<nRanks+1; r++) {
2022-05-24 02:02:31 -07:00
struct ncclChannelPeer* peer = channel->peers+r;
2021-04-12 16:00:11 -07:00
for (int b=0; b<NCCL_MAX_CONNS; b++) {
2022-01-07 06:39:55 -08:00
if (peer->send[b].transportComm) NCCLCHECK(peer->send[b].transportComm->free(peer->send+b));
2021-04-12 16:00:11 -07:00
}
2020-01-16 16:02:42 -08:00
}
for (int r=0; r<nRanks+1; r++) {
2022-05-24 02:02:31 -07:00
struct ncclChannelPeer* peer = channel->peers+r;
2021-04-12 16:00:11 -07:00
for (int b=0; b<NCCL_MAX_CONNS; b++) {
2022-01-07 06:39:55 -08:00
if (peer->recv[b].transportComm) NCCLCHECK(peer->recv[b].transportComm->free(peer->recv+b));
2021-04-12 16:00:11 -07:00
}
2018-12-13 15:56:12 -08:00
}
2019-03-14 19:39:20 -07:00
2018-12-13 15:56:12 -08:00
return ncclSuccess;
}