Skip to content

Commit

Permalink
rocm: hip_toolchain_override rule to compile rocm-related projects
Browse files Browse the repository at this point in the history
Summary:
Sometimes we want to compile C/C++ sources that _aren't_ .hip files.

The cxx toolchains today only use the rocm toolchain if you give it a .hip file. So what do we do? We can either:
1. Rename all the .cpp files as .hip so cxx rules pick the right toolchain. This is kinda meh, and unclear if this would work for header files either.
2. We can construct our own toolchain override and use the `hip_compiler_info` instead of `cxx_compiler_info`

(2) is what this diff is. `hip_toolchain_override` borrows from `cxx_toolchain_override` and overrides enough of the toolchain info struct to s/cxx/hip/ for things that matter.

This also overrides some linking behavior so we can maybe get to the point to where we can replace the `hip_link` rccl action with a real `cxx_library`.

Reviewed By: blackm00n

Differential Revision: D69506114

fbshipit-source-id: 018f28c9141155c9cf5d8f04211595f95ef62b43
  • Loading branch information
get9 authored and facebook-github-bot committed Feb 20, 2025
1 parent 7bb7705 commit a3a2b68
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions prelude/cxx/archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def _archive_flags(
return ["/Brepro", "/d2threads1"]
elif archiver_type == "windows_clang":
return ["/llvmlibthin"] if thin else []
elif archiver_type == "amdclang":
# amdclang can be used to create archives with --emit-static-lib, so let's
# prefer to let the toolchain define the args instead of hardcoding them here.
return []
flags = ""

# Operate in quick append mode, so that objects with identical basenames
Expand Down Expand Up @@ -69,6 +73,8 @@ def _archive(
))
if archiver_type == "windows" or archiver_type == "windows_clang":
command.add([cmd_args(archive_output.as_output(), format = "/OUT:{}")])
elif archiver_type == "amdclang":
command.add(["-o", archive_output.as_output()])
else:
command.add([archive_output.as_output()])

Expand Down

0 comments on commit a3a2b68

Please sign in to comment.