Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Driver][SYCL][NewOffloadModel] Incorporate -device settings for GPU #14151

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading