Skip to content

Commit 48d194d

Browse files
committed
Merge branch 'master' into patchesbegone
2 parents 7850226 + ac5448f commit 48d194d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tools/amd_build/pyHIPIFY/hipify-python.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,26 @@ def disable_asserts(input_string):
331331
output_string = output_string.replace(input_string[start:p_end + 1], "")
332332
return output_string
333333

334+
def replace_forceinline(input_string):
335+
"""__forceinline__'d methods can cause 'symbol multiply defined' errors in HIP.
336+
Adding 'static' to all such methods leads to compilation errors, so
337+
replacing '__forceinline__' with 'inline' as a workaround
338+
https://github.com/ROCm-Developer-Tools/HIP/blob/master/docs/markdown/hip_faq.md#what-if-hip-generates-error-of-symbol-multiply-defined-only-on-amd-machine
339+
"""
340+
output_string = input_string
341+
output_string = re.sub("__forceinline__", "inline", output_string)
342+
return output_string
343+
344+
def replace_math_functions(input_string):
345+
""" FIXME: Temporarily replace std:: invocations of math functions with non-std:: versions to prevent linker errors
346+
NOTE: This can lead to correctness issues when running tests, since the correct version of the math function (exp/expf) might not get called.
347+
Plan is to remove this function once HIP supports std:: math function calls inside device code
348+
"""
349+
output_string = input_string
350+
output_string = re.sub("std::exp\(", "::exp(", output_string)
351+
output_string = re.sub("std::log\(", "::log(", output_string)
352+
output_string = re.sub("std::pow\(", "::pow(", output_string)
353+
return output_string
334354

335355
def disable_function(input_string, function, replace_style):
336356
""" Finds and disables a function in a particular file.
@@ -497,6 +517,12 @@ def preprocessor(filepath, stats):
497517
if not filepath.endswith("THCGeneral.h.in"):
498518
output_source = disable_asserts(output_source)
499519

520+
# Replace std:: with non-std:: versions
521+
output_source = replace_math_functions(output_source)
522+
523+
# Replace __forceinline__ with inline
524+
output_source = replace_forceinline(output_source)
525+
500526
# Overwrite file contents
501527
fileobj.seek(0)
502528
fileobj.write(output_source)

0 commit comments

Comments
 (0)