-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathscale_validation.cpp
305 lines (269 loc) · 11 KB
/
scale_validation.cpp
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
/******************************************************************************
# Copyright (c) 2022 Habana Labs, Ltd.
# SPDX-License-Identifier: Apache-2.0
******************************************************************************/
#include "common.h"
#include <algorithm> // for std::for_each
#include <chrono> // for Bandwidth calculation
#include <iostream> // for io stream
static constexpr float SCALE_VALIDATION_MARGIN = 0.05; // fraction of expected BW
enum class ControlType : uint8_t
{
SEND = 1,
RECEIVE,
END,
};
#ifdef MPI_ENABLED
static synDeviceType getDeviceType(const synDeviceId deviceId)
{
synDeviceInfoV2 deviceInfo;
CHECK_SYNAPSE_STATUS(synDeviceGetInfoV2(deviceId, &deviceInfo));
return deviceInfo.deviceType;
}
static uint64_t getExpectedScaleupBW(const DeviceResources& resources)
{
synDeviceType deviceType = getDeviceType(resources.deviceHandle);
switch (deviceType)
{
case synDeviceGaudi:
return 12.5e9;
case synDeviceGaudi2:
return 37.5e9;
case synDeviceGaudi3:
return 75e9;
default:
log() << "Unknown device, setting expected scaleup bandwidth to 37.5GB" << std::endl;
return 37.5e9;
}
}
static void getScaleupPairs(const EnvData& envData, std::vector<RanksPairSendRecv>& ranksList)
{
for (HCL_Rank sender = 0; sender < envData.nranks; sender++)
{
size_t boxNum = sender / envData.scaleupGroupSize;
for (HCL_Rank receiver = boxNum * envData.scaleupGroupSize; receiver < (boxNum + 1) * envData.scaleupGroupSize;
receiver++)
{
if (sender == receiver) continue;
ranksList.push_back({sender, receiver});
}
}
}
static void getScaleoutPairs(const EnvData& envData, std::vector<RanksPairSendRecv>& ranksList)
{
for (HCL_Rank sender = 0; sender < envData.nranks; sender++)
{
for (HCL_Rank receiver = sender % envData.scaleupGroupSize; receiver < envData.nranks;
receiver += envData.scaleupGroupSize)
{
if (sender == receiver) continue;
ranksList.push_back({sender, receiver});
}
}
}
static void scaleValidationSend(const EnvData& envData,
const DeviceResources& resources,
const Buffers& buffers,
const HCL_Rank receiver,
uint64_t& result)
{
// run single iteration as warmup
CHECK_HCCL_STATUS(hcclSend((void*) buffers.inputDevPtrs[0],
buffers.inputSize / getDataTypeSize(envData),
getDataType(envData),
receiver,
resources.comm,
resources.collectiveStream));
CHECK_SYNAPSE_STATUS(synStreamSynchronize(resources.collectiveStream));
auto startTime = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < envData.numIters; ++i)
{
uint64_t index = i % buffers.inputDevPtrs.size();
CHECK_HCCL_STATUS(hcclSend((void*) buffers.inputDevPtrs[index],
buffers.inputSize / getDataTypeSize(envData),
getDataType(envData),
receiver,
resources.comm,
resources.collectiveStream));
}
// calculate result
CHECK_SYNAPSE_STATUS(synStreamSynchronize(resources.collectiveStream));
auto duration = std::chrono::high_resolution_clock::now() - startTime;
auto rankDurationInSec = std::chrono::duration_cast<std::chrono::duration<double>>(duration).count();
rankDurationInSec = rankDurationInSec / envData.numIters;
result = buffers.inputSize / rankDurationInSec;
}
static void scaleValidationReceive(const EnvData& envData,
const DeviceResources& resources,
const Buffers& buffers,
const HCL_Rank sender)
{
// run single iteration as warmup
CHECK_HCCL_STATUS(hcclRecv((void*) buffers.outputDevPtrs[0],
buffers.inputSize / getDataTypeSize(envData),
getDataType(envData),
sender,
resources.comm,
resources.collectiveStream));
for (size_t i = 0; i < envData.numIters; ++i)
{
uint64_t index = i % buffers.inputDevPtrs.size();
CHECK_HCCL_STATUS(hcclRecv((void*) buffers.outputDevPtrs[index],
buffers.inputSize / getDataTypeSize(envData),
getDataType(envData),
sender,
resources.comm,
resources.collectiveStream));
}
}
static void scaleValidationEnd(const EnvData& envData)
{
for (HCL_Rank rank = 0; rank < envData.nranks; rank++)
{
if (rank != envData.root)
{
ControlType control = ControlType::END;
CHECK_MPI_STATUS(MPI_Send((void*) &control, 1, MPI_UINT8_T, rank, 0, MPI_COMM_WORLD));
}
}
}
static bool scaleValidationServerStep(const EnvData& envData,
const DeviceResources& resources,
const Buffers& buffers,
const HCL_Rank sender,
const HCL_Rank receiver,
const uint64_t expectedBW)
{
ControlType control;
MPI_Status status;
// trigger receiver
if (envData.rank != receiver) // do server receive only after sending send request
{
control = ControlType::RECEIVE;
CHECK_MPI_STATUS(MPI_Send((void*) &control, 1, MPI_UINT8_T, receiver, 0, MPI_COMM_WORLD));
CHECK_MPI_STATUS(MPI_Send((void*) &sender, 1, MPI_INT, receiver, 0, MPI_COMM_WORLD));
}
// trigger sender
if (envData.rank != sender) // server send at the result stage
{
control = ControlType::SEND;
CHECK_MPI_STATUS(MPI_Send((void*) &control, 1, MPI_UINT8_T, sender, 0, MPI_COMM_WORLD));
CHECK_MPI_STATUS(MPI_Send((void*) &receiver, 1, MPI_INT, sender, 0, MPI_COMM_WORLD));
}
// server receive
if (envData.rank == receiver)
{
scaleValidationReceive(envData, resources, buffers, sender);
}
// get result
uint64_t result;
if (envData.rank == sender)
{
scaleValidationSend(envData, resources, buffers, receiver, result);
}
else
{
// wait for result
CHECK_MPI_STATUS(MPI_Recv((void*) &result, 1, MPI_UINT64_T, sender, 0, MPI_COMM_WORLD, &status))
}
// log
if (result < (expectedBW - SCALE_VALIDATION_MARGIN * expectedBW))
{
log() << sender << "-->" << receiver << ": Test failed, Actual BW does not meet the expectation" << " ("
<< formatBW(result) << " - " << result * 100 / expectedBW << "% of expected BW)" << std::endl;
return false;
}
return true;
}
static void scaleValidationClient(const EnvData& envData, const DeviceResources& resources, const Buffers& buffers)
{
while (true)
{
MPI_Status status;
ControlType control;
CHECK_MPI_STATUS(MPI_Recv((void*) &control, 1, MPI_UINT8_T, envData.root, 0, MPI_COMM_WORLD, &status))
switch (control)
{
case ControlType::END:
return;
case ControlType::SEND:
uint64_t result;
int receiver;
CHECK_MPI_STATUS(MPI_Recv((void*) &receiver, 1, MPI_INT, envData.root, 0, MPI_COMM_WORLD, &status))
scaleValidationSend(envData, resources, buffers, receiver, result);
// send result to server
CHECK_MPI_STATUS(MPI_Send((void*) &result, 1, MPI_UINT64_T, envData.root, 0, MPI_COMM_WORLD));
break;
case ControlType::RECEIVE:
int sender;
CHECK_MPI_STATUS(MPI_Recv((void*) &sender, 1, MPI_INT, envData.root, 0, MPI_COMM_WORLD, &status))
scaleValidationReceive(envData, resources, buffers, sender);
break;
default:
throw std::runtime_error {" Unexpected control message type"};
}
}
}
static bool scaleValidationCommonDriver(const EnvData& envData,
const DeviceResources& resources,
const Buffers& buffers,
const std::vector<RanksPairSendRecv>& ranksPairsList,
const uint64_t expectedBW)
{
bool isOK = true;
if (isRoot(envData))
{
std::for_each(ranksPairsList.cbegin(), ranksPairsList.cend(), [&](RanksPairSendRecv pair) {
if (!scaleValidationServerStep(envData, resources, buffers, pair.sendFromRank, pair.recvInRank, expectedBW))
isOK = false;
});
scaleValidationEnd(envData);
}
else
{
scaleValidationClient(envData, resources, buffers);
}
return isOK;
}
void scaleValidationTestDriver(EnvData& envData,
const DeviceResources& resources,
const Buffers& buffers,
const uint64_t size)
{
bool isOK = false;
// scaleup
uint64_t expectedBW = getExpectedScaleupBW(resources);
if (isRoot(envData))
{
log() << "ScaleUp - Expected " << formatBW(expectedBW) << std::endl;
}
std::vector<RanksPairSendRecv> scaleupPairsList;
getScaleupPairs(envData, scaleupPairsList);
isOK = scaleValidationCommonDriver(envData, resources, buffers, scaleupPairsList, expectedBW);
if (isOK && isRoot(envData))
{
log() << "Test passed. The BW between all nodes meets the expectations" << std::endl;
}
// scaleout
if (envData.nranks > envData.ranksPerNode)
{
expectedBW = envData.expectedScaleoutBW;
if (expectedBW == 0)
{
throw std::runtime_error {"missing mandatory argument for scale validation: --scaleout_bw"};
}
if (isRoot(envData))
{
log() << "ScaleOut - Expected " << formatBW(expectedBW) << std::endl;
}
std::vector<RanksPairSendRecv> scaleoutPairsList;
getScaleoutPairs(envData, scaleoutPairsList);
isOK = scaleValidationCommonDriver(envData, resources, buffers, scaleoutPairsList, expectedBW);
if (isOK && isRoot(envData))
{
log() << "Test passed. The BW between all nodes meets the expectations" << std::endl;
}
}
envData.shouldCheckCorrectness = false;
}
#endif //MPI_ENABLED