Schmoo.hpp 5.78 KB
Newer Older
1
/*
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

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.
*/
22
23
24
int SchmooPreset(EnvVars&           ev,
                 size_t      const  numBytesPerTransfer,
                 std::string const  presetName)
25
{
26
27
28
29
30
  if (TransferBench::GetNumRanks() > 1) {
    Utils::Print("[ERROR] Schmoo preset currently not supported for multi-node\n");
    return 1;
  }

31
32
33
34
  int numDetectedGpus = TransferBench::GetNumExecutors(EXE_GPU_GFX);

  if (numDetectedGpus < 2) {
    printf("[ERROR] Schmoo benchmark requires at least 2 GPUs\n");
35
    return 1;
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
  }

  // Collect env vars for this preset
  int localIdx     = EnvVars::GetEnvVar("LOCAL_IDX",      0);
  int remoteIdx    = EnvVars::GetEnvVar("REMOTE_IDX",     1);
  int sweepMax     = EnvVars::GetEnvVar("SWEEP_MAX",      32);
  int sweepMin     = EnvVars::GetEnvVar("SWEEP_MIN",      1);
  int useFineGrain = EnvVars::GetEnvVar("USE_FINE_GRAIN", 0);

  // Display environment variables
  ev.DisplayEnvVars();
  if (!ev.hideEnv) {
    int outputToCsv = ev.outputToCsv;
    if (!outputToCsv) printf("[Schmoo Related]\n");
    ev.Print("LOCAL_IDX",      localIdx,     "Local GPU index");
    ev.Print("REMOTE_IDX",     remoteIdx,    "Remote GPU index");
    ev.Print("SWEEP_MAX",      sweepMax,     "Max number of subExecutors to use");
    ev.Print("SWEEP_MIN",      sweepMin,     "Min number of subExecutors to use");
    ev.Print("USE_FINE_GRAIN", useFineGrain, "Using %s-grained memory", useFineGrain ? "fine" : "coarse");
    printf("\n");
  }

  // Validate env vars
  if (localIdx >= numDetectedGpus || remoteIdx >= numDetectedGpus) {
    printf("[ERROR] Cannot execute schmoo test with local GPU device %d, remote GPU device %d\n", localIdx, remoteIdx);
61
    return 1;
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
  }

  TransferBench::ConfigOptions cfg = ev.ToConfigOptions();
  TransferBench::TestResults results;

  char memChar = useFineGrain ? 'F' : 'G';
  printf("Bytes to transfer: %lu Local GPU: %d Remote GPU: %d\n", numBytesPerTransfer, localIdx, remoteIdx);
  printf("       | Local Read  | Local Write | Local Copy  | Remote Read | Remote Write| Remote Copy |\n");
  printf("  #CUs |%c%02d->G%02d->N00|N00->G%02d->%c%02d|%c%02d->G%02d->%c%02d|%c%02d->G%02d->N00|N00->G%02d->%c%02d|%c%02d->G%02d->%c%02d|\n",
         memChar, localIdx, localIdx,
         localIdx, memChar, localIdx,
         memChar, localIdx, localIdx, memChar, localIdx,
         memChar, remoteIdx, localIdx,
         localIdx, memChar, remoteIdx,
         memChar, localIdx, localIdx, memChar, remoteIdx);
  printf("|------|-------------|-------------|-------------|-------------|-------------|-------------|\n");

  std::vector<Transfer> transfers(1);
  Transfer& t   = transfers[0];
  t.exeDevice   = {EXE_GPU_GFX, localIdx};
  t.exeSubIndex = -1;
  t.numBytes    = numBytesPerTransfer;

  MemType memType = (useFineGrain ? MEM_GPU_FINE : MEM_GPU);

  for (int numCUs = sweepMin; numCUs <= sweepMax; numCUs++) {
    t.numSubExecs = numCUs;

    // Local Read
    t.srcs = {{memType, localIdx}};
    t.dsts = {};
93
94
95
    if (!TransferBench::RunTransfers(cfg, transfers, results)) {
      Utils::PrintErrors(results.errResults);
      return 1;
96
97
98
99
100
101
    }
    double const localRead = results.tfrResults[0].avgBandwidthGbPerSec;

    // Local Write
    t.srcs = {};
    t.dsts = {{memType, localIdx}};
102
103
104
    if (!TransferBench::RunTransfers(cfg, transfers, results)) {
      Utils::PrintErrors(results.errResults);
      return 1;
105
106
107
108
109
110
111
112
    }
    double const localWrite = results.tfrResults[0].avgBandwidthGbPerSec;

    // Local Copy
    t.srcs = {{memType, localIdx}};
    t.dsts = {{memType, localIdx}};
    t.srcs = {};
    t.dsts = {{memType, localIdx}};
113
114
115
    if (!TransferBench::RunTransfers(cfg, transfers, results)) {
      Utils::PrintErrors(results.errResults);
      return 1;
116
117
118
119
120
121
    }
    double const localCopy = results.tfrResults[0].avgBandwidthGbPerSec;

    // Remote Read
    t.srcs = {{memType, remoteIdx}};
    t.dsts = {};
122
123
124
    if (!TransferBench::RunTransfers(cfg, transfers, results)) {
      Utils::PrintErrors(results.errResults);
      return 1;
125
126
127
128
129
130
    }
    double const remoteRead = results.tfrResults[0].avgBandwidthGbPerSec;

    // Remote Write
    t.srcs = {};
    t.dsts = {{memType, remoteIdx}};
131
132
133
    if (!TransferBench::RunTransfers(cfg, transfers, results)) {
      Utils::PrintErrors(results.errResults);
      return 1;
134
135
136
137
138
139
    }
    double const remoteWrite = results.tfrResults[0].avgBandwidthGbPerSec;

    // Remote Copy
    t.srcs = {{memType, localIdx}};
    t.dsts = {{memType, remoteIdx}};
140
141
142
    if (!TransferBench::RunTransfers(cfg, transfers, results)) {
      Utils::PrintErrors(results.errResults);
      return 1;
143
144
145
146
147
148
    }
    double const remoteCopy = results.tfrResults[0].avgBandwidthGbPerSec;

    printf("   %3d   %11.3f   %11.3f   %11.3f   %11.3f   %11.3f   %11.3f  \n",
           numCUs, localRead, localWrite, localCopy, remoteRead, remoteWrite, remoteCopy);
  }
149
  return 0;
150
}