Debian Codegraph @

tensilelite/Tensile/ClientExecutable.py

raw symbols SCIP
1 ################################################################################
2 #
3 # Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved.
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 # SOFTWARE.
22 #
23 ################################################################################
24
25 import itertools
26 import os
27 import subprocess
28 from typing import Optional
29 from pathlib import Path
30
31 from . import SOURCE_PATH
32 from Tensile.Common import print2, ClientExecutionLock, ensurePath, CLIENT_BUILD_DIR
33 from Tensile.Common.GlobalParameters import globalParameters
34
35 class CMakeEnvironment:
36 def __init__(self, sourceDir, buildDir, **options):
37 self.sourceDir = sourceDir
38 self.buildDir = buildDir
39 self.options = options
40
41 def generate(self):
42
43 args = ['cmake']
44 args += itertools.chain.from_iterable([ ['-D', '{}={}'.format(key, value)] for key,value in self.options.items()])
45 args += [self.sourceDir]
46
47 print2(' '.join(args))
48 with ClientExecutionLock(globalParameters["ClientExecutionLockPath"]):
49 subprocess.check_call(args, cwd=ensurePath(self.buildDir))
50
51 def build(self):
52 args = ['make', '-j']
53 print2(' '.join(args))
54 with ClientExecutionLock(globalParameters["ClientExecutionLockPath"]):
55 subprocess.check_call(args, cwd=self.buildDir)
56
57 def builtPath(self, path, *paths):
58 return os.path.join(self.buildDir, path, *paths)
59
60 def clientExecutableEnvironment(builddir: Optional[str], cxxCompiler: str, cCompiler: str):
61 sourcedir = SOURCE_PATH
62
63 builddir = ensurePath(builddir)
64
65 options = {'CMAKE_BUILD_TYPE': globalParameters["CMakeBuildType"],
66 'TENSILE_USE_MSGPACK': 'ON',
67 'TENSILE_USE_LLVM': 'OFF' if (os.name == "nt") else 'ON',
68 'Tensile_LIBRARY_FORMAT': globalParameters["LibraryFormat"],
69 'Tensile_ENABLE_MARKER' : globalParameters["EnableMarker"],
70 'CMAKE_CXX_COMPILER': os.path.join(globalParameters["ROCmBinPath"], cxxCompiler),
71 'CMAKE_C_COMPILER': os.path.join(globalParameters["ROCmBinPath"], cCompiler)}
72
73 if "CCACHE_BASEDIR" in os.environ:
74 options.update({'CMAKE_C_COMPILER_LAUNCHER': 'ccache', 'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache'})
75 print('Is Using CCACHE')
76
77 return CMakeEnvironment(sourcedir, builddir, **options)
78
79
80 buildEnv = None
81
82 def getClientExecutable(cxxCompiler: str, cCompiler: str, builddir: Path):
83 if "PrebuiltClient" in globalParameters:
84 return globalParameters["PrebuiltClient"]
85
86 global buildEnv
87
88 if buildEnv is None:
89 buildEnv = clientExecutableEnvironment(builddir / CLIENT_BUILD_DIR, cxxCompiler, cCompiler)
90 buildEnv.generate()
91 buildEnv.build()
92
93 return buildEnv.builtPath("client/tensile_client")