Skip to content

Commit 374f655

Browse files
authored
[OpenMP] Fix passing target id features to AMDGPU offloading (#94765)
Summary: AMDGPU supports a `target-id` feature which is used to qualify targets with different incompatible features. These are both rules and target features. Currently, we pass `-target-cpu` twice when offloading to OpenMP, and do not pass the target-id features at all. The effect was that passing something like `--offload-arch=gfx90a:xnack+` would show up as `-target-cpu=gfx90a:xnack+ -target-cpu=gfx90a`. Thus ignoring the xnack completely and passing it twice. This patch fixes that to pass it once and then separate it like how HIP does.
1 parent 1539da4 commit 374f655

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,11 @@ void amdgpu::getAMDGPUTargetFeatures(const Driver &D,
645645
std::vector<StringRef> &Features) {
646646
// Add target ID features to -target-feature options. No diagnostics should
647647
// be emitted here since invalid target ID is diagnosed at other places.
648-
StringRef TargetID = Args.getLastArgValue(options::OPT_mcpu_EQ);
648+
StringRef TargetID;
649+
if (Args.hasArg(options::OPT_mcpu_EQ))
650+
TargetID = Args.getLastArgValue(options::OPT_mcpu_EQ);
651+
else if (Args.hasArg(options::OPT_march_EQ))
652+
TargetID = Args.getLastArgValue(options::OPT_march_EQ);
649653
if (!TargetID.empty()) {
650654
llvm::StringMap<bool> FeatureMap;
651655
auto OptionalGpuArch = parseTargetID(Triple, TargetID, &FeatureMap);

clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,9 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
4444
Action::OffloadKind DeviceOffloadingKind) const {
4545
HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
4646

47-
StringRef GPUArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
48-
assert(!GPUArch.empty() && "Must have an explicit GPU arch.");
49-
5047
assert(DeviceOffloadingKind == Action::OFK_OpenMP &&
5148
"Only OpenMP offloading kinds are supported.");
5249

53-
CC1Args.push_back("-target-cpu");
54-
CC1Args.push_back(DriverArgs.MakeArgStringRef(GPUArch));
5550
CC1Args.push_back("-fcuda-is-device");
5651

5752
if (DriverArgs.hasArg(options::OPT_nogpulib))

clang/test/Driver/amdgpu-openmp-toolchain.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// verify the tools invocations
99
// CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-llvm-bc"{{.*}}"-x" "c"
10-
// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu"{{.*}}"-target-cpu" "gfx906"{{.*}}"-fcuda-is-device"{{.*}}
10+
// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu"{{.*}}"-fcuda-is-device"{{.*}}"-target-cpu" "gfx906"
1111
// CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
1212
// CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
1313

@@ -63,6 +63,7 @@
6363

6464
// RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a:sramecc-:xnack+ \
6565
// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID
66+
// CHECK-TARGET-ID: "-cc1" "-triple" "amdgcn-amd-amdhsa" {{.*}} "-target-cpu" "gfx90a" "-target-feature" "-sramecc" "-target-feature" "+xnack"
6667
// CHECK-TARGET-ID: clang-offload-packager{{.*}}arch=gfx90a:sramecc-:xnack+,kind=openmp,feature=-sramecc,feature=+xnack
6768

6869
// RUN: not %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a,gfx90a:xnack+ \

0 commit comments

Comments
 (0)