Files
rocm-systems/src/channel.cc
T

58 líneas
2.0 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.
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;
}
// Per-channel operation list.
2020-05-12 14:40:18 -07:00
NCCLCHECK(ncclCudaHostCalloc(&channel->collectives, 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
NCCLCHECK(ncclCudaHostFree(channel->collectives));
// Free Ring index to rank tables
free(channel->ring.userRanks);
CUDACHECK(cudaFree(channel->ring.devUserRanks));
// 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));
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));
}
2019-03-14 19:39:20 -07:00
// Free the peer structures.
CUDACHECK(cudaFree(channel->devPeers));
free(channel->peers);
2018-12-13 15:56:12 -08:00
return ncclSuccess;
}