Files
rocm-systems/src/collectives/device/all_reduce.h
T

417 строки
19 KiB
C++
Исходник Обычный вид История

2018-09-24 16:06:59 -07:00
/*************************************************************************
2021-04-12 16:00:11 -07:00
* Copyright (c) 2015-2021, NVIDIA CORPORATION. All rights reserved.
2021-01-28 09:45:01 -07:00
* Modifications Copyright (c) 2019-2021 Advanced Micro Devices, Inc. All rights reserved.
2018-09-24 16:06:59 -07:00
*
* See LICENSE.txt for license information
************************************************************************/
2019-03-14 19:39:20 -07:00
#include "devcomm.h"
2018-09-24 16:06:59 -07:00
#include "collectives.h"
2021-07-08 14:12:04 -07:00
#include "primitives.h"
2021-01-28 09:45:01 -07:00
#include "clique/AllReduceCliqueKernel.h" // [RCCL] AllReduce Clique-based kernel support
2018-09-24 16:06:59 -07:00
2021-07-08 14:12:04 -07:00
namespace {
template<typename T, typename RedOp, typename Proto>
2021-09-08 13:56:25 -07:00
__device__ __forceinline__ void runRing(ncclWorkElem *args) {
2020-09-04 14:35:05 -07:00
const int tid = threadIdx.x;
const int nthreads = args->nThreads;
2020-09-04 14:35:05 -07:00
const int bid = args->coll.bid;
const int nChannels = args->coll.nChannels;
ncclRing *ring = &ncclShmem->channel.ring;
2021-07-08 14:12:04 -07:00
int ringIx = ring->index;
const ssize_t chunkSize = int(Proto::calcBytePerStep()/sizeof(T) * (Proto::Id == NCCL_PROTO_SIMPLE ? ALLREDUCE_CHUNKSTEPS : 1));
const int nranks = ncclShmem->comm.nRanks;
2021-07-08 14:12:04 -07:00
const ssize_t loopSize = nChannels*nranks*chunkSize;
2020-09-04 14:35:05 -07:00
const ssize_t size = args->coll.count;
2019-07-05 15:43:00 -07:00
#ifdef ENABLE_PROFILING
auto devProf = ncclShmem->comm.devProf;
uint64_t clk, t0 = 0ULL, ws;
if (tid == 0) clk = __builtin_amdgcn_s_memrealtime();
2019-07-05 15:43:00 -07:00
#endif
2018-09-24 16:06:59 -07:00
2021-07-08 14:12:04 -07:00
int minChunkSize;
if (Proto::Id == NCCL_PROTO_LL)
minChunkSize = nthreads*(Proto::calcBytePerGrain()/sizeof(T));
if (Proto::Id == NCCL_PROTO_LL128) {
// We should not need the final /2 but it makes performance much, much smoother. Might be a bug somewhere.
minChunkSize = nthreads*(Proto::calcBytePerGrain()/sizeof(T))/2;
}
2018-12-13 15:56:12 -08:00
Primitives<T, RedOp, FanSymmetric<1>, 0, Proto> prims
(tid, nthreads, &ring->prev, &ring->next, args->sendbuff, args->recvbuff, args->coll.redOpArg, args->coll.connIndex << 16);
2018-09-24 16:06:59 -07:00
2021-07-08 14:12:04 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
ssize_t realChunkSize;
if (Proto::Id == NCCL_PROTO_SIMPLE) {
realChunkSize = min(chunkSize, divUp(size-gridOffset, nChannels*nranks));
realChunkSize = roundUp(realChunkSize, nthreads*sizeof(uint64_t)/sizeof(T));
2021-07-08 14:12:04 -07:00
}
else
realChunkSize = min(chunkSize, divUp(size-gridOffset, nChannels*nranks*minChunkSize)*minChunkSize);
realChunkSize = int(realChunkSize);
auto calcOffset = [&]__device__(int chunk)->ssize_t {
if (Proto::Id == NCCL_PROTO_SIMPLE)
return gridOffset + bid*nranks*realChunkSize + chunk*realChunkSize;
else
return gridOffset + (chunk*nChannels + bid)*realChunkSize;
};
auto modRanks = [&]__device__(int r)->int {
return r - (r >= nranks ? nranks : 0);
};
2018-09-24 16:06:59 -07:00
2020-09-04 14:35:05 -07:00
ssize_t offset;
int nelem;
int chunk;
2018-09-24 16:06:59 -07:00
2020-09-04 14:35:05 -07:00
// step 0: push data to next GPU
2021-07-08 14:12:04 -07:00
chunk = modRanks(ringIx + nranks-1);
offset = calcOffset(chunk);
2018-12-13 15:56:12 -08:00
nelem = min(realChunkSize, size-offset);
2019-07-05 15:43:00 -07:00
INIT_COUNTER;
2021-07-08 14:12:04 -07:00
prims.send(offset, nelem);
ACCUMULATE_COUNTER(send);
2018-09-24 16:06:59 -07:00
2020-09-04 14:35:05 -07:00
// k-2 steps: reduce and copy to next GPU
for (int j=2; j<nranks; ++j) {
2021-07-08 14:12:04 -07:00
chunk = modRanks(ringIx + nranks-j);
offset = calcOffset(chunk);
2020-09-04 14:35:05 -07:00
nelem = min(realChunkSize, size-offset);
INIT_COUNTER;
2021-07-08 14:12:04 -07:00
prims.recvReduceSend(offset, nelem);
ACCUMULATE_COUNTER(recvReduceSend);
2020-09-04 14:35:05 -07:00
}
2018-09-24 16:06:59 -07:00
2020-09-04 14:35:05 -07:00
// step k-1: reduce this buffer and data, which will produce the final
// result that we store in this data and push to the next GPU
2021-07-08 14:12:04 -07:00
chunk = ringIx + 0;
offset = calcOffset(chunk);
2018-12-13 15:56:12 -08:00
nelem = min(realChunkSize, size-offset);
2019-07-05 15:43:00 -07:00
INIT_COUNTER;
2021-07-08 14:12:04 -07:00
prims.directRecvReduceCopySend(offset, offset, offset, nelem, /*postOp=*/true);
ACCUMULATE_COUNTER(directRecvReduceCopySend);
2018-09-24 16:06:59 -07:00
2020-09-04 14:35:05 -07:00
// k-2 steps: copy to next GPU
for (int j=1; j<nranks-1; ++j) {
2021-07-08 14:12:04 -07:00
chunk = modRanks(ringIx + nranks-j);
offset = calcOffset(chunk);
2020-09-04 14:35:05 -07:00
nelem = min(realChunkSize, size-offset);
INIT_COUNTER;
2021-07-08 14:12:04 -07:00
prims.directRecvCopySend(offset, offset, nelem);
ACCUMULATE_COUNTER(directRecvCopySend);
2020-09-04 14:35:05 -07:00
}
// Make final copy from buffer to dest.
2021-07-08 14:12:04 -07:00
chunk = modRanks(ringIx + 1);
offset = calcOffset(chunk);
2020-09-04 14:35:05 -07:00
nelem = min(realChunkSize, size-offset);
INIT_COUNTER;
2021-07-08 14:12:04 -07:00
prims.directRecv(offset, nelem);
ACCUMULATE_COUNTER(directRecv);
2020-09-04 14:35:05 -07:00
}
2019-07-05 15:43:00 -07:00
#ifdef ENABLE_PROFILING
if (tid == 0 && args->coll.opCount) devProf->elems[blockIdx.x].total_cycle += (__builtin_amdgcn_s_memrealtime() - clk);
2019-07-05 15:43:00 -07:00
#endif
2019-11-19 14:57:39 -08:00
}
2020-09-04 14:35:05 -07:00
2021-07-08 14:12:04 -07:00
template<typename T, typename RedOp, typename Proto>
2021-09-08 13:56:25 -07:00
__device__ __forceinline__ void runTreeUpDown(ncclWorkElem *args) {
2020-09-04 14:35:05 -07:00
const int tid = threadIdx.x;
const int nthreads = args->nThreads;
2020-09-04 14:35:05 -07:00
const int bid = args->coll.bid;
const int nChannels = args->coll.nChannels;
ncclTree *tree = &ncclShmem->channel.tree;
2021-07-08 14:12:04 -07:00
ssize_t chunkSize = int(
Proto::Id == NCCL_PROTO_SIMPLE ? args->coll.lastChunkSize
/* LL & LL128 */ : Proto::calcBytePerStep()/sizeof(T));
const ssize_t minChunkSize = int(
Proto::Id == NCCL_PROTO_SIMPLE ? nthreads*8*(sizeof(uint64_t)/sizeof(T))
2021-07-08 14:12:04 -07:00
/* LL & LL128 */ : nthreads*(Proto::calcBytePerGrain()/sizeof(T)));
const ssize_t loopSize = int(nChannels*chunkSize);
2020-09-04 14:35:05 -07:00
const ssize_t size = args->coll.count;
2021-07-08 14:12:04 -07:00
if (loopSize > size)
chunkSize = divUp((int)size, int(nChannels*minChunkSize))*int(minChunkSize);
2019-11-19 14:57:39 -08:00
2021-07-08 14:12:04 -07:00
{ // Reduce : max number of recv is 3, max number of send is 1 (binary tree + local)
Primitives<T, RedOp, FanAsymmetric<NCCL_MAX_DEV_ARITY, 1>, /*Direct=*/0, Proto> prims
2021-09-08 13:56:25 -07:00
(tid, nthreads, tree->down, &tree->up, args->sendbuff, args->recvbuff, args->coll.redOpArg);
2021-07-08 14:12:04 -07:00
if (tree->up == -1) {
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
ssize_t offset = gridOffset + bid*int(chunkSize);
int nelem = min(chunkSize, size-offset);
prims.recvReduceCopy(offset, offset, nelem, /*postOp=*/true);
2020-09-04 14:35:05 -07:00
}
2018-12-13 15:56:12 -08:00
}
2021-07-08 14:12:04 -07:00
else if (tree->down[0] == -1) {
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
ssize_t offset = gridOffset + bid*int(chunkSize);
int nelem = min(chunkSize, size-offset);
prims.send(offset, nelem);
}
}
else {
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
ssize_t offset = gridOffset + bid*int(chunkSize);
int nelem = min(chunkSize, size-offset);
prims.recvReduceSend(offset, nelem);
2020-09-04 14:35:05 -07:00
}
}
}
2018-12-13 15:56:12 -08:00
2021-07-08 14:12:04 -07:00
{ // Broadcast : max number of recv is 1, max number of send is 3 (binary tree + local)
Primitives<T, RedOp, FanAsymmetric<1, NCCL_MAX_DEV_ARITY>, /*Direct=*/0, Proto> prims
2021-09-08 13:56:25 -07:00
(tid, nthreads, &tree->up, tree->down, args->sendbuff, args->recvbuff, args->coll.redOpArg);
2021-07-08 14:12:04 -07:00
if (tree->up == -1) {
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-07-08 14:12:04 -07:00
ssize_t offset = gridOffset + bid*int(chunkSize);
2020-09-04 14:35:05 -07:00
int nelem = min(chunkSize, size-offset);
2021-07-08 14:12:04 -07:00
prims.directSendFromOutput(offset, offset, nelem);
2020-09-04 14:35:05 -07:00
}
}
2021-07-08 14:12:04 -07:00
else if (tree->down[0] == -1) {
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-07-08 14:12:04 -07:00
ssize_t offset = gridOffset + bid*int(chunkSize);
2020-09-04 14:35:05 -07:00
int nelem = min(chunkSize, size-offset);
2021-07-08 14:12:04 -07:00
prims.directRecv(offset, nelem);
2020-09-04 14:35:05 -07:00
}
2021-07-08 14:12:04 -07:00
}
else {
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-07-08 14:12:04 -07:00
ssize_t offset = gridOffset + bid*int(chunkSize);
2020-09-04 14:35:05 -07:00
int nelem = min(chunkSize, size-offset);
2021-07-08 14:12:04 -07:00
prims.directRecvCopySend(offset, offset, nelem);
2020-09-04 14:35:05 -07:00
}
2018-12-13 15:56:12 -08:00
}
}
2020-01-16 16:02:42 -08:00
}
2018-12-13 15:56:12 -08:00
2021-07-08 14:12:04 -07:00
template<typename T, typename RedOp, typename Proto>
2021-09-08 13:56:25 -07:00
__device__ __forceinline__ void runTreeSplit(ncclWorkElem *args) {
2020-09-04 14:35:05 -07:00
const int tid = threadIdx.x;
2021-07-08 14:12:04 -07:00
const int nthreads = args->nThreads;
2020-09-04 14:35:05 -07:00
const int bid = args->coll.bid;
const int nChannels = args->coll.nChannels;
ncclTree *tree = &ncclShmem->channel.tree;
2021-07-08 14:12:04 -07:00
ssize_t chunkSize = int(
Proto::Id != NCCL_PROTO_LL ? args->coll.lastChunkSize
: Proto::calcBytePerStep()/sizeof(T));
const ssize_t minChunkSize = int(
Proto::Id == NCCL_PROTO_SIMPLE ? nthreads*8*(sizeof(uint64_t)/sizeof(T)) :
2021-07-08 14:12:04 -07:00
Proto::Id == NCCL_PROTO_LL ? nthreads*(Proto::calcBytePerGrain()/sizeof(T))
/* LL128 */ : nthreads*(Proto::calcBytePerGrain()/sizeof(T))/8);
const ssize_t loopSize = int(nChannels*chunkSize);
2020-09-04 14:35:05 -07:00
const ssize_t size = args->coll.count;
2020-01-16 16:02:42 -08:00
2021-07-08 14:12:04 -07:00
int nthreadsSplit;
if (Proto::Id == NCCL_PROTO_SIMPLE) {
nthreadsSplit = nthreads/2;
if (nthreadsSplit >= 256) nthreadsSplit += 64;
} else { // LL & LL128
// Receiving from up to 3 sources is more compute intensive than sending
// to 3 dests. Use 70% for reduce and 30% for bcast.
nthreadsSplit = (nthreads*7/(10*WARP_SIZE))*WARP_SIZE;
}
2020-01-16 16:02:42 -08:00
2021-07-08 14:12:04 -07:00
if (loopSize > size)
chunkSize = divUp((int)size, nChannels*int(minChunkSize))*int(minChunkSize);
2021-04-12 16:00:11 -07:00
2021-07-08 14:12:04 -07:00
if (tree->up == -1) {
// Reduce and broadcast. Max number of recv is 3, max number of send is 3
Primitives<T, RedOp, FanSymmetric<NCCL_MAX_DEV_ARITY>, /*Direct=*/0, Proto>
2021-09-08 13:56:25 -07:00
prims(tid, nthreads, tree->down, tree->down, args->sendbuff, args->recvbuff, args->coll.redOpArg);
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-07-08 14:12:04 -07:00
ssize_t offset = gridOffset + bid*int(chunkSize);
2020-09-04 14:35:05 -07:00
int nelem = min(chunkSize, size-offset);
2021-07-08 14:12:04 -07:00
prims.directRecvReduceCopySend(offset, offset, offset, nelem, /*doPost=*/true);
2020-09-04 14:35:05 -07:00
}
}
2021-07-08 14:12:04 -07:00
else if (tid < nthreadsSplit) {
/* Reduce up. Max number of recv is 3, max number of send is 1 (binary tree + local).
* Why Direct=1????
* Answer: Because despite not performing any direct operations, the ctor
* must assume Direct so that it can exchange direct pointers with remote ctors
* that are Direct, otherwise it hangs. A cleaner solution would be to seperate
* into DirectRecv and DirectSend capabilities, this ctor would have both=0,
* but the ctor above for tree roots would be DirectRecv=0 DirectSend=1.
*/
Primitives<T, RedOp, FanAsymmetric<NCCL_MAX_DEV_ARITY, 1>, /*Direct=*/0, Proto>
2021-09-08 13:56:25 -07:00
prims(tid, nthreadsSplit, tree->down, &tree->up, args->sendbuff, args->recvbuff, args->coll.redOpArg, 0*Proto::MaxGroupWidth);
2021-07-08 14:12:04 -07:00
if (tree->down[0] == -1) {
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-07-08 14:12:04 -07:00
ssize_t offset = gridOffset + bid*int(chunkSize);
2020-09-04 14:35:05 -07:00
int nelem = min(chunkSize, size-offset);
2021-07-08 14:12:04 -07:00
prims.send(offset, nelem);
2020-09-04 14:35:05 -07:00
}
}
2021-07-08 14:12:04 -07:00
else {
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-07-08 14:12:04 -07:00
ssize_t offset = gridOffset + bid*int(chunkSize);
2020-09-04 14:35:05 -07:00
int nelem = min(chunkSize, size-offset);
2021-07-08 14:12:04 -07:00
prims.recvReduceSend(offset, nelem);
2020-09-04 14:35:05 -07:00
}
2020-01-16 16:02:42 -08:00
}
}
2021-07-08 14:12:04 -07:00
else {
// Broadcast down. Max number of recv is 1, max number of send is 3 (binary tree + local)
Primitives<T, RedOp, FanAsymmetric<1, NCCL_MAX_DEV_ARITY>, /*Direct=*/0, Proto>
2021-09-08 13:56:25 -07:00
prims(tid-nthreadsSplit, nthreads-nthreadsSplit, &tree->up, tree->down, args->sendbuff, args->recvbuff, args->coll.redOpArg, 1*Proto::MaxGroupWidth);
2021-07-08 14:12:04 -07:00
if (tree->down[0] == -1) {
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
ssize_t offset = gridOffset + bid*int(chunkSize);
int nelem = min(chunkSize, size-offset);
prims.directRecv(offset, nelem);
}
2020-09-04 14:35:05 -07:00
}
2021-07-08 14:12:04 -07:00
else {
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-07-08 14:12:04 -07:00
ssize_t offset = gridOffset + bid*int(chunkSize);
2020-09-04 14:35:05 -07:00
int nelem = min(chunkSize, size-offset);
2021-07-08 14:12:04 -07:00
prims.directRecvCopySend(offset, offset, nelem);
2020-09-04 14:35:05 -07:00
}
2018-12-13 15:56:12 -08:00
}
}
2019-11-19 14:57:39 -08:00
}
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>
struct RunWorkElement<ncclFuncAllReduce, T, RedOp, NCCL_ALGO_RING, NCCL_PROTO_SIMPLE> {
2021-09-08 13:56:25 -07:00
__device__ __forceinline__ void run(ncclWorkElem *args) {
2021-07-08 14:12:04 -07:00
using Proto = ProtoSimple<ALLREDUCE_CHUNKSTEPS/ALLREDUCE_SLICESTEPS, ALLREDUCE_SLICESTEPS>;
runRing<T, RedOp, Proto>(args);
2020-01-16 16:02:42 -08:00
}
2020-09-04 14:35:05 -07:00
};
2021-07-08 14:12:04 -07:00
template<typename T, typename RedOp>
struct RunWorkElement<ncclFuncAllReduce, T, RedOp, NCCL_ALGO_TREE, NCCL_PROTO_SIMPLE> {
2021-09-08 13:56:25 -07:00
__device__ __forceinline__ void run(ncclWorkElem *args) {
runTreeUpDown<T, RedOp, ProtoSimple<1, 1>>(args);
2021-07-08 14:12:04 -07:00
}
2020-09-04 14:35:05 -07:00
};
2020-01-16 16:02:42 -08:00
2021-07-08 14:12:04 -07:00
template<typename T, typename RedOp>
struct RunWorkElement<ncclFuncAllReduce, T, RedOp, NCCL_ALGO_COLLNET, NCCL_PROTO_SIMPLE> {
2021-09-08 13:56:25 -07:00
__device__ __forceinline__ void run(ncclWorkElem *args) {
static constexpr int COLLNET_COPY_THREADS = 64;
2020-09-04 14:35:05 -07:00
const int tid = threadIdx.x;
const int bid = args->coll.bid;
const int nChannels = args->coll.nChannels;
struct ncclDirect* tree = &ncclShmem->channel.collTree;
2021-07-08 14:12:04 -07:00
const ssize_t chunkSize = int(args->coll.lastChunkSize);
2020-09-04 14:35:05 -07:00
const ssize_t size = args->coll.count;
2021-04-12 16:00:11 -07:00
const ssize_t loopSize = nChannels*tree->nHeads*chunkSize;
2020-01-16 16:02:42 -08:00
2021-04-12 16:00:11 -07:00
const int hasUp = (tree->up[0] >= 0) ? 1 : 0;
const int hasDn = (tree->down[0] >= 0) ? 1 : 0;
const int nThreadsScatter = ((hasUp && hasDn) ? COLLNET_COPY_THREADS : hasUp ? 2*COLLNET_COPY_THREADS : 0);
const int nThreadsGather = ((hasUp && hasDn) ? COLLNET_COPY_THREADS : hasUp ? 1*COLLNET_COPY_THREADS : 0);
const int nThreadsBcast = ((hasUp && hasDn) ? COLLNET_COPY_THREADS : hasUp ? 0 : 1*COLLNET_COPY_THREADS);
2021-07-08 14:12:04 -07:00
const int nThreadsReduce = args->nThreads - nThreadsScatter - nThreadsGather - nThreadsBcast;
2021-04-12 16:00:11 -07:00
const int tidStartBcast = nThreadsGather;
const int tidStartScatter = tidStartBcast + nThreadsBcast;
const int tidStartReduce = tidStartScatter + nThreadsScatter;
2021-04-12 16:00:11 -07:00
2021-07-08 14:12:04 -07:00
using Proto = ProtoSimple<1, 1>;
2019-11-19 14:57:39 -08:00
2021-04-12 16:00:11 -07:00
if (tid >= tidStartScatter && tid < tidStartReduce && hasUp) {
// Scatter
2021-09-08 13:56:25 -07:00
int group = (2*Proto::MaxGroupWidth) | (1<<16);
2021-07-08 14:12:04 -07:00
Primitives<T, RedOp, FanAsymmetric<0, NCCL_MAX_DIRECT_ARITY>, /*Direct=*/0, Proto>
2021-09-08 13:56:25 -07:00
prims(tid-tidStartScatter, nThreadsScatter, NULL, tree->up, args->sendbuff, args->recvbuff, args->coll.redOpArg, group, args);
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-04-12 16:00:11 -07:00
ssize_t offset = gridOffset + bid*tree->nHeads*chunkSize;
int nelem = min(tree->nHeads*chunkSize, size-offset);
2021-09-08 13:56:25 -07:00
if (args->regUsed) {
prims.directScatter(offset, nelem, chunkSize, tree->headRank, tree->shift);
} else {
prims.scatter(offset, nelem, chunkSize, tree->headRank, tree->shift);
}
2021-04-12 16:00:11 -07:00
}
} else if (tid >= tidStartReduce && tree->out != -1) {
2021-09-08 13:56:25 -07:00
int group = (3*Proto::MaxGroupWidth) | (1<<16);
2021-07-08 14:12:04 -07:00
if (hasDn) {
// Reduce, send to network
Primitives<T, RedOp, FanAsymmetric<NCCL_MAX_DIRECT_ARITY, 1>, /*Direct=*/0, Proto>
2021-09-08 13:56:25 -07:00
prims(tid-tidStartReduce, nThreadsReduce, tree->down, &tree->out, args->sendbuff, args->recvbuff, args->coll.redOpArg, group, args);
2021-07-08 14:12:04 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
ssize_t offset = gridOffset + (bid*tree->nHeads+tree->headRank)*chunkSize;
int nelem = min(chunkSize, size-offset);
2021-09-08 13:56:25 -07:00
if (args->regUsed) {
prims.directRecvReduceSend(offset, offset, nelem);
} else {
prims.recvReduceSend(offset, nelem);
}
2021-07-08 14:12:04 -07:00
}
} else {
// Directly send to network
Primitives<T, RedOp, FanAsymmetric<0, 1>, /*Direct=*/0, Proto>
2021-09-08 13:56:25 -07:00
prims(tid-tidStartReduce, nThreadsReduce, nullptr, &tree->out, args->sendbuff, args->recvbuff, args->coll.redOpArg, group);
2021-07-08 14:12:04 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
ssize_t offset = gridOffset + (bid*tree->nHeads+tree->headRank)*chunkSize;
int nelem = min(chunkSize, size-offset);
prims.send(offset, nelem);
2020-09-04 14:35:05 -07:00
}
2020-01-16 16:02:42 -08:00
}
2021-04-12 16:00:11 -07:00
} else if (tid < tidStartBcast && hasUp) {
// Gather
2021-09-08 13:56:25 -07:00
int group = (0*Proto::MaxGroupWidth) | (0<<16);
2021-07-08 14:12:04 -07:00
Primitives<T, RedOp, FanAsymmetric<NCCL_MAX_DIRECT_ARITY, 0>, /*Direct=*/0, Proto>
2021-09-08 13:56:25 -07:00
prims(tid, nThreadsGather, tree->up, NULL, args->sendbuff, args->recvbuff, args->coll.redOpArg, group, args);
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-04-12 16:00:11 -07:00
ssize_t offset = gridOffset + bid*tree->nHeads*chunkSize;
int nelem = min(tree->nHeads*chunkSize, size-offset);
2021-09-08 13:56:25 -07:00
prims.directGather(offset, nelem, chunkSize, tree->headRank, tree->shift);
2021-04-12 16:00:11 -07:00
}
} else if (tid >= tidStartBcast && tid < tidStartScatter && tree->out != -1) {
2021-09-08 13:56:25 -07:00
int group = (1*Proto::MaxGroupWidth) | (0<<16);
2021-07-08 14:12:04 -07:00
if (hasDn) {
// Recv from network, broadcast
Primitives<T, RedOp, FanAsymmetric<1, NCCL_MAX_DIRECT_ARITY>, /*Direct=*/0, Proto>
2021-09-08 13:56:25 -07:00
prims(tid-tidStartBcast, nThreadsBcast, &tree->out, tree->down, args->sendbuff, args->recvbuff, args->coll.redOpArg, group, args);
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-07-08 14:12:04 -07:00
ssize_t offset = gridOffset + (bid*tree->nHeads+tree->headRank)*chunkSize;
2020-09-04 14:35:05 -07:00
int nelem = min(chunkSize, size-offset);
2021-09-08 13:56:25 -07:00
prims.recvCopyDirectSend(offset, offset, nelem, /*postOp=*/true);
2020-09-04 14:35:05 -07:00
}
} else {
2021-07-08 14:12:04 -07:00
// Recv from network (no post thread needed)
Primitives<T, RedOp, FanAsymmetric<1, 0>, /*Direct=*/0, Proto>
2021-09-08 13:56:25 -07:00
prims(tid-tidStartBcast, nThreadsBcast, &tree->out, nullptr, args->sendbuff, args->recvbuff, args->coll.redOpArg, group);
2020-09-04 14:35:05 -07:00
for (ssize_t gridOffset = 0; gridOffset < size; gridOffset += loopSize) {
2021-07-08 14:12:04 -07:00
ssize_t offset = gridOffset + (bid*tree->nHeads+tree->headRank)*chunkSize;
2020-09-04 14:35:05 -07:00
int nelem = min(chunkSize, size-offset);
2021-07-08 14:12:04 -07:00
prims.recv(offset, nelem, /*postOp=*/true);
2020-09-04 14:35:05 -07:00
}
2020-01-16 16:02:42 -08:00
}
}
}
2020-09-04 14:35:05 -07:00
};
2021-07-08 14:12:04 -07:00
template<typename T, typename RedOp>
struct RunWorkElement<ncclFuncAllReduce, T, RedOp, NCCL_ALGO_RING, NCCL_PROTO_LL> {
2021-09-08 13:56:25 -07:00
__device__ __forceinline__ void run(ncclWorkElem *args) {
2021-07-08 14:12:04 -07:00
runRing<T, RedOp, ProtoLL>(args);
2019-11-19 14:57:39 -08:00
}
2020-09-04 14:35:05 -07:00
};
2021-07-08 14:12:04 -07:00
template<typename T, typename RedOp>
struct RunWorkElement<ncclFuncAllReduce, T, RedOp, NCCL_ALGO_TREE, NCCL_PROTO_LL> {
2021-09-08 13:56:25 -07:00
__device__ __forceinline__ void run(ncclWorkElem *args) {
runTreeUpDown<T, RedOp, ProtoLL>(args);
2020-01-16 16:02:42 -08:00
}
2020-09-04 14:35:05 -07:00
};
2021-07-08 14:12:04 -07:00
template<typename T, typename RedOp>
struct RunWorkElement<ncclFuncAllReduce, T, RedOp, NCCL_ALGO_RING, NCCL_PROTO_LL128> {
2021-09-08 13:56:25 -07:00
__device__ __forceinline__ void run(ncclWorkElem *args) {
LAUNCH_CLIQUE_KERNEL(AllReduceCliqueSplitKernel, RedOp, T, args);
2020-09-04 14:35:05 -07:00
}
};
2021-07-08 14:12:04 -07:00
template<typename T, typename RedOp>
struct RunWorkElement<ncclFuncAllReduce, T, RedOp, NCCL_ALGO_TREE, NCCL_PROTO_LL128> {
2021-09-08 13:56:25 -07:00
__device__ __forceinline__ void run(ncclWorkElem *args) {
LAUNCH_CLIQUE_KERNEL(AllReduceCliqueSplitKernel, RedOp, T, args);
2019-11-19 14:57:39 -08:00
}
2020-09-04 14:35:05 -07:00
};