Skip to content

Commit 0fd9a4e

Browse files
authored
[SYCL] Fix triple in offload mismatch warning (#10385)
This patch fixes small issues after #9631 When standardizing the triples the format should be: ``` <arch><sub>-<vendor>-<sys>-<env> ``` * https://clang.llvm.org/docs/CrossCompilation.html#target-triple And then we add our offload arch afterwards, so the final triples should look something like: `nvptx64-nvidia-cuda--sm_50`, instead of `nvptx64-nvidia-cuda-sm_50-`. In addition never skip standardization so that triples like `nvptx64-nvidia-cuda-`, are also properly standardized to `nvptx64-nvidia-cuda--`.
1 parent bf60383 commit 0fd9a4e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ using namespace llvm::opt;
122122
// triple. This routine transforms the triple specified by user as input to this
123123
// 'standardized' format to facilitate checks.
124124
static std::string standardizedTriple(std::string OrigTriple) {
125-
if (OrigTriple.back() == '-') // Already standardized
126-
return OrigTriple;
127125
llvm::Triple t = llvm::Triple(OrigTriple);
128126
return llvm::Triple(t.getArchName(), t.getVendorName(), t.getOSName(),
129127
t.getEnvironmentName())
@@ -6036,9 +6034,21 @@ class OffloadingActionBuilder final {
60366034
// use the default FPGA triple to reduce possible match confusion.
60376035
if (Arch.compare(0, 4, "fpga") == 0)
60386036
Arch = C.getDriver().MakeSYCLDeviceTriple("spir64_fpga").str();
6037+
6038+
// The last component for the triple may be a GPU arch
6039+
auto TripleOrGPU = StringRef(Arch).rsplit('-');
6040+
if (clang::StringToCudaArch(TripleOrGPU.second.str()) !=
6041+
clang::CudaArch::UNKNOWN) {
6042+
Arch = standardizedTriple(TripleOrGPU.first.str());
6043+
Arch += TripleOrGPU.second.str();
6044+
} else {
6045+
Arch = standardizedTriple(Arch);
6046+
}
6047+
60396048
if (std::find(UniqueSections.begin(), UniqueSections.end(), Arch) ==
6040-
UniqueSections.end())
6041-
UniqueSections.push_back(standardizedTriple(Arch));
6049+
UniqueSections.end()) {
6050+
UniqueSections.push_back(Arch);
6051+
}
60426052
}
60436053
}
60446054

@@ -6047,11 +6057,10 @@ class OffloadingActionBuilder final {
60476057

60486058
for (auto &SyclTarget : Targets) {
60496059
std::string SectionTriple = SyclTarget.TC->getTriple().str();
6060+
SectionTriple = standardizedTriple(SectionTriple);
60506061
if (SyclTarget.BoundArch) {
6051-
SectionTriple += "-";
60526062
SectionTriple += SyclTarget.BoundArch;
60536063
}
6054-
SectionTriple = standardizedTriple(SectionTriple);
60556064
// If any matching section is found, we are good.
60566065
if (std::find(UniqueSections.begin(), UniqueSections.end(),
60576066
SectionTriple) != UniqueSections.end())

clang/test/Driver/sycl-target-mismatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_60 \
3434
// RUN: %S/Inputs/SYCL/objnvptx64-sm_50.o -### %s 2>&1 \
3535
// RUN: | FileCheck %s -check-prefix=NVPTX64_DIAG
36-
// NVPTX64_DIAG: linked binaries do not contain expected 'nvptx64-nvidia-cuda-sm_60-' target; found targets: 'nvptx64-nvidia-cuda-sm_50-' [-Wsycl-target]
36+
// NVPTX64_DIAG: linked binaries do not contain expected 'nvptx64-nvidia-cuda--sm_60' target; found targets: 'nvptx64-nvidia-cuda--sm_50' [-Wsycl-target]
3737

3838
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_50 \
3939
// RUN: %S/Inputs/SYCL/libnvptx64-sm_50.a -### %s 2>&1 \
@@ -61,7 +61,7 @@
6161
// RUN: %clangxx -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx906 \
6262
// RUN: %S/Inputs/SYCL/objamdgcn-gfx908.o -### %s 2>&1 \
6363
// RUN: | FileCheck %s -check-prefix=AMDGCN_DIAG
64-
// AMDGCN_DIAG: linked binaries do not contain expected 'amdgcn-amd-amdhsa-gfx906-' target; found targets: 'amdgcn-amd-amdhsa-gfx908-' [-Wsycl-target]
64+
// AMDGCN_DIAG: linked binaries do not contain expected 'amdgcn-amd-amdhsa--gfx906' target; found targets: 'amdgcn-amd-amdhsa--gfx908' [-Wsycl-target]
6565

6666
// RUN: %clangxx -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 \
6767
// RUN: %S/Inputs/SYCL/libamdgcn-gfx908.a -### %s 2>&1 \

0 commit comments

Comments
 (0)