Skip to content

Commit

Permalink
[Driver][SYCL] Fix issue using -fsycl-force-target with offload depen…
Browse files Browse the repository at this point in the history
…dencies (#7025)

When using performing offloading with archives, an additional
clang-offload-deps step is taken that determines the device dependencies
during the link. When using -fsycl-force-target, we need to be sure that
the target in which the dependency information is associated with
matches so the proper device objects are referenced and pulled out.
  • Loading branch information
mdtoguchi authored Oct 12, 2022
1 parent c44a84a commit 54777c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 13 additions & 3 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9407,9 +9407,19 @@ void OffloadDeps::constructJob(Compilation &C, const JobAction &JA,
Targets += ',';
Targets += Action::GetOffloadKindName(Dep.DependentOffloadKind);
Targets += '-';
std::string NormalizedTriple =
Dep.DependentToolChain->getTriple().normalize();
Targets += NormalizedTriple;
// When -fsycl-force-target is used, this value overrides the expected
// output type we are creating deps for.
if (Dep.DependentOffloadKind == Action::OFK_SYCL &&
TCArgs.hasArg(options::OPT_fsycl_force_target_EQ)) {
StringRef Val(
TCArgs.getLastArg(options::OPT_fsycl_force_target_EQ)->getValue());
llvm::Triple TT(C.getDriver().MakeSYCLDeviceTriple(Val));
Targets += TT.normalize();
} else {
std::string NormalizedTriple =
Dep.DependentToolChain->getTriple().normalize();
Targets += NormalizedTriple;
}
if ((Dep.DependentOffloadKind == Action::OFK_HIP ||
Dep.DependentOffloadKind == Action::OFK_SYCL) &&
!Dep.DependentBoundArch.empty()) {
Expand Down
12 changes: 12 additions & 0 deletions clang/test/Driver/sycl-force-target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
// CHECK_FORCE_TARGET_GEN: llvm-foreach{{.*}} {{.*}}ocloc{{.*}}
// CHECK_FORCE_TARGET_CPU: llvm-foreach{{.*}} {{.*}}opencl-aot{{.*}}

/// Verify the usage of -fsycl-force-target applies to all expected unbundlings
/// and also applies to clang-offload-deps step
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -fsycl-force-target=spir64 \
// RUN: -target x86_64-unknown-linux-gnu -fno-sycl-device-lib=all \
// RUN: %s %S/Inputs/SYCL/liblin64.a -### 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK_FORCE_TARGET_ARCHIVE
// CHECK_FORCE_TARGET_ARCHIVE: clang-offload-deps{{.*}} "-targets=sycl-spir64-unknown-unknown" "-outputs={{.*}}"
// CHECK_FORCE_TARGET_ARCHIVE: clang-offload-bundler{{.*}} "-type=aoo" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}liblin64.a" "-output=[[DEVICELISTOUT:.+]]" "-unbundle" "-allow-missing-bundles"
// CHECK_FORCE_TARGET_ARCHIVE: spirv-to-ir-wrapper{{.*}} "[[DEVICELISTOUT]]" "-o" "[[DEVICELISTBC:.+\.txt]]"
// CHECK_FORCE_TARGET_ARCHIVE: llvm-link{{.*}} "@[[DEVICELISTBC]]"{{.*}} "-o" "[[DEVICEARCHIVELINKED:.+\.bc]]" "--suppress-warnings"
// CHECK_FORCE_TARGET_ARCHIVE: llvm-foreach{{.*}} {{.*}}ocloc{{.*}}

/// -fsycl-force-target is only valid with -fsycl-target with single targets
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen,spir64_x86_64 \
// RUN: -fsycl-force-target=spir64 %s -### 2>&1 \
Expand Down

0 comments on commit 54777c0

Please sign in to comment.