Skip to content

Commit

Permalink
add amdclang support
Browse files Browse the repository at this point in the history
  • Loading branch information
fsx950223 authored and i-chaochen committed Jan 29, 2025
1 parent 38ed029 commit b26ba66
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions third_party/gpus/crosstool/BUILD.rocm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ cc_toolchain_config(
"-fuse-ld=gold",
"-Wl,-no-as-needed",
"-Wl,-z,relro,-z,now",
"-pass-exit-codes",
# "-pass-exit-codes",
"-lstdc++",
"-lm",
],
link_libs = [],
opt_link_flags = [],
unfiltered_compile_flags = [
"-fno-canonical-system-headers",
# "-fno-canonical-system-headers",
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def GetHostCompilerOptions(argv):
parser.add_argument('-iquote', nargs='*', action='append')
parser.add_argument('--sysroot', nargs=1)
parser.add_argument('-g', nargs='*', action='append')
parser.add_argument('-fno-canonical-system-headers', action='store_true')
parser.add_argument('-no-canonical-prefixes', action='store_true')
parser.add_argument('-Wno-unused-variable', action='store_true')
parser.add_argument('-Wno-unused-but-set-variable', action='store_true')

args, _ = parser.parse_known_args(argv)

Expand All @@ -87,10 +89,16 @@ def GetHostCompilerOptions(argv):
opts += ' -iquote ' + ' -iquote '.join(sum(args.iquote, []))
if args.g:
opts += ' -g' + ' -g'.join(sum(args.g, []))
if args.fno_canonical_system_headers:
if args.no_canonical_prefixes:
opts += ' -no-canonical-prefixes'
if args.sysroot:
opts += ' --sysroot ' + args.sysroot[0]
if args.Wno_unused_variable:
opts += ' -Wno-unused-variable'

if args.Wno_unused_but_set_variable:
opts += ' -Wno-unused-but-set-variable'


return opts

Expand Down Expand Up @@ -282,7 +290,13 @@ def main():
if not flag.startswith(('--rocm_log'))]

# XXX: SE codes need to be built with gcc, but need this macro defined
cpu_compiler_flags.append("-D__HIP_PLATFORM_HCC__")
cpu_compiler_flags.append("-D__HIP_PLATFORM_AMD__")
cpu_compiler_flags.append('-L' + HIP_RUNTIME_PATH)
cpu_compiler_flags.append('-Wl,-rpath=' + HIP_RUNTIME_PATH)
cpu_compiler_flags.append('-l' + HIP_RUNTIME_LIBRARY)
cpu_compiler_flags.append("-lrt")
cpu_compiler_flags.append("-Wno-unused-command-line-argument")
cpu_compiler_flags.append("-Wno-gnu-offsetof-extensions")
if VERBOSE: print(' '.join([CPU_COMPILER] + cpu_compiler_flags))
return subprocess.call([CPU_COMPILER] + cpu_compiler_flags)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ def _impl(ctx):
flag_group(
flags = [
"-no-canonical-prefixes",
"-fno-canonical-system-headers",
#"-fno-canonical-system-headers",
]
),
],
Expand Down
4 changes: 3 additions & 1 deletion third_party/gpus/rocm_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,14 @@ def _create_local_rocm_repository(repository_ctx):
# .d file - given that includes that are prefixed with "../" multiple
# time quickly grow longer than the root of the tree, this can lead to
# bazel's header check failing.
rocm_defines["%{extra_no_canonical_prefixes_flags}"] = "\"-fno-canonical-system-headers\""
rocm_defines["%{extra_no_canonical_prefixes_flags}"] = ""

rocm_defines["%{unfiltered_compile_flags}"] = to_list_of_strings([
"-DTENSORFLOW_USE_ROCM=1",
"-D__HIP_PLATFORM_AMD__",
"-DEIGEN_USE_HIP",
"-Wno-unused-but-set-variable",
"-Wno-c++11-narrowing",
])

rocm_defines["%{host_compiler_path}"] = "clang/bin/crosstool_wrapper_driver_is_not_gcc"
Expand Down

0 comments on commit b26ba66

Please sign in to comment.