Files
rocm-systems/src/channel.cc
T

84 lines
3.0 KiB
C++
Raw Normal View History

2018-12-13 15:56:12 -08:00
/*************************************************************************
2021-04-12 16:00:11 -07:00
* Copyright (c) 2015-2021, NVIDIA CORPORATION. All rights reserved.
* Modifications Copyright (c) 2019-2021 Advanced Micro Devices, Inc. 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"
// GDRCOPY support: FIFO_ENABLE when enabled locates a workFifo in CUDA memory
NCCL_PARAM(GdrCopyFifoEnable, "GDRCOPY_FIFO_ENABLE", 1);
2018-12-13 15:56:12 -08: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
channel->id = channelid;
// Ring index to user rank table.
NCCLCHECK(ncclCudaCalloc(&channel->ring.devUserRanks, comm->nRanks));
NCCLCHECK(ncclCalloc(&channel->ring.userRanks, comm->nRanks));
// Communication structures with peers.
2020-01-16 16:02:42 -08:00
NCCLCHECK(ncclCudaCalloc(&channel->devPeers, comm->nRanks+1)); // The extra one rank is for collnet root (i.e. network)
NCCLCHECK(ncclCalloc(&channel->peers, comm->nRanks+1));
for (size_t i=0; i<comm->nRanks+1; ++i) {
2021-04-12 16:00:11 -07:00
for (int b=0; b<NCCL_MAX_CONNS; b++) {
channel->peers[i].send[b].comm = comm;
channel->peers[i].recv[b].comm = comm;
}
2018-12-13 15:56:12 -08:00
}
// Per-channel operation list.
2020-09-04 14:35:05 -07:00
NCCLCHECK(ncclCudaHostCalloc(&channel->workFifo, NCCL_MAX_OPS));
2021-04-12 16:00:11 -07:00
if (ncclGdrCopy != NULL && ncclParamGdrCopyFifoEnable() == 1) {
// GDRCOPY support
// We allocate a workFifo in GDR mapped CUDA memory
// But we still allocate the Host workFifo so that we
// can copy the work elements to CUDA memory on kernel launch
NCCLCHECK(ncclGdrCudaCalloc(&channel->workFifoGdr, &channel->workFifoDev, NCCL_MAX_OPS, &channel->gdrMemDesc));
} else {
// The device workFifo is the Host one
channel->workFifoDev = channel->workFifo;
}
2018-12-13 15:56:12 -08:00
return ncclSuccess;
}
ncclResult_t freeChannel(struct ncclChannel* channel, int nRanks) {
2020-05-12 14:40:18 -07:00
if (channel->id == -1) return ncclSuccess;
2018-12-13 15:56:12 -08:00
// Operation list
2020-09-04 14:35:05 -07:00
NCCLCHECK(ncclCudaHostFree(channel->workFifo));
2021-04-12 16:00:11 -07:00
if (channel->gdrMemDesc) {
// GDRCOPY support
NCCLCHECK(ncclGdrCudaFree(channel->gdrMemDesc));
}
2018-12-13 15:56:12 -08:00
// Free Ring index to rank tables
free(channel->ring.userRanks);
2019-07-05 15:43:00 -07:00
CUDACHECK(hipFree(channel->ring.devUserRanks));
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++) {
2018-12-13 15:56:12 -08:00
struct ncclPeer* peer = channel->peers+r;
2021-04-12 16:00:11 -07:00
for (int b=0; b<NCCL_MAX_CONNS; b++) {
if (peer->send[b].transportResources) NCCLCHECK(peer->send[b].transportComm->free(peer->send[b].transportResources));
}
2020-01-16 16:02:42 -08:00
}
for (int r=0; r<nRanks+1; r++) {
struct ncclPeer* peer = channel->peers+r;
2021-04-12 16:00:11 -07:00
for (int b=0; b<NCCL_MAX_CONNS; b++) {
if (peer->recv[b].transportResources) NCCLCHECK(peer->recv[b].transportComm->free(peer->recv[b].transportResources));
}
2018-12-13 15:56:12 -08:00
}
2019-03-14 19:39:20 -07:00
// Free the peer structures.
2019-07-05 15:43:00 -07:00
CUDACHECK(hipFree(channel->devPeers));
2019-03-14 19:39:20 -07:00
free(channel->peers);
2018-12-13 15:56:12 -08:00
return ncclSuccess;
}