HealthCheck.hpp 15.7 KB
Newer Older
1
/*
gilbertlee-amd's avatar
gilbertlee-amd committed
2
Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

gilbertlee-amd's avatar
gilbertlee-amd committed
23
24
25
26
27
28
29
enum {
  HBM_READ      = 0,
  HBM_WRITE     = 1,
  HBM_COPY      = 2,
  HBM_ADD       = 3,
  NUM_HBM_TESTS = 4
} HbmTests;
30

gilbertlee-amd's avatar
gilbertlee-amd committed
31
struct HbmTestConfig
32
{
gilbertlee-amd's avatar
gilbertlee-amd committed
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
  std::string name;
  int numInputs;
  int numOutputs;
};

HbmTestConfig HbmTestConfigs[NUM_HBM_TESTS] =
{ {"READ",  1, 0},
  {"WRITE", 0, 1},
  {"COPY",  1, 1},
  {"ADD",   2, 1}
};

typedef struct
{
  double unidirHostToDeviceCopyLimit;
  double unidirDeviceToHostCopyLimit;
  double bidirDmaCopyLimit;
  int    a2aUnrollFactor;
  int    a2aNumSubExecs;
  double a2aCopyLimit;

  int    hbmBlockSize   [NUM_HBM_TESTS];
  int    hbmUnrollFactor[NUM_HBM_TESTS];
  int    hbmTemporalMode[NUM_HBM_TESTS];
  double hbmLimit       [NUM_HBM_TESTS];
} TestConfig;

typedef enum
{
  MODEL_08_GFX0942_304 = 0,
  MODEL_08_GFX0942_064 = 1,
  NUM_SUPPORTED_MODELS = 2
} ModelEnum;

// All limits are scaled by this factor
#define SFACTOR 0.97

TestConfig Config_08_GFX0942_304 = {
  .unidirHostToDeviceCopyLimit   = 50,
  .unidirDeviceToHostCopyLimit   = 50,
  .bidirDmaCopyLimit             = 90,
  .a2aUnrollFactor               = 2,
  .a2aNumSubExecs                = 8,
  .a2aCopyLimit                  = 45,
  .hbmBlockSize                  = { 384,  256,  320,  256},
  .hbmUnrollFactor               = {   7,    4,    8,    7},
  .hbmTemporalMode               = {   3,    3,    3,    3},
  .hbmLimit                      = {4980, 4850, 2045, 1405},
};

TestConfig Config_08_GFX0942_064 = {
  .unidirHostToDeviceCopyLimit   = 50,
  .unidirDeviceToHostCopyLimit   = 50,
  .bidirDmaCopyLimit             = 90,
  .a2aUnrollFactor               = 2,
  .a2aNumSubExecs                = 8,
  .a2aCopyLimit                  = 45,
  .hbmBlockSize                  = { 448,  448,  448,  384},
  .hbmUnrollFactor               = {   8,    3,    8,    7},
  .hbmTemporalMode               = {   3,    3,    3,    3},
  .hbmLimit                      = {4180, 2800, 1400, 1055},
};

TestConfig TestConfigs[NUM_SUPPORTED_MODELS] =
{
  Config_08_GFX0942_304,
  Config_08_GFX0942_064,
};
101

gilbertlee-amd's avatar
gilbertlee-amd committed
102
103
int DetectModel()
{
104
105
  int numGpuDevices = TransferBench::GetNumExecutors(EXE_GPU_GFX);

gilbertlee-amd's avatar
gilbertlee-amd committed
106
107
  std::string archName = "";
  int numSubExecutors = 0;
108

gilbertlee-amd's avatar
gilbertlee-amd committed
109
  // Loop over all GPUs and determine if they are identical
110
  for (int gpuId = 0; gpuId < numGpuDevices; gpuId++) {
gilbertlee-amd's avatar
gilbertlee-amd committed
111
    // Check that arch name is identical
112
113
114
    hipDeviceProp_t prop;
    HIP_CALL(hipGetDeviceProperties(&prop, gpuId));
    std::string fullName = prop.gcnArchName;
gilbertlee-amd's avatar
gilbertlee-amd committed
115
116
117
118
    std::string currArchName = fullName.substr(0, fullName.find(':'));
    if (archName != "" && archName != currArchName) {
      printf("[WARN] healthcheck preset is currently only supported when all GPUs are identical\n");
      printf("       Detected both %s and %s\n", archName.c_str(), currArchName.c_str());
119
120
      exit(1);
    }
gilbertlee-amd's avatar
gilbertlee-amd committed
121
122
123
124
125
126
127
128
129
130
    archName = currArchName;

    // Check number of subexecutors
    int currNumSubExecutors = TransferBench::GetNumSubExecutors({EXE_GPU_GFX, gpuId});
    if (numSubExecutors != 0 && numSubExecutors != currNumSubExecutors) {
      printf("[WARN] healthcheck preset is currently only supported when all GPUs are identical\n");
      printf("       Detected different subexecutor counts: %d and %d\n", numSubExecutors, currNumSubExecutors);
      exit(1);
    }
    numSubExecutors = currNumSubExecutors;
131
132
  }

gilbertlee-amd's avatar
gilbertlee-amd committed
133
134
135
136
137
138
139
140
141
  // Classify based on detected configuration
  if (numGpuDevices == 8) {
    if (archName == "gfx942") {
      switch (numSubExecutors) {
      case 304: return MODEL_08_GFX0942_304;
      case 64:  return MODEL_08_GFX0942_064;
      }
    }
  }
142

gilbertlee-amd's avatar
gilbertlee-amd committed
143
144
145
146
  printf("[WARN] healthcheck preset is currently not supported on this hardware\n");
  printf("       Detected %d x [%s] with [%d] subexecutors per GPU\n", numGpuDevices, archName.c_str(), numSubExecutors);
  exit(1);
}
147

gilbertlee-amd's avatar
gilbertlee-amd committed
148
149
150
151
152
153
154
155
156
157
158
159
int TestUnidir(int modelId, bool verbose)
{
  TestConfig const& testConfig = TestConfigs[modelId];
  TransferBench::ConfigOptions cfg;
  TransferBench::TestResults results;

  int hasFail = 0;
  int numGpuDevices = TransferBench::GetNumExecutors(EXE_GPU_GFX);
  cfg.dma.useHsaCopy = 1;

  // Run unidirectional host to device copy
  printf("Testing unidirectional host to device copy%c", verbose ? '\n' : ' ');
160
  {
gilbertlee-amd's avatar
gilbertlee-amd committed
161
162
    double limit = testConfig.unidirHostToDeviceCopyLimit * SFACTOR;

163
164
    std::vector<std::pair<int, double>> fails;
    for (int gpuId = 0; gpuId < numGpuDevices; gpuId++) {
gilbertlee-amd's avatar
gilbertlee-amd committed
165
166
      if (!verbose) printf(".");
      fflush(stdout);
167
168
169
170
171
172
173
174

      int memIndex = TransferBench::GetClosestCpuNumaToGpu(gpuId);
      if (memIndex == -1) {
        printf("[ERROR] Unable to detect closest CPU NUMA node to GPU %d\n", gpuId);
        exit(1);
      }

      std::vector<Transfer> transfers(1);
gilbertlee-amd's avatar
gilbertlee-amd committed
175
176
177
178
179
180
181
182
183
184
185
      Transfer& t   = transfers[0];
      t.exeDevice   = {EXE_GPU_DMA, gpuId};
      t.numBytes    = 256*1024*1024;
      t.srcs        = {{MEM_CPU, memIndex}};
      t.dsts        = {{MEM_GPU, gpuId}};
      t.numSubExecs = 1;

      if (TransferBench::RunTransfers(cfg, transfers, results)) {
        double measuredBw = results.tfrResults[0].avgBandwidthGbPerSec;
        if (measuredBw < limit) {
          fails.push_back(std::make_pair(gpuId, measuredBw));
186
        }
gilbertlee-amd's avatar
gilbertlee-amd committed
187
188
        if (verbose) printf("   GPU %02d: Measured %6.2f Limit %6.2f\n", gpuId, measuredBw, limit);
      } else {
189
        Utils::PrintErrors(results.errResults);
190
191
      }
    }
gilbertlee-amd's avatar
gilbertlee-amd committed
192

193
194
195
    if (fails.size() == 0) {
      printf("PASS\n");
    } else {
gilbertlee-amd's avatar
gilbertlee-amd committed
196
      hasFail = 1;
197
198
      printf("FAIL (%lu test(s))\n", fails.size());
      for (auto p : fails) {
gilbertlee-amd's avatar
gilbertlee-amd committed
199
        printf(" GPU %02d: Measured: %6.2f GB/s      Criteria: %6.2f GB/s\n", p.first, p.second, limit);
200
201
202
203
      }
    }
  }

gilbertlee-amd's avatar
gilbertlee-amd committed
204
205
  // Run unidirectional device to host copy
  printf("Testing unidirectional device to host copy%c", verbose ? '\n' : ' ');
206
  {
gilbertlee-amd's avatar
gilbertlee-amd committed
207
    double limit = testConfig.unidirDeviceToHostCopyLimit * SFACTOR;
208
209
210

    std::vector<std::pair<int, double>> fails;
    for (int gpuId = 0; gpuId < numGpuDevices; gpuId++) {
gilbertlee-amd's avatar
gilbertlee-amd committed
211
212
      if (!verbose) printf(".");
      fflush(stdout);
213
214
215
216
217
218
219
220

      int memIndex = TransferBench::GetClosestCpuNumaToGpu(gpuId);
      if (memIndex == -1) {
        printf("[ERROR] Unable to detect closest CPU NUMA node to GPU %d\n", gpuId);
        exit(1);
      }

      std::vector<Transfer> transfers(1);
gilbertlee-amd's avatar
gilbertlee-amd committed
221
222
223
224
225
226
227
228
229
230
231
      Transfer& t   = transfers[0];
      t.exeDevice   = {EXE_GPU_DMA, gpuId};
      t.numBytes    = 256*1024*1024;
      t.srcs        = {{MEM_GPU, gpuId}};
      t.dsts        = {{MEM_CPU, memIndex}};
      t.numSubExecs = 1;

      if (TransferBench::RunTransfers(cfg, transfers, results)) {
        double measuredBw = results.tfrResults[0].avgBandwidthGbPerSec;
        if (measuredBw < limit) {
          fails.push_back(std::make_pair(gpuId, measuredBw));
232
        }
gilbertlee-amd's avatar
gilbertlee-amd committed
233
234
        if (verbose) printf("   GPU %02d: Measured %6.2f Limit %6.2f\n", gpuId, measuredBw, limit);
      } else {
235
        Utils::PrintErrors(results.errResults);
236
237
      }
    }
gilbertlee-amd's avatar
gilbertlee-amd committed
238

239
240
241
    if (fails.size() == 0) {
      printf("PASS\n");
    } else {
gilbertlee-amd's avatar
gilbertlee-amd committed
242
      hasFail = 1;
243
244
      printf("FAIL (%lu test(s))\n", fails.size());
      for (auto p : fails) {
gilbertlee-amd's avatar
gilbertlee-amd committed
245
        printf(" GPU %02d: Measured: %6.2f GB/s      Criteria: %6.2f GB/s\n", p.first, p.second, limit);
246
247
248
      }
    }
  }
gilbertlee-amd's avatar
gilbertlee-amd committed
249
250
  return hasFail;
}
251

gilbertlee-amd's avatar
gilbertlee-amd committed
252
253
254
255
256
257
258
259
260
261
int TestBidir(int modelId, bool verbose)
{
  TestConfig const& testConfig = TestConfigs[modelId];
  TransferBench::ConfigOptions cfg;


  int hasFail = 0;
  int numGpuDevices = TransferBench::GetNumExecutors(EXE_GPU_GFX);

  printf("Testing bidirectional host<->device copies%c", verbose ? '\n' : ' ');
262
  {
gilbertlee-amd's avatar
gilbertlee-amd committed
263
    double limit = testConfig.bidirDmaCopyLimit * SFACTOR;
264
265
266

    std::vector<std::pair<int, double>> fails;
    for (int gpuId = 0; gpuId < numGpuDevices; gpuId++) {
gilbertlee-amd's avatar
gilbertlee-amd committed
267
268
      if (!verbose)  printf(".");
      fflush(stdout);
269
270
271
272
273
274
275
276
277
278
279

      int memIndex = TransferBench::GetClosestCpuNumaToGpu(gpuId);
      if (memIndex == -1) {
        printf("[ERROR] Unable to detect closest CPU NUMA node to GPU %d\n", gpuId);
        exit(1);
      }

      std::vector<Transfer> transfers(2);
      Transfer& t0 = transfers[0];
      Transfer& t1 = transfers[1];

gilbertlee-amd's avatar
gilbertlee-amd committed
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
      t0.exeDevice   = {EXE_GPU_DMA, gpuId};
      t0.numBytes    = 256*1024*1024;
      t0.srcs        = {{MEM_GPU, gpuId}};
      t0.dsts        = {{MEM_CPU, memIndex}};
      t0.numSubExecs = 1;

      t1.exeDevice   = {EXE_GPU_DMA, gpuId};
      t1.numBytes    = 256*1024*1024;
      t1.srcs        = {{MEM_CPU, memIndex}};
      t1.dsts        = {{MEM_GPU, gpuId}};
      t1.numSubExecs = 1;

      TransferBench::TestResults results;
      if (TransferBench::RunTransfers(cfg, transfers, results)) {
        double measuredBw = (results.tfrResults[0].avgBandwidthGbPerSec +
                             results.tfrResults[1].avgBandwidthGbPerSec);
        if (measuredBw < limit) {
          fails.push_back(std::make_pair(gpuId, measuredBw));
298
        }
gilbertlee-amd's avatar
gilbertlee-amd committed
299
300
        if (verbose) printf("   GPU %02d: Measured %6.2f Limit %6.2f\n", gpuId, measuredBw, limit);
      } else {
301
        Utils::PrintErrors(results.errResults);
302
303
      }
    }
gilbertlee-amd's avatar
gilbertlee-amd committed
304

305
306
307
    if (fails.size() == 0) {
      printf("PASS\n");
    } else {
gilbertlee-amd's avatar
gilbertlee-amd committed
308
      hasFail = 1;
309
310
      printf("FAIL (%lu test(s))\n", fails.size());
      for (auto p : fails) {
gilbertlee-amd's avatar
gilbertlee-amd committed
311
        printf(" GPU %02d: Measured: %6.2f GB/s      Criteria: %6.2f GB/s\n", p.first, p.second, limit);
312
313
314
      }
    }
  }
gilbertlee-amd's avatar
gilbertlee-amd committed
315
316
  return hasFail;
}
317

gilbertlee-amd's avatar
gilbertlee-amd committed
318
319
320
321
322
323
324
325
326
327
328
int TestAllToAll(int modelId, bool verbose)
{
  TestConfig const& testConfig = TestConfigs[modelId];
  TransferBench::ConfigOptions cfg;
  cfg.gfx.unrollFactor = testConfig.a2aUnrollFactor;

  int numSubExecs = testConfig.a2aNumSubExecs;
  int hasFail = 0;
  int numGpuDevices = TransferBench::GetNumExecutors(EXE_GPU_GFX);

  printf("Testing all-to-all XGMI copies            %c", verbose ? '\n' : ' '); fflush(stdout);
329
  {
gilbertlee-amd's avatar
gilbertlee-amd committed
330
    double limit = testConfig.a2aCopyLimit * SFACTOR;
331
332
333
334
335
336

    std::vector<Transfer> transfers;
    for (int i = 0; i < numGpuDevices; i++) {
      for (int j = 0; j < numGpuDevices; j++) {
        if (i == j) continue;
        Transfer t;
gilbertlee-amd's avatar
gilbertlee-amd committed
337
338
        t.numBytes    = 256*1024*1024;
        t.numSubExecs = numSubExecs;
339
340
341
342
343
344
345
        t.exeDevice   = {EXE_GPU_GFX, i};
        t.srcs        = {{MEM_GPU_FINE, i}};
        t.dsts        = {{MEM_GPU_FINE, j}};
        transfers.push_back(t);
      }
    }
    std::vector<std::pair<std::pair<int,int>, double>> fails;
gilbertlee-amd's avatar
gilbertlee-amd committed
346
    TransferBench::TestResults results;
347
348
349
    if (TransferBench::RunTransfers(cfg, transfers, results)) {
      int transferIdx = 0;
      for (int i = 0; i < numGpuDevices; i++) {
gilbertlee-amd's avatar
gilbertlee-amd committed
350
        if (!verbose) printf("."); fflush(stdout);
351
352
353
        for (int j = 0; j < numGpuDevices; j++) {
          if (i == j) continue;
          double bw = results.tfrResults[transferIdx].avgBandwidthGbPerSec;
gilbertlee-amd's avatar
gilbertlee-amd committed
354
          if (bw < limit) {
355
356
            fails.push_back(std::make_pair(std::make_pair(i,j), bw));
          }
gilbertlee-amd's avatar
gilbertlee-amd committed
357
          if (verbose) printf("   GPU %02d to GPU %02d: : Measured %6.2f Limit %6.2f\n", i, j, bw, limit);
358
359
360
361
362
363
364
          transferIdx++;
        }
      }
    }
    if (fails.size() == 0) {
      printf("PASS\n");
    } else {
gilbertlee-amd's avatar
gilbertlee-amd committed
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
      hasFail = 1;
      printf("FAIL (%lu test(s))\n", fails.size());
      for (auto p : fails) {
        printf(" GPU %02d to GPU %02d: %6.2f GB/s      Criteria: %6.2f GB/s\n", p.first.first, p.first.second, p.second, limit);
      }
    }
  }
  return hasFail;
}

int TestHbmPerformance(int modelId, bool verbose)
{
  TestConfig const& testConfig = TestConfigs[modelId];

  int hasFail = 0;
  int numGpuDevices = TransferBench::GetNumExecutors(EXE_GPU_GFX);
  char testname[50];

  for (int testId = 0; testId < NUM_HBM_TESTS; testId++) {
    TransferBench::ConfigOptions cfg;
    cfg.general.numIterations = 1000;
    cfg.general.numWarmups    = 50;
    cfg.gfx.blockSize         = testConfig.hbmBlockSize[testId];
    cfg.gfx.unrollFactor      = testConfig.hbmUnrollFactor[testId];
    cfg.gfx.temporalMode      = testConfig.hbmTemporalMode[testId];

    sprintf(testname, "Testing HBM performance [%s]", HbmTestConfigs[testId].name.c_str());
    if (verbose) printf("[Blocksize: %d Unroll: %d TemporalMode: %d]\n", cfg.gfx.blockSize, cfg.gfx.unrollFactor, cfg.gfx.temporalMode);
    printf("%-42s%c", testname, verbose ? '\n' : ' ');
    fflush(stdout);

    int numInputs = HbmTestConfigs[testId].numInputs;
    int numOutputs = HbmTestConfigs[testId].numOutputs;

    double limit = testConfig.hbmLimit[testId] * SFACTOR;

    std::vector<std::pair<int, double>> fails;
    TransferBench::TestResults results;
    std::vector<Transfer> transfers;

    for (int gpuId = 0; gpuId < numGpuDevices; gpuId++) {
      Transfer t;
      t.numSubExecs = TransferBench::GetNumSubExecutors({EXE_GPU_GFX, gpuId});
      t.numBytes    = 16777216ULL * t.numSubExecs;
      t.exeDevice   = {EXE_GPU_GFX, gpuId};
      for (int i = 0; i < numInputs; i++) t.srcs.push_back({MEM_GPU, gpuId});
      for (int i = 0; i < numOutputs; i++) t.dsts.push_back({MEM_GPU, gpuId});
      transfers.push_back(t);
    }

    if (TransferBench::RunTransfers(cfg, transfers, results)) {
      for (int gpuId = 0; gpuId < numGpuDevices; gpuId++) {
        if (!verbose) printf(".");
        fflush(stdout);
        double measuredBw = results.tfrResults[gpuId].avgBandwidthGbPerSec;
        if (measuredBw < limit) {
          fails.push_back(std::make_pair(gpuId, measuredBw));
        }
        if (verbose) printf("   GPU %02d: Measured %6.2f Limit %6.2f\n", gpuId, measuredBw, limit);
      }
    } else {
426
      Utils::PrintErrors(results.errResults);
gilbertlee-amd's avatar
gilbertlee-amd committed
427
428
429
430
431
432
    }

    if (fails.size() == 0) {
      printf("PASS\n");
    } else {
      hasFail = 1;
433
434
      printf("FAIL (%lu test(s))\n", fails.size());
      for (auto p : fails) {
gilbertlee-amd's avatar
gilbertlee-amd committed
435
        printf(" GPU %02d: Measured: %6.2f GB/s      Criteria: %6.2f GB/s\n", p.first, p.second, limit);
436
437
438
      }
    }
  }
gilbertlee-amd's avatar
gilbertlee-amd committed
439
440
441
  return hasFail;
}

442
443
444
int HealthCheckPreset(EnvVars&           ev,
                      size_t      const  numBytesPerTransfer,
                      std::string const  presetName)
gilbertlee-amd's avatar
gilbertlee-amd committed
445
{
446
447
448
449
450
  if (TransferBench::GetNumRanks() > 1) {
    Utils::Print("[ERROR] Healthcheck preset currently not supported for multi-node\n");
    return 1;
  }

gilbertlee-amd's avatar
gilbertlee-amd committed
451
452
453
  // Check for supported platforms
#if defined(__NVCC__)
  printf("[WARN] healthcheck preset not supported on NVIDIA hardware\n");
454
  return 0;
gilbertlee-amd's avatar
gilbertlee-amd committed
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#endif

  printf("Disclaimer:\n");
  printf("==================================================================\n");
  printf("NOTE: This is an experimental feature and may be subject to change\n");
  printf("      Failures do not necessarily indicate hardware issues, as other factors\n");
  printf("      such as simultaneous workloads may influence results\n");
  printf("\n");

  // Collect custom env vars for this preset
  int verbose = EnvVars::GetEnvVar("VERBOSE", 0);

  // Determine if this is a supported model
  int modelId = DetectModel();

  // Run through all tests
  int numFails = 0;
  numFails += TestHbmPerformance(modelId, verbose);
  numFails += TestUnidir(modelId, verbose);
  numFails += TestBidir(modelId, verbose);
  numFails += TestAllToAll(modelId, verbose);
476
  return numFails ? 1 : 0;
477
}