Skip to content

Verify toolchain components at program invocation #1413

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

Merged
merged 15 commits into from
Dec 12, 2024
Merged
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
41 changes: 22 additions & 19 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 All @@ -67,17 +67,18 @@ def generateForkedSolutions(problemType, constantParams, forkPermutations):
return solutions


def getCustomKernelSolutionObj(kernelName, internalSupportParams, directory=globalParameters["CustomKernelDirectory"]):
def getCustomKernelSolutionObj(kernelName, internalSupportParams, cxxCompiler: str, directory=globalParameters["CustomKernelDirectory"]):
"""Creates the Solution object for a custom kernel"""
return Solution(getCustomKernelConfig(kernelName, internalSupportParams, directory))
config = getCustomKernelConfig(kernelName, internalSupportParams, directory)
return Solution(config, cxxCompiler)


def generateCustomKernelSolutions(problemType, customKernels, internalSupportParams, failOnMismatch):
def generateCustomKernelSolutions(problemType, customKernels, internalSupportParams, failOnMismatch, cxxCompiler: str):
"""Creates a list with a Solution object for each name in customKernel"""
solutions = []
for kernelName in customKernels:
print1("# Processing custom kernel {}".format(kernelName))
solution = getCustomKernelSolutionObj(kernelName, internalSupportParams)
solution = getCustomKernelSolutionObj(kernelName, internalSupportParams, cxxCompiler)
# The ActivationType setting in YAML is meaningless in customKernel case.
# Therefore, we override the customKernel setting with the ActivationType value from ProblemType to avoid false alarms during subsequent problemType checks.
solution["ProblemType"]["ActivationType"] = problemType["ActivationType"]
Expand Down Expand Up @@ -109,7 +110,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, assembler, 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 +141,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, assembler, 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 +194,9 @@ def writeBenchmarkFiles(stepBaseDir, solutions, problemSizes, \
return codeObjectFiles


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

Expand Down Expand Up @@ -275,10 +278,10 @@ 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)
not benchmarkStep.customKernelWildcard, cxxCompiler)

maxPossibleSolutions += len(kcSolutions)
solutions = regSolutions + kcSolutions
Expand Down Expand Up @@ -307,7 +310,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, assembler, offloadBundler)
# ^ this mutates solutions

# write cache data
Expand Down Expand Up @@ -356,7 +359,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 +379,9 @@ def benchmarkProblemType(problemTypeConfig, problemSizeGroupConfig, problemSizeG
return (resultsFileBaseFinal, benchmarkTestFails)


def main(config, useCache):
def main(config, useCache, cxxCompiler: str, cCompiler: str, assembler: 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 +420,7 @@ def main(config, useCache):

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

print("clientExit={} {} for {}" \
Expand Down
10 changes: 5 additions & 5 deletions tensilelite/Tensile/BuildCommands/AssemblyCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .SharedCommands import compressCodeObject

def _linkIntoCodeObject(
objFiles: List[str], coPathDest: Union[Path, str], kernelWriterAssembly: KernelWriterAssembly
objFiles: List[str], coPathDest: Union[Path, str], kernelWriterAssembly: KernelWriterAssembly, assembler: str
):
"""Links object files into a code object file.

Expand All @@ -31,7 +31,7 @@ def _linkIntoCodeObject(
with open(Path.cwd() / "clangArgs.txt", 'wt') as file:
file.write(" ".join(objFiles))
file.flush()
args = [globalParameters['AssemblerPath'], '-target', 'amdgcn-amd-amdhsa', '-o', coFileRaw, '@clangArgs.txt']
args = [assembler, '-target', 'amdgcn-amd-amdhsa', '-o', coFileRaw, '@clangArgs.txt']
subprocess.check_call(args, cwd=asmDir)
else:
numObjFiles = len(objFiles)
Expand Down Expand Up @@ -61,7 +61,7 @@ def _linkIntoCodeObject(



def buildAssemblyCodeObjectFiles(kernels, kernelWriterAssembly, outputPath, compress: bool=True):
def buildAssemblyCodeObjectFiles(kernels, kernelWriterAssembly, outputPath, assembler: str, offloadBundler: str, compress: bool=True):

isAsm = lambda k: k["KernelLanguage"] == "Assembly"

Expand Down Expand Up @@ -98,10 +98,10 @@ def buildAssemblyCodeObjectFiles(kernels, kernelWriterAssembly, outputPath, comp

for coFileRaw, objFiles in coFileMap.items():

_linkIntoCodeObject(objFiles, coFileRaw, kernelWriterAssembly)
_linkIntoCodeObject(objFiles, coFileRaw, kernelWriterAssembly, assembler)
coFile = destDir / coFileRaw.name.replace(extCoRaw, extCo)
if compress:
compressCodeObject(coFileRaw, coFile, gfx, globalParameters["ClangOffloadBundlerPath"])
compressCodeObject(coFileRaw, coFile, gfx, offloadBundler)
else:
shutil.move(coFileRaw, coFile)

Expand Down
17 changes: 7 additions & 10 deletions tensilelite/Tensile/BuildCommands/SourceCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Iterable, List, Union

from ..Common import globalParameters, print2, ensurePath, supportedCompiler, ParallelMap2, splitArchs, which
from .SharedCommands import compressCodeObject

def _compileSourceObjectFile(cmdlineArchs: List[str], cxxCompiler: str, cxxSrcPath: str, objDestPath: str, outputPath: str):
"""Compiles a source file into an object file.
Expand Down Expand Up @@ -128,7 +127,7 @@ def _unbundleSourceCodeObjects(bundler: str, target: str, infile: str, outfileRa
raise RuntimeError(f"Error unbundling source code object file: {err.output}\nFailed command: {' '.join(args)}")


def _buildSourceCodeObjectFile(cxxCompiler: str, outputPath: Union[Path, str], kernelPath: Union[Path, str]) -> List[str]:
def _buildSourceCodeObjectFile(cxxCompiler: str, offloadBundler: str, outputPath: Union[Path, str], kernelPath: Union[Path, str]) -> List[str]:
"""Compiles a HIP source code file into a code object file.

Args:
Expand Down Expand Up @@ -158,17 +157,15 @@ def _buildSourceCodeObjectFile(cxxCompiler: str, outputPath: Union[Path, str], k
objPath = str(buildPath / objFilename)
_compileSourceObjectFile(cmdlineArchs, cxxCompiler, str(kernelPath), objPath, str(outputPath))

bundler = globalParameters["ClangOffloadBundlerPath"]
if not bundler:
if not offloadBundler:
raise RuntimeError("No bundler found; set TENSILE_ROCM_OFFLOAD_BUNDLER_PATH to point to clang-offload-bundler")

for target in _listTargetTriples(bundler, objPath):
match = re.search("gfx.*$", target)
if match:
for target in _listTargetTriples(offloadBundler, objPath):
if match := re.search("gfx.*$", target):
arch = re.sub(":", "-", match.group())
coPathRaw = _computeSourceCodeObjectFilename(target, kernelPath.stem, buildPath, arch)
if not coPathRaw: continue
_unbundleSourceCodeObjects(bundler, target, objPath, str(coPathRaw))
_unbundleSourceCodeObjects(offloadBundler, target, objPath, str(coPathRaw))

coPath = str(destPath / coPathRaw.stem)
coPathsRaw.append(coPathRaw)
Expand All @@ -179,7 +176,7 @@ def _buildSourceCodeObjectFile(cxxCompiler: str, outputPath: Union[Path, str], k

return coPaths

def buildSourceCodeObjectFiles(cxxCompiler: str, kernelFiles: List[Path], outputPath: Path) -> Iterable[str]:
def buildSourceCodeObjectFiles(cxxCompiler: str, offloadBundler: str, kernelFiles: List[Path], outputPath: Path) -> Iterable[str]:
"""Compiles HIP source code files into code object files.

Args:
Expand All @@ -191,6 +188,6 @@ def buildSourceCodeObjectFiles(cxxCompiler: str, kernelFiles: List[Path], output
Returns:
List of paths to the created code objects.
"""
args = zip(itertools.repeat(cxxCompiler), itertools.repeat(outputPath), kernelFiles)
args = zip(itertools.repeat(cxxCompiler), itertools.repeat(offloadBundler), itertools.repeat(outputPath), kernelFiles)
coFiles = ParallelMap2(_buildSourceCodeObjectFile, args, "Compiling source kernels")
return itertools.chain.from_iterable(coFiles)
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
Loading