| 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 os |
| 26 |
import re |
| 27 |
from argparse import ArgumentParser |
| 28 |
from typing import Any, Dict, List, Optional |
| 29 |
|
| 30 |
from Tensile.Common import coVersionMap, printExit |
| 31 |
from Tensile.Common.Architectures import architectureMap |
| 32 |
from Tensile.Toolchain.Validators import ToolchainDefaults |
| 33 |
|
| 34 |
|
| 35 |
def parseArguments(input: Optional[List[str]] = None) -> Dict[str, Any]: |
| 36 |
"""Parse command line arguments for TensileCreateLibrary. |
| 37 |
|
| 38 |
Args: |
| 39 |
input: List of strings representing command line arguments used when |
| 40 |
calling parseArguments prgrammatically e.g. in testing. |
| 41 |
|
| 42 |
Returns: |
| 43 |
A dictionary containing the keys representing options and their values. |
| 44 |
""" |
| 45 |
|
| 46 |
argParser = ArgumentParser( |
| 47 |
description="TensileCreateLibrary generates libraries and code object files " |
| 48 |
"for a set of supplied logic files.", |
| 49 |
) |
| 50 |
|
| 51 |
argParser.add_argument("LogicPath", help="Path to LibraryLogic.yaml files.") |
| 52 |
argParser.add_argument("OutputPath", help="Where to write library files?") |
| 53 |
argParser.add_argument( |
| 54 |
"RuntimeLanguage", help="Which runtime language?", choices=["OCL", "HIP", "HSA"] |
| 55 |
) |
| 56 |
argParser.add_argument( |
| 57 |
"--cxx-compiler", |
| 58 |
dest="CxxCompiler", |
| 59 |
action="store", |
| 60 |
default=ToolchainDefaults.CXX_COMPILER, |
| 61 |
help=f"Default: {ToolchainDefaults.CXX_COMPILER}", |
| 62 |
) |
| 63 |
argParser.add_argument( |
| 64 |
"--c-compiler", dest="CCompiler", action="store", default=ToolchainDefaults.C_COMPILER |
| 65 |
) |
| 66 |
argParser.add_argument("--cmake-cxx-compiler", dest="CmakeCxxCompiler", action="store") |
| 67 |
argParser.add_argument( |
| 68 |
"--offload-bundler", |
| 69 |
dest="OffloadBundler", |
| 70 |
action="store", |
| 71 |
default=ToolchainDefaults.OFFLOAD_BUNDLER, |
| 72 |
) |
| 73 |
argParser.add_argument( |
| 74 |
"--assembler", dest="Assembler", action="store", default=ToolchainDefaults.ASSEMBLER |
| 75 |
) |
| 76 |
argParser.add_argument( |
| 77 |
"--code-object-version", |
| 78 |
dest="CodeObjectVersion", |
| 79 |
choices=["4", "5", "V4", "V5", "default"], |
| 80 |
default="4", |
| 81 |
action="store", |
| 82 |
) |
| 83 |
argParser.add_argument( |
| 84 |
"--architecture", |
| 85 |
dest="Architecture", |
| 86 |
type=str, |
| 87 |
action="store", |
| 88 |
default="all", |
| 89 |
help="Supported archs: " + " ".join(architectureMap.keys()), |
| 90 |
) |
| 91 |
argParser.add_argument( |
| 92 |
"--no-compress", |
| 93 |
dest="NoCompress", |
| 94 |
action="store_true", |
| 95 |
help="Don't compress assembly code objects.", |
| 96 |
) |
| 97 |
argParser.add_argument( |
| 98 |
"--experimental", |
| 99 |
dest="Experimental", |
| 100 |
action="store_true", |
| 101 |
help="Include logic files in directories named 'Experimental'.", |
| 102 |
) |
| 103 |
argParser.add_argument( |
| 104 |
"--no-enumerate", action="store_true", help="Do not run rocm_agent_enumerator." |
| 105 |
) |
| 106 |
argParser.add_argument("--version", help="Version string to embed into library file.") |
| 107 |
argParser.add_argument( |
| 108 |
"--logic-format", |
| 109 |
dest="LogicFormat", |
| 110 |
choices=["yaml", "json"], |
| 111 |
action="store", |
| 112 |
default="yaml", |
| 113 |
help="select which logic format to use", |
| 114 |
) |
| 115 |
argParser.add_argument( |
| 116 |
"--library-format", |
| 117 |
dest="LibraryFormat", |
| 118 |
choices=["yaml", "msgpack"], |
| 119 |
action="store", |
| 120 |
default="msgpack", |
| 121 |
help="select which library format to use", |
| 122 |
) |
| 123 |
argParser.add_argument( |
| 124 |
"--jobs", |
| 125 |
"-j", |
| 126 |
dest="CpuThreads", |
| 127 |
type=int, |
| 128 |
default=-1, |
| 129 |
help="Number of parallel jobs to launch.", |
| 130 |
) |
| 131 |
argParser.add_argument( |
| 132 |
"--verbose", |
| 133 |
"-v", |
| 134 |
dest="PrintLevel", |
| 135 |
type=int, |
| 136 |
default=1, |
| 137 |
help="Set printout verbosity level.", |
| 138 |
) |
| 139 |
argParser.add_argument( |
| 140 |
"--no-lazy-library-loading", |
| 141 |
dest="LazyLibraryLoading", |
| 142 |
action="store_false", |
| 143 |
default=True, |
| 144 |
help="Disable building for lazy library loading.", |
| 145 |
) |
| 146 |
argParser.add_argument( |
| 147 |
"--enable-marker", |
| 148 |
dest="EnableMarker", |
| 149 |
action="store_true", |
| 150 |
default=False, |
| 151 |
help="Enable marker in Tensile.", |
| 152 |
) |
| 153 |
argParser.add_argument( |
| 154 |
"--no-generate-solution-table", |
| 155 |
dest="GenSolTable", |
| 156 |
action="store_false", |
| 157 |
default=True, |
| 158 |
help="Skip generating solution-yaml matching table", |
| 159 |
) |
| 160 |
argParser.add_argument( |
| 161 |
"--asm-debug", |
| 162 |
dest="AsmDebug", |
| 163 |
action="store_true", |
| 164 |
default=False, |
| 165 |
help="Keep debug information for built code objects", |
| 166 |
) |
| 167 |
argParser.add_argument("--build-id", dest="BuildIdKind", action="store", default="sha1") |
| 168 |
argParser.add_argument( |
| 169 |
"--address-sanitizer", |
| 170 |
dest="AsanBuild", |
| 171 |
action="store_true", |
| 172 |
default=False, |
| 173 |
help="Enable ASAN build.", |
| 174 |
) |
| 175 |
argParser.add_argument( |
| 176 |
"--keep-build-tmp", |
| 177 |
dest="KeepBuildTmp", |
| 178 |
action="store_true", |
| 179 |
default=False, |
| 180 |
help="Do not remove the temporary build directory (may required hundreds of GBs of space)", |
| 181 |
), |
| 182 |
argParser.add_argument( |
| 183 |
"--logic-filter", |
| 184 |
dest="LogicFilter", |
| 185 |
action="store", |
| 186 |
default="*", |
| 187 |
type=str, |
| 188 |
help="Cutomsized logic filter, default is *, i.e. all logics." |
| 189 |
" Example: gfx942/Equality/* for building equality of gfx942 only", |
| 190 |
) |
| 191 |
|
| 192 |
args = argParser.parse_args() |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
predicatePattern = re.compile(r"\[(.*?)\]") |
| 200 |
if predicatePattern.search(args.Architecture): |
| 201 |
printExit( |
| 202 |
"Predicate based tensilelite library builds are supported; however, since " |
| 203 |
"the runtime lookup and selection of these libraries is incomplete, the " |
| 204 |
"requested build is currently disabled. Please re-run using only the " |
| 205 |
"architecture name without a predicate (`--architecture=gfx950`)." |
| 206 |
) |
| 207 |
|
| 208 |
arguments = {} |
| 209 |
arguments["RuntimeLanguage"] = args.RuntimeLanguage |
| 210 |
arguments["CodeObjectVersion"] = coVersionMap[args.CodeObjectVersion] |
| 211 |
arguments["Architecture"] = args.Architecture |
| 212 |
arguments["LazyLibraryLoading"] = args.LazyLibraryLoading |
| 213 |
arguments["EnableMarker"] = args.EnableMarker |
| 214 |
if args.CmakeCxxCompiler: |
| 215 |
os.environ["CMAKE_CXX_COMPILER"] = args.CmakeCxxCompiler |
| 216 |
arguments["LogicFormat"] = args.LogicFormat |
| 217 |
arguments["LibraryFormat"] = args.LibraryFormat |
| 218 |
arguments["CpuThreads"] = args.CpuThreads |
| 219 |
arguments["PrintLevel"] = args.PrintLevel |
| 220 |
arguments["AsmDebug"] = args.AsmDebug |
| 221 |
arguments["BuildIdKind"] = args.BuildIdKind |
| 222 |
arguments["KeepBuildTmp"] = args.KeepBuildTmp |
| 223 |
arguments["AsanBuild"] = args.AsanBuild |
| 224 |
arguments["UseCompression"] = not args.NoCompress |
| 225 |
arguments["CxxCompiler"] = args.CxxCompiler |
| 226 |
arguments["CCompiler"] = args.CCompiler |
| 227 |
arguments["OffloadBundler"] = args.OffloadBundler |
| 228 |
arguments["Assembler"] = args.Assembler |
| 229 |
arguments["LogicPath"] = args.LogicPath |
| 230 |
arguments["LogicFilter"] = args.LogicFilter |
| 231 |
arguments["OutputPath"] = args.OutputPath |
| 232 |
arguments["Experimental"] = args.Experimental |
| 233 |
arguments["GenSolTable"] = args.GenSolTable |
| 234 |
|
| 235 |
return arguments |