Skip to content

Commit 848d9dd

Browse files
t-viwweic
authored andcommitted
tvm/contrib/rocm: improve finding of ld.lld (apache#3664)
This refines the detection of ld.lld matching the neighbouring clang file. This is particularly helpful on Ubuntu/Debian when either the default ld.lld is not installed or the versioned one is preferable for consistency. @tqchen I think you last touched the clang equivalent in apache#3590 .
1 parent 31ebae8 commit 848d9dd

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

python/tvm/contrib/rocm.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,43 @@
1919
from os.path import join, exists
2020
from . import util
2121
from .._ffi.base import py_str
22+
from .. import codegen
2223
from ..api import register_func, convert
2324

24-
def rocm_link(in_file, out_file):
25+
def find_lld(required=True):
26+
"""Find ld.lld in system.
27+
28+
Parameters
29+
----------
30+
required : bool
31+
Whether it is required,
32+
runtime error will be raised if the compiler is required.
33+
34+
Returns
35+
-------
36+
valid_list : list of str
37+
List of possible paths.
38+
39+
Note
40+
----
41+
This function will first search ld.lld that
42+
matches the major llvm version that built with tvm
43+
"""
44+
lld_list = []
45+
if hasattr(codegen, "llvm_version_major"):
46+
major = codegen.llvm_version_major()
47+
lld_list += ["ld.lld-%d.0" % major]
48+
lld_list += ["ld.lld-%d" % major]
49+
lld_list += ["lld"]
50+
valid_list = [util.which(x) for x in lld_list]
51+
valid_list = [x for x in valid_list if x]
52+
if not valid_list and required:
53+
raise RuntimeError(
54+
"cannot find ld.lld, candidates are: " + str(lld_list))
55+
return valid_list
56+
57+
58+
def rocm_link(in_file, out_file, lld=None):
2559
"""Link relocatable ELF object to shared ELF object using lld
2660
2761
Parameters
@@ -31,8 +65,12 @@ def rocm_link(in_file, out_file):
3165
3266
out_file : str
3367
Output file name (shared ELF object file)
68+
69+
lld : str, optional
70+
The lld linker, if not specified,
71+
we will try to guess the matched clang version.
3472
"""
35-
args = ["ld.lld", "-shared", in_file, "-o", out_file]
73+
args = [lld if lld is not None else find_lld()[0], "-shared", in_file, "-o", out_file]
3674
proc = subprocess.Popen(
3775
args,
3876
stdout=subprocess.PIPE,

0 commit comments

Comments
 (0)