Файли
rocm-systems/src/channel.cc
T

58 рядки
2.0 KiB
C++
Неформатований Звичайний вигляд Історія

2018-12-13 15:56:12 -08:00
/*************************************************************************
2019-03-14 19:39:20 -07:00
* Copyright (c) 2015-2019, NVIDIA CORPORATION. All rights reserved.
2019-07-05 15:43:00 -07:00
* Modifications Copyright (c) 2019 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"
NCCL_PARAM(Buffsize, "BUFFSIZE", DEFAULT_BUFFER_SIZE_BYTES);
ncclResult_t initChannel(struct ncclComm* comm, int channelid) {
struct ncclChannel* channel = comm->channels+channelid;
channel->id = channelid;
// Setup intermediate buffering
channel->buffSize = ncclParamBuffsize();
// Ring index to user rank table.
NCCLCHECK(ncclCudaCalloc(&channel->ring.devUserRanks, comm->nRanks));
NCCLCHECK(ncclCalloc(&channel->ring.userRanks, comm->nRanks));
// Communication structures with peers.
NCCLCHECK(ncclCudaCalloc(&channel->devPeers, comm->nRanks));
NCCLCHECK(ncclCalloc(&channel->peers, comm->nRanks));
for (size_t i=0; i<comm->nRanks; ++i) {
channel->peers[i].send.comm = comm;
channel->peers[i].recv.comm = comm;
}
// Per-channel operation list.
NCCLCHECK(ncclCudaHostAlloc((void**)&channel->collectives, (void**)&channel->devCollectives, sizeof(struct ncclColl)*NCCL_MAX_OPS));
return ncclSuccess;
}
ncclResult_t freeChannel(struct ncclChannel* channel, int nRanks) {
// Operation list
NCCLCHECK(ncclCudaHostFree(channel->collectives));
// 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
for (int r=0; r<nRanks; r++) {
struct ncclPeer* peer = channel->peers+r;
if (peer->send.transportResources) NCCLCHECK(peer->send.transportComm->free(peer->send.transportResources));
if (peer->recv.transportResources) NCCLCHECK(peer->recv.transportComm->free(peer->recv.transportResources));
}
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;
}