Skip to content

Commit

Permalink
[Driver][SYCL][NewOffloadModel] Incorporate -device settings for GPU (i…
Browse files Browse the repository at this point in the history
…ntel#14151)

One of the models that is used for specifying the device architecture
for spir64_gen is to use the -Xsycl-target-backend "-device arg" syntax
on the command line.

Hook up the ability to scan the target backend values to embed the
proper information in the packaged binary when using the new offload
model.
  • Loading branch information
mdtoguchi authored Jun 13, 2024
1 parent 4e41992 commit f9fd95e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
28 changes: 26 additions & 2 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,11 +1225,36 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
continue;
}

if (!isValidSYCLTriple(MakeSYCLDeviceTriple(UserTargetName))) {
llvm::Triple DeviceTriple(MakeSYCLDeviceTriple(UserTargetName));
if (!isValidSYCLTriple(DeviceTriple)) {
Diag(clang::diag::err_drv_invalid_sycl_target) << Val;
continue;
}

// For any -fsycl-targets=spir64_gen additions, we will scan the
// additional -X* options for potential -device settings. These
// need to be added as a known Arch to the packager.
if (DeviceTriple.isSPIRAOT() && Arch.empty() &&
DeviceTriple.getSubArch() == llvm::Triple::SPIRSubArch_gen) {
const ToolChain *HostTC =
C.getSingleOffloadToolChain<Action::OFK_Host>();
auto DeviceTC = std::make_unique<toolchains::SYCLToolChain>(
*this, DeviceTriple, *HostTC, C.getInputArgs());
assert(DeviceTC && "Device toolchain not defined.");
ArgStringList TargetArgs;
DeviceTC->TranslateBackendTargetArgs(DeviceTC->getTriple(),
C.getInputArgs(), TargetArgs);
// Look for -device <string> and use that as the known arch to
// be associated with the current spir64_gen entry. Grab the
// right most entry.
for (int i = TargetArgs.size() - 2; i >= 0; --i) {
if (StringRef(TargetArgs[i]) == "-device") {
Arch = TargetArgs[i + 1];
break;
}
}
}

// Make sure we don't have a duplicate triple.
std::string NormalizedName = MakeSYCLDeviceTriple(Val).normalize();
auto Duplicate = FoundNormalizedTriples.find(NormalizedName);
Expand All @@ -1242,7 +1267,6 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
// Store the current triple so that we can check for duplicates in
// the following iterations.
FoundNormalizedTriples[NormalizedName] = Val;
llvm::Triple DeviceTriple(MakeSYCLDeviceTriple(UserTargetName));
SYCLTriples.insert(DeviceTriple.normalize());
if (!Arch.empty())
DerivedArchs[DeviceTriple.getTriple()].insert(Arch);
Expand Down
11 changes: 11 additions & 0 deletions clang/test/Driver/sycl-offload-new-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@
// RUN: | FileCheck -check-prefix=CHK_ARCH \
// RUN: -DTRIPLE=spir64_gen-unknown-unknown -DARCH=pvc %s
// RUN: %clangxx -### --target=x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen \
// RUN: "-device pvc" --offload-new-driver %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK_ARCH \
// RUN: -DTRIPLE=spir64_gen-unknown-unknown -DARCH=pvc %s
// RUN: %clangxx -### --target=x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen \
// RUN: "-device pvc" -Xsycl-target-backend=spir64_gen "-device dg1" \
// RUN: --offload-new-driver %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK_ARCH \
// RUN: -DTRIPLE=spir64_gen-unknown-unknown -DARCH=dg1 %s
// RUN: %clangxx -### --target=x86_64-unknown-linux-gnu -fsycl \
// RUN: -fno-sycl-libspirv -fsycl-targets=amd_gpu_gfx900 \
// RUN: -nogpulib --offload-new-driver %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK_ARCH \
Expand Down

0 comments on commit f9fd95e

Please sign in to comment.