| 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 |
import inspect |
| 26 |
import os |
| 27 |
import subprocess |
| 28 |
import shlex |
| 29 |
import shutil |
| 30 |
|
| 31 |
from pathlib import Path |
| 32 |
from enum import Enum |
| 33 |
from glob import glob |
| 34 |
|
| 35 |
from Tensile.SolutionStructs.Problem import ProblemType, ProblemSizesMock, ProblemSizesMockDummy |
| 36 |
from Tensile.SolutionStructs import ActivationArgs, BiasTypeArgs, FactorDimArgs |
| 37 |
from Tensile.Toolchain.Component import Assembler |
| 38 |
|
| 39 |
import rocisa |
| 40 |
|
| 41 |
from . import ROOT_PATH |
| 42 |
from . import LibraryIO |
| 43 |
from Tensile.Common import ensurePath, print1, printExit, printWarning, ClientExecutionLock,\ |
| 44 |
LIBRARY_LOGIC_DIR, LIBRARY_CLIENT_DIR |
| 45 |
from Tensile.Common.Architectures import isaToGfx |
| 46 |
from Tensile.Common.GlobalParameters import globalParameters |
| 47 |
from .TensileCreateLibrary import copyStaticFiles |
| 48 |
from .Contractions import FreeIndex, BatchIndex |
| 49 |
from .Contractions import ProblemType as ContractionsProblemType |
| 50 |
|
| 51 |
class DataInitName(Enum): |
| 52 |
Zero = 0 |
| 53 |
One = 1 |
| 54 |
Two = 2 |
| 55 |
Random = 3 |
| 56 |
NaN = 4 |
| 57 |
Inf = 5 |
| 58 |
BadInput = 6 |
| 59 |
BadOutput = 7 |
| 60 |
SerialIdx = 8 |
| 61 |
SerialDim0 = 9 |
| 62 |
SerialDim1 = 10 |
| 63 |
Identity = 11 |
| 64 |
TrigSin = 12 |
| 65 |
TrigCos = 13 |
| 66 |
TrigAbsSin = 14 |
| 67 |
TrigAbsCos = 15 |
| 68 |
RandomNarrow = 16 |
| 69 |
NegOne = 17 |
| 70 |
Max = 18 |
| 71 |
DenormMin = 19 |
| 72 |
DenormMax = 20 |
| 73 |
RandomNegPosLimited = 21 |
| 74 |
TrigIndSin = 23 |
| 75 |
TrigIndCos = 24 |
| 76 |
TrigIndAbsSin = 25 |
| 77 |
TrigIndAbsCos = 26 |
| 78 |
|
| 79 |
class ClientLogLevel(Enum): |
| 80 |
Error = 0 |
| 81 |
Terse = 1 |
| 82 |
Verbose = 2 |
| 83 |
Debug = 3 |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
def main(config, assembler: Assembler, cCompiler: str, isaInfoMap, outputPath: Path, deviceId: int, gfxName: str): |
| 90 |
|
| 91 |
libraryLogicPath = ensurePath(outputPath / LIBRARY_LOGIC_DIR) |
| 92 |
clientLibraryPath = ensurePath(outputPath / LIBRARY_CLIENT_DIR) |
| 93 |
sourcePath = ensurePath(clientLibraryPath / "source") |
| 94 |
copyStaticFiles(sourcePath) |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
logicFiles = [os.path.join(libraryLogicPath, f) for f \ |
| 100 |
in os.listdir(libraryLogicPath) \ |
| 101 |
if (os.path.isfile(os.path.join(libraryLogicPath, f)) \ |
| 102 |
and os.path.splitext(f)[1]==".yaml")] |
| 103 |
print1("LogicFiles: %s" % logicFiles) |
| 104 |
functions = [] |
| 105 |
functionNames = [] |
| 106 |
|
| 107 |
|
| 108 |
module_path = os.path.dirname(inspect.getfile(rocisa)) |
| 109 |
env = os.environ.copy() |
| 110 |
if 'PYTHONPATH' in env: |
| 111 |
if not module_path in env['PYTHONPATH']: |
| 112 |
env["PYTHONPATH"] = module_path + ":" + env["PYTHONPATH"] |
| 113 |
else: |
| 114 |
env["PYTHONPATH"] = module_path |
| 115 |
|
| 116 |
createLibraryScript = getBuildClientLibraryScript(clientLibraryPath, libraryLogicPath, str(assembler.path), isaToGfx(list(isaInfoMap.keys())[0])) |
| 117 |
subprocess.run(shlex.split(createLibraryScript), env=env, cwd=clientLibraryPath) |
| 118 |
coList = glob(os.path.join(clientLibraryPath, "library/*.co")) |
| 119 |
yamlList = glob(os.path.join(clientLibraryPath, "library/*.yaml")) |
| 120 |
|
| 121 |
clientParametersPaths = [] |
| 122 |
splitGSU = False |
| 123 |
printSolutionRejectionReason = True |
| 124 |
printIndexAssignmentInfo = False |
| 125 |
for logicFileName in logicFiles: |
| 126 |
(scheduleName, _, problemType, _, exactLogic, newLibrary) \ |
| 127 |
= LibraryIO.parseLibraryLogicFile(logicFileName, |
| 128 |
assembler, |
| 129 |
splitGSU, |
| 130 |
printSolutionRejectionReason, |
| 131 |
printIndexAssignmentInfo, |
| 132 |
isaInfoMap, |
| 133 |
globalParameters["LazyLibraryLoading"]) |
| 134 |
functions.append((scheduleName, problemType)) |
| 135 |
functionNames.append("tensile_%s" % (problemType)) |
| 136 |
problemSizes = ProblemSizesMock(exactLogic) if exactLogic else ProblemSizesMockDummy() |
| 137 |
if len(problemType["BiasDataTypeList"]) > 0: |
| 138 |
biasTypeArgs = BiasTypeArgs(problemType, [problemType["BiasDataTypeList"][0]]) |
| 139 |
else: |
| 140 |
biasTypeArgs = "" |
| 141 |
|
| 142 |
activationEnums = [[{'Enum': 'relu'}]] |
| 143 |
factorDimEnums = [0] |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
icacheFlushArgs = [False,] |
| 152 |
if len(config) > 0: |
| 153 |
for lc in config[0:]: |
| 154 |
if "ActivationArgs" in lc: |
| 155 |
activationEnums = lc["ActivationArgs"] |
| 156 |
break |
| 157 |
if "FactorDimArgs" in lc: |
| 158 |
factorDimEnums = lc["FactorDimArgs"] |
| 159 |
if "ICacheFlush" in lc: |
| 160 |
icacheFlushArgs = lc["ICacheFlush"] |
| 161 |
isForAll = True if problemType["ActivationType"] in ['all', 'hipblaslt_all'] else False |
| 162 |
activationArgs = ActivationArgs(problemType, activationEnums) if isForAll else "" |
| 163 |
factorDimArgs = FactorDimArgs(problemType, factorDimEnums) |
| 164 |
|
| 165 |
clientParametersPaths.append(writeClientConfig( |
| 166 |
forBenchmark=False, |
| 167 |
solutions=None, |
| 168 |
problemSizes=problemSizes, |
| 169 |
biasTypeArgs=biasTypeArgs, |
| 170 |
factorDimArgs=factorDimArgs, |
| 171 |
activationArgs=activationArgs, |
| 172 |
icacheFlushArgs=icacheFlushArgs, |
| 173 |
stepName=str(ProblemType(problemType, False)), |
| 174 |
stepBaseDir=str(clientLibraryPath), |
| 175 |
newLibrary=newLibrary, |
| 176 |
configBase="ClientParameters_%s"%str(ProblemType(problemType, False)), |
| 177 |
codeObjectFiles=coList, |
| 178 |
deviceId=deviceId, |
| 179 |
gfxName=gfxName, |
| 180 |
tileAwareSelection=False, |
| 181 |
libraryFile=yamlList[0])) |
| 182 |
|
| 183 |
forBenchmark = False |
| 184 |
problemSizes = None |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
if globalParameters["ForceRedoLibraryClient"]: |
| 192 |
shutil.rmtree(os.path.join(clientLibraryPath, "build"), \ |
| 193 |
ignore_errors=True) |
| 194 |
|
| 195 |
forBenchmark = False |
| 196 |
enableTileSelection = False |
| 197 |
returncode = runClient(libraryLogicPath, forBenchmark, enableTileSelection, str(assembler.path), cCompiler, clientLibraryPath, clientParametersPaths) |
| 198 |
|
| 199 |
return returncode |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
def runNewClient(scriptPath, clientParametersPath, cxxCompiler: str, cCompiler: str, clientBuildDir=None): |
| 205 |
|
| 206 |
clientExe = getClientExecutablePath() |
| 207 |
iniFile = "--config-file={}".format(clientParametersPath) |
| 208 |
args = [clientExe, iniFile] |
| 209 |
|
| 210 |
try: |
| 211 |
subprocess.run(args, check=True) |
| 212 |
except (subprocess.CalledProcessError, OSError) as e: |
| 213 |
printWarning("ClientWriter Benchmark Process exited with error: {}".format(e)) |
| 214 |
|
| 215 |
|
| 216 |
def runClient(libraryLogicPath, forBenchmark, enableTileSelection, cxxCompiler: str, cCompiler: str, outputPath, configPaths=None): |
| 217 |
|
| 218 |
buildPath = ensurePath(outputPath / "build") |
| 219 |
|
| 220 |
runScriptName = writeRunScript(buildPath, forBenchmark, enableTileSelection, cxxCompiler, cCompiler, buildPath, configPaths) |
| 221 |
with ClientExecutionLock(globalParameters["ClientExecutionLockPath"]): |
| 222 |
process = subprocess.Popen(runScriptName, cwd=buildPath) |
| 223 |
process.communicate() |
| 224 |
|
| 225 |
if process.returncode: |
| 226 |
printWarning("ClientWriter Benchmark Process exited with code %u" % process.returncode) |
| 227 |
|
| 228 |
return process.returncode |
| 229 |
|
| 230 |
def getBuildClientLibraryScript(buildPath, libraryLogicPath, cxxCompiler, targetGfx): |
| 231 |
import io |
| 232 |
runScriptFile = io.StringIO() |
| 233 |
|
| 234 |
callCreateLibraryCmd = ROOT_PATH + "/bin/TensileCreateLibrary" |
| 235 |
|
| 236 |
if not globalParameters["LazyLibraryLoading"]: |
| 237 |
callCreateLibraryCmd += " --no-lazy-library-loading" |
| 238 |
|
| 239 |
if globalParameters.get("AsmDebug", False): |
| 240 |
callCreateLibraryCmd += " --asm-debug" |
| 241 |
|
| 242 |
if globalParameters["KeepBuildTmp"]: |
| 243 |
callCreateLibraryCmd += " --keep-build-tmp" |
| 244 |
|
| 245 |
callCreateLibraryCmd += " --architecture=" + targetGfx |
| 246 |
callCreateLibraryCmd += " --code-object-version=" + globalParameters["CodeObjectVersion"] |
| 247 |
callCreateLibraryCmd += " --cxx-compiler=" + cxxCompiler |
| 248 |
callCreateLibraryCmd += " --library-format=" + globalParameters["LibraryFormat"] |
| 249 |
|
| 250 |
callCreateLibraryCmd += " %s" % libraryLogicPath |
| 251 |
callCreateLibraryCmd += " %s" % buildPath |
| 252 |
callCreateLibraryCmd += " %s\n" % globalParameters["RuntimeLanguage"] |
| 253 |
|
| 254 |
runScriptFile.write(callCreateLibraryCmd) |
| 255 |
|
| 256 |
return runScriptFile.getvalue() |
| 257 |
|
| 258 |
|
| 259 |
def writeRunScript(path, forBenchmark, enableTileSelection, cxxCompiler: str, cCompiler: str, buildDir, configPaths=None): |
| 260 |
if configPaths is None: |
| 261 |
configPaths = [] |
| 262 |
|
| 263 |
configPaths.append(os.path.join(buildDir, "../source/ClientParameters.ini")) |
| 264 |
if enableTileSelection is True: |
| 265 |
configPaths.append(os.path.join(buildDir, "../source/ClientParameters_Granularity.ini")) |
| 266 |
|
| 267 |
|
| 268 |
runScriptName = os.path.join(buildDir, \ |
| 269 |
"run.%s" % ("bat" if os.name == "nt" else "sh") ) |
| 270 |
runScriptFile = open(runScriptName, "w") |
| 271 |
if os.name != "nt": |
| 272 |
runScriptFile.write("#!/bin/bash\n\n") |
| 273 |
|
| 274 |
runScriptFile.write("set -ex\n") |
| 275 |
|
| 276 |
|
| 277 |
if forBenchmark: |
| 278 |
if os.name == "nt": |
| 279 |
runScriptFile.write(os.path.join(globalParameters["CMakeBuildType"], \ |
| 280 |
"client.exe") ) |
| 281 |
else: |
| 282 |
if globalParameters["PinClocks"] and globalParameters["ROCmSMIPath"]: |
| 283 |
runScriptFile.write("%s -d 0 --setfan 255 --setsclk 7\n" % globalParameters["ROCmSMIPath"]) |
| 284 |
runScriptFile.write("sleep 1\n") |
| 285 |
runScriptFile.write("%s -d 0 -a\n" % globalParameters["ROCmSMIPath"]) |
| 286 |
|
| 287 |
runScriptFile.write("set +e\n") |
| 288 |
|
| 289 |
|
| 290 |
if globalParameters["DataInitTypeA"] == -1 : |
| 291 |
globalParameters["DataInitTypeA"] = globalParameters["DataInitTypeAB"] |
| 292 |
if globalParameters["DataInitTypeB"] == -1 : |
| 293 |
globalParameters["DataInitTypeB"] = globalParameters["DataInitTypeAB"] |
| 294 |
|
| 295 |
runScriptFile.write("ERR1=0\n") |
| 296 |
|
| 297 |
clientExe = getClientExecutablePath() |
| 298 |
for configFile in configPaths: |
| 299 |
runScriptFile.write("{} --config-file {}\n".format(clientExe, configFile)) |
| 300 |
runScriptFile.write("ERR2=$?\n\n") |
| 301 |
|
| 302 |
runScriptFile.write(""" |
| 303 |
ERR=0 |
| 304 |
if [[ $ERR1 -ne 0 ]] |
| 305 |
then |
| 306 |
echo one |
| 307 |
ERR=$ERR1 |
| 308 |
fi |
| 309 |
if [[ $ERR2 -ne 0 ]] |
| 310 |
then |
| 311 |
echo two |
| 312 |
ERR=$ERR2 |
| 313 |
fi |
| 314 |
""") |
| 315 |
|
| 316 |
if os.name != "nt": |
| 317 |
if globalParameters["PinClocks"] and globalParameters["ROCmSMIPath"]: |
| 318 |
runScriptFile.write("%s -d 0 --resetclocks\n" % globalParameters["ROCmSMIPath"]) |
| 319 |
runScriptFile.write("%s -d 0 --setfan 50\n" % globalParameters["ROCmSMIPath"]) |
| 320 |
else: |
| 321 |
for configFile in configPaths: |
| 322 |
runScriptFile.write("{} --config-file {} --best-solution 1\n".format(getClientExecutablePath(), configFile)) |
| 323 |
|
| 324 |
if os.name != "nt": |
| 325 |
runScriptFile.write("exit $ERR\n") |
| 326 |
runScriptFile.close() |
| 327 |
if os.name != "nt": |
| 328 |
os.chmod(runScriptName, 0o777) |
| 329 |
return runScriptName |
| 330 |
|
| 331 |
|
| 332 |
def toCppBool(yamlBool): |
| 333 |
return "true" if yamlBool else "false" |
| 334 |
|
| 335 |
def getMaxSolutionSizes(solutions, solutionSummationSizes): |
| 336 |
|
| 337 |
maxK = max(solutionSummationSizes) |
| 338 |
maxMT0 = 0 |
| 339 |
maxMT1 = 0 |
| 340 |
for solution in solutions: |
| 341 |
|
| 342 |
wg = solution["WorkGroup"] |
| 343 |
tt = solution["ThreadTile"] |
| 344 |
mt0 = wg[0] * tt[0] |
| 345 |
mt1 = wg[1] * tt[1] |
| 346 |
|
| 347 |
if (mt0 > maxMT0): |
| 348 |
maxMT0 = mt0 |
| 349 |
|
| 350 |
if (mt1 > maxMT1): |
| 351 |
maxMT1 = mt1 |
| 352 |
|
| 353 |
return [maxMT0, maxMT1, maxK] |
| 354 |
|
| 355 |
def checkConstStride(constStrideMap, keyIdx): |
| 356 |
finalVal = None |
| 357 |
for (mapIdx, val) in constStrideMap: |
| 358 |
if keyIdx == mapIdx: |
| 359 |
finalVal = val |
| 360 |
|
| 361 |
return finalVal |
| 362 |
|
| 363 |
|
| 364 |
def problemSizeParams(problemType, problem, factorDim): |
| 365 |
|
| 366 |
numIndices = len(problemType.indices) |
| 367 |
rv = [] |
| 368 |
|
| 369 |
if problem.stridesA: |
| 370 |
astrides = list(problem.stridesA) |
| 371 |
else: |
| 372 |
astrides = [-1] * problemType.aDims |
| 373 |
for sc in problemType.setConstStrideA: |
| 374 |
index = problemType.indices[sc[0]] |
| 375 |
if type(index) == FreeIndex: |
| 376 |
assert(index.isA) |
| 377 |
astrides[index.i] = sc[1] |
| 378 |
else: |
| 379 |
astrides[index.a] = sc[1] |
| 380 |
|
| 381 |
if problem.stridesB: |
| 382 |
bstrides = list(problem.stridesB) |
| 383 |
else: |
| 384 |
bstrides = [-1] * problemType.bDims |
| 385 |
for sc in problemType.setConstStrideB: |
| 386 |
index = problemType.indices[sc[0]] |
| 387 |
if type(index) == FreeIndex: |
| 388 |
assert(not index.isA) |
| 389 |
bstrides[index.i] = sc[1] |
| 390 |
else: |
| 391 |
bstrides[index.b] = sc[1] |
| 392 |
|
| 393 |
if problem.stridesC: |
| 394 |
cstrides = list(problem.stridesC) |
| 395 |
else: |
| 396 |
cstrides = [-1] * problemType.cDims |
| 397 |
|
| 398 |
if problem.stridesD: |
| 399 |
dstrides = list(problem.stridesD) |
| 400 |
else: |
| 401 |
dstrides = [-1] * problemType.dDims |
| 402 |
|
| 403 |
if len(problem.sizes) == numIndices: |
| 404 |
None |
| 405 |
elif len(problem.sizes) == numIndices + 4: |
| 406 |
|
| 407 |
|
| 408 |
if astrides[1] == -1: |
| 409 |
astrides[1] = problem.sizes[numIndices+2] |
| 410 |
elif astrides[1] != problem.sizes[numIndices+2]: |
| 411 |
raise RuntimeError("problem-specified lda(%u) conflicts with setConstStrideA(%u)" % \ |
| 412 |
(astrides[1], problem.sizes[numIndices+2])) |
| 413 |
|
| 414 |
if bstrides[1] == -1: |
| 415 |
bstrides[1] = problem.sizes[numIndices+3] |
| 416 |
elif bstrides[1] != problem.sizes[numIndices+3]: |
| 417 |
raise RuntimeError("problem-specified ldb(%u) conflicts with setConstStrideB(%u)" % \ |
| 418 |
(bstrides[1], problem.sizes[numIndices+3])) |
| 419 |
|
| 420 |
if cstrides[1] == -1: |
| 421 |
cstrides[1] = problem.sizes[numIndices+1] |
| 422 |
|
| 423 |
if dstrides[1] == -1: |
| 424 |
dstrides[1] = problem.sizes[numIndices+0] |
| 425 |
|
| 426 |
else: |
| 427 |
raise RuntimeError( |
| 428 |
"Invalid number of problem type indices: {0} - Indices: {1}, problemSize: {2}".format(len(problem.sizes), numIndices, |
| 429 |
', '.join(map(str, problem.sizes)))) |
| 430 |
|
| 431 |
problemSizeArg = ('problem-size', ','.join(map(str, problem.sizes[:numIndices]))) |
| 432 |
rv.insert(0, problemSizeArg) |
| 433 |
|
| 434 |
rv.append(('a-strides', ",".join(map(str, astrides)))) |
| 435 |
rv.append(('b-strides', ",".join(map(str, bstrides)))) |
| 436 |
if cstrides: |
| 437 |
rv.append(('c-strides', ",".join(map(str, cstrides)))) |
| 438 |
if dstrides: |
| 439 |
rv.append(('d-strides', ",".join(map(str, dstrides)))) |
| 440 |
if problemType.useE: |
| 441 |
rv.append(('e-strides', ",".join(map(str, dstrides)))) |
| 442 |
if problemType.useBias: |
| 443 |
length = problem.sizes[0] |
| 444 |
err_str = "M" |
| 445 |
if problemType.sparse: |
| 446 |
if len(factorDim) > 1: |
| 447 |
length = max(problem.sizes[0], problem.sizes[1]) |
| 448 |
err_str = "max(M,N)" |
| 449 |
elif 1 in factorDim: |
| 450 |
length = problem.sizes[1] |
| 451 |
err_str = "N" |
| 452 |
biasstrides = [1, length, 0] |
| 453 |
for sc in problemType.setConstStrideBias: |
| 454 |
index = problemType.indices[sc[0]] |
| 455 |
if type(index) == BatchIndex: |
| 456 |
biasstrides[2] = sc[1] |
| 457 |
if biasstrides[2] == -1: |
| 458 |
biasstrides[2] = length |
| 459 |
elif biasstrides[2] != 0 and biasstrides[2] < length: |
| 460 |
raise RuntimeError("problem-specified bias stride(%u) must >= %s (%u)" % \ |
| 461 |
(biasstrides[2], err_str, length)) |
| 462 |
rv.append(('bias-strides', ",".join(map(str, biasstrides)))) |
| 463 |
|
| 464 |
return rv |
| 465 |
|
| 466 |
def dataInitParams(problemType): |
| 467 |
initA = globalParameters['DataInitTypeA'] |
| 468 |
initB = globalParameters['DataInitTypeB'] |
| 469 |
initC = globalParameters['DataInitTypeC'] |
| 470 |
initD = globalParameters['DataInitTypeD'] |
| 471 |
initE = globalParameters['DataInitTypeE'] |
| 472 |
initAlpha = globalParameters['DataInitTypeAlpha'] |
| 473 |
initBeta = globalParameters['DataInitTypeBeta'] |
| 474 |
initBias = globalParameters['DataInitTypeBias'] |
| 475 |
initScaleA = globalParameters['DataInitTypeScaleA'] |
| 476 |
initScaleB = globalParameters['DataInitTypeScaleB'] |
| 477 |
initScaleC = globalParameters['DataInitTypeScaleC'] |
| 478 |
initScaleD = globalParameters['DataInitTypeScaleD'] |
| 479 |
initScaleAlphaVec = globalParameters['DataInitTypeScaleAlphaVec'] |
| 480 |
|
| 481 |
if not problemType.useBeta: |
| 482 |
initBeta = 0 |
| 483 |
|
| 484 |
if initA == -1: initA = globalParameters['DataInitTypeAB'] |
| 485 |
if initB == -1: initB = globalParameters['DataInitTypeAB'] |
| 486 |
|
| 487 |
return [('init-a', DataInitName(initA).name), |
| 488 |
('init-b', DataInitName(initB).name), |
| 489 |
('init-c', DataInitName(initC).name), |
| 490 |
('init-d', DataInitName(initD).name), |
| 491 |
('init-e', DataInitName(initE).name), |
| 492 |
('init-alpha', DataInitName(initAlpha).name), |
| 493 |
('init-beta', DataInitName(initBeta).name), |
| 494 |
('init-bias', DataInitName(initBias).name), |
| 495 |
('init-scaleA', DataInitName(initScaleA).name), |
| 496 |
('init-scaleB', DataInitName(initScaleB).name), |
| 497 |
('init-scaleC', DataInitName(initScaleC).name), |
| 498 |
('init-scaleD', DataInitName(initScaleD).name), |
| 499 |
('init-scaleAlphaVec', DataInitName(initScaleAlphaVec).name)] |
| 500 |
|
| 501 |
def boundsCheckName(mode): |
| 502 |
if mode == 0: return 'Disable' |
| 503 |
if mode == 1: return 'NaN' |
| 504 |
if mode == 2: return 'GuardPageFront' |
| 505 |
if mode == 3: return 'GuardPageBack' |
| 506 |
if mode == 4: return 'GuardPageAll' |
| 507 |
|
| 508 |
def pruneModeName(mode): |
| 509 |
if mode == 0: return 'PruneRandom' |
| 510 |
if mode == 1: return 'PruneXX00' |
| 511 |
if mode == 2: return 'PruneX0X0' |
| 512 |
if mode == 3: return 'Prune0XX0' |
| 513 |
if mode == 4: return 'PruneX00X' |
| 514 |
if mode == 5: return 'Prune0X0X' |
| 515 |
if mode == 6: return 'Prune00XX' |
| 516 |
|
| 517 |
def writeClientConfigIni(forBenchmark, problemSizes, biasTypeArgs, factorDimArgs, activationArgs, icacheFlushArgs, problemType, sourceDir, codeObjectFiles, resultsFileName, parametersFilePath, deviceId: int, gfxName: str, libraryFile=None, probSolMap={}): |
| 518 |
|
| 519 |
assert os.path.exists(sourceDir), f"sourceDir={sourceDir} does not exist" |
| 520 |
|
| 521 |
with open(parametersFilePath, "w") as f: |
| 522 |
def param(key, value): |
| 523 |
f.write("{}={}\n".format(key, value)) |
| 524 |
|
| 525 |
if libraryFile is None: |
| 526 |
libraryFilename = "TensileLibrary.yaml" if globalParameters["LibraryFormat"] == "yaml" else "TensileLibrary.dat" |
| 527 |
libraryFile = os.path.join(sourceDir, "library", libraryFilename) |
| 528 |
param("library-file", libraryFile) |
| 529 |
|
| 530 |
for coFile in codeObjectFiles: |
| 531 |
if 'gfx' not in coFile or gfxName in coFile: |
| 532 |
param("code-object", os.path.join(sourceDir,coFile)) |
| 533 |
|
| 534 |
param('results-file', resultsFileName) |
| 535 |
param('performance-metric', globalParameters["PerformanceMetric"]) |
| 536 |
param('problem-identifier', problemType.operationIdentifier) |
| 537 |
param('compute-input-type', problemType.computeInputType.toName()) |
| 538 |
param('a-type', problemType.aType.toName()) |
| 539 |
param('b-type', problemType.bType.toName()) |
| 540 |
param('c-type', problemType.cType.toName()) |
| 541 |
param('d-type', problemType.dType.toName()) |
| 542 |
if problemType.useE: |
| 543 |
param('e-type', problemType.eType.toName()) |
| 544 |
if problemType.outputAmaxD: |
| 545 |
param('amaxD-type', problemType.amaxDType.toName()) |
| 546 |
param('alpha-type', problemType.alphaType.toName()) |
| 547 |
param('beta-type', problemType.betaType.toName()) |
| 548 |
param('f32-xdl-math-op', problemType.f32XdlMathOp.toName()) |
| 549 |
param('activation-compute-type', problemType.activationComputeDataType.toName()) |
| 550 |
param('use-gradient', problemType.useGradient) |
| 551 |
param('use-bias', problemType.useBias) |
| 552 |
param('bias-source', problemType.biasSrcWhiteList[0]) |
| 553 |
param('use-e', problemType.useE) |
| 554 |
param('output-amaxD', problemType.outputAmaxD) |
| 555 |
param('use-scaleAB', problemType.useScaleAB) |
| 556 |
param('use-scaleCD', problemType.useScaleCD) |
| 557 |
param('use-scaleAlphaVec', problemType.useScaleAlphaVec) |
| 558 |
param('swizzle-tensor-a', problemType.swizzleTensorA) |
| 559 |
param('swizzle-tensor-b', problemType.swizzleTensorB) |
| 560 |
if biasTypeArgs: |
| 561 |
for btype in biasTypeArgs.biasTypes: |
| 562 |
param('bias-type-args', btype.toName()) |
| 563 |
if factorDimArgs: |
| 564 |
for fdim in factorDimArgs.factorDims: |
| 565 |
param('factor-dim-args', fdim) |
| 566 |
|
| 567 |
|
| 568 |
if icacheFlushArgs: |
| 569 |
for opt in icacheFlushArgs: |
| 570 |
param('icache-flush-args', opt) |
| 571 |
|
| 572 |
param('sparse', problemType.sparse) |
| 573 |
param('high-precision-accumulate', problemType.highPrecisionAccumulate) |
| 574 |
param('strided-batched', problemType.stridedBatched) |
| 575 |
param('grouped-gemm', problemType.groupedGemm) |
| 576 |
|
| 577 |
probIdx = 0 |
| 578 |
for problem in problemSizes.problems: |
| 579 |
for key,value in problemSizeParams(problemType, problem, factorDimArgs.factorDims): |
| 580 |
param(key,value) |
| 581 |
if probIdx in probSolMap: |
| 582 |
solutionIdx = probSolMap[probIdx] |
| 583 |
param('prob-sol-map', str(f'{probIdx},{solutionIdx}'),) |
| 584 |
probIdx += 1 |
| 585 |
|
| 586 |
if activationArgs: |
| 587 |
for setting in activationArgs.settingList: |
| 588 |
param('activation-enum-args', setting.activationEnum.toEnum()) |
| 589 |
param('activation-type', problemType.activationType.toEnum()) |
| 590 |
param('activation-no-guard', problemType.activationNoGuard) |
| 591 |
if globalParameters["DataInitValueActivationArgs"]: |
| 592 |
param('activation-additional-args', ','.join(map(str, globalParameters["DataInitValueActivationArgs"]))) |
| 593 |
|
| 594 |
param("device-idx", deviceId) |
| 595 |
|
| 596 |
param("init-seed", globalParameters["DataInitSeed"]) |
| 597 |
|
| 598 |
for key,value in dataInitParams(problemType): |
| 599 |
param(key, value) |
| 600 |
|
| 601 |
param("c-equal-d", globalParameters["CEqualD"]) |
| 602 |
|
| 603 |
if globalParameters["PrintTensorA"]: |
| 604 |
param("print-tensor-a", 1) |
| 605 |
if globalParameters["PrintTensorB"]: |
| 606 |
param("print-tensor-b", 1) |
| 607 |
if globalParameters["PrintTensorC"]: |
| 608 |
param("print-tensor-c", 1) |
| 609 |
if globalParameters["PrintTensorD"]: |
| 610 |
param("print-tensor-d", 1) |
| 611 |
if globalParameters["PrintTensorRef"]: |
| 612 |
param("print-tensor-ref", 1) |
| 613 |
if globalParameters["PrintTensorBias"]: |
| 614 |
param("print-tensor-bias", 1) |
| 615 |
if globalParameters["PrintTensorScaleAlphaVec"]: |
| 616 |
param("print-tensor-scale-alpha-vec", 1) |
| 617 |
if globalParameters["PrintTensorAmaxD"]: |
| 618 |
param("print-tensor-amaxd", 1) |
| 619 |
if globalParameters["DumpTensors"]: |
| 620 |
param("dump-tensors", 1) |
| 621 |
if globalParameters["ExitOnFails"] > 1: |
| 622 |
param("exit-on-error", 1) |
| 623 |
|
| 624 |
param('prune-mode', pruneModeName(int(globalParameters["PruneSparseMode"]))) |
| 625 |
param("bounds-check", boundsCheckName(int(globalParameters["BoundsCheck"]))) |
| 626 |
param("print-valids", globalParameters["ValidationPrintValids"]) |
| 627 |
param("print-max", globalParameters["ValidationMaxToPrint"]) |
| 628 |
param("num-benchmarks", globalParameters["NumBenchmarks"]) |
| 629 |
|
| 630 |
numElementsToValidate = globalParameters["NumElementsToValidate"] |
| 631 |
if not forBenchmark: |
| 632 |
if globalParameters["NumElementsToValidateWinner"] == -1 or numElementsToValidate == -1: |
| 633 |
numElementsToValidate = -1 |
| 634 |
else: |
| 635 |
numElementsToValidate = max(globalParameters["NumElementsToValidateWinner"], globalParameters["NumElementsToValidate"]) |
| 636 |
param("num-elements-to-validate", numElementsToValidate) |
| 637 |
param("num-enqueues-per-sync", globalParameters["EnqueuesPerSync"]) |
| 638 |
param("max-enqueues-per-sync", globalParameters["MaxEnqueuesPerSync"]) |
| 639 |
param("num-syncs-per-benchmark", globalParameters["SyncsPerBenchmark"]) |
| 640 |
param("skip-slow-solution-ratio", globalParameters["SkipSlowSolutionRatio"]) |
| 641 |
param("use-gpu-timer", globalParameters["KernelTime"]) |
| 642 |
param("hardware-monitor", globalParameters["HardwareMonitor"]) |
| 643 |
param("num-warmups", globalParameters["NumWarmups"]) |
| 644 |
param("min-flops-per-sync", globalParameters["MinFlopsPerSync"]) |
| 645 |
param("sleep-percent", globalParameters["SleepPercent"]) |
| 646 |
param("perf-l2-read-hits", globalParameters["PerfModelL2ReadHits"]) |
| 647 |
param("perf-l2-write-hits", globalParameters["PerfModelL2WriteHits"]) |
| 648 |
param("perf-l2-read-bw-mul", globalParameters["PerfModelL2ReadBwMul"]) |
| 649 |
param("perf-read-efficiency", globalParameters["PerfModelReadEfficiency"]) |
| 650 |
param("csv-export-extra-cols", globalParameters["CSVExportWinner"]) |
| 651 |
param("csv-merge-same-problems", globalParameters["CSVMergeSameProblemID"]) |
| 652 |
param("log-level", ClientLogLevel(globalParameters["ClientLogLevel"]).name) |
| 653 |
param("max-workspace-size", globalParameters["MaxWorkspaceSize"]) |
| 654 |
param("PrintWinnersOnly", globalParameters["PrintWinnersOnly"]) |
| 655 |
param("granularity-threshold", globalParameters["GranularityThreshold"]) |
| 656 |
param("pristine-on-gpu", globalParameters["PristineOnGPU"]) |
| 657 |
|
| 658 |
param("library-update-file", globalParameters["LibraryUpdateFile"]) |
| 659 |
param("library-update-comment", globalParameters["LibraryUpdateComment"]) |
| 660 |
|
| 661 |
param("use-user-args", globalParameters["UseUserArgs"]) |
| 662 |
param("rotating-buffer-size", globalParameters["RotatingBufferSize"]) |
| 663 |
param("rotating-buffer-mode", globalParameters["RotatingMode"]) |
| 664 |
|
| 665 |
|
| 666 |
def writeClientConfig( |
| 667 |
forBenchmark, |
| 668 |
solutions, |
| 669 |
problemSizes, |
| 670 |
biasTypeArgs, |
| 671 |
factorDimArgs, |
| 672 |
activationArgs, |
| 673 |
icacheFlushArgs, |
| 674 |
stepName, |
| 675 |
stepBaseDir, |
| 676 |
newLibrary, |
| 677 |
codeObjectFiles, |
| 678 |
tileAwareSelection, |
| 679 |
deviceId: int, |
| 680 |
gfxName: str, |
| 681 |
configBase = "ClientParameters", |
| 682 |
libraryFile = None, |
| 683 |
probSolMap = {} |
| 684 |
): |
| 685 |
|
| 686 |
sourceDir = os.path.join(stepBaseDir, "source") |
| 687 |
|
| 688 |
if tileAwareSelection: |
| 689 |
filename = os.path.join(sourceDir, "%s_Granularity.ini"%configBase) |
| 690 |
else: |
| 691 |
filename = os.path.join(sourceDir, "%s.ini"%configBase) |
| 692 |
|
| 693 |
if len(newLibrary.solutions)==0: |
| 694 |
raise RuntimeError ("No valid solutions found") |
| 695 |
|
| 696 |
resultsFileName = None |
| 697 |
if tileAwareSelection: |
| 698 |
resultsFileName = os.path.join(stepBaseDir, "../Data", stepName+"_Granularity.csv") |
| 699 |
else: |
| 700 |
resultsFileName = os.path.join(stepBaseDir, "../Data", stepName+".csv") |
| 701 |
|
| 702 |
newSolution = next(iter(newLibrary.solutions.values())) |
| 703 |
writeClientConfigIni(forBenchmark, problemSizes, biasTypeArgs, factorDimArgs, activationArgs, icacheFlushArgs, newSolution.problemType, sourceDir, codeObjectFiles, resultsFileName, filename, deviceId, gfxName, libraryFile, probSolMap) |
| 704 |
|
| 705 |
return filename |
| 706 |
|
| 707 |
def CreateBenchmarkClientParametersForSizes(libraryRootPath, problemSizes, dataFilePath, configFile, deviceId, gfxName, problemTypeDict=None): |
| 708 |
|
| 709 |
libraryPath = os.path.join(libraryRootPath, "library") |
| 710 |
libraryFiles = [os.path.join(libraryPath, f) for f in os.listdir(libraryPath)] |
| 711 |
codeObjectFiles = [f for f in libraryFiles if f.endswith("co")] |
| 712 |
|
| 713 |
if problemTypeDict: |
| 714 |
problemType = ContractionsProblemType.FromOriginalState(problemTypeDict) |
| 715 |
else: |
| 716 |
|
| 717 |
metaDataFilePath = os.path.join(libraryPath, "metadata.yaml") |
| 718 |
if not os.path.exists(metaDataFilePath): |
| 719 |
printExit ("meta data file %s does not exist" % metaDataFilePath) |
| 720 |
metaData = LibraryIO.read(metaDataFilePath) |
| 721 |
problemTypeDict = metaData["ProblemType"] |
| 722 |
problemType = ContractionsProblemType.FromOriginalState(problemTypeDict) |
| 723 |
|
| 724 |
writeClientConfigIni(True, problemSizes, "", "", "", "", problemType, libraryRootPath, codeObjectFiles, dataFilePath, configFile, deviceId, gfxName) |
| 725 |
|
| 726 |
def getClientExecutablePath(): |
| 727 |
clientExe = globalParameters.get("PrebuiltClient") |
| 728 |
|
| 729 |
if not os.path.isfile(clientExe): |
| 730 |
raise FileNotFoundError( |
| 731 |
f"Tensile client executable not found at '{clientExe}'.\n" |
| 732 |
"Please ensure the client is built or provide a valid path using the --prebuilt-client flag.\n" |
| 733 |
"To build, run: `invoke build-client` (you may need to `pip3 install invoke` first).\n" |
| 734 |
"For custom cmake build instructions, please refer to the README in next-cmake." |
| 735 |
) |
| 736 |
return clientExe |