Skip to content

Commit 9829897

Browse files
authored
[Driver][SYCL] Do not pull in late static device libs for AMD GPU (#6498)
The addition of the new OpenMP offloading driver path, which unbundles archives later in the toolchain is interfering with the device linking behaviors involving AMD GPU targets for SYCL offload compiles. Disable the inclusion of these unbundled static archives as we do not yet take advantage of the new offloading paths.
1 parent 0cc408e commit 9829897

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

clang/include/clang/Driver/Driver.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ class Driver {
733733

734734
void setOffloadStaticLibSeen() { OffloadStaticLibSeen = true; }
735735

736+
/// Use the new offload driver for OpenMP
737+
bool UseNewOffloadingDriver = false;
738+
void setUseNewOffloadingDriver() { UseNewOffloadingDriver = true; }
739+
736740
/// FPGA Emulation Mode. By default, this is true due to the fact that
737741
/// an external option setting is required to target hardware.
738742
bool FPGAEmulationMode = true;
@@ -798,6 +802,9 @@ class Driver {
798802

799803
bool getOffloadStaticLibSeen() const { return OffloadStaticLibSeen; };
800804

805+
/// getUseNewOffloadingDriver - use the new offload driver for OpenMP.
806+
bool getUseNewOffloadingDriver() const { return UseNewOffloadingDriver; };
807+
801808
/// addFPGATempDepFile - Add a file to be added to the bundling step of
802809
/// an FPGA object.
803810
void addFPGATempDepFile(const std::string &DepName,

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,16 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
16621662
// Populate the tool chains for the offloading devices, if any.
16631663
CreateOffloadingDeviceToolChains(*C, Inputs);
16641664

1665+
// Use new offloading path for OpenMP. This is disabled as the SYCL
1666+
// offloading path is not properly setup to use the updated device linking
1667+
// scheme.
1668+
if ((C->isOffloadingHostKind(Action::OFK_OpenMP) &&
1669+
Args.hasFlag(options::OPT_fopenmp_new_driver,
1670+
options::OPT_no_offload_new_driver, true)) ||
1671+
Args.hasFlag(options::OPT_offload_new_driver,
1672+
options::OPT_no_offload_new_driver, false))
1673+
setUseNewOffloadingDriver();
1674+
16651675
// Determine FPGA emulation status.
16661676
if (C->hasOffloadToolChain<Action::OFK_SYCL>()) {
16671677
auto SYCLTCRange = C->getOffloadToolChains<Action::OFK_SYCL>();

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
157157
// Look for archive of bundled bitcode in arguments, and add temporary files
158158
// for the extracted archive of bitcode to inputs.
159159
auto TargetID = Args.getLastArgValue(options::OPT_mcpu_EQ);
160-
AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, LldArgs, "amdgcn",
161-
TargetID,
162-
/*IsBitCodeSDL=*/true,
163-
/*PostClangLink=*/false);
160+
if (C.getDriver().getUseNewOffloadingDriver() ||
161+
JA.getOffloadingDeviceKind() != Action::OFK_SYCL)
162+
AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, LldArgs, "amdgcn",
163+
TargetID,
164+
/*IsBitCodeSDL=*/true,
165+
/*PostClangLink=*/false);
164166

165167
const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld"));
166168
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),

clang/test/Driver/sycl-offload-amdgcn.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@
4343
// CHK-PHASES-NO-CC: 19: file-table-tform, {12, 18}, tempfiletable, (device-sycl, gfx906)
4444
// CHK-PHASES-NO-CC: 20: clang-offload-wrapper, {19}, object, (device-sycl, gfx906)
4545
// CHK-PHASES-NO-CC: 21: offload, "host-sycl (x86_64-unknown-linux-gnu)" {10}, "device-sycl (amdgcn-amd-amdhsa:gfx906)" {20}, image
46+
47+
/// Check that we only unbundle an archive once.
48+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl \
49+
// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend \
50+
// RUN: --offload-arch=gfx906 %s -L%S/Inputs/SYCL -llin64 2>&1 \
51+
// RUN: | FileCheck -check-prefix=CHK-ARCHIVE %s
52+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl \
53+
// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend \
54+
// RUN: --offload-arch=gfx906 %s %S/Inputs/SYCL/liblin64.a 2>&1 \
55+
// RUN: | FileCheck -check-prefix=CHK-ARCHIVE %s
56+
// CHK-ARCHIVE: clang-offload-bundler{{.*}} "-input={{.*}}/Inputs/SYCL/liblin64.a"
57+
// CHK-ARCHIVE: llvm-link{{.*}}
58+
// CHK-ARCHIVE-NOT: clang-offload-bundler{{.*}} "-unbundle"

0 commit comments

Comments
 (0)