-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathtestcase.cpp
More file actions
296 lines (242 loc) · 11.8 KB
/
Copy pathtestcase.cpp
File metadata and controls
296 lines (242 loc) · 11.8 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
/*
* SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "common.h"
#include "output.h"
#include "testcase.h"
#include "inline_common.h"
std::map<std::string, std::map<std::string, std::shared_ptr<PeerValueMatrix<double>>>> Testcase::globalTestCache;
Testcase::Testcase(std::string key, std::string desc) :
key(std::move(key)), desc(std::move(desc))
{}
std::string Testcase::testKey() { return key; }
std::string Testcase::testDesc() { return desc; }
FilterResult Testcase::filterHasMultipleGPUs() {
int n = 0;
CU_ASSERT(cuDeviceGetCount(&n));
if (n < 2) return FilterResult::waive("requires at least 2 GPUs");
return FilterResult::pass();
}
FilterResult Testcase::filterHasAccessiblePeerPairs() {
int deviceCount = 0;
CU_ASSERT(cuDeviceGetCount(&deviceCount));
for (int currentDevice = 0; currentDevice < deviceCount; currentDevice++) {
for (int peer = 0; peer < deviceCount; peer++) {
int canAccessPeer = 0;
if (peer == currentDevice) {
continue;
}
CU_ASSERT(cuDeviceCanAccessPeer(&canAccessPeer, currentDevice, peer));
if (canAccessPeer) {
return FilterResult::pass();
}
}
}
return FilterResult::waive("no accessible peer GPU pairs (P2P not supported between any devices)");
}
FilterResult Testcase::filterSupportsMulticast() {
int deviceCount = 0;
CU_ASSERT(cuDeviceGetCount(&deviceCount));
for (int currentDevice = 0; currentDevice < deviceCount; currentDevice++) {
CUdevice dev;
CU_ASSERT(cuDeviceGet(&dev, currentDevice));
int supportsMulticast = 0;
CU_ASSERT(cuDeviceGetAttribute(&supportsMulticast, CU_DEVICE_ATTRIBUTE_MULTICAST_SUPPORTED, dev));
if (!supportsMulticast) {
return FilterResult::waive("multicast not supported on device " + std::to_string(currentDevice));
}
}
return FilterResult::pass();
}
FilterResult Testcase::filterSupportsTMA() {
int deviceCount = 0;
CU_ASSERT(cuDeviceGetCount(&deviceCount));
for (int currentDevice = 0; currentDevice < deviceCount; currentDevice++) {
CUdevice dev;
CU_ASSERT(cuDeviceGet(&dev, currentDevice));
int major = 0;
CU_ASSERT(cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, dev));
if (major < 9) {
return FilterResult::waive(
"TMA requires compute capability 9.0+ (Hopper or later), device "
+ std::to_string(currentDevice) + " has " + std::to_string(major) + ".x");
}
}
return FilterResult::pass();
}
FilterResult Testcase::filterBounceBufferConfComputeEnabled() {
if (gSettings.bounceBufferConfComputeEnabled) {
return FilterResult::waive("bounce-buffer confidential computing enabled");
}
return FilterResult::pass();
}
#ifdef MULTINODE
// Each MPI rank handles one GPU, so we simply have to check if we have more than 1 process
FilterResult Testcase::filterHasMultipleGPUsMultinode() {
if (worldSize > 1) return FilterResult::pass();
return FilterResult::waive("requires multiple MPI ranks (only 1 process)");
}
#endif
template<typename AlignedLatencyNode>
void Testcase::latencyHelper(const MemcpyBuffer &dataBuffer, bool measureDeviceToDeviceLatency) {
uint64_t n_ptrs = dataBuffer.getBufferSize() / sizeof(AlignedLatencyNode);
if (measureDeviceToDeviceLatency) {
// For device-to-device latency, create and initialize pattern on device
for (uint64_t i = 0; i < n_ptrs; i++) {
AlignedLatencyNode alignedNode;
size_t nextOffset = ((i + strideLen) % n_ptrs) * sizeof(AlignedLatencyNode);
// Set up pattern with device addresses
alignedNode.next = (AlignedLatencyNode *)(dataBuffer.getBuffer() + nextOffset);
CU_ASSERT(cuMemcpyHtoD(dataBuffer.getBuffer() + i*sizeof(AlignedLatencyNode),
&alignedNode, sizeof(AlignedLatencyNode)));
}
} else {
// For host-device latency, initialize pattern with host addresses
AlignedLatencyNode* hostMem = (AlignedLatencyNode*)dataBuffer.getBuffer();
for (uint64_t i = 0; i < n_ptrs; i++) {
hostMem[i].next = &hostMem[(i + strideLen) % n_ptrs];
}
}
}
template void Testcase::latencyHelper<struct LatencyNode>(const MemcpyBuffer &dataBuffer, bool measureDeviceToDeviceLatency);
template void Testcase::latencyHelper<struct TMALatencyNode>(const MemcpyBuffer &dataBuffer, bool measureDeviceToDeviceLatency);
void Testcase::forEachAllToOneBufferPairing(unsigned long long size, allToOneOneToAllCallback callback) {
std::vector<const DeviceBuffer*> allBuffersPreallocated;
// allocate the all-group buffers up front, re-use to avoid reallocation
for (int deviceId = 0; deviceId < deviceCount; deviceId++) {
allBuffersPreallocated.push_back(new DeviceBuffer(size, deviceId));
}
for (int oneDeviceId = 0; oneDeviceId < deviceCount; oneDeviceId++) {
std::vector<const MemcpyBuffer*> oneBuffers;
std::vector<const MemcpyBuffer*> allBuffers;
for (int allDeviceId = 0; allDeviceId < deviceCount; allDeviceId++) {
if (allDeviceId == oneDeviceId) {
continue;
}
DeviceBuffer* oneBuffer = new DeviceBuffer(size, oneDeviceId);
if (!oneBuffer->enablePeerAcess(*allBuffersPreallocated[allDeviceId])) {
delete oneBuffer;
continue;
}
// Pairs a buffer on a GPU in the all group, with a buffer on a GPU in the one group
allBuffers.push_back(allBuffersPreallocated[allDeviceId]);
oneBuffers.push_back(oneBuffer);
}
// If no peer GPUs, skip measurements.
if (!allBuffers.empty()) {
callback(oneDeviceId, allBuffers, oneBuffers);
}
for (auto node : oneBuffers) {
delete node;
}
}
for (auto node : allBuffersPreallocated) {
delete node;
}
}
void Testcase::allToOneHelper(unsigned long long size, MemcpyOperation &memcpyInstance, PeerValueMatrix<double> &bandwidthValues) {
forEachAllToOneBufferPairing(size, [&](int oneDeviceId,
std::vector<const MemcpyBuffer*>& allBuffers,
std::vector<const MemcpyBuffer*>& oneBuffers) {
if (memcpyInstance.ctxPreference == PREFER_DST_CONTEXT) {
// Do a read from each GPU in the all group, by reading from the one GPU
bandwidthValues.value(0, oneDeviceId) = memcpyInstance.doMemcpy(oneBuffers, allBuffers);
} else {
// Do a write from each GPU in the all group, by writing to the one GPU
bandwidthValues.value(0, oneDeviceId) = memcpyInstance.doMemcpy(allBuffers, oneBuffers);
}
});
recordStability(bandwidthValues, memcpyInstance);
}
void Testcase::oneToAllHelper(unsigned long long size, MemcpyOperation &memcpyInstance, PeerValueMatrix<double> &bandwidthValues) {
forEachAllToOneBufferPairing(size, [&](int oneDeviceId,
std::vector<const MemcpyBuffer*>& allBuffers,
std::vector<const MemcpyBuffer*>& oneBuffers) {
if (memcpyInstance.ctxPreference == PREFER_DST_CONTEXT) {
// Do a read from the GPU in the one group, by reading from each GPU in the all group
bandwidthValues.value(0, oneDeviceId) = memcpyInstance.doMemcpy(allBuffers, oneBuffers);
} else {
// Do a write from the GPU in the one group, by writing to each GPU in the all group
bandwidthValues.value(0, oneDeviceId) = memcpyInstance.doMemcpy(oneBuffers, allBuffers);
}
});
recordStability(bandwidthValues, memcpyInstance);
}
void Testcase::allHostHelper(unsigned long long size, MemcpyOperation &memcpyInstance, PeerValueMatrix<double> &bandwidthValues, bool sourceIsHost) {
for (int deviceId = 0; deviceId < deviceCount; deviceId++) {
std::vector<const MemcpyBuffer*> deviceBuffers;
std::vector<const MemcpyBuffer*> hostBuffers;
deviceBuffers.push_back(new DeviceBuffer(size, deviceId));
hostBuffers.push_back(new HostBuffer(size, deviceId));
for (int interferenceDeviceId = 0; interferenceDeviceId < deviceCount; interferenceDeviceId++) {
if (interferenceDeviceId == deviceId) {
continue;
}
// Double the size of the interference copy to ensure it interferes correctly
deviceBuffers.push_back(new DeviceBuffer(size * 2, interferenceDeviceId));
hostBuffers.push_back(new HostBuffer(size * 2, interferenceDeviceId));
}
if (sourceIsHost) {
bandwidthValues.value(0, deviceId) = memcpyInstance.doMemcpy(hostBuffers, deviceBuffers);
} else {
bandwidthValues.value(0, deviceId) = memcpyInstance.doMemcpy(deviceBuffers, hostBuffers);
}
for (auto node : deviceBuffers) {
delete node;
}
for (auto node : hostBuffers) {
delete node;
}
}
recordStability(bandwidthValues, memcpyInstance);
}
void Testcase::allHostBidirHelper(unsigned long long size, MemcpyOperation &memcpyInstance, PeerValueMatrix<double> &bandwidthValues, bool sourceIsHost) {
for (int deviceId = 0; deviceId < deviceCount; deviceId++) {
std::vector<const MemcpyBuffer*> srcBuffers;
std::vector<const MemcpyBuffer*> dstBuffers;
if (sourceIsHost) {
srcBuffers.push_back(new HostBuffer(size, deviceId));
dstBuffers.push_back(new DeviceBuffer(size, deviceId));
// Double the size of the interference copy to ensure it interferes correctly
srcBuffers.push_back(new DeviceBuffer(size * 2, deviceId));
dstBuffers.push_back(new HostBuffer(size * 2, deviceId));
} else {
srcBuffers.push_back(new DeviceBuffer(size, deviceId));
dstBuffers.push_back(new HostBuffer(size, deviceId));
// Double the size of the interference copy to ensure it interferes correctly
srcBuffers.push_back(new HostBuffer(size * 2, deviceId));
dstBuffers.push_back(new DeviceBuffer(size * 2, deviceId));
}
for (int interferenceDeviceId = 0; interferenceDeviceId < deviceCount; interferenceDeviceId++) {
if (interferenceDeviceId == deviceId) {
continue;
}
// Double the size of the interference copy to ensure it interferes correctly
srcBuffers.push_back(new DeviceBuffer(size * 2, interferenceDeviceId));
dstBuffers.push_back(new HostBuffer(size * 2, interferenceDeviceId));
srcBuffers.push_back(new HostBuffer(size * 2, interferenceDeviceId));
dstBuffers.push_back(new DeviceBuffer(size * 2, interferenceDeviceId));
}
bandwidthValues.value(0, deviceId) = memcpyInstance.doMemcpy(srcBuffers, dstBuffers);
for (auto node : srcBuffers) {
delete node;
}
for (auto node : dstBuffers) {
delete node;
}
}
recordStability(bandwidthValues, memcpyInstance);
}