Files
rocm-systems/src/channel.cc
T

67 líneas
2.8 KiB
C++
Original Vista normal Histórico

2018-12-13 15:56:12 -08:00
/*************************************************************************
2020-05-12 14:40:18 -07:00
* Copyright (c) 2015-2020, NVIDIA CORPORATION. All rights reserved.
2020-01-15 17:54:27 -07:00
* Modifications Copyright (c) 2019-2020 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"
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) {
2018-12-13 15:56:12 -08:00
channel->peers[i].send.comm = comm;
channel->peers[i].recv.comm = comm;
channel->peers[i].p2pSend.comm = comm;
channel->peers[i].p2pRecv.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));
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));
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;
if (peer->send.transportResources) NCCLCHECK(peer->send.transportComm->free(peer->send.transportResources));
if (peer->send.transportResources == peer->p2pSend.transportResources) peer->p2pSend.transportResources = NULL;
peer->send.transportResources = NULL;
if (peer->p2pSend.transportResources) NCCLCHECK(peer->p2pSend.transportComm->free(peer->p2pSend.transportResources));
2020-01-16 16:02:42 -08:00
}
for (int r=0; r<nRanks+1; r++) {
struct ncclPeer* peer = channel->peers+r;
2018-12-13 15:56:12 -08:00
if (peer->recv.transportResources) NCCLCHECK(peer->recv.transportComm->free(peer->recv.transportResources));
if (peer->recv.transportResources == peer->p2pRecv.transportResources) peer->p2pRecv.transportResources = NULL;
peer->recv.transportResources = NULL;
if (peer->p2pRecv.transportResources) NCCLCHECK(peer->p2pRecv.transportComm->free(peer->p2pRecv.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;
}