Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
916649c
draft: move validate mi to module
bstefanuk Feb 4, 2025
c8eaec3
draft: try ray
bstefanuk Feb 5, 2025
73d9777
Merge branch 'move-common-to-module' into valid-mi-test
bstefanuk Feb 5, 2025
8fb2aa4
feat: use asserts for checks
bstefanuk Feb 6, 2025
353c1f9
style: updating printing and output
bstefanuk Feb 6, 2025
aa37e27
feat: update error printing
bstefanuk Feb 7, 2025
83c1579
Merge branch 'move-common-to-module' into valid-mi-test
bstefanuk Feb 7, 2025
cfd24ef
Merge branch 'move-common-to-module' into valid-mi-test
bstefanuk Feb 10, 2025
e1ccd66
feat: update error printing
bstefanuk Feb 7, 2025
16a90ac
fix: reviewer comments
bstefanuk Feb 10, 2025
3e15ca0
fix: remove mem bloat check in SolutionStructs
bstefanuk Feb 10, 2025
8055876
fix: remove unused test logic file
bstefanuk Feb 10, 2025
8b494b0
fix: purge library-print-debug
bstefanuk Feb 10, 2025
4034d5c
feat: make build paths static
bstefanuk Feb 10, 2025
96378bd
feat: remove 'SortProblems' global param
bstefanuk Feb 10, 2025
a990ad8
feat: remove 'ExpandRanges' global param
bstefanuk Feb 10, 2025
714b9a4
feat: remove 'WavefrontWidth' global param
bstefanuk Feb 10, 2025
e16bd5b
feat: remove 'ValidateLibrary' global param
bstefanuk Feb 10, 2025
aada843
feat: remove 'EnableHalf' and 'ClientArgs' global params
bstefanuk Feb 10, 2025
8b47b35
feat: prefer profile decorator over 'Profiler' global param
bstefanuk Feb 10, 2025
b0e44be
chore: remove 'LibraryPrintDebug' from build_client.yaml
bstefanuk Feb 10, 2025
e403138
feat: remove 'MaxFileName' from global params
bstefanuk Feb 10, 2025
855a7c1
Merge branch 'move-common-to-module' into global-removal-unused-and-s…
bstefanuk Feb 10, 2025
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
8 changes: 4 additions & 4 deletions tensilelite/Tensile/BenchmarkProblems.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
from .Toolchain.Assembly import AssemblyToolchain
from .Toolchain.Source import SourceToolchain
from .Common import globalParameters, HR, print1, print2, \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume removing globalParams isn't in scope.

printExit, printWarning, ensurePath, startTime, tqdm, state
printExit, printWarning, ensurePath, startTime, tqdm, state, \
BENCHMARK_PROBLEMS_DIR, BENCHMARK_DATA_DIR


def generateForkedSolutions(problemType, constantParams, forkPermutations, cxxCompiler):
Expand Down Expand Up @@ -386,7 +387,7 @@ def main(config, useCache, asmToolchain: AssemblyToolchain, srcToolchain: Source
print(f'No config specified in {globalParameters["ConfigPath"]}, built client only')
return

benchmarkDataPath = ensurePath(outputPath / globalParameters["BenchmarkDataPath"])
benchmarkDataPath = ensurePath(outputPath / BENCHMARK_DATA_DIR)

totalTestFails = 0
for benchmarkProblemTypeConfig in config:
Expand All @@ -399,7 +400,6 @@ def main(config, useCache, asmToolchain: AssemblyToolchain, srcToolchain: Source
for idx, sizeGroupConfig in enumerate(problemSizeGroupConfigs):
print2("ProblemTypeConfig: {}".format(problemTypeConfig))
problemTypeObj = ProblemType(problemTypeConfig)
globalParameters["EnableHalf"] = problemTypeObj["DataType"].isHalf()

# using a suffix to check the csv version (for later addFromCSV())
csvSuffix = "_CSVWinner" if globalParameters["CSVExportWinner"] else ""
Expand All @@ -416,7 +416,7 @@ def main(config, useCache, asmToolchain: AssemblyToolchain, srcToolchain: Source
or not os.path.exists(newResultsFileName):

# benchmark problem size group
benchmarkProblemsPath = ensurePath(outputPath / globalParameters["BenchmarkProblemsPath"])
benchmarkProblemsPath = ensurePath(outputPath / BENCHMARK_PROBLEMS_DIR)
(resultsFileBaseFinal, benchmarkErrors) = \
benchmarkProblemType(problemTypeConfig, sizeGroupConfig, idx, useCache, asmToolchain, srcToolchain, cCompiler, buildTmpPath, benchmarkProblemsPath)
totalTestFails += benchmarkErrors
Expand Down
4 changes: 2 additions & 2 deletions tensilelite/Tensile/ClientExecutable.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pathlib import Path

from . import SOURCE_PATH
from .Common import globalParameters, print2, ClientExecutionLock, ensurePath
from .Common import globalParameters, print2, ClientExecutionLock, ensurePath, CLIENT_BUILD_DIR

class CMakeEnvironment:
def __init__(self, sourceDir, buildDir, **options):
Expand Down Expand Up @@ -81,7 +81,7 @@ def getClientExecutable(cxxCompiler: str, cCompiler: str, builddir):
global buildEnv

if buildEnv is None:
buildEnv = clientExecutableEnvironment(builddir / globalParameters["ClientBuildPath"], cxxCompiler, cCompiler)
buildEnv = clientExecutableEnvironment(builddir / CLIENT_BUILD_DIR, cxxCompiler, cCompiler)
buildEnv.generate()
buildEnv.build()

Expand Down
15 changes: 6 additions & 9 deletions tensilelite/Tensile/ClientWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
from . import ROOT_PATH
from . import ClientExecutable
from . import LibraryIO
from .Common import globalParameters, ensurePath, print1, printExit, printWarning, ClientExecutionLock, isaToGfx
from .Common import globalParameters, ensurePath, print1, printExit, printWarning, ClientExecutionLock, isaToGfx, \
LIBRARY_LOGIC_DIR, LIBRARY_CLIENT_DIR
from .SolutionStructs import ProblemType, ProblemSizesMock, ProblemSizesMockDummy, ActivationArgs, BiasTypeArgs, FactorDimArgs
from .TensileCreateLibrary import copyStaticFiles
from .Contractions import FreeIndex, BatchIndex
Expand Down Expand Up @@ -80,8 +81,8 @@ class ClientLogLevel(Enum):
################################################################################
def main(config, cxxCompiler: str, cCompiler: str, outputPath: Path):

libraryLogicPath = ensurePath(outputPath / globalParameters["LibraryLogicPath"])
clientLibraryPath = ensurePath(outputPath / globalParameters["LibraryClientPath"])
libraryLogicPath = ensurePath(outputPath / LIBRARY_LOGIC_DIR)
clientLibraryPath = ensurePath(outputPath / LIBRARY_CLIENT_DIR)
sourcePath = ensurePath(clientLibraryPath / "source")
copyStaticFiles(sourcePath)

Expand All @@ -95,7 +96,6 @@ def main(config, cxxCompiler: str, cCompiler: str, outputPath: Path):
print1("LogicFiles: %s" % logicFiles)
functions = []
functionNames = []
enableHalf = False

createLibraryScript = getBuildClientLibraryScript(clientLibraryPath, libraryLogicPath, cxxCompiler)
subprocess.run(shlex.split(createLibraryScript), cwd=clientLibraryPath)
Expand All @@ -106,8 +106,6 @@ def main(config, cxxCompiler: str, cCompiler: str, outputPath: Path):
for logicFileName in logicFiles:
(scheduleName, _, problemType, _, exactLogic, newLibrary) \
= LibraryIO.parseLibraryLogicFile(logicFileName, cxxCompiler)
if problemType["DataType"].isHalf():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was this replaced with?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only ever set not ever used.

enableHalf = True
functions.append((scheduleName, problemType))
functionNames.append("tensile_%s" % (problemType))
problemSizes = ProblemSizesMock(exactLogic) if exactLogic else ProblemSizesMockDummy()
Expand Down Expand Up @@ -154,7 +152,6 @@ def main(config, cxxCompiler: str, cCompiler: str, outputPath: Path):
codeObjectFiles=coList,
tileAwareSelection=False,
libraryFile=yamlList[0]))
globalParameters["EnableHalf"] = enableHalf

forBenchmark = False
problemSizes = None
Expand Down Expand Up @@ -286,7 +283,7 @@ def writeRunScript(path, forBenchmark, enableTileSelection, cxxCompiler: str, cC

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we remove args here?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClientArgs is only ever an empty string

runScriptFile.write("ERR2=$?\n\n")

runScriptFile.write("""
Expand All @@ -309,7 +306,7 @@ def writeRunScript(path, forBenchmark, enableTileSelection, cxxCompiler: str, cC
runScriptFile.write("%s -d 0 --setfan 50\n" % globalParameters["ROCmSMIPath"])
else:
for configFile in configPaths:
runScriptFile.write("{} --config-file {} {} --best-solution 1\n".format(ClientExecutable.getClientExecutable(cxxCompiler, cCompiler, buildDir), configFile, globalParameters["ClientArgs"]))
runScriptFile.write("{} --config-file {} --best-solution 1\n".format(ClientExecutable.getClientExecutable(cxxCompiler, cCompiler, buildDir), configFile))
if os.name != "nt":
runScriptFile.write("exit $ERR\n")
runScriptFile.close()
Expand Down
10 changes: 10 additions & 0 deletions tensilelite/Tensile/Common/Constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Subdirectories for Tensile build artifacts
CLIENT_BUILD_DIR: str = "0_Build"
BENCHMARK_PROBLEMS_DIR: str = "1_BenchmarkProblems"
BENCHMARK_DATA_DIR: str = "2_BenchmarkData"
LIBRARY_LOGIC_DIR: str = "3_LibraryLogic"
LIBRARY_CLIENT_DIR: str = "4_LibraryClient"

# If a file name is longer than this value, and `--short-filenames` is set, shorten it with a hash.
MAX_FILENAME_LENGTH: int = 64

# Characters to use for GEMM naming, e.g., C[ij]=Sum[k] A[ik]*B[jk]
INDEX_CHARS: str = "IJKLMNOPQRSTUVWXYZ"

Expand Down
32 changes: 0 additions & 32 deletions tensilelite/Tensile/Common/GlobalParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
globalParameters["CodeFromFiles"] = (
True # if False byte arrays will be generated during Benchmarking phase as before
)
globalParameters["SortProblems"] = False # sort problems by size; else use order in YAML file
globalParameters["PinClocks"] = False # T=pin gpu clocks and fan, F=don't
globalParameters["HardwareMonitor"] = (
True # False: disable benchmarking client monitoring clocks using rocm-smi.
Expand All @@ -87,10 +86,6 @@
# Medium size: 0.75
# Large size : 0.9

# cProfile
globalParameters["Profiler"] = (
0 # Enable profiler. 0=off, 1=cProfile. This will set CpuThreads to 1.
)
# validation
globalParameters["NumElementsToValidate"] = (
128 # number of elements to validate, 128 will be evenly spaced out (with prime number stride) across C tensor
Expand Down Expand Up @@ -123,13 +118,7 @@
globalParameters["SolutionSelectionAlg"] = (
1 # algorithm to determine which solutions to keep. 0=removeLeastImportantSolutions, 1=keepWinnerSolutions (faster)
)
globalParameters["ExpandRanges"] = (
True # expand ranges into exact configs before writing logic file. False ignores ranges.
)
globalParameters["GenerateSourcesAndExit"] = False # Exit after kernel source generation.
globalParameters["WavefrontWidth"] = (
64 # if False and library client already built, then building library client will be skipped when tensile is re-run
)
globalParameters["ExitOnFails"] = (
1 # 1: Exit after benchmark run if failures detected. 2: Exit during benchmark run.
)
Expand Down Expand Up @@ -271,9 +260,6 @@
False # on windows kernel names can get too long; =True will convert solution/kernel names to serial ids
)

globalParameters["MaxFileName"] = (
64 # If a file name would be longer than this, shorten it with a hash.
)
globalParameters["SupportedISA"] = [
(8, 0, 3),
(9, 0, 0),
Expand All @@ -295,19 +281,6 @@
] # assembly kernels writer supports these architectures

globalParameters["NewClient"] = 2 # Old client deprecated: NewClient must be set to 2.
globalParameters["ClientBuildPath"] = "0_Build" # subdirectory for host code build directory
globalParameters["BenchmarkProblemsPath"] = (
"1_BenchmarkProblems" # subdirectory for benchmarking phases
)
globalParameters["BenchmarkDataPath"] = (
"2_BenchmarkData" # subdirectory for storing final benchmarking data
)
globalParameters["LibraryLogicPath"] = (
"3_LibraryLogic" # subdirectory for library logic produced by analysis
)
globalParameters["LibraryClientPath"] = (
"4_LibraryClient" # subdirectory for building example library client
)
globalParameters["ClientExecutionLockPath"] = (
None # Path for a file lock to ensure only one client is executed at once. filelock module is required if this is enabled.
)
Expand All @@ -334,10 +307,6 @@
globalParameters["CodeObjectVersion"] = "4"
globalParameters["Architecture"] = "all"

# might be deprecated
globalParameters["EnableHalf"] = False
globalParameters["ClientArgs"] = ""

# perf model
globalParameters["PerfModelL2ReadHits"] = 0.0
globalParameters["PerfModelL2WriteHits"] = 0.15
Expand Down Expand Up @@ -374,7 +343,6 @@
# Mode 0 requires memcpy everytime when the problem changes to reset the data, but mode 1 doesn't.

globalParameters["BuildIdKind"] = "sha1"
globalParameters["ValidateLibrary"] = False
globalParameters["AsmDebug"] = (
False # Set to True to keep debug information for compiled code objects
)
Expand Down
6 changes: 5 additions & 1 deletion tensilelite/Tensile/Common/Parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ def ParallelMapReturnAsGenerator(function, objects, message="", enable=True, mul
yield result.result()


def ParallelMap2(function, objects, message="", enable=True, multiArg=True, return_as="list"):
def ParallelMap2(
function, objects, message="", enable=True, multiArg=True, return_as="list", procs=None
):
"""
Generally equivalent to list(map(function, objects)), possibly executing in parallel.

Expand All @@ -209,6 +211,8 @@ def ParallelMap2(function, objects, message="", enable=True, multiArg=True, retu

from .GlobalParameters import globalParameters

threadCount = procs if procs else CPUThreadCount(enable)

threadCount = CPUThreadCount(enable)

if threadCount <= 1 and globalParameters["ShowProgressBar"]:
Expand Down
7 changes: 4 additions & 3 deletions tensilelite/Tensile/KernelWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
from .SolutionStructs import Solution, isPackedIndex
from .AsmMemoryInstruction import MemoryInstruction
from .Activation import ActivationModule
from .Common import globalParameters, printWarning, roundUp, print2, printExit, INDEX_CHARS, DataDirection, SemanticVersion
from .Common import globalParameters, printWarning, roundUp, print2, printExit, DataDirection, SemanticVersion, \
INDEX_CHARS, MAX_FILENAME_LENGTH

import abc
import os
Expand Down Expand Up @@ -4947,13 +4948,13 @@ def _syncThreads(self, kernel, comment="", skipForceWaitcnt0=False):

def _shortenFileBase(self, kernel):
base = self.getKernelName(kernel)
if len(base) <= globalParameters["MaxFileName"]:
if len(base) <= MAX_FILENAME_LENGTH:
return base

import hashlib
import base64

pivot = globalParameters["MaxFileName"] * 3 // 4
pivot = MAX_FILENAME_LENGTH * 3 // 4
firstPart = base[:pivot]
secondPart = base[pivot:]

Expand Down
34 changes: 7 additions & 27 deletions tensilelite/Tensile/LibraryLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

from pathlib import Path
from .Common import print1, print2, HR, printExit, defaultAnalysisParameters, globalParameters, \
assignParameterWithDefault, startTime, ProgressBar, printWarning, ensurePath
assignParameterWithDefault, startTime, ProgressBar, printWarning, ensurePath, \
LIBRARY_LOGIC_DIR, BENCHMARK_DATA_DIR
from .SolutionStructs import Solution
from . import LibraryIO
from . import SolutionSelectionLibrary
Expand Down Expand Up @@ -317,30 +318,9 @@ def __init__(self, problemType, problemSizesList, solutionsList, \
#FIXME-problem
self.rangeProblemSizes.update([tuple(problem.sizes) for problem in problemSizes.problems])
for rangeSize in problemSizes.ranges:

if globalParameters["ExpandRanges"]:
# Treat ranges as pile of exacts:
for rsize in rangeSize.problemSizes:
self.exactProblemSizes.add(tuple(rsize))
else:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never take the else branch?

@bstefanuk bstefanuk Feb 10, 2025 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, never, "ExpandRanges" is only ever set to True, and isn't overridden in any logic files.

# Create the ranges info in the logic file
#print "RangeSize", rangeSize
sizedIdx = 0
mappedIdx = 0
for i in range(0, self.numIndices):
if rangeSize.indexIsSized[i]:
index = rangeSize.indicesSized[sizedIdx]
sizedIdx += 1
else:
index = rangeSize.indicesSized[ \
rangeSize.indicesMapped[mappedIdx]]
mappedIdx += 1
currentSize = index[0]
currentStride = index[1]
while currentSize <= index[3]:
unifiedProblemSizes[i].add(currentSize)
currentSize += currentStride
currentStride += index[2]
# Treat ranges as pile of exacts:
for rsize in rangeSize.problemSizes:
self.exactProblemSizes.add(tuple(rsize))
for i in range(0, len(unifiedProblemSizes)):
unifiedProblemSizes[i] = sorted(list(unifiedProblemSizes[i]))
print2("UnifiedProblemSizes: %s" % unifiedProblemSizes)
Expand Down Expand Up @@ -1567,6 +1547,6 @@ def read_max_freq():
################################################################################
################################################################################
def main(config, cxxCompiler: str, outputPath: Path):
benchmarkDataPath = outputPath / globalParameters["BenchmarkDataPath"]
libraryLogicPath = outputPath / globalParameters["LibraryLogicPath"]
benchmarkDataPath = outputPath / BENCHMARK_DATA_DIR
libraryLogicPath = outputPath / LIBRARY_LOGIC_DIR
generateLogic(config, benchmarkDataPath, libraryLogicPath, cxxCompiler)
5 changes: 1 addition & 4 deletions tensilelite/Tensile/SolutionStructs.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,10 +889,7 @@ def __init__(self, problemType, config):
self.problems.update({Problem(rangeSize) : 1})
for e in self.exacts:
self.problems.update({e : 1})
if globalParameters["SortProblems"]:
self.problems = sorted(list( self.problems.keys()), key=operator.attrgetter("sizes"))
else:
self.problems = list(self.problems.keys())
self.problems = list(self.problems.keys())
self.totalProblemSizes = len(self.problems)

# max sizes
Expand Down
3 changes: 1 addition & 2 deletions tensilelite/Tensile/Source/TensileCreateLibrary.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
#
# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (C) 2022-2025 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
Expand Down Expand Up @@ -35,7 +35,6 @@ function(TensileCreateLibraryCmake
Tensile_ARCHITECTURE
Tensile_LIBRARY_FORMAT
Tensile_SHORT_FILE_NAMES
Tensile_LIBRARY_PRINT_DEBUG
Tensile_CPU_THREADS
Tensile_SEPARATE_ARCHITECTURES
Tensile_LAZY_LIBRARY_LOADING,
Expand Down
Loading