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

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

#include "EnvVars.hpp"

25
26
27
int AllToAllRdmaPreset(EnvVars&           ev,
                       size_t      const  numBytesPerTransfer,
                       std::string const  presetName)
gilbertlee-amd's avatar
gilbertlee-amd committed
28
{
29
30
31
32
  if (TransferBench::GetNumRanks() > 1) {
    Utils::Print("[ERROR]a2an preset currently not supported for multi-node\n");
    return 1;
  }
gilbertlee-amd's avatar
gilbertlee-amd committed
33
34
35
36
37
38

  int numDetectedGpus = TransferBench::GetNumExecutors(EXE_GPU_GFX);

  // Collect env vars for this preset
  int numGpus       = EnvVars::GetEnvVar("NUM_GPU_DEVICES", numDetectedGpus);
  int numQueuePairs = EnvVars::GetEnvVar("NUM_QUEUE_PAIRS", 1);
39
40
41
42
43
44
45
46
47
48
  int memTypeIdx    = EnvVars::GetEnvVar("MEM_TYPE"       , 2);
  int useFineGrain  = EnvVars::GetEnvVar("USE_FINE_GRAIN" , -999); // Deprecated

  // Deprecated env var check
  if (useFineGrain != -999) {
    memTypeIdx = useFineGrain ? 2 : 0;
  }

  MemType memType = Utils::GetGpuMemType(memTypeIdx);
  std::string memTypeStr = Utils::GetGpuMemTypeStr(memTypeIdx);
gilbertlee-amd's avatar
gilbertlee-amd committed
49
50

  // Print off environment variables
51
52
53
54
55
56
57
58
59
  if (Utils::RankDoesOutput()) {
    ev.DisplayEnvVars();
    if (!ev.hideEnv) {
      if (!ev.outputToCsv) printf("[AllToAll Network Related]\n");
      ev.Print("NUM_GPU_DEVICES", numGpus      , "Using %d GPUs", numGpus);
      ev.Print("NUM_QUEUE_PAIRS", numQueuePairs, "Using %d queue pairs for NIC transfers", numQueuePairs);
      ev.Print("MEM_TYPE"       , memTypeIdx   , "Using %s memory (%s)", memTypeStr.c_str(), Utils::GetAllGpuMemTypeStr().c_str());
      printf("\n");
    }
gilbertlee-amd's avatar
gilbertlee-amd committed
60
61
62
63
  }

  // Validate env vars
  if (numGpus < 0 || numGpus > numDetectedGpus) {
64
65
    Utils::Print("[ERROR] Cannot use %d GPUs.  Detected %d GPUs\n", numGpus, numDetectedGpus);
    return 1;
gilbertlee-amd's avatar
gilbertlee-amd committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  }


  std::map<std::pair<int, int>, int> reIndex;
  std::vector<Transfer> transfers;
  for (int i = 0; i < numGpus; i++) {
    for (int j = 0; j < numGpus; j++) {
      // Build Transfer and add it to list
      TransferBench::Transfer transfer;
      transfer.numBytes = numBytesPerTransfer;
      transfer.srcs.push_back({memType, i});
      transfer.dsts.push_back({memType, j});
      transfer.exeDevice = {EXE_NIC_NEAREST, i};
      transfer.exeSubIndex = j;
      transfer.numSubExecs = numQueuePairs;

      reIndex[std::make_pair(i,j)] = transfers.size();
      transfers.push_back(transfer);
    }
  }

87
88
89
  Utils::Print("GPU-RDMA All-To-All benchmark:\n");
  Utils::Print("==========================\n");
  Utils::Print("- Copying %lu bytes between all pairs of GPUs using %d QPs per Transfer (%lu Transfers)\n",
gilbertlee-amd's avatar
gilbertlee-amd committed
90
         numBytesPerTransfer, numQueuePairs, transfers.size());
91
  if (transfers.size() == 0) return 0;
gilbertlee-amd's avatar
gilbertlee-amd committed
92
93
94
95
96
97

  // Execute Transfers
  TransferBench::ConfigOptions cfg = ev.ToConfigOptions();
  TransferBench::TestResults results;
  if (!TransferBench::RunTransfers(cfg, transfers, results)) {
    for (auto const& err : results.errResults)
98
99
      Utils::Print("%s\n", err.errMsg.c_str());
    return 1;
gilbertlee-amd's avatar
gilbertlee-amd committed
100
  } else {
101
    Utils::PrintResults(ev, 1, transfers, results);
gilbertlee-amd's avatar
gilbertlee-amd committed
102
103
104
105
  }

  // Print results
  char separator = (ev.outputToCsv ? ',' : ' ');
106
107
108
  Utils::Print("\nSummary: [%lu bytes per Transfer]\n", numBytesPerTransfer);
  Utils::Print("==========================================================\n");
  Utils::Print("SRC\\DST ");
gilbertlee-amd's avatar
gilbertlee-amd committed
109
  for (int dst = 0; dst < numGpus; dst++)
110
111
    Utils::Print("%cGPU %02d    ", separator, dst);
  Utils::Print("   %cSTotal     %cActual\n", separator, separator);
gilbertlee-amd's avatar
gilbertlee-amd committed
112
113
114
115
116
117
118
119
120

  double totalBandwidthGpu = 0.0;
  double minActualBandwidth = std::numeric_limits<double>::max();
  double maxActualBandwidth = 0.0;
  std::vector<double> colTotalBandwidth(numGpus+2, 0.0);
  for (int src = 0; src < numGpus; src++) {
    double rowTotalBandwidth = 0;
    int    transferCount = 0;
    double minBandwidth = std::numeric_limits<double>::max();
121
    Utils::Print("GPU %02d", src);
gilbertlee-amd's avatar
gilbertlee-amd committed
122
123
124
125
126
127
128
129
130
    for (int dst = 0; dst < numGpus; dst++) {
      if (reIndex.count(std::make_pair(src, dst))) {
        int const transferIdx = reIndex[std::make_pair(src,dst)];
        TransferBench::TransferResult const& r = results.tfrResults[transferIdx];
        colTotalBandwidth[dst]  += r.avgBandwidthGbPerSec;
        rowTotalBandwidth       += r.avgBandwidthGbPerSec;
        totalBandwidthGpu       += r.avgBandwidthGbPerSec;
        minBandwidth             = std::min(minBandwidth, r.avgBandwidthGbPerSec);
        transferCount++;
131
        Utils::Print("%c%8.3f  ", separator, r.avgBandwidthGbPerSec);
gilbertlee-amd's avatar
gilbertlee-amd committed
132
      } else {
133
        Utils::Print("%c%8s  ", separator, "N/A");
gilbertlee-amd's avatar
gilbertlee-amd committed
134
135
136
      }
    }
    double actualBandwidth = minBandwidth * transferCount;
137
    Utils::Print("   %c%8.3f   %c%8.3f\n", separator, rowTotalBandwidth, separator, actualBandwidth);
gilbertlee-amd's avatar
gilbertlee-amd committed
138
139
140
141
    minActualBandwidth = std::min(minActualBandwidth, actualBandwidth);
    maxActualBandwidth = std::max(maxActualBandwidth, actualBandwidth);
    colTotalBandwidth[numGpus+1] += rowTotalBandwidth;
  }
142
  Utils::Print("\nRTotal");
gilbertlee-amd's avatar
gilbertlee-amd committed
143
  for (int dst = 0; dst < numGpus; dst++) {
144
    Utils::Print("%c%8.3f  ", separator, colTotalBandwidth[dst]);
gilbertlee-amd's avatar
gilbertlee-amd committed
145
  }
146
  Utils::Print("   %c%8.3f   %c%8.3f   %c%8.3f\n", separator, colTotalBandwidth[numGpus+1],
gilbertlee-amd's avatar
gilbertlee-amd committed
147
         separator, minActualBandwidth, separator, maxActualBandwidth);
148
149
150
151
152
  Utils::Print("\n");

  Utils::Print("Average   bandwidth (Tx Thread Timed): %8.3f GB/s\n", totalBandwidthGpu / transfers.size());
  Utils::Print("Aggregate bandwidth (Tx Thread Timed): %8.3f GB/s\n", totalBandwidthGpu);
  Utils::Print("Aggregate bandwidth       (CPU Timed): %8.3f GB/s\n", results.avgTotalBandwidthGbPerSec);
gilbertlee-amd's avatar
gilbertlee-amd committed
153

154
  Utils::PrintErrors(results.errResults);
gilbertlee-amd's avatar
gilbertlee-amd committed
155

156
  return 0;
gilbertlee-amd's avatar
gilbertlee-amd committed
157
}