@@ -331,6 +331,26 @@ def disable_asserts(input_string):
331
331
output_string = output_string .replace (input_string [start :p_end + 1 ], "" )
332
332
return output_string
333
333
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
334
354
335
355
def disable_function (input_string , function , replace_style ):
336
356
""" Finds and disables a function in a particular file.
@@ -497,6 +517,12 @@ def preprocessor(filepath, stats):
497
517
if not filepath .endswith ("THCGeneral.h.in" ):
498
518
output_source = disable_asserts (output_source )
499
519
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
+
500
526
# Overwrite file contents
501
527
fileobj .seek (0 )
502
528
fileobj .write (output_source )
0 commit comments