Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify toolchain components at program invocation #1413

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions tensilelite/Tensile/BenchmarkProblems.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from .CustomKernels import getCustomKernelConfig


def generateForkedSolutions(problemType, constantParams, forkPermutations):
def generateForkedSolutions(problemType, constantParams, forkPermutations, cxxCompiler):
"""Creates a list with a Solution object for each parameter combination in forkPermutations"""
print1("# Enumerating Solutions")

Expand All @@ -56,7 +56,7 @@ def generateForkedSolutions(problemType, constantParams, forkPermutations):
solution.update(perm)

# TODO check if solution matches problem size for exact tile kernels
solutionObject = Solution(solution)
solutionObject = Solution(solution, cxxCompiler)
if solutionObject["Valid"]:
if solutionObject not in solutionSet:
solutionSet.add(solutionObject)
Expand Down Expand Up @@ -109,7 +109,7 @@ def generateCustomKernelSolutions(problemType, customKernels, internalSupportPar
return solutions

def writeBenchmarkFiles(stepBaseDir, solutions, problemSizes, \
biasTypeArgs, factorDimArgs, activationArgs, icacheFlushArgs, stepName, solutionSummationSizes):
biasTypeArgs, factorDimArgs, activationArgs, icacheFlushArgs, stepName, solutionSummationSizes, cxxCompiler, offloadBundler):
"""Write all the files needed for a given benchmarking step"""
if not globalParameters["MergeFiles"]:
ensurePath(os.path.join(globalParameters["WorkingPath"], "Solutions"))
Expand Down Expand Up @@ -140,19 +140,19 @@ def writeBenchmarkFiles(stepBaseDir, solutions, problemSizes, \

kernelSerialNaming = Solution.getSerialNaming(kernels)
kernelMinNaming = Solution.getMinNaming(kernels)
kernelWriterAssembly = KernelWriterAssembly(kernelMinNaming, kernelSerialNaming)
kernelWriterAssembly = KernelWriterAssembly(kernelMinNaming, kernelSerialNaming, cxxCompiler)

# write solution, kernels and CMake
problemType = solutions[0]["ProblemType"]
codeObjectFiles = writeSolutionsAndKernels( \
globalParameters["WorkingPath"], globalParameters["CxxCompiler"], \
[problemType], solutions, kernels, kernelHelperOjbs, \
globalParameters["WorkingPath"], cxxCompiler, offloadBundler, \
solutions, kernels, kernelHelperOjbs, \
kernelWriterAssembly, errorTolerant=True )
# ^ this is where solutions is mutated

newLibraryDir = ensurePath(os.path.join(globalParameters["WorkingPath"], 'library'))
newLibraryFile = os.path.join(newLibraryDir, "TensileLibrary")
newLibrary = SolutionLibrary.MasterSolutionLibrary.BenchmarkingLibrary(solutions)
newLibrary = SolutionLibrary.MasterSolutionLibrary.BenchmarkingLibrary(solutions, cxxCompiler)
newLibrary.applyNaming(kernelMinNaming)
LibraryIO.write(newLibraryFile, Utils.state(newLibrary), globalParameters["LibraryFormat"])

Expand Down Expand Up @@ -193,7 +193,7 @@ def writeBenchmarkFiles(stepBaseDir, solutions, problemSizes, \
return codeObjectFiles


def benchmarkProblemType(problemTypeConfig, problemSizeGroupConfig, problemSizeGroupIdx, useCache):
def benchmarkProblemType(problemTypeConfig, problemSizeGroupConfig, problemSizeGroupIdx, useCache, cxxCompiler: str, cCompiler: str, offloadBundler: str):
"""Run the benchmarking for a single entry in the BenchmarkProblems of a Tensile config"""
benchmarkTestFails = 0

Expand Down Expand Up @@ -275,7 +275,7 @@ def benchmarkProblemType(problemTypeConfig, problemSizeGroupConfig, problemSizeG
maxPossibleSolutions = len(forkPermutations)

regSolutions = generateForkedSolutions(benchmarkProcess.problemType, \
benchmarkStep.constantParams, forkPermutations)
benchmarkStep.constantParams, forkPermutations, cxxCompiler)
kcSolutions = generateCustomKernelSolutions(benchmarkProcess.problemType, \
benchmarkStep.customKernels, benchmarkStep.internalSupportParams, \
not benchmarkStep.customKernelWildcard)
Expand Down Expand Up @@ -307,7 +307,7 @@ def benchmarkProblemType(problemTypeConfig, problemSizeGroupConfig, problemSizeG
codeObjectFiles = writeBenchmarkFiles(stepBaseDir, solutions, \
benchmarkStep.problemSizes, benchmarkStep.biasTypeArgs, \
benchmarkStep.factorDimArgs, benchmarkStep.activationArgs, \
benchmarkStep.icacheFlushArgs, shortName, [])
benchmarkStep.icacheFlushArgs, shortName, [], cxxCompiler, offloadBundler)
# ^ this mutates solutions

# write cache data
Expand Down Expand Up @@ -356,7 +356,7 @@ def benchmarkProblemType(problemTypeConfig, problemSizeGroupConfig, problemSizeG
if not os.path.exists(resultsFileName) or globalParameters["ForceRedoBenchmarkProblems"]:
libraryLogicPath = None
forBenchmark = True
returncode = runClient(libraryLogicPath, forBenchmark, enableTileSelection)
returncode = runClient(libraryLogicPath, forBenchmark, enableTileSelection, cxxCompiler, cCompiler)

if returncode:
benchmarkTestFails += 1
Expand All @@ -376,9 +376,9 @@ def benchmarkProblemType(problemTypeConfig, problemSizeGroupConfig, problemSizeG
return (resultsFileBaseFinal, benchmarkTestFails)


def main(config, useCache):
def main(config, useCache, cxxCompiler: str, cCompiler: str, offloadBundler: str):
"""Entry point for the "BenchmarkProblems" section of a Tensile config yaml"""
ClientExecutable.getClientExecutable()
ClientExecutable.getClientExecutable(cxxCompiler, cCompiler)

if config is None:
print(f'No config specified in {globalParameters["ConfigPath"]}, built client only')
Expand Down Expand Up @@ -417,7 +417,7 @@ def main(config, useCache):

# benchmark problem size group
(resultsFileBaseFinal, benchmarkErrors) = \
benchmarkProblemType(problemTypeConfig, sizeGroupConfig, idx, useCache)
benchmarkProblemType(problemTypeConfig, sizeGroupConfig, idx, useCache, cxxCompiler, cCompiler, offloadBundler)
totalTestFails += benchmarkErrors

print("clientExit={} {} for {}" \
Expand Down
16 changes: 7 additions & 9 deletions tensilelite/Tensile/ClientExecutable.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import itertools
import os
import subprocess
from typing import Optional

from . import Common
from .Common import globalParameters, supportedCompiler
from .Common import globalParameters

class CMakeEnvironment:
def __init__(self, sourceDir, buildDir, **options):
Expand All @@ -54,36 +55,33 @@ def build(self):
def builtPath(self, path, *paths):
return os.path.join(self.buildDir, path, *paths)

def clientExecutableEnvironment(builddir=None):
def clientExecutableEnvironment(builddir: Optional[str], cxxCompiler: str, cCompiler: str):
sourcedir = globalParameters["SourcePath"]
if builddir is None:
builddir = os.path.join(globalParameters["OutputPath"], globalParameters["ClientBuildPath"])
builddir = Common.ensurePath(builddir)

CxxCompiler = "clang++.exe" if ((os.name == "nt") and supportedCompiler(globalParameters['CxxCompiler'])) else globalParameters['CxxCompiler']
CCompiler = "clang.exe" if ((os.name == "nt") and supportedCompiler(globalParameters['CxxCompiler'])) else globalParameters['CCompiler']

options = {'CMAKE_BUILD_TYPE': globalParameters["CMakeBuildType"],
'TENSILE_USE_MSGPACK': 'ON',
'TENSILE_USE_LLVM': 'OFF' if (os.name == "nt") else 'ON',
'Tensile_LIBRARY_FORMAT': globalParameters["LibraryFormat"],
'Tensile_ENABLE_MARKER' : globalParameters["EnableMarker"],
'CMAKE_CXX_COMPILER': os.path.join(globalParameters["ROCmBinPath"], CxxCompiler),
'CMAKE_C_COMPILER': os.path.join(globalParameters["ROCmBinPath"], CCompiler)}
'CMAKE_CXX_COMPILER': os.path.join(globalParameters["ROCmBinPath"], cxxCompiler),
'CMAKE_C_COMPILER': os.path.join(globalParameters["ROCmBinPath"], cCompiler)}

return CMakeEnvironment(sourcedir, builddir, **options)


buildEnv = None

def getClientExecutable(builddir=None):
def getClientExecutable(cxxCompiler: str, cCompiler: str, builddir=None):
if "PrebuiltClient" in globalParameters:
return globalParameters["PrebuiltClient"]

global buildEnv

if buildEnv is None:
buildEnv = clientExecutableEnvironment(builddir)
buildEnv = clientExecutableEnvironment(builddir, cxxCompiler, cCompiler)
buildEnv.generate()
buildEnv.build()

Expand Down
28 changes: 14 additions & 14 deletions tensilelite/Tensile/ClientWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ClientLogLevel(Enum):
################################################################################
# Main
################################################################################
def main( config ):
def main(config, cxxCompiler: str, cCompiler: str):
libraryLogicPath = os.path.join(globalParameters["WorkingPath"], \
globalParameters["LibraryLogicPath"])
stepBaseDir = pushWorkingPath(globalParameters["LibraryClientPath"])
Expand All @@ -96,7 +96,7 @@ def main( config ):
functionNames = []
enableHalf = False

createLibraryScript = getBuildClientLibraryScript(stepBaseDir, libraryLogicPath)
createLibraryScript = getBuildClientLibraryScript(stepBaseDir, libraryLogicPath, cxxCompiler)
subprocess.run(shlex.split(createLibraryScript), cwd=stepBaseDir)
coList = []
yamlList = []
Expand All @@ -108,7 +108,7 @@ def main( config ):
clientParametersPaths = []
for logicFileName in logicFiles:
(scheduleName, _, problemType, _, exactLogic, newLibrary, _) \
= LibraryIO.parseLibraryLogicFile(logicFileName)
= LibraryIO.parseLibraryLogicFile(logicFileName, cxxCompiler)
if problemType["DataType"].isHalf():
enableHalf = True
functions.append((scheduleName, problemType))
Expand Down Expand Up @@ -175,7 +175,7 @@ def main( config ):

forBenchmark = False
enableTileSelection = False
returncode = runClient(libraryLogicPath, forBenchmark, enableTileSelection, clientParametersPaths)
returncode = runClient(libraryLogicPath, forBenchmark, enableTileSelection, cxxCompiler, cCompiler, clientParametersPaths)

popWorkingPath() # LibraryClient

Expand All @@ -184,9 +184,9 @@ def main( config ):
################################################################################
# Write Run Script
################################################################################
def runNewClient(scriptPath, clientParametersPath, clientBuildDir=None):
def runNewClient(scriptPath, clientParametersPath, cxxCompiler: str, cCompiler: str, clientBuildDir=None):

clientExe = ClientExecutable.getClientExecutable(clientBuildDir)
clientExe = ClientExecutable.getClientExecutable(cxxCompiler, cCompiler, clientBuildDir)
iniFile = "--config-file={}".format(clientParametersPath)
args = [clientExe, iniFile]

Expand All @@ -196,12 +196,12 @@ def runNewClient(scriptPath, clientParametersPath, clientBuildDir=None):
printWarning("ClientWriter Benchmark Process exited with error: {}".format(e))


def runClient(libraryLogicPath, forBenchmark, enableTileSelection, configPaths=None):
def runClient(libraryLogicPath, forBenchmark, enableTileSelection, cxxCompiler: str, cCompiler: str, configPaths=None):
# write runScript
pushWorkingPath("build")
path = globalParameters["WorkingPath"]

runScriptName = writeRunScript(path, forBenchmark, enableTileSelection, configPaths)
runScriptName = writeRunScript(path, forBenchmark, enableTileSelection, cxxCompiler, cCompiler, configPaths)
with ClientExecutionLock():
process = subprocess.Popen(runScriptName, cwd=path)
process.communicate()
Expand All @@ -212,7 +212,7 @@ def runClient(libraryLogicPath, forBenchmark, enableTileSelection, configPaths=N

return process.returncode

def getBuildClientLibraryScript(buildPath, libraryLogicPath):
def getBuildClientLibraryScript(buildPath, libraryLogicPath, cxxCompiler):
import io
runScriptFile = io.StringIO()

Expand Down Expand Up @@ -245,7 +245,7 @@ def getBuildClientLibraryScript(buildPath, libraryLogicPath):

callCreateLibraryCmd += " --architecture=" + globalParameters["Architecture"]
callCreateLibraryCmd += " --code-object-version=" + globalParameters["CodeObjectVersion"]
callCreateLibraryCmd += " --cxx-compiler=" + globalParameters["CxxCompiler"]
callCreateLibraryCmd += " --cxx-compiler=" + cxxCompiler
callCreateLibraryCmd += " --library-format=" + globalParameters["LibraryFormat"]

callCreateLibraryCmd += " %s" % libraryLogicPath
Expand All @@ -256,19 +256,19 @@ def getBuildClientLibraryScript(buildPath, libraryLogicPath):

return runScriptFile.getvalue()

def writeBuildClientLibraryScript(path, libraryLogicPath):
def writeBuildClientLibraryScript(path, libraryLogicPath, cxxCompiler):
filename = os.path.join(path, \
"build.%s" % ("bat" if os.name == "nt" else "sh") )
with open(filename, "w") as file:
file.write("#!/bin/bash\n\n")
file.write("set -ex\n")
file.write(getBuildClientLibraryScript(path, libraryLogicPath))
file.write(getBuildClientLibraryScript(path, libraryLogicPath, cxxCompiler))

if os.name != "nt":
os.chmod(filename, 0o777)
return filename

def writeRunScript(path, forBenchmark, enableTileSelection, configPaths=None):
def writeRunScript(path, forBenchmark, enableTileSelection, cxxCompiler: str, cCompiler: str, configPaths=None):
if configPaths is None:
configPaths = []
configPaths.append(os.path.join(globalParameters["WorkingPath"], "../source/ClientParameters.ini"))
Expand Down Expand Up @@ -305,7 +305,7 @@ def writeRunScript(path, forBenchmark, enableTileSelection, configPaths=None):

runScriptFile.write("ERR1=0\n")

clientExe = ClientExecutable.getClientExecutable()
clientExe = ClientExecutable.getClientExecutable(cxxCompiler, cCompiler)
for configFile in configPaths:
runScriptFile.write("{} --config-file {} {}\n".format(clientExe, configFile, globalParameters["ClientArgs"]))
runScriptFile.write("ERR2=$?\n\n")
Expand Down
Loading