HealthCheck.hpp 18.1 KB
Newer Older
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
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
/*
Copyright (c) Advanced Micro Devices, Inc. All rights reserved.

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.
*/

#ifndef HEALTH_CHECK_PRESET_HPP
#define HEALTH_CHECK_PRESET_HPP

#include "EnvVars.hpp"

#include <cstddef>
#include <cstdint>
#include <map>
#include <string>
#include <vector>


enum
{
    HBM_READ      = 0,
    HBM_WRITE     = 1,
    HBM_COPY      = 2,
    HBM_ADD       = 3,
    NUM_HBM_TESTS = 4
} HbmTests;

struct HbmTestConfig
{
    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,
};

int DetectModel()
{
    int numGpuDevices = TransferBench::GetNumExecutors(EXE_GPU_GFX);

    std::string archName = "";
    int numSubExecutors  = 0;

    // Loop over all GPUs and determine if they are identical
    for (int gpuId = 0; gpuId < numGpuDevices; gpuId++) {
        // Check that arch name is identical
        hipDeviceProp_t prop;
        HIP_CALL(hipGetDeviceProperties(&prop, gpuId));
        std::string fullName     = prop.gcnArchName;
        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());
            exit(1);
        }
        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;
    }

    // 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;
            }
        }
    }

    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);
}

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' : ' ');
    {
        double limit = testConfig.unidirHostToDeviceCopyLimit * SFACTOR;

        std::vector<std::pair<int, double>> fails;
        for (int gpuId = 0; gpuId < numGpuDevices; gpuId++) {
            if (!verbose) { printf("."); }
            fflush(stdout);

            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);
            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)); }
                if (verbose) {
                    printf("   GPU %02d: Measured %6.2f Limit %6.2f\n", gpuId, measuredBw, limit);
                }
            } else {
                PrintErrors(results.errResults);
            }
        }

        if (fails.size() == 0) {
            printf("PASS\n");
        } else {
            hasFail = 1;
            printf("FAIL (%lu test(s))\n", fails.size());
            for (auto p : fails) {
                printf(" GPU %02d: Measured: %6.2f GB/s      Criteria: %6.2f GB/s\n",
                       p.first,
                       p.second,
                       limit);
            }
        }
    }

    // Run unidirectional device to host copy
    printf("Testing unidirectional device to host copy%c", verbose ? '\n' : ' ');
    {
        double limit = testConfig.unidirDeviceToHostCopyLimit * SFACTOR;

        std::vector<std::pair<int, double>> fails;
        for (int gpuId = 0; gpuId < numGpuDevices; gpuId++) {
            if (!verbose) { printf("."); }
            fflush(stdout);

            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);
            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)); }
                if (verbose) {
                    printf("   GPU %02d: Measured %6.2f Limit %6.2f\n", gpuId, measuredBw, limit);
                }
            } else {
                PrintErrors(results.errResults);
            }
        }

        if (fails.size() == 0) {
            printf("PASS\n");
        } else {
            hasFail = 1;
            printf("FAIL (%lu test(s))\n", fails.size());
            for (auto p : fails) {
                printf(" GPU %02d: Measured: %6.2f GB/s      Criteria: %6.2f GB/s\n",
                       p.first,
                       p.second,
                       limit);
            }
        }
    }
    return hasFail;
}

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' : ' ');
    {
        double limit = testConfig.bidirDmaCopyLimit * SFACTOR;

        std::vector<std::pair<int, double>> fails;
        for (int gpuId = 0; gpuId < numGpuDevices; gpuId++) {
            if (!verbose) { printf("."); }
            fflush(stdout);

            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];

            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)); }
                if (verbose) {
                    printf("   GPU %02d: Measured %6.2f Limit %6.2f\n", gpuId, measuredBw, limit);
                }
            } else {
                PrintErrors(results.errResults);
            }
        }

        if (fails.size() == 0) {
            printf("PASS\n");
        } else {
            hasFail = 1;
            printf("FAIL (%lu test(s))\n", fails.size());
            for (auto p : fails) {
                printf(" GPU %02d: Measured: %6.2f GB/s      Criteria: %6.2f GB/s\n",
                       p.first,
                       p.second,
                       limit);
            }
        }
    }
    return hasFail;
}

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);
    {
        double limit = testConfig.a2aCopyLimit * SFACTOR;

        std::vector<Transfer> transfers;
        for (int i = 0; i < numGpuDevices; i++) {
            for (int j = 0; j < numGpuDevices; j++) {
                if (i == j) { continue; }
                Transfer t;
                t.numBytes    = 256 * 1024 * 1024;
                t.numSubExecs = numSubExecs;
                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;
        TransferBench::TestResults results;
        if (TransferBench::RunTransfers(cfg, transfers, results)) {
            int transferIdx = 0;
            for (int i = 0; i < numGpuDevices; i++) {
                if (!verbose) { printf("."); }
                fflush(stdout);
                for (int j = 0; j < numGpuDevices; j++) {
                    if (i == j) { continue; }
                    double bw = results.tfrResults[transferIdx].avgBandwidthGbPerSec;
                    if (bw < limit) { fails.push_back(std::make_pair(std::make_pair(i, j), bw)); }
                    if (verbose) {
                        printf("   GPU %02d to GPU %02d: : Measured %6.2f Limit %6.2f\n",
                               i,
                               j,
                               bw,
                               limit);
                    }
                    transferIdx++;
                }
            }
        }
        if (fails.size() == 0) {
            printf("PASS\n");
        } else {
            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 {
            PrintErrors(results.errResults);
        }

        if (fails.size() == 0) {
            printf("PASS\n");
        } else {
            hasFail = 1;
            printf("FAIL (%lu test(s))\n", fails.size());
            for (auto p : fails) {
                printf(" GPU %02d: Measured: %6.2f GB/s      Criteria: %6.2f GB/s\n",
                       p.first,
                       p.second,
                       limit);
            }
        }
    }
    return hasFail;
}

void HealthCheckPreset([[maybe_unused]] EnvVars& ev,
                       [[maybe_unused]] size_t const numBytesPerTransfer,
                       [[maybe_unused]] std::string const presetName)
{
    // Check for supported platforms
#if defined(__NVCC__)
    printf("[WARN] healthcheck preset not supported on NVIDIA hardware\n");
    return;
#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);
    exit(numFails ? 1 : 0);
}

#endif    // HEALTH_CHECK_PRESET_HPP