-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathtest_alltoall.cc
More file actions
378 lines (341 loc) · 14 KB
/
test_alltoall.cc
File metadata and controls
378 lines (341 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/**
* Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* See file LICENSE for terms.
*/
#include "common/test_ucc.h"
#include "utils/ucc_math.h"
using Param_0 = std::tuple<int, ucc_datatype_t, ucc_memory_type_t, gtest_ucc_inplace_t, int>;
using Param_1 = std::tuple<ucc_datatype_t, ucc_memory_type_t, gtest_ucc_inplace_t, int>;
class test_alltoall : public UccCollArgs, public ucc::test
{
public:
uint64_t coll_mask;
uint64_t coll_flags;
test_alltoall() : coll_mask(0), coll_flags(0) {}
void data_init(int nprocs, ucc_datatype_t dtype,
size_t single_rank_count, UccCollCtxVec &ctxs,
UccTeam_h team, bool persistent)
{
bool is_onesided = (NULL != team);
void *sbuf;
void *rbuf;
long *work_buf;
ctxs.resize(nprocs);
for (auto i = 0; i < nprocs; i++) {
ucc_coll_args_t *coll =
(ucc_coll_args_t *)calloc(1, sizeof(ucc_coll_args_t));
ctxs[i] =
(gtest_ucc_coll_ctx_t *)calloc(1, sizeof(gtest_ucc_coll_ctx_t));
ctxs[i]->args = coll;
coll->mask = coll_mask;
coll->coll_type = UCC_COLL_TYPE_ALLTOALL;
coll->src.info.mem_type = mem_type;
coll->src.info.count = (ucc_count_t)single_rank_count * nprocs;
coll->src.info.datatype = dtype;
coll->dst.info.mem_type = mem_type;
coll->dst.info.count = (ucc_count_t)single_rank_count * nprocs;
coll->dst.info.datatype = dtype;
ctxs[i]->init_buf = ucc_malloc(
ucc_dt_size(dtype) * single_rank_count * nprocs, "init buf");
EXPECT_NE(ctxs[i]->init_buf, nullptr);
for (int r = 0; r < nprocs; r++) {
size_t rank_size = ucc_dt_size(dtype) * single_rank_count;
alltoallx_init_buf(r, i,
(uint8_t *)ctxs[i]->init_buf + r * rank_size,
rank_size);
}
if (is_onesided) {
sbuf = team->procs[i].p->onesided_buf[0];
rbuf = team->procs[i].p->onesided_buf[1];
work_buf = (long *)team->procs[i].p->onesided_buf[2];
coll->mask |= UCC_COLL_ARGS_FIELD_FLAGS |
UCC_COLL_ARGS_FIELD_GLOBAL_WORK_BUFFER;
coll->flags |= UCC_COLL_ARGS_FLAG_MEM_MAPPED_BUFFERS;
coll->src.info.buffer = sbuf;
coll->src.info.mem_type = UCC_MEMORY_TYPE_HOST;
coll->dst.info.buffer = rbuf;
coll->dst.info.mem_type = UCC_MEMORY_TYPE_HOST;
coll->global_work_buffer = work_buf;
} else {
UCC_CHECK(ucc_mc_alloc(
&ctxs[i]->dst_mc_header,
ucc_dt_size(dtype) * single_rank_count * nprocs, mem_type));
coll->dst.info.buffer = ctxs[i]->dst_mc_header->addr;
}
if (TEST_INPLACE == inplace) {
coll->mask |= UCC_COLL_ARGS_FIELD_FLAGS;
coll->flags |= UCC_COLL_ARGS_FLAG_IN_PLACE;
UCC_CHECK(ucc_mc_memcpy(
coll->dst.info.buffer, ctxs[i]->init_buf,
ucc_dt_size(dtype) * single_rank_count * nprocs, mem_type,
UCC_MEMORY_TYPE_HOST));
} else {
if (!is_onesided) {
UCC_CHECK(ucc_mc_alloc(&ctxs[i]->src_mc_header,
ucc_dt_size(dtype) *
single_rank_count * nprocs,
mem_type));
coll->src.info.buffer = ctxs[i]->src_mc_header->addr;
}
UCC_CHECK(ucc_mc_memcpy(
coll->src.info.buffer, ctxs[i]->init_buf,
ucc_dt_size(dtype) * single_rank_count * nprocs, mem_type,
UCC_MEMORY_TYPE_HOST));
}
if (persistent) {
coll->mask |= UCC_COLL_ARGS_FIELD_FLAGS;
coll->flags |= UCC_COLL_ARGS_FLAG_PERSISTENT;
}
}
}
void data_init(int nprocs, ucc_datatype_t dtype, size_t single_rank_count,
UccCollCtxVec &ctxs, bool persistent = false)
{
data_init(nprocs, dtype, single_rank_count, ctxs, NULL, persistent);
}
void reset(UccCollCtxVec ctxs)
{
for (auto r = 0; r < ctxs.size(); r++) {
ucc_coll_args_t *coll = ctxs[r]->args;
size_t single_rank_count = coll->dst.info.count / ctxs.size();
ucc_datatype_t dtype = coll->dst.info.datatype;
clear_buffer(coll->dst.info.buffer,
single_rank_count * ucc_dt_size(dtype), mem_type, 0);
if (TEST_INPLACE == inplace) {
UCC_CHECK(ucc_mc_memcpy(
(void *)(ptrdiff_t)coll->dst.info.buffer, ctxs[r]->init_buf,
ucc_dt_size(dtype) * single_rank_count, mem_type,
UCC_MEMORY_TYPE_HOST));
}
}
}
void data_fini(UccCollCtxVec ctxs)
{
for (gtest_ucc_coll_ctx_t* ctx : ctxs) {
ucc_coll_args_t* coll = ctx->args;
if (coll->src.info.buffer) { /* no inplace */
UCC_CHECK(ucc_mc_free(ctx->src_mc_header));
}
UCC_CHECK(ucc_mc_free(ctx->dst_mc_header));
ucc_free(ctx->init_buf);
free(coll);
free(ctx);
}
ctxs.clear();
}
void data_fini_onesided(UccCollCtxVec ctxs)
{
for (gtest_ucc_coll_ctx_t *ctx : ctxs) {
ucc_free(ctx->init_buf);
free(ctx->args);
free(ctx);
}
ctxs.clear();
}
bool data_validate(UccCollCtxVec ctxs)
{
bool ret = true;
std::vector<uint8_t *> dsts(ctxs.size());
if (UCC_MEMORY_TYPE_HOST != mem_type) {
for (int r = 0; r < ctxs.size(); r++) {
size_t buf_size =
ucc_dt_size(ctxs[r]->args->dst.info.datatype) *
(size_t)ctxs[r]->args->dst.info.count;
dsts[r] = (uint8_t *) ucc_malloc(buf_size, "dsts buf");
EXPECT_NE(dsts[r], nullptr);
UCC_CHECK(ucc_mc_memcpy(dsts[r], ctxs[r]->args->dst.info.buffer,
buf_size, UCC_MEMORY_TYPE_HOST, mem_type));
}
} else {
for (int r = 0; r < ctxs.size(); r++) {
dsts[r] = (uint8_t *)(ctxs[r]->args->dst.info.buffer);
}
}
for (int r = 0; r < ctxs.size(); r++) {
ucc_coll_args_t* coll = ctxs[r]->args;
for (int i = 0; i < ctxs.size(); i++) {
size_t rank_size = ucc_dt_size(coll->dst.info.datatype) *
(size_t)(coll->dst.info.count / ctxs.size());
if (0 != alltoallx_validate_buf(i, r, (uint8_t*)dsts[r] +
rank_size * i, rank_size)) {
ret = false;
break;
}
}
}
if (UCC_MEMORY_TYPE_HOST != mem_type) {
for (int r = 0; r < ctxs.size(); r++) {
ucc_free(dsts[r]);
}
}
return ret;
}
};
class test_alltoall_0 : public test_alltoall,
public ::testing::WithParamInterface<Param_0> {};
UCC_TEST_P(test_alltoall_0, single)
{
const int team_id = std::get<0>(GetParam());
const ucc_datatype_t dtype = std::get<1>(GetParam());
ucc_memory_type_t mem_type = std::get<2>(GetParam());
gtest_ucc_inplace_t inplace = std::get<3>(GetParam());
const int count = std::get<4>(GetParam());
UccTeam_h team = UccJob::getStaticTeams()[team_id];
int size = team->procs.size();
UccCollCtxVec ctxs;
this->set_inplace(inplace);
SET_MEM_TYPE(mem_type);
data_init(size, dtype, count, ctxs, false);
UccReq req(team, ctxs);
req.start();
req.wait();
EXPECT_EQ(true, data_validate(ctxs));
data_fini(ctxs);
}
UCC_TEST_P(test_alltoall_0, single_onesided)
{
const int team_id = std::get<0>(GetParam());
const ucc_datatype_t dtype = std::get<1>(GetParam());
ucc_memory_type_t mem_type = std::get<2>(GetParam());
gtest_ucc_inplace_t inplace = std::get<3>(GetParam());
const int count = std::get<4>(GetParam());
UccTeam_h reference_team = UccJob::getStaticTeams()[team_id];
int size = reference_team->procs.size();
ucc_job_env_t env = {{"UCC_TL_UCP_TUNE", "alltoall:0-inf:@1"}};
bool is_contig = true;
UccJob job(size, UccJob::UCC_JOB_CTX_GLOBAL_ONESIDED, env);
UccTeam_h team;
std::vector<int> reference_ranks;
UccCollCtxVec ctxs;
for (auto i = 0; i < reference_team->n_procs; i++) {
int rank = reference_team->procs[i].p->job_rank;
reference_ranks.push_back(rank);
if (is_contig && i > 0 &&
(rank - reference_ranks[i - 1] > 1 ||
reference_ranks[i - 1] - rank > 1)) {
is_contig = false;
}
}
team = job.create_team(reference_ranks, true, is_contig, true);
this->set_inplace(inplace);
SET_MEM_TYPE(mem_type);
data_init(size, dtype, count, ctxs, team, false);
UccReq req(team, ctxs);
req.start();
req.wait();
EXPECT_EQ(true, data_validate(ctxs));
data_fini_onesided(ctxs);
}
UCC_TEST_P(test_alltoall_0, single_onesided_dynamic_segment)
{
const int team_id = std::get<0>(GetParam());
const ucc_datatype_t dtype = std::get<1>(GetParam());
ucc_memory_type_t mem_type = std::get<2>(GetParam());
gtest_ucc_inplace_t inplace = std::get<3>(GetParam());
const int count = std::get<4>(GetParam());
UccTeam_h reference_team = UccJob::getStaticTeams()[team_id];
int size = reference_team->procs.size();
ucc_job_env_t env = {{"UCC_TL_UCP_TUNE", "alltoall:0-inf:@onesided"}};
bool is_contig = true;
UccJob job(size, UccJob::UCC_JOB_CTX_GLOBAL_ONESIDED, env);
UccTeam_h team;
std::vector<int> reference_ranks;
UccCollCtxVec ctxs;
for (auto i = 0; i < reference_team->n_procs; i++) {
int rank = reference_team->procs[i].p->job_rank;
reference_ranks.push_back(rank);
if (is_contig && i > 0 &&
(rank - reference_ranks[i - 1] > 1 ||
reference_ranks[i - 1] - rank > 1)) {
is_contig = false;
}
}
team = job.create_team(reference_ranks, true, is_contig, true);
this->set_inplace(inplace);
SET_MEM_TYPE(mem_type);
data_init(size, dtype, count, ctxs, team, false);
for (auto i = 0; i < ctxs.size(); i++) {
ctxs[i]->args->mask = UCC_COLL_ARGS_FIELD_GLOBAL_WORK_BUFFER;
ctxs[i]->args->flags = 0; // No special flags for dynamic segments
}
UccReq req(team, ctxs);
req.start();
req.wait();
EXPECT_EQ(true, data_validate(ctxs));
data_fini_onesided(ctxs);
}
UCC_TEST_P(test_alltoall_0, single_persistent)
{
const int team_id = std::get<0>(GetParam());
const ucc_datatype_t dtype = std::get<1>(GetParam());
ucc_memory_type_t mem_type = std::get<2>(GetParam());
gtest_ucc_inplace_t inplace = std::get<3>(GetParam());
const int count = std::get<4>(GetParam());
UccTeam_h team = UccJob::getStaticTeams()[team_id];
int size = team->procs.size();
const int n_calls = 3;
UccCollCtxVec ctxs;
this->set_inplace(inplace);
SET_MEM_TYPE(mem_type);
data_init(size, dtype, count, ctxs, true);
UccReq req(team, ctxs);
for (auto i = 0; i < n_calls; i++) {
req.start();
req.wait();
EXPECT_EQ(true, data_validate(ctxs));
reset(ctxs);
}
data_fini(ctxs);
}
INSTANTIATE_TEST_CASE_P(
, test_alltoall_0,
::testing::Combine(
::testing::Range(1, UccJob::nStaticTeams), // team_ids
PREDEFINED_DTYPES,
#ifdef HAVE_CUDA
::testing::Values(UCC_MEMORY_TYPE_HOST, UCC_MEMORY_TYPE_CUDA,
UCC_MEMORY_TYPE_CUDA_MANAGED),
#else
::testing::Values(UCC_MEMORY_TYPE_HOST),
#endif
::testing::Values(/*TEST_INPLACE,*/ TEST_NO_INPLACE),
::testing::Values(1,3)));
class test_alltoall_1 : public test_alltoall,
public ::testing::WithParamInterface<Param_1> {};
UCC_TEST_P(test_alltoall_1, multiple)
{
const ucc_datatype_t dtype = std::get<0>(GetParam());
ucc_memory_type_t mem_type = std::get<1>(GetParam());
gtest_ucc_inplace_t inplace = std::get<2>(GetParam());
const int count = std::get<3>(GetParam());
std::vector<UccReq> reqs;
std::vector<UccCollCtxVec> ctxs;
for (int tid = 0; tid < UccJob::nStaticTeams; tid++) {
UccTeam_h team = UccJob::getStaticTeams()[tid];
int size = team->procs.size();
UccCollCtxVec ctx;
this->set_inplace(inplace);
SET_MEM_TYPE(mem_type);
data_init(size, dtype, count, ctx, false);
reqs.push_back(UccReq(team, ctx));
ctxs.push_back(ctx);
}
UccReq::startall(reqs);
UccReq::waitall(reqs);
for (auto ctx : ctxs) {
EXPECT_EQ(true, data_validate(ctx));
data_fini(ctx);
}
}
INSTANTIATE_TEST_CASE_P(
, test_alltoall_1,
::testing::Combine(
PREDEFINED_DTYPES,
#ifdef HAVE_CUDA
::testing::Values(UCC_MEMORY_TYPE_HOST, UCC_MEMORY_TYPE_CUDA,
UCC_MEMORY_TYPE_CUDA_MANAGED),
#else
::testing::Values(UCC_MEMORY_TYPE_HOST),
#endif
::testing::Values(/*TEST_INPLACE,*/ TEST_NO_INPLACE),
::testing::Values(1,3,8192))); // count