| 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 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") |