From a3a2b6803b0955f401d53b7fd4dbcaae9b813d8d Mon Sep 17 00:00:00 2001 From: Sean Vong-Karlage Date: Thu, 20 Feb 2025 13:34:49 -0800 Subject: [PATCH] rocm: hip_toolchain_override rule to compile rocm-related projects 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 --- prelude/cxx/archive.bzl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/prelude/cxx/archive.bzl b/prelude/cxx/archive.bzl index 2f3bf2e5a3614..046307b23e5e1 100644 --- a/prelude/cxx/archive.bzl +++ b/prelude/cxx/archive.bzl @@ -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 @@ -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()])