|
| 1 | +/* |
| 2 | +Copyright (c) Advanced Micro Devices, Inc. All rights reserved. |
| 3 | +
|
| 4 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +of this software and associated documentation files (the "Software"), to deal |
| 6 | +in the Software without restriction, including without limitation the rights |
| 7 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +copies of the Software, and to permit persons to whom the Software is |
| 9 | +furnished to do so, subject to the following conditions: |
| 10 | +
|
| 11 | +The above copyright notice and this permission notice shall be included in |
| 12 | +all copies or substantial portions of the Software. |
| 13 | +
|
| 14 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | +THE SOFTWARE. |
| 21 | +*/ |
| 22 | + |
| 23 | +int BmaSweepPreset(EnvVars& ev, |
| 24 | + size_t const numBytesPerTransfer, |
| 25 | + std::string const presetName, |
| 26 | + bool const bytesSpecified) |
| 27 | +{ |
| 28 | + if (TransferBench::GetNumRanks() > 1) { |
| 29 | + Utils::Print("[ERROR] BMA sweep preset currently not supported for multi-node\n"); |
| 30 | + return 1; |
| 31 | + } |
| 32 | + |
| 33 | +#ifndef BMA_EXEC_ENABLED |
| 34 | + Utils::Print("[ERROR] BMA executor requires ROCm 7.0 or newer\n"); |
| 35 | + return 1; |
| 36 | +#endif |
| 37 | + |
| 38 | + int numDetectedGpus = TransferBench::GetNumExecutors(EXE_GPU_GFX); |
| 39 | + |
| 40 | + // Collect env vars for this preset |
| 41 | + int exeIndex = EnvVars::GetEnvVar("EXE_INDEX" , 0); |
| 42 | + int localCopy = EnvVars::GetEnvVar("LOCAL_COPY" , 0); |
| 43 | + int gpuMemTypeIdx = EnvVars::GetEnvVar("GPU_MEM_TYPE" , 0); |
| 44 | + int numGpuDevices = EnvVars::GetEnvVar("NUM_GPU_DEVICES" , numDetectedGpus); |
| 45 | + vector<int> numSesList = EnvVars::GetEnvVarArray("NUM_SUB_EXECS", {1,2,4,8}); |
| 46 | + |
| 47 | + MemType gpuMemType = Utils::GetGpuMemType(gpuMemTypeIdx); |
| 48 | + |
| 49 | + // Display environment variables |
| 50 | + if (Utils::RankDoesOutput()) { |
| 51 | + ev.DisplayEnvVars(); |
| 52 | + if (!ev.hideEnv) { |
| 53 | + int outputToCsv = ev.outputToCsv; |
| 54 | + if (!outputToCsv) printf("[BMA Sweep Related]\n"); |
| 55 | + ev.Print("EXE_INDEX" , exeIndex, "Executing on GPU %d", exeIndex); |
| 56 | + ev.Print("LOCAL_COPY" , localCopy, "%s local copy to GPU %d", localCopy ? "Including" : "Excluding", exeIndex); |
| 57 | + ev.Print("GPU_MEM_TYPE" , gpuMemTypeIdx, "Using %s (%s)", Utils::GetGpuMemTypeStr(gpuMemTypeIdx).c_str(), Utils::GetAllGpuMemTypeStr().c_str()); |
| 58 | + ev.Print("NUM_GPU_DEVICES", numGpuDevices, "Using %d GPUs", numGpuDevices); |
| 59 | + ev.Print("NUM_SUB_EXECS" , numSesList.size(), EnvVars::ToStr(numSesList).c_str()); |
| 60 | + printf("\n"); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + if (exeIndex < 0 || exeIndex >= numGpuDevices) { |
| 65 | + Utils::Print("EXE_INDEX must be between 0 and %d inclusively\n", numGpuDevices - 1); |
| 66 | + return 1; |
| 67 | + } |
| 68 | + |
| 69 | + int numTransfers = numGpuDevices - 1 + (localCopy ? 1 : 0); |
| 70 | + |
| 71 | + TransferBench::ConfigOptions cfg = ev.ToConfigOptions(); |
| 72 | + TransferBench::TestResults results; |
| 73 | + |
| 74 | + // Prepare table of results |
| 75 | + int minPow2Exp = 12; |
| 76 | + int maxPow2Exp = 30; |
| 77 | + int numRows = (maxPow2Exp - minPow2Exp + 1) + 1; |
| 78 | + int numCols = 2 + numSesList.size(); |
| 79 | + |
| 80 | + Utils::TableHelper table(numRows, numCols); |
| 81 | + |
| 82 | + Utils::Print("Performing %d simultaneous DMA Transfers from GPU %0 to other GPUs\n", numTransfers, exeIndex); |
| 83 | + |
| 84 | + // Prepare headers |
| 85 | + table.Set(0, 0, " Bytes "); |
| 86 | + table.Set(0, 1, " DMA "); |
| 87 | + for (int i = 0; i < numSesList.size(); i++) { |
| 88 | + table.Set(0, 2+i, " BMA (%d) ", numSesList[i]); |
| 89 | + } |
| 90 | + table.DrawRowBorder(0); |
| 91 | + table.DrawRowBorder(1); |
| 92 | + table.DrawRowBorder(numRows); |
| 93 | + table.DrawColBorder(0); |
| 94 | + table.DrawColBorder(1); |
| 95 | + table.DrawColBorder(2); |
| 96 | + table.DrawColBorder(numCols); |
| 97 | + |
| 98 | + if (!ev.outputToCsv){ |
| 99 | + Utils::Print("Executing: "); |
| 100 | + fflush(stdout); |
| 101 | + }; |
| 102 | + |
| 103 | + for (size_t numBytes = 1ULL<<minPow2Exp, currRow=1; numBytes <= (1ULL<<maxPow2Exp); numBytes<<=1, currRow++) { |
| 104 | + if (!ev.outputToCsv) { |
| 105 | + Utils::Print("."); |
| 106 | + fflush(stdout); |
| 107 | + } |
| 108 | + |
| 109 | + table.Set(currRow, 0, " %lu ", numBytes); |
| 110 | + std::vector<Transfer> transfers(1); |
| 111 | + |
| 112 | + Transfer& t = transfers[0]; |
| 113 | + t.numBytes = numBytes; |
| 114 | + t.srcs = {{gpuMemType, exeIndex}}; |
| 115 | + t.dsts.clear(); |
| 116 | + for (int i = 0; i < numGpuDevices; i++) { |
| 117 | + if (i == exeIndex && localCopy == 0) continue; |
| 118 | + t.dsts.push_back({gpuMemType, i}); |
| 119 | + } |
| 120 | + |
| 121 | + // DMA executor first |
| 122 | + t.exeDevice = {EXE_GPU_DMA, exeIndex}; |
| 123 | + t.numSubExecs = 1; |
| 124 | + |
| 125 | + if (!TransferBench::RunTransfers(cfg, transfers, results)) { |
| 126 | + for (auto const& err : results.errResults) |
| 127 | + Utils::Print("%s\n", err.errMsg.c_str()); |
| 128 | + return 1; |
| 129 | + } |
| 130 | + |
| 131 | + table.Set(currRow, 1, " %6.2f ", numTransfers * results.tfrResults[0].avgBandwidthGbPerSec); |
| 132 | + |
| 133 | + // BMA executor next |
| 134 | + t.exeDevice = {EXE_GPU_BDMA, exeIndex}; |
| 135 | + for (int i = 0; i < numSesList.size(); i++) { |
| 136 | + t.numSubExecs = numSesList[i]; |
| 137 | + |
| 138 | + if (!TransferBench::RunTransfers(cfg, transfers, results)) { |
| 139 | + for (auto const& err : results.errResults) |
| 140 | + Utils::Print("%s\n", err.errMsg.c_str()); |
| 141 | + return 1; |
| 142 | + } |
| 143 | + |
| 144 | + table.Set(currRow, 2+i, " %6.2f ", numTransfers * results.tfrResults[0].avgBandwidthGbPerSec); |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + if (!ev.outputToCsv) { |
| 149 | + Utils::Print("\n"); |
| 150 | + } |
| 151 | + table.PrintTable(ev.outputToCsv, ev.showBorders); |
| 152 | + Utils::Print("Reported numbers are all GB/s, normalized for per Transfer for %d Transfers\n", numTransfers); |
| 153 | + |
| 154 | + return 0; |
| 155 | +} |
0 commit comments