Skip to content

Commit fd9bd33

Browse files
t-vitrevor-m
authored andcommitted
Update search for bitcode files for rocm 3.9 (apache#6865)
rocm 3.9 moved the bitcodes, we adapt to that. As this gives opaque error messages that are hard to debug (loading the module fails with could not initialize shared object but does not tell you about the missing symbols), we tighten the checks at this stage: - we become more strict with missing bitcodes, - we let the linker fail loudly for unresolved symbols.
1 parent 5e7fa0c commit fd9bd33

File tree

1 file changed

+51
-21
lines changed

1 file changed

+51
-21
lines changed

python/tvm/contrib/rocm.py

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,20 @@ def rocm_link(in_file, out_file, lld=None):
7373
The lld linker, if not specified,
7474
we will try to guess the matched clang version.
7575
"""
76-
args = [lld if lld is not None else find_lld()[0], "-shared", in_file, "-o", out_file]
76+
77+
# if our result has undefined symbols, it will fail to load
78+
# (hipModuleLoad/hipModuleLoadData), but with a somewhat opaque message
79+
# so we have ld.lld check this here.
80+
# If you get a complaint about missing symbols you might want to check the
81+
# list of bitcode files below.
82+
args = [
83+
lld if lld is not None else find_lld()[0],
84+
"--no-undefined",
85+
"-shared",
86+
in_file,
87+
"-o",
88+
out_file,
89+
]
7790
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
7891
(out, _) = proc.communicate()
7992

@@ -108,7 +121,7 @@ def callback_rocm_link(obj_bin):
108121

109122

110123
@tvm._ffi.register_func("tvm_callback_rocm_bitcode_path")
111-
def callback_rocm_bitcode_path(rocdl_dir="/opt/rocm/lib/"):
124+
def callback_rocm_bitcode_path(rocdl_dir=None):
112125
"""Utility function to find ROCm device library bitcodes
113126
114127
Parameters
@@ -118,23 +131,40 @@ def callback_rocm_bitcode_path(rocdl_dir="/opt/rocm/lib/"):
118131
The default value is the standard location
119132
"""
120133
# seems link order matters.
121-
bitcode_files = [
122-
"oclc_daz_opt_on.amdgcn.bc",
123-
"ocml.amdgcn.bc",
124-
"hc.amdgcn.bc",
125-
"irif.amdgcn.bc",
126-
"ockl.amdgcn.bc",
127-
"oclc_correctly_rounded_sqrt_off.amdgcn.bc",
128-
"oclc_correctly_rounded_sqrt_on.amdgcn.bc",
129-
"oclc_daz_opt_off.amdgcn.bc",
130-
"oclc_finite_only_off.amdgcn.bc",
131-
"oclc_finite_only_on.amdgcn.bc",
132-
"oclc_isa_version_803.amdgcn.bc",
133-
"oclc_isa_version_900.amdgcn.bc",
134-
"oclc_isa_version_906.amdgcn.bc",
135-
"oclc_unsafe_math_off.amdgcn.bc",
136-
"oclc_unsafe_math_on.amdgcn.bc",
137-
"oclc_wavefrontsize64_on.amdgcn.bc",
134+
135+
if rocdl_dir is None:
136+
if exists("/opt/rocm/amdgcn/bitcode/"):
137+
rocdl_dir = "/opt/rocm/amdgcn/bitcode/" # starting with rocm 3.9
138+
else:
139+
rocdl_dir = "/opt/rocm/lib/" # until rocm 3.8
140+
141+
bitcode_names = [
142+
"oclc_daz_opt_on",
143+
"ocml",
144+
"hc",
145+
"irif", # this does not exist in rocm 3.9, drop eventually
146+
"ockl",
147+
"oclc_correctly_rounded_sqrt_off",
148+
"oclc_correctly_rounded_sqrt_on",
149+
"oclc_daz_opt_off",
150+
"oclc_finite_only_off",
151+
"oclc_finite_only_on",
152+
"oclc_isa_version_803", # todo (t-vi): an alternative might be to scan for the
153+
"oclc_isa_version_900", # isa version files (if the linker throws out
154+
"oclc_isa_version_906", # the unneeded ones or we filter for the arch we need)
155+
"oclc_unsafe_math_off",
156+
"oclc_unsafe_math_on",
157+
"oclc_wavefrontsize64_on",
138158
]
139-
paths = [join(rocdl_dir, bitcode) for bitcode in bitcode_files]
140-
return tvm.runtime.convert([path for path in paths if exists(path)])
159+
160+
bitcode_files = []
161+
for n in bitcode_names:
162+
p = join(rocdl_dir, n + ".bc") # rocm >= 3.9
163+
if not exists(p): # rocm <= 3.8
164+
p = join(rocdl_dir, n + ".amdgcn.bc")
165+
if exists(p):
166+
bitcode_files.append(p)
167+
elif "isa_version" not in n and n not in {"irif"}:
168+
raise RuntimeError("could not find bitcode " + n)
169+
170+
return tvm.runtime.convert(bitcode_files)

0 commit comments

Comments
 (0)