Skip to content

Commit 6016ebd

Browse files
npmillermdtoguchi
authored andcommitted
[SYCL] Fix triple in offload mismatch warning (intel#10385)
This patch fixes small issues after intel#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 9a18c8a commit 6016ebd

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())
@@ -6062,9 +6060,21 @@ class OffloadingActionBuilder final {
60626060
// use the default FPGA triple to reduce possible match confusion.
60636061
if (Arch.compare(0, 4, "fpga") == 0)
60646062
Arch = C.getDriver().MakeSYCLDeviceTriple("spir64_fpga").str();
6063+
6064+
// The last component for the triple may be a GPU arch
6065+
auto TripleOrGPU = StringRef(Arch).rsplit('-');
6066+
if (clang::StringToCudaArch(TripleOrGPU.second.str()) !=
6067+
clang::CudaArch::UNKNOWN) {
6068+
Arch = standardizedTriple(TripleOrGPU.first.str());
6069+
Arch += TripleOrGPU.second.str();
6070+
} else {
6071+
Arch = standardizedTriple(Arch);
6072+
}
6073+
60656074
if (std::find(UniqueSections.begin(), UniqueSections.end(), Arch) ==
6066-
UniqueSections.end())
6067-
UniqueSections.push_back(standardizedTriple(Arch));
6075+
UniqueSections.end()) {
6076+
UniqueSections.push_back(Arch);
6077+
}
60686078
}
60696079
}
60706080

@@ -6073,11 +6083,10 @@ class OffloadingActionBuilder final {
60736083

60746084
for (auto &SyclTarget : Targets) {
60756085
std::string SectionTriple = SyclTarget.TC->getTriple().str();
6086+
SectionTriple = standardizedTriple(SectionTriple);
60766087
if (SyclTarget.BoundArch) {
6077-
SectionTriple += "-";
60786088
SectionTriple += SyclTarget.BoundArch;
60796089
}
6080-
SectionTriple = standardizedTriple(SectionTriple);
60816090
// If any matching section is found, we are good.
60826091
if (std::find(UniqueSections.begin(), UniqueSections.end(),
60836092
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)