/* 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 ENVVARS_HPP #define ENVVARS_HPP // Helper macro for catching HIP errors #define HIP_CALL(cmd) \ do { \ hipError_t error = (cmd); \ if (error != hipSuccess) { \ std::cerr << "Encountered HIP error (" << hipGetErrorString(error) \ << ") at line " << __LINE__ << " in file " << __FILE__ << "\n"; \ exit(-1); \ } \ } while (0) #include #include #include #include #include #define CLIENT_VERSION "00" #include "TransferBench.hpp" using namespace TransferBench; // Redefinitions for CUDA compatibility //========================================================================================== #if defined(__NVCC__) #define hipError_t cudaError_t #define hipGetErrorString cudaGetErrorString #define hipDeviceProp_t cudaDeviceProp #define hipDeviceGetPCIBusId cudaDeviceGetPCIBusId #define hipGetDeviceProperties cudaGetDeviceProperties #define hipSuccess cudaSuccess #define gcnArchName name #define hipGetDeviceCount cudaGetDeviceCount #endif // This class manages environment variable that affect TransferBench class EnvVars { public: // Default configuration values int const DEFAULT_SAMPLING_FACTOR = 1; // Environment variables // General options int numIterations; // Number of timed iterations to perform. If negative, run for -numIterations seconds instead int numSubIterations; // Number of subiterations to perform int numWarmups; // Number of un-timed warmup iterations to perform int showBorders; // Show ASCII box-drawing characaters in tables int showIterations; // Show per-iteration timing info int useInteractive; // Pause for user-input before starting transfer loop // Data options int alwaysValidate; // Validate after each iteration instead of once after all iterations int blockBytes; // Each subexecutor, except the last, gets a multiple of this many bytes to copy int byteOffset; // Byte-offset for memory allocations vector fillPattern; // Pattern of floats used to fill source data vector fillCompress; // Percentages of 64B lines to be filled by random/1B0/2B0/4B0/32B0 int validateDirect; // Validate GPU destination memory directly instead of staging GPU memory on host int validateSource; // Validate source GPU memory immediately after preparation // DMA options int useHsaDma; // Use hsa_amd_async_copy instead of hipMemcpy for non-targetted DMA executions // GFX options int gfxBlockOrder; // How threadblocks for multiple Transfers are ordered 0=sequential 1=interleaved int gfxBlockSize; // Size of each threadblock (must be multiple of 64) vector cuMask; // Bit-vector representing the CU mask vector> prefXccTable; // Specifies XCC to use for given exe->dst pair int gfxSeType; // GFX subexecutor type (0=threadblock, 1=warp) int gfxTemporal; // Non-temporal load/store mode (0=none, 1=load, 2=store, 3=both) int gfxUnroll; // GFX-kernel unroll factor int useHipEvents; // Use HIP events for timing GFX/DMA Executor int useSingleStream; // Use a single stream per GPU GFX executor instead of stream per Transfer int gfxSingleTeam; // Team all subExecutors across the data array int gfxWaveOrder; // GFX-kernel wavefront ordering int gfxWordSize; // GFX-kernel packed data size (4=DWORDx4, 2=DWORDx2, 1=DWORDx1) // Client options int hideEnv; // Skip printing environment variable int minNumVarSubExec; // Minimum # of subexecutors to use for variable subExec Transfers int maxNumVarSubExec; // Maximum # of subexecutors to use for variable subExec Transfers (0 to use device limit) int outputToCsv; // Output in CSV format int samplingFactor; // Affects how many different values of N are generated (when N set to 0) // NIC options int ibGidIndex; // GID Index for RoCE NICs uint8_t ibPort; // NIC port number to be used int ipAddressFamily; // IP Address Famliy int nicChunkBytes; // Number of bytes to send per chunk for RDMA operations int nicRelaxedOrder; // Use relaxed ordering for RDMA int roceVersion; // RoCE version number // Developer features int gpuMaxHwQueues; // Tracks GPU_MAX_HW_QUEUES environment variable // Constructor that collects values EnvVars() { // Try to detect the GPU hipDeviceProp_t prop; std::string fullName = ""; std::string archName = ""; int numDetectedGpus = TransferBench::GetNumExecutors(EXE_GPU_GFX); if (numDetectedGpus > 0) { HIP_CALL(hipGetDeviceProperties(&prop, 0)); fullName = prop.gcnArchName; archName = fullName.substr(0, fullName.find(':')); } // Different hardware pick different GPU kernels // This performance difference is generally only noticable when executing fewer CUs int defaultGfxUnroll = 4; if (archName == "gfx906") defaultGfxUnroll = 8; else if (archName == "gfx90a") defaultGfxUnroll = 8; else if (archName == "gfx942") defaultGfxUnroll = 4; else if (archName == "gfx950") defaultGfxUnroll = 4; alwaysValidate = GetEnvVar("ALWAYS_VALIDATE" , 0); blockBytes = GetEnvVar("BLOCK_BYTES" , 256); byteOffset = GetEnvVar("BYTE_OFFSET" , 0); fillCompress = GetEnvVarArray("FILL_COMPRESS" , {}); gfxBlockOrder = GetEnvVar("GFX_BLOCK_ORDER" , 0); gfxBlockSize = GetEnvVar("GFX_BLOCK_SIZE" , 256); gfxSeType = GetEnvVar("GFX_SE_TYPE" , 0); gfxSingleTeam = GetEnvVar("GFX_SINGLE_TEAM" , 1); gfxTemporal = GetEnvVar("GFX_TEMPORAL" , 0); gfxUnroll = GetEnvVar("GFX_UNROLL" , defaultGfxUnroll); gfxWaveOrder = GetEnvVar("GFX_WAVE_ORDER" , 0); gfxWordSize = GetEnvVar("GFX_WORD_SIZE" , 4); hideEnv = GetEnvVar("HIDE_ENV" , 0); minNumVarSubExec = GetEnvVar("MIN_VAR_SUBEXEC" , 1); maxNumVarSubExec = GetEnvVar("MAX_VAR_SUBEXEC" , 0); numIterations = GetEnvVar("NUM_ITERATIONS" , 10); numSubIterations = GetEnvVar("NUM_SUBITERATIONS" , 1); numWarmups = GetEnvVar("NUM_WARMUPS" , 3); outputToCsv = GetEnvVar("OUTPUT_TO_CSV" , 0); samplingFactor = GetEnvVar("SAMPLING_FACTOR" , 1); showBorders = GetEnvVar("SHOW_BORDERS" , 1); showIterations = GetEnvVar("SHOW_ITERATIONS" , 0); useHipEvents = GetEnvVar("USE_HIP_EVENTS" , 1); useHsaDma = GetEnvVar("USE_HSA_DMA" , 0); useInteractive = GetEnvVar("USE_INTERACTIVE" , 0); useSingleStream = GetEnvVar("USE_SINGLE_STREAM" , 1); validateDirect = GetEnvVar("VALIDATE_DIRECT" , 0); validateSource = GetEnvVar("VALIDATE_SOURCE" , 0); ibGidIndex = GetEnvVar("IB_GID_INDEX" ,-1); ibPort = GetEnvVar("IB_PORT_NUMBER" , 1); roceVersion = GetEnvVar("ROCE_VERSION" , 2); ipAddressFamily = GetEnvVar("IP_ADDRESS_FAMILY" , 4); nicChunkBytes = GetEnvVar("NIC_CHUNK_BYTES" , 1073741824); nicRelaxedOrder = GetEnvVar("NIC_RELAX_ORDER" , 1); gpuMaxHwQueues = GetEnvVar("GPU_MAX_HW_QUEUES" , 4); // Check for fill pattern char* pattern = getenv("FILL_PATTERN"); if (pattern != NULL) { int patternLen = strlen(pattern); if (patternLen % 2) { printf("[ERROR] FILL_PATTERN must contain an even-number of hex digits\n"); exit(1); } // Read in bytes std::vector bytes; unsigned char val = 0; for (int i = 0; i < patternLen; i++) { if ('0' <= pattern[i] && pattern[i] <= '9') val += (pattern[i] - '0'); else if ('A' <= pattern[i] && pattern[i] <= 'F') val += (pattern[i] - 'A' + 10); else if ('a' <= pattern[i] && pattern[i] <= 'f') val += (pattern[i] - 'a' + 10); else { printf("[ERROR] FILL_PATTERN must contain an even-number of hex digits (0-9'/a-f/A-F). (not %c)\n", pattern[i]); exit(1); } if (i % 2 == 0) val <<= 4; else { bytes.push_back(val); val = 0; } } // Reverse bytes (input is assumed to be given in big-endian) std::reverse(bytes.begin(), bytes.end()); // Figure out how many copies of the pattern are necessary to fill a 4-byte float properly int copies; switch (patternLen % 8) { case 0: copies = 1; break; case 4: copies = 2; break; default: copies = 4; break; } // Fill floats int numFloats = copies * patternLen / 8; fillPattern.resize(numFloats); unsigned char* rawData = (unsigned char*) fillPattern.data(); for (int i = 0; i < numFloats * 4; i++) rawData[i] = bytes[i % bytes.size()]; } else fillPattern.clear(); // Check for CU mask int numXccs = TransferBench::GetNumExecutorSubIndices({EXE_GPU_GFX, 0}); cuMask.clear(); char* cuMaskStr = getenv("CU_MASK"); if (cuMaskStr != NULL) { #if defined(__NVCC__) printf("[WARN] CU_MASK is not supported in CUDA\n"); #else std::vector> ranges; int maxCU = 0; char* token = strtok(cuMaskStr, ","); while (token) { int start, end; if (sscanf(token, "%d-%d", &start, &end) == 2) { ranges.push_back(std::make_pair(std::min(start, end), std::max(start, end))); maxCU = std::max(maxCU, std::max(start, end)); } else if (sscanf(token, "%d", &start) == 1) { ranges.push_back(std::make_pair(start, start)); maxCU = std::max(maxCU, start); } else { printf("[ERROR] Unrecognized token [%s]\n", token); exit(1); } token = strtok(NULL, ","); } cuMask.resize(2 * numXccs, 0); for (auto range : ranges) { for (int i = range.first; i <= range.second; i++) { for (int x = 0; x < numXccs; x++) { int targetBit = i * numXccs + x; cuMask[targetBit/32] |= (1<<(targetBit%32)); } } } #endif } // Parse preferred XCC table (if provided) char* prefXccStr = getenv("XCC_PREF_TABLE"); if (prefXccStr) { prefXccTable.resize(numDetectedGpus); for (int i = 0; i < numDetectedGpus; i++){ prefXccTable[i].resize(numDetectedGpus, -1); } char* token = strtok(prefXccStr, ","); int tokenCount = 0; while (token) { int xccId; if (sscanf(token, "%d", &xccId) == 1) { int src = tokenCount / numDetectedGpus; int dst = tokenCount % numDetectedGpus; if (xccId < 0 || xccId >= numXccs) { printf("[ERROR] XCC index (%d) out of bounds. Expect value less than %d\n", xccId, numXccs); exit(1); } prefXccTable[src][dst] = xccId; tokenCount++; if (tokenCount == (numDetectedGpus * numDetectedGpus)) break; } else { printf("[ERROR] Unrecognized token [%s]\n", token); exit(1); } token = strtok(NULL, ","); } } } static std::string ToStr(std::vector const& values) { std::string result = ""; bool isFirst = true; for (int v : values) { if (isFirst) isFirst = false; else result += ","; result += std::to_string(v); } return result; } // Display info on the env vars that can be used static void DisplayUsage() { printf("Environment variables:\n"); printf("======================\n"); printf(" ALWAYS_VALIDATE - Validate after each iteration instead of once after all iterations\n"); printf(" BLOCK_BYTES - Controls granularity of how work is divided across subExecutors\n"); printf(" BYTE_OFFSET - Initial byte-offset for memory allocations. Must be multiple of 4\n"); printf(" CU_MASK - CU mask for streams. Can specify ranges e.g '5,10-12,14'\n"); printf(" FILL_COMPRESS - Percentages of 64B lines to be filled by random/1B0/2B0/4B0/32B0\n"); printf(" FILL_PATTERN - Big-endian pattern for source data, specified in hex digits. Must be even # of digits\n"); printf(" GFX_BLOCK_ORDER - How blocks for transfers are ordered. 0=sequential, 1=interleaved\n"); printf(" GFX_BLOCK_SIZE - # of threads per threadblock (Must be multiple of 64)\n"); printf(" GFX_SE_TYPE - SubExecutor granularity type (0=threadblock, 1=warp)\n"); printf(" GFX_TEMPORAL - Use of non-temporal loads or stores (0=none 1=loads 2=stores 3=both)\n"); printf(" GFX_UNROLL - Unroll factor for GFX kernel (0=auto), must be less than %d\n", TransferBench::GetIntAttribute(ATR_GFX_MAX_UNROLL)); printf(" GFX_SINGLE_TEAM - Have subexecutors work together on full array instead of working on disjoint subarrays\n"); printf(" GFX_WAVE_ORDER - Stride pattern for GFX kernel (0=UWC,1=UCW,2=WUC,3=WCU,4=CUW,5=CWU)\n"); printf(" GFX_WORD_SIZE - GFX kernel packed data size (4=DWORDx4, 2=DWORDx2, 1=DWORDx1)\n"); printf(" HIDE_ENV - Hide environment variable value listing\n"); #if NIC_EXEC_ENABLED printf(" IB_GID_INDEX - Required for RoCE NICs (default=-1/auto)\n"); printf(" IB_PORT_NUMBER - RDMA port count for RDMA NIC (default=1)\n"); printf(" IP_ADDRESS_FAMILY - IP address family (4=v4, 6=v6, default=v4)\n"); #endif printf(" MIN_VAR_SUBEXEC - Minumum # of subexecutors to use for variable subExec Transfers\n"); printf(" MAX_VAR_SUBEXEC - Maximum # of subexecutors to use for variable subExec Transfers (0 for device limits)\n"); #if NIC_EXEC_ENABLED printf(" NIC_CHUNK_BYTES - Number of bytes to send at a time using NIC (default = 1GB)\n"); printf(" NIC_RELAX_ORDER - Set to non-zero to use relaxed ordering"); #endif printf(" NUM_ITERATIONS - # of timed iterations per test. If negative, run for this many seconds instead\n"); printf(" NUM_SUBITERATIONS - # of sub-iterations to run per iteration. Must be non-negative\n"); printf(" NUM_WARMUPS - # of untimed warmup iterations per test\n"); printf(" OUTPUT_TO_CSV - Outputs to CSV format if set\n"); #if NIC_EXEC_ENABLED printf(" ROCE_VERSION - RoCE version (default=2)\n"); #endif printf(" SAMPLING_FACTOR - Add this many samples (when possible) between powers of 2 when auto-generating data sizes\n"); printf(" SHOW_BORDERS - Show ASCII box-drawing characaters in tables\n"); printf(" SHOW_ITERATIONS - Show per-iteration timing info\n"); printf(" USE_HIP_EVENTS - Use HIP events for GFX executor timing\n"); printf(" USE_HSA_DMA - Use hsa_amd_async_copy instead of hipMemcpy for non-targeted DMA execution\n"); printf(" USE_INTERACTIVE - Pause for user-input before starting transfer loop\n"); printf(" USE_SINGLE_STREAM - Use a single stream per GPU GFX executor instead of stream per Transfer\n"); printf(" VALIDATE_DIRECT - Validate GPU destination memory directly instead of staging GPU memory on host\n"); printf(" VALIDATE_SOURCE - Validate GPU src memory immediately after preparation\n"); } void Print(std::string const& name, int32_t const value, const char* format, ...) const { printf("%-20s%s%12d%s", name.c_str(), outputToCsv ? "," : " = ", value, outputToCsv ? "," : " : "); va_list args; va_start(args, format); vprintf(format, args); va_end(args); printf("\n"); } void Print(std::string const& name, std::string const& value, const char* format, ...) const { printf("%-20s%s%12s%s", name.c_str(), outputToCsv ? "," : " = ", value.c_str(), outputToCsv ? "," : " : "); va_list args; va_start(args, format); vprintf(format, args); va_end(args); printf("\n"); } // Display env var settings void DisplayEnvVars() const { int numGpuDevices = TransferBench::GetNumExecutors(EXE_GPU_GFX); std::string nicSupport = ""; #if NIC_EXEC_ENABLED nicSupport = " (with NIC support)"; #endif if (!outputToCsv) { if (!hideEnv) printf("[Common] (Suppress by setting HIDE_ENV=1)\n"); } else if (!hideEnv) printf("EnvVar,Value,Description,(TransferBench Client v%s Backend v%s)\n", CLIENT_VERSION, TransferBench::VERSION); if (hideEnv) return; Print("ALWAYS_VALIDATE", alwaysValidate, "Validating after %s", (alwaysValidate ? "each iteration" : "all iterations")); Print("BLOCK_BYTES", blockBytes, "Each CU gets a mulitple of %d bytes to copy", blockBytes); Print("BYTE_OFFSET", byteOffset, "Using byte offset of %d", byteOffset); Print("CU_MASK", getenv("CU_MASK") ? 1 : 0, "%s", (cuMask.size() ? GetCuMaskDesc().c_str() : "All")); Print("FILL_COMPRESS", getenv("FILL_COMPRESS") ? 1 : 0, "%s", (fillCompress.size() ? GetStr(fillCompress).c_str() : "Not specified")); Print("FILL_PATTERN", getenv("FILL_PATTERN") ? 1 : 0, "%s", (fillPattern.size() ? getenv("FILL_PATTERN") : TransferBench::GetStrAttribute(ATR_SRC_PREP_DESCRIPTION).c_str())); Print("GFX_BLOCK_ORDER", gfxBlockOrder, "Thread block ordering: %s", gfxBlockOrder == 0 ? "Sequential" : "Interleaved"); Print("GFX_BLOCK_SIZE", gfxBlockSize, "Threadblock size of %d", gfxBlockSize); Print("GFX_SE_TYPE", gfxSeType, "SubExecutor granularity: %s", gfxSeType == 0 ? "Threadblock" : "Warp"); Print("GFX_SINGLE_TEAM", gfxSingleTeam, "%s", (gfxSingleTeam ? "Combining CUs to work across entire data array" : "Each CUs operates on its own disjoint subarray")); Print("GFX_TEMPORAL", gfxTemporal, "%s", (gfxTemporal == 0 ? "Not using non-temporal loads/stores" : gfxTemporal == 1 ? "Using non-temporal loads" : gfxTemporal == 2 ? "Using non-temporal stores" : "Using non-temporal loads and stores")); Print("GFX_UNROLL", gfxUnroll, "Using GFX unroll factor of %d", gfxUnroll); Print("GFX_WAVE_ORDER", gfxWaveOrder, "Using GFX wave ordering of %s", (gfxWaveOrder == 0 ? "Unroll,Wavefront,CU" : gfxWaveOrder == 1 ? "Unroll,CU,Wavefront" : gfxWaveOrder == 2 ? "Wavefront,Unroll,CU" : gfxWaveOrder == 3 ? "Wavefront,CU,Unroll" : gfxWaveOrder == 4 ? "CU,Unroll,Wavefront" : "CU,Wavefront,Unroll")); Print("GFX_WORD_SIZE", gfxWordSize, "Using GFX word size of %d (DWORDx%d)", gfxWordSize, gfxWordSize); #if NIC_EXEC_ENABLED Print("IP_ADDRESS_FAMILY", ipAddressFamily, "IP address family is set to IPv%d", ipAddressFamily); Print("IB_GID_INDEX", ibGidIndex, "RoCE GID index is set to %s", (ibGidIndex < 0 ? "auto" : std::to_string(ibGidIndex).c_str())); Print("IB_PORT_NUMBER", ibPort, "IB port number is set to %d", ibPort); #endif Print("MIN_VAR_SUBEXEC", minNumVarSubExec, "Using at least %d subexecutor(s) for variable subExec tranfers", minNumVarSubExec); Print("MAX_VAR_SUBEXEC", maxNumVarSubExec, "Using up to %s subexecutors for variable subExec transfers", maxNumVarSubExec ? std::to_string(maxNumVarSubExec).c_str() : "all available"); #if NIC_EXEC_ENABLED Print("NIC_CHUNK_BYTES", nicChunkBytes, "Sending %lu bytes at a time for NIC RDMA", nicChunkBytes); Print("NIC_RELAX_ORDER", nicRelaxedOrder, "Using %s ordering for NIC RDMA", nicRelaxedOrder ? "relaxed" : "strict"); #endif Print("NUM_ITERATIONS", numIterations, (numIterations == 0) ? "Running infinitely" : "Running %d %s", abs(numIterations), (numIterations > 0 ? " timed iteration(s)" : "seconds(s) per Test")); Print("NUM_SUBITERATIONS", numSubIterations, "Running %s subiterations", (numSubIterations == 0 ? "infinite" : std::to_string(numSubIterations)).c_str()); Print("NUM_WARMUPS", numWarmups, "Running %d warmup iteration(s) per Test", numWarmups); #if NIC_EXEC_ENABLED Print("ROCE_VERSION", roceVersion, "RoCE version is set to %d", roceVersion); #endif Print("SHOW_BORDERS", showBorders, "%s ASCII box-drawing characaters in tables", showBorders ? "Showing" : "Hiding"); Print("SHOW_ITERATIONS", showIterations, "%s per-iteration timing", showIterations ? "Showing" : "Hiding"); Print("USE_HIP_EVENTS", useHipEvents, "Using %s for GFX/DMA Executor timing", useHipEvents ? "HIP events" : "CPU wall time"); Print("USE_HSA_DMA", useHsaDma, "Using %s for DMA execution", useHsaDma ? "hsa_amd_async_copy" : "hipMemcpyAsync"); Print("USE_INTERACTIVE", useInteractive, "Running in %s mode", useInteractive ? "interactive" : "non-interactive"); Print("USE_SINGLE_STREAM", useSingleStream, "Using single stream per GFX %s", useSingleStream ? "device" : "Transfer"); if (getenv("XCC_PREF_TABLE")) { printf("%36s: Preferred XCC Table (XCC_PREF_TABLE)\n", ""); printf("%36s: ", ""); for (int i = 0; i < numGpuDevices; i++) printf(" %3d", i); printf(" (#XCCs)\n"); for (int i = 0; i < numGpuDevices; i++) { printf("%36s: GPU %3d ", "", i); for (int j = 0; j < numGpuDevices; j++) printf(" %3d", prefXccTable[i][j]); printf(" %3d\n", TransferBench::GetNumExecutorSubIndices({EXE_GPU_GFX, i})); } } Print("VALIDATE_DIRECT", validateDirect, "Validate GPU destination memory %s", validateDirect ? "directly" : "via CPU staging buffer"); Print("VALIDATE_SOURCE", validateSource, validateSource ? "Validate source after preparation" : "Do not perform source validation after prep"); printf("\n"); }; // Helper function that gets parses environment variable or sets to default value static int GetEnvVar(std::string const& varname, int defaultValue) { char const* varStr = getenv(varname.c_str()); if (varStr) { int val = atoi(varStr); char units = varStr[strlen(varStr)-1]; switch (units) { case 'G': case 'g': val *= 1024; case 'M': case 'm': val *= 1024; case 'K': case 'k': val *= 1024; } return val; } return defaultValue; } static std::vector GetEnvVarArray(std::string const& varname, std::vector const& defaultValue) { if (getenv(varname.c_str())) { std::vector values; char* arrayStr = getenv(varname.c_str()); char* token = strtok(arrayStr, ","); while (token) { int val; if (sscanf(token, "%d", &val) == 1) { values.push_back(val); } else { printf("[ERROR] Unrecognized token [%s]\n", token); exit(1); } token = strtok(NULL, ","); } return values; } return defaultValue; } static std::vector GetEnvVarRangeArray(std::string const& varname, std::vector const& defaultValue) { if (getenv(varname.c_str())) { char* rangeStr = getenv(varname.c_str()); std::set values; char* token = strtok(rangeStr, ","); while (token) { int start, end; if (sscanf(token, "%d-%d", &start, &end) == 2) { for (int i = start; i <= end; i++) values.insert(i); } else if (sscanf(token, "%d", &start) == 1) { values.insert(start); } else { printf("[ERROR] Unrecognized token [%s]\n", token); exit(1); } token = strtok(NULL, ","); } std::vector result; for (auto v : values) result.push_back(v); return result; } return defaultValue; } static std::string GetEnvVar(std::string const& varname, std::string const& defaultValue) { if (getenv(varname.c_str())) return getenv(varname.c_str()); return defaultValue; } std::string GetStr(std::vector const& varnameList) const { std::string result = ""; for (int i = 0; i < varnameList.size(); i++) { if (i) result += ","; result += std::to_string(varnameList[i]); } return result; } std::string GetCuMaskDesc() const { std::vector> runs; int numXccs = TransferBench::GetNumExecutorSubIndices({EXE_GPU_GFX, 0}); bool inRun = false; std::pair curr; int used = 0; for (int targetBit = 0; targetBit < cuMask.size() * 32; targetBit += numXccs) { if (cuMask[targetBit/32] & (1 << (targetBit%32))) { used++; if (!inRun) { inRun = true; curr.first = targetBit / numXccs; } } else { if (inRun) { inRun = false; curr.second = targetBit / numXccs - 1; runs.push_back(curr); } } } if (inRun) curr.second = (cuMask.size() * 32) / numXccs - 1; std::string result = "CUs used: (" + std::to_string(used) + ") "; for (int i = 0; i < runs.size(); i++) { if (i) result += ","; if (runs[i].first == runs[i].second) result += std::to_string(runs[i].first); else result += std::to_string(runs[i].first) + "-" + std::to_string(runs[i].second); } return result; } TransferBench::ConfigOptions ToConfigOptions() { TransferBench::ConfigOptions cfg; cfg.general.numIterations = numIterations; cfg.general.numSubIterations = numSubIterations; cfg.general.numWarmups = numWarmups; cfg.general.recordPerIteration = showIterations; cfg.general.useInteractive = useInteractive; cfg.data.alwaysValidate = alwaysValidate; cfg.data.blockBytes = blockBytes; cfg.data.byteOffset = byteOffset; cfg.data.fillCompress = fillCompress; cfg.data.fillPattern = fillPattern; cfg.data.validateDirect = validateDirect; cfg.data.validateSource = validateSource; cfg.dma.useHipEvents = useHipEvents; cfg.dma.useHsaCopy = useHsaDma; cfg.gfx.blockOrder = gfxBlockOrder; cfg.gfx.blockSize = gfxBlockSize; cfg.gfx.cuMask = cuMask; cfg.gfx.prefXccTable = prefXccTable; cfg.gfx.seType = gfxSeType; cfg.gfx.unrollFactor = gfxUnroll; cfg.gfx.temporalMode = gfxTemporal; cfg.gfx.useHipEvents = useHipEvents; cfg.gfx.useMultiStream = !useSingleStream; cfg.gfx.useSingleTeam = gfxSingleTeam; cfg.gfx.waveOrder = gfxWaveOrder; cfg.gfx.wordSize = gfxWordSize; cfg.nic.chunkBytes = nicChunkBytes; cfg.nic.ibGidIndex = ibGidIndex; cfg.nic.ibPort = ibPort; cfg.nic.ipAddressFamily = ipAddressFamily; cfg.nic.useRelaxedOrder = nicRelaxedOrder; cfg.nic.roceVersion = roceVersion; return cfg; } }; #endif