2017-08-08 16:18:34 -07:00
|
|
|
/*************************************************************************
|
2022-09-20 02:21:36 -07:00
|
|
|
* Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
|
2022-10-14 16:02:54 -05:00
|
|
|
* Modifications Copyright (c) 2019-2022 Advanced Micro Devices, Inc. All rights reserved.
|
2017-08-08 16:18:34 -07:00
|
|
|
*
|
2019-03-06 18:17:20 -08:00
|
|
|
* See LICENSE.txt for license information
|
2017-08-08 16:18:34 -07:00
|
|
|
************************************************************************/
|
|
|
|
|
|
2024-03-05 09:47:18 -07:00
|
|
|
#include "cuda_runtime.h"
|
2017-08-08 16:18:34 -07:00
|
|
|
#include "common.h"
|
2025-09-26 18:09:01 -04:00
|
|
|
#include "rccl_compat.h"
|
2017-08-08 16:18:34 -07:00
|
|
|
|
2024-12-18 11:14:18 -08:00
|
|
|
void ReduceScatterGetCollByteCount(size_t *sendcount, size_t *recvcount, size_t *paramcount, size_t *sendInplaceOffset, size_t *recvInplaceOffset, size_t count, size_t eltSize, int nranks) {
|
|
|
|
|
size_t base = (count/nranks) & -(16/eltSize);
|
2022-09-20 02:21:36 -07:00
|
|
|
*sendcount = base*nranks;
|
|
|
|
|
*recvcount = base;
|
2019-03-06 18:17:20 -08:00
|
|
|
*sendInplaceOffset = 0;
|
2022-09-20 02:21:36 -07:00
|
|
|
*recvInplaceOffset = base;
|
|
|
|
|
*paramcount = base;
|
2017-08-08 16:18:34 -07:00
|
|
|
}
|
|
|
|
|
|
2019-03-06 18:17:20 -08:00
|
|
|
testResult_t ReduceScatterInitData(struct threadArgs* args, ncclDataType_t type, ncclRedOp_t op, int root, int rep, int in_place) {
|
2017-08-08 16:18:34 -07:00
|
|
|
size_t sendcount = args->sendBytes / wordSize(type);
|
2019-03-06 18:17:20 -08:00
|
|
|
size_t recvcount = args->expectedBytes / wordSize(type);
|
|
|
|
|
int nranks = args->nProcs*args->nThreads*args->nGpus;
|
2017-08-08 16:18:34 -07:00
|
|
|
|
|
|
|
|
for (int i=0; i<args->nGpus; i++) {
|
2024-03-05 09:47:18 -07:00
|
|
|
CUDACHECK(cudaSetDevice(args->gpus[i]));
|
2019-03-06 18:17:20 -08:00
|
|
|
int rank = ((args->proc*args->nThreads + args->thread)*args->nGpus + i);
|
2024-03-05 09:47:18 -07:00
|
|
|
CUDACHECK(cudaMemset(args->recvbuffs[i], 0, args->expectedBytes));
|
2017-08-08 16:18:34 -07:00
|
|
|
void* data = in_place ? args->recvbuffs[i] : args->sendbuffs[i];
|
2022-08-19 15:15:10 -05:00
|
|
|
TESTCHECK(InitData(data, sendcount, 0, type, op, rep, nranks, rank));
|
2024-03-05 09:47:18 -07:00
|
|
|
CUDACHECK(cudaMemcpy(args->expected[i], args->recvbuffs[i], args->expectedBytes, cudaMemcpyDefault));
|
2019-03-06 18:17:20 -08:00
|
|
|
TESTCHECK(InitDataReduce(args->expected[i], recvcount, rank*recvcount, type, op, rep, nranks));
|
2024-03-05 09:47:18 -07:00
|
|
|
CUDACHECK(cudaDeviceSynchronize());
|
2017-08-08 16:18:34 -07:00
|
|
|
}
|
2019-03-06 18:17:20 -08:00
|
|
|
return testSuccess;
|
2017-08-08 16:18:34 -07:00
|
|
|
}
|
|
|
|
|
|
2025-09-26 18:09:01 -04:00
|
|
|
testResult_t ReduceScatterGetAlgoProtoChannels(ncclComm_t comm, size_t count, ncclDataType_t type, int* algo, int* proto, int* nchannels) {
|
|
|
|
|
if(rcclTestsGetAlgoInfo == NULL) return testInternalError;
|
|
|
|
|
NCCLCHECK(rcclTestsGetAlgoInfo(comm, ncclFuncReduceScatter , count, type , 0, 0, 1, algo, proto, nchannels));
|
|
|
|
|
return testSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-03-06 18:17:20 -08:00
|
|
|
void ReduceScatterGetBw(size_t count, int typesize, double sec, double* algBw, double* busBw, int nranks) {
|
2020-06-19 10:40:33 -07:00
|
|
|
double baseBw = (double)(count * typesize * nranks) / 1.0E9 / sec;
|
2017-08-08 16:18:34 -07:00
|
|
|
|
|
|
|
|
*algBw = baseBw;
|
2020-06-19 10:40:33 -07:00
|
|
|
double factor = ((double)(nranks - 1))/((double)nranks);
|
2017-08-08 16:18:34 -07:00
|
|
|
*busBw = baseBw * factor;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 14:09:10 -07:00
|
|
|
testResult_t ReduceScatterRunColl(void* sendbuff, void* recvbuff, size_t count, ncclDataType_t type, ncclRedOp_t op, int root, ncclComm_t comm, cudaStream_t stream, void* bias = nullptr) {
|
2017-08-08 16:18:34 -07:00
|
|
|
NCCLCHECK(ncclReduceScatter(sendbuff, recvbuff, count, type, op, comm, stream));
|
2019-03-06 18:17:20 -08:00
|
|
|
return testSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct testColl reduceScatterTest = {
|
|
|
|
|
"ReduceScatter",
|
|
|
|
|
ReduceScatterGetCollByteCount,
|
|
|
|
|
ReduceScatterInitData,
|
|
|
|
|
ReduceScatterGetBw,
|
2025-09-26 18:09:01 -04:00
|
|
|
ReduceScatterRunColl,
|
|
|
|
|
ReduceScatterGetAlgoProtoChannels
|
2019-03-06 18:17:20 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void ReduceScatterGetBuffSize(size_t *sendcount, size_t *recvcount, size_t count, int nranks) {
|
|
|
|
|
size_t paramcount, sendInplaceOffset, recvInplaceOffset;
|
2024-12-18 11:14:18 -08:00
|
|
|
ReduceScatterGetCollByteCount(sendcount, recvcount, ¶mcount, &sendInplaceOffset, &recvInplaceOffset, count, /*eltSize=*/1, nranks);
|
2017-08-08 16:18:34 -07:00
|
|
|
}
|
|
|
|
|
|
2019-03-06 18:17:20 -08:00
|
|
|
testResult_t ReduceScatterRunTest(struct threadArgs* args, int root, ncclDataType_t type, const char* typeName, ncclRedOp_t op, const char* opName) {
|
|
|
|
|
args->collTest = &reduceScatterTest;
|
2017-08-08 16:18:34 -07:00
|
|
|
ncclDataType_t *run_types;
|
|
|
|
|
ncclRedOp_t *run_ops;
|
|
|
|
|
const char **run_typenames, **run_opnames;
|
|
|
|
|
int type_count, op_count;
|
|
|
|
|
|
2019-03-06 18:17:20 -08:00
|
|
|
if ((int)type != -1) {
|
2017-08-08 16:18:34 -07:00
|
|
|
type_count = 1;
|
|
|
|
|
run_types = &type;
|
|
|
|
|
run_typenames = &typeName;
|
|
|
|
|
} else {
|
2021-06-17 14:08:43 -07:00
|
|
|
type_count = test_typenum;
|
2017-08-08 16:18:34 -07:00
|
|
|
run_types = test_types;
|
|
|
|
|
run_typenames = test_typenames;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-06 18:17:20 -08:00
|
|
|
if ((int)op != -1) {
|
2017-08-08 16:18:34 -07:00
|
|
|
run_ops = &op;
|
|
|
|
|
run_opnames = &opName;
|
|
|
|
|
op_count = 1;
|
2019-03-06 18:17:20 -08:00
|
|
|
} else {
|
2021-06-17 14:08:43 -07:00
|
|
|
op_count = test_opnum;
|
2017-08-08 16:18:34 -07:00
|
|
|
run_ops = test_ops;
|
|
|
|
|
run_opnames = test_opnames;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-06 18:17:20 -08:00
|
|
|
for (int i=0; i<type_count; i++) {
|
|
|
|
|
for (int j=0; j<op_count; j++) {
|
2025-04-15 09:38:33 -05:00
|
|
|
#if defined(RCCL_FLOAT8)
|
2025-05-14 15:30:07 -05:00
|
|
|
if((run_types[i] == ncclFloat8e4m3 || run_types[i] == ncclFloat8e5m2) && (run_ops[j] == ncclProd || run_ops[j] == ncclAvg || strcmp(run_opnames[j],"mulsum") == 0))
|
|
|
|
|
continue;
|
2025-04-15 09:38:33 -05:00
|
|
|
#endif
|
2019-03-06 18:17:20 -08:00
|
|
|
TESTCHECK(TimeTest(args, run_types[i], run_typenames[i], run_ops[j], run_opnames[j], -1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return testSuccess;
|
2017-08-08 16:18:34 -07:00
|
|
|
}
|
2019-03-06 18:17:20 -08:00
|
|
|
|
2019-04-18 10:34:55 -07:00
|
|
|
struct testEngine ncclTestEngine = {
|
2019-03-06 18:17:20 -08:00
|
|
|
ReduceScatterGetBuffSize,
|
|
|
|
|
ReduceScatterRunTest
|
2022-03-18 11:42:15 -04:00
|
|
|
};
|