Skip to content

Commit 5ddc688

Browse files
authored
[Driver][SYCL][NewOffloadModel] Improve arch association for device (#13898)
When using the new offloading model, the values being passed to -fsycl-targets were not fully being realized when attempting to target specific architectures. Uses of -fsycl-targets=intel_gpu_* were not properly setting the arch values that are used down the line (namely the packaging step). Improve this situation by populating the assocated architecture mappings with what is seen when parsing the -fsycl-targets option. This applies to all intel_gpu, nvidia_gpu and amd_gpu targets.
1 parent 010d9a5 commit 5ddc688

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
11741174
}
11751175
bool HasSYCLTargetsOption = SYCLTargets;
11761176

1177+
llvm::StringMap<llvm::DenseSet<StringRef>> DerivedArchs;
11771178
llvm::StringMap<StringRef> FoundNormalizedTriples;
11781179
llvm::SmallVector<llvm::Triple, 4> UniqueSYCLTriplesVec;
11791180
if (HasSYCLTargetsOption) {
@@ -1192,24 +1193,28 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
11921193
<< SYCLForceTarget->getAsString(C.getInputArgs());
11931194

11941195
for (StringRef Val : SYCLTargetsValues->getValues()) {
1196+
StringRef Arch;
11951197
StringRef UserTargetName(Val);
11961198
if (auto Device = gen::isGPUTarget<gen::IntelGPU>(Val)) {
11971199
if (Device->empty()) {
11981200
Diag(clang::diag::err_drv_invalid_sycl_target) << Val;
11991201
continue;
12001202
}
1203+
Arch = Device->data();
12011204
UserTargetName = "spir64_gen";
12021205
} else if (auto Device = gen::isGPUTarget<gen::NvidiaGPU>(Val)) {
12031206
if (Device->empty()) {
12041207
Diag(clang::diag::err_drv_invalid_sycl_target) << Val;
12051208
continue;
12061209
}
1210+
Arch = Device->data();
12071211
UserTargetName = "nvptx64-nvidia-cuda";
12081212
} else if (auto Device = gen::isGPUTarget<gen::AmdGPU>(Val)) {
12091213
if (Device->empty()) {
12101214
Diag(clang::diag::err_drv_invalid_sycl_target) << Val;
12111215
continue;
12121216
}
1217+
Arch = Device->data();
12131218
UserTargetName = "amdgcn-amd-amdhsa";
12141219
} else if (Val == "native_cpu") {
12151220
const ToolChain *HostTC =
@@ -1236,7 +1241,10 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
12361241
// Store the current triple so that we can check for duplicates in
12371242
// the following iterations.
12381243
FoundNormalizedTriples[NormalizedName] = Val;
1239-
UniqueSYCLTriplesVec.push_back(MakeSYCLDeviceTriple(UserTargetName));
1244+
llvm::Triple DeviceTriple(MakeSYCLDeviceTriple(UserTargetName));
1245+
UniqueSYCLTriplesVec.push_back(DeviceTriple);
1246+
if (!Arch.empty())
1247+
DerivedArchs[DeviceTriple.getTriple()].insert(Arch);
12401248
}
12411249
addSYCLDefaultTriple(C, UniqueSYCLTriplesVec);
12421250
} else
@@ -1277,6 +1285,8 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
12771285
auto SYCLTC = &getOffloadingDeviceToolChain(C.getInputArgs(), TT, *HostTC,
12781286
Action::OFK_SYCL);
12791287
C.addOffloadDeviceToolChain(SYCLTC, Action::OFK_SYCL);
1288+
if (DerivedArchs.contains(TT.getTriple()))
1289+
KnownArchs[SYCLTC] = DerivedArchs[TT.getTriple()];
12801290
}
12811291

12821292
//

clang/test/Driver/sycl-offload-new-driver.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,26 @@
8383
// RUN: -shared %s 2>&1 \
8484
// RUN: | FileCheck -check-prefix=CHECK_SHARED %s
8585
// CHECK_SHARED: clang-linker-wrapper{{.*}} "-shared"
86+
87+
// Verify 'arch' offload-packager values for known targets
88+
// RUN: %clangxx -### --target=x86_64-unknown-linux-gnu -fsycl \
89+
// RUN: -fsycl-targets=spir64 --offload-new-driver %s 2>&1 \
90+
// RUN: | FileCheck -check-prefix=CHK_ARCH \
91+
// RUN: -DTRIPLE=spir64-unknown-unknown -DARCH= %s
92+
// RUN: %clangxx -### --target=x86_64-unknown-linux-gnu -fsycl \
93+
// RUN: -fsycl-targets=intel_gpu_pvc --offload-new-driver %s 2>&1 \
94+
// RUN: | FileCheck -check-prefix=CHK_ARCH \
95+
// RUN: -DTRIPLE=spir64_gen-unknown-unknown -DARCH=pvc %s
96+
// RUN: %clangxx -### --target=x86_64-unknown-linux-gnu -fsycl \
97+
// RUN: -fno-sycl-libspirv -fsycl-targets=amd_gpu_gfx900 \
98+
// RUN: -nogpulib --offload-new-driver %s 2>&1 \
99+
// RUN: | FileCheck -check-prefix=CHK_ARCH \
100+
// RUN: -DTRIPLE=amdgcn-amd-amdhsa -DARCH=gfx900 %s
101+
// RUN: %clangxx -### --target=x86_64-unknown-linux-gnu -fsycl \
102+
// RUN: -fno-sycl-libspirv -fsycl-targets=nvidia_gpu_sm_50 \
103+
// RUN: -nogpulib --offload-new-driver %s 2>&1 \
104+
// RUN: | FileCheck -check-prefix=CHK_ARCH \
105+
// RUN: -DTRIPLE=nvptx64-nvidia-cuda -DARCH=sm_50 %s
106+
// CHK_ARCH: clang{{.*}} "-triple" "[[TRIPLE]]"
107+
// CHK_ARCH-SAME: "-fsycl-is-device" {{.*}} "--offload-new-driver"{{.*}} "-o" "[[CC1DEVOUT:.+\.bc]]"
108+
// CHK_ARCH-NEXT: clang-offload-packager{{.*}} "--image=file=[[CC1DEVOUT]],triple=[[TRIPLE]],arch=[[ARCH]],kind=sycl"

0 commit comments

Comments
 (0)