2018-09-24 16:06:59 -07:00
|
|
|
/*************************************************************************
|
2022-01-07 06:39:55 -08:00
|
|
|
* Copyright (c) 2015-2022, NVIDIA CORPORATION. All rights reserved.
|
2018-09-24 16:06:59 -07:00
|
|
|
*
|
|
|
|
|
* See LICENSE.txt for license information
|
|
|
|
|
************************************************************************/
|
|
|
|
|
|
2023-09-26 05:47:28 -07:00
|
|
|
#include "device.h"
|
2018-09-24 16:06:59 -07:00
|
|
|
#include "collectives.h"
|
2021-07-08 14:12:04 -07:00
|
|
|
#include "primitives.h"
|
2018-09-24 16:06:59 -07:00
|
|
|
|
2021-07-08 14:12:04 -07:00
|
|
|
namespace {
|
|
|
|
|
template<typename T, typename RedOp, typename Proto>
|
2024-06-11 01:28:01 -07:00
|
|
|
__device__ __forceinline__ void runRing(int tid, int nthreads, struct ncclDevWorkColl* work) {
|
2021-07-08 14:12:04 -07:00
|
|
|
ncclRing *ring = &ncclShmem.channel.ring;
|
|
|
|
|
const int nranks = ncclShmem.comm.nRanks;
|
|
|
|
|
const int rank = ncclShmem.comm.rank;
|
2022-05-24 02:02:31 -07:00
|
|
|
const int prevRank = ring->userRanks[nranks-1];
|
2024-06-11 01:28:01 -07:00
|
|
|
const int root = work->root;
|
|
|
|
|
size_t chunkCount;
|
|
|
|
|
size_t channelCount;
|
|
|
|
|
size_t gridOffset;
|
|
|
|
|
ncclCollCbdPart(work, ncclShmem.channelId, Proto::Id, sizeof(T), (size_t*)nullptr, &gridOffset, &channelCount, &chunkCount);
|
2024-02-05 05:06:02 -08:00
|
|
|
size_t offset;
|
|
|
|
|
int nelem;
|
2021-07-08 14:12:04 -07:00
|
|
|
|
2022-01-07 06:39:55 -08:00
|
|
|
Primitives<T, RedOp, FanSymmetric<1>, 0, Proto, 0>
|
2024-06-11 01:28:01 -07:00
|
|
|
prims(tid, nthreads, &ring->prev, &ring->next, work->sendbuff, work->recvbuff, work->redOpArg);
|
2021-07-08 14:12:04 -07:00
|
|
|
|
|
|
|
|
if (prevRank == root) {
|
2024-02-05 05:06:02 -08:00
|
|
|
for (size_t elemOffset = 0; elemOffset < channelCount; elemOffset += chunkCount) {
|
|
|
|
|
offset = gridOffset + elemOffset;
|
|
|
|
|
nelem = min(chunkCount, channelCount - elemOffset);
|
2021-07-08 14:12:04 -07:00
|
|
|
prims.send(offset, nelem);
|
2020-09-04 14:35:05 -07:00
|
|
|
}
|
2018-09-24 16:06:59 -07:00
|
|
|
}
|
2021-07-08 14:12:04 -07:00
|
|
|
else if (rank == root) {
|
2024-02-05 05:06:02 -08:00
|
|
|
for (size_t elemOffset = 0; elemOffset < channelCount; elemOffset += chunkCount) {
|
|
|
|
|
offset = gridOffset + elemOffset;
|
|
|
|
|
nelem = min(chunkCount, channelCount - elemOffset);
|
2021-07-08 14:12:04 -07:00
|
|
|
prims.recvReduceCopy(offset, offset, nelem, /*postOp=*/true);
|
2020-09-04 14:35:05 -07:00
|
|
|
}
|
2018-09-24 16:06:59 -07:00
|
|
|
}
|
2021-07-08 14:12:04 -07:00
|
|
|
else {
|
2024-02-05 05:06:02 -08:00
|
|
|
for (size_t elemOffset = 0; elemOffset < channelCount; elemOffset += chunkCount) {
|
|
|
|
|
offset = gridOffset + elemOffset;
|
|
|
|
|
nelem = min(chunkCount, channelCount - elemOffset);
|
2021-07-08 14:12:04 -07:00
|
|
|
prims.recvReduceSend(offset, nelem);
|
2020-09-04 14:35:05 -07:00
|
|
|
}
|
2019-11-19 14:57:39 -08:00
|
|
|
}
|
2021-07-08 14:12:04 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename RedOp>
|
2024-06-11 01:28:01 -07:00
|
|
|
struct RunWorkColl<ncclFuncReduce, T, RedOp, NCCL_ALGO_RING, NCCL_PROTO_SIMPLE> {
|
|
|
|
|
__device__ __forceinline__ void run(int tid, int nthreads, struct ncclDevWorkColl* work) {
|
2021-07-08 14:12:04 -07:00
|
|
|
using Proto = ProtoSimple<REDUCE_CHUNKSTEPS/REDUCE_SLICESTEPS, REDUCE_SLICESTEPS>;
|
2024-06-11 01:28:01 -07:00
|
|
|
runRing<T, RedOp, Proto>(tid, nthreads, work);
|
2021-07-08 14:12:04 -07:00
|
|
|
}
|
2020-09-04 14:35:05 -07:00
|
|
|
};
|
|
|
|
|
|
2021-07-08 14:12:04 -07:00
|
|
|
template<typename T, typename RedOp>
|
2024-06-11 01:28:01 -07:00
|
|
|
struct RunWorkColl<ncclFuncReduce, T, RedOp, NCCL_ALGO_RING, NCCL_PROTO_LL> {
|
|
|
|
|
__device__ __forceinline__ void run(int tid, int nthreads, struct ncclDevWorkColl* work) {
|
|
|
|
|
runRing<T, RedOp, ProtoLL>(tid, nthreads, work);
|
2021-07-08 14:12:04 -07:00
|
|
|
}
|
2020-09-04 14:35:05 -07:00
|
|
|
};
|
|
|
|
|
|
2021-07-08 14:12:04 -07:00
|
|
|
template<typename T, typename RedOp>
|
2024-06-11 01:28:01 -07:00
|
|
|
struct RunWorkColl<ncclFuncReduce, T, RedOp, NCCL_ALGO_RING, NCCL_PROTO_LL128> {
|
|
|
|
|
__device__ __forceinline__ void run(int tid, int nthreads, struct ncclDevWorkColl* work) {
|
|
|
|
|
runRing<T, RedOp, ProtoLL128>(tid, nthreads, work);
|
2021-07-08 14:12:04 -07:00
|
|
|
}
|
2020-09-04 14:35:05 -07:00
|
|
|
};
|