@@ -73,7 +73,20 @@ def rocm_link(in_file, out_file, lld=None):
73
73
The lld linker, if not specified,
74
74
we will try to guess the matched clang version.
75
75
"""
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
+ ]
77
90
proc = subprocess .Popen (args , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
78
91
(out , _ ) = proc .communicate ()
79
92
@@ -108,7 +121,7 @@ def callback_rocm_link(obj_bin):
108
121
109
122
110
123
@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 ):
112
125
"""Utility function to find ROCm device library bitcodes
113
126
114
127
Parameters
@@ -118,23 +131,40 @@ def callback_rocm_bitcode_path(rocdl_dir="/opt/rocm/lib/"):
118
131
The default value is the standard location
119
132
"""
120
133
# 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" ,
138
158
]
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