Skip to content

[SYCL] Fix triple in offload mismatch warning #10385

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

Merged
merged 2 commits into from
Jul 28, 2023
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
21 changes: 15 additions & 6 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ using namespace llvm::opt;
// triple. This routine transforms the triple specified by user as input to this
// 'standardized' format to facilitate checks.
static std::string standardizedTriple(std::string OrigTriple) {
if (OrigTriple.back() == '-') // Already standardized
return OrigTriple;
llvm::Triple t = llvm::Triple(OrigTriple);
return llvm::Triple(t.getArchName(), t.getVendorName(), t.getOSName(),
t.getEnvironmentName())
Expand Down Expand Up @@ -6023,9 +6021,21 @@ class OffloadingActionBuilder final {
// use the default FPGA triple to reduce possible match confusion.
if (Arch.compare(0, 4, "fpga") == 0)
Arch = C.getDriver().MakeSYCLDeviceTriple("spir64_fpga").str();

// The last component for the triple may be a GPU arch
auto TripleOrGPU = StringRef(Arch).rsplit('-');
if (clang::StringToCudaArch(TripleOrGPU.second.str()) !=
clang::CudaArch::UNKNOWN) {
Arch = standardizedTriple(TripleOrGPU.first.str());
Arch += TripleOrGPU.second.str();
} else {
Arch = standardizedTriple(Arch);
}

if (std::find(UniqueSections.begin(), UniqueSections.end(), Arch) ==
UniqueSections.end())
UniqueSections.push_back(standardizedTriple(Arch));
UniqueSections.end()) {
UniqueSections.push_back(Arch);
}
}
}

Expand All @@ -6034,11 +6044,10 @@ class OffloadingActionBuilder final {

for (auto &SyclTarget : Targets) {
std::string SectionTriple = SyclTarget.TC->getTriple().str();
SectionTriple = standardizedTriple(SectionTriple);
if (SyclTarget.BoundArch) {
SectionTriple += "-";
SectionTriple += SyclTarget.BoundArch;
}
SectionTriple = standardizedTriple(SectionTriple);
// If any matching section is found, we are good.
if (std::find(UniqueSections.begin(), UniqueSections.end(),
SectionTriple) != UniqueSections.end())
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Driver/sycl-target-mismatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_60 \
// RUN: %S/Inputs/SYCL/objnvptx64-sm_50.o -### %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=NVPTX64_DIAG
// NVPTX64_DIAG: linked binaries do not contain expected 'nvptx64-nvidia-cuda-sm_60-' target; found targets: 'nvptx64-nvidia-cuda-sm_50-' [-Wsycl-target]
// NVPTX64_DIAG: linked binaries do not contain expected 'nvptx64-nvidia-cuda--sm_60' target; found targets: 'nvptx64-nvidia-cuda--sm_50' [-Wsycl-target]

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

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