Skip to content

[SYCL][clang tools] Revert "Reintroduce reverted commit "[clang-offload-bundler] Standardize TargetID field for bundler (#9631)"" #10950

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
Aug 24, 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
15 changes: 1 addition & 14 deletions clang/docs/ClangOffloadBundler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,7 @@ Where:
============= ==============================================================

**target-triple**
The target triple of the code object. See `Target Triple
<https://clang.llvm.org/docs/CrossCompilation.html#target-triple>`.

The bundler accepts target triples with or without the optional environment
field:

``<arch><sub>-<vendor>-<sys>``, or
``<arch><sub>-<vendor>-<sys>-<env>``

However, in order to standardize outputs for tools that consume bitcode
bundles, bundles written by the bundler internally use only the 4-field
target triple:

``<arch><sub>-<vendor>-<sys>-<env>``
The target triple of the code object.

**target-id**
The canonical target ID of the code object. Present only if the target
Expand Down
28 changes: 2 additions & 26 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,6 @@ using namespace clang::driver;
using namespace clang;
using namespace llvm::opt;

// clang-offload-bundler is currently generating a 'standardized' target triple.
// Triple's format - Architecture-Vendor-OS-Environment.
// Bundle sections created by clang-offload-bundler contain the 'standardized'
// 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) {
llvm::Triple t = llvm::Triple(OrigTriple);
return llvm::Triple(t.getArchName(), t.getVendorName(), t.getOSName(),
t.getEnvironmentName())
.str() +
"-";
}

static std::optional<llvm::Triple> getOffloadTargetTriple(const Driver &D,
const ArgList &Args) {
auto OffloadTargets = Args.getAllArgValues(options::OPT_offload_EQ);
Expand Down Expand Up @@ -6101,20 +6088,9 @@ class OffloadingActionBuilder final {
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.end())
UniqueSections.push_back(Arch);
}
}
}

Expand All @@ -6123,8 +6099,8 @@ class OffloadingActionBuilder final {

for (auto &SyclTarget : Targets) {
std::string SectionTriple = SyclTarget.TC->getTriple().str();
SectionTriple = standardizedTriple(SectionTriple);
if (SyclTarget.BoundArch) {
SectionTriple += "-";
SectionTriple += SyclTarget.BoundArch;
}
// If any matching section is found, we are good.
Expand Down
35 changes: 10 additions & 25 deletions clang/lib/Driver/OffloadBundler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,12 @@ OffloadTargetInfo::OffloadTargetInfo(const StringRef Target,
if (clang::StringToCudaArch(TripleOrGPU.second) != clang::CudaArch::UNKNOWN) {
auto KindTriple = TripleOrGPU.first.split('-');
this->OffloadKind = KindTriple.first;

// Enforce optional env field to standardize bundles
llvm::Triple t = llvm::Triple(KindTriple.second);
this->Triple = llvm::Triple(t.getArchName(), t.getVendorName(),
t.getOSName(), t.getEnvironmentName());

if (TripleOrGPU.second.empty())
this->TargetID = "";
else
this->TargetID = Target.substr(Target.find(TripleOrGPU.second));
this->Triple = llvm::Triple(KindTriple.second);
this->TargetID = Target.substr(Target.find(TripleOrGPU.second));
} else {
auto KindTriple = TargetFeatures.first.split('-');
this->OffloadKind = KindTriple.first;

// Enforce optional env field to standardize bundles
llvm::Triple t = llvm::Triple(KindTriple.second);
this->Triple = llvm::Triple(t.getArchName(), t.getVendorName(),
t.getOSName(), t.getEnvironmentName());

this->Triple = llvm::Triple(KindTriple.second);
this->TargetID = "";
}
}
Expand Down Expand Up @@ -1590,34 +1577,34 @@ Error OffloadBundler::UnbundleFiles() {
return Error::success();
}

// Unbundle the files. Return false if an error was found.
// Unbundle the files. Return true if an error was found.
Expected<bool>
clang::CheckBundledSection(const OffloadBundlerConfig &BundlerConfig) {
// Open Input file.
ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
MemoryBuffer::getFileOrSTDIN(BundlerConfig.InputFileNames.front());
if (std::error_code EC = CodeOrErr.getError())
return false;
return createFileError(BundlerConfig.InputFileNames.front(), EC);
MemoryBuffer &Input = *CodeOrErr.get();

// Select the right files handler.
Expected<std::unique_ptr<FileHandler>> FileHandlerOrErr =
CreateFileHandler(Input, BundlerConfig);
if (!FileHandlerOrErr)
return false;
return FileHandlerOrErr.takeError();

std::unique_ptr<FileHandler> &FH = *FileHandlerOrErr;

// Quit if we don't have a handler.
if (!FH)
return false;
return true;

// Seed temporary filename generation with the stem of the input file.
FH->SetTempFileNameBase(llvm::sys::path::stem(BundlerConfig.InputFileNames.front()));

// Read the header of the bundled file.
if (Error Err = FH->ReadHeader(Input))
return false;
return std::move(Err);

StringRef triple = BundlerConfig.TargetNames.front();

Expand All @@ -1628,15 +1615,13 @@ clang::CheckBundledSection(const OffloadBundlerConfig &BundlerConfig) {
Expected<std::optional<StringRef>> CurTripleOrErr =
FH->ReadBundleStart(Input);
if (!CurTripleOrErr)
return false;
return CurTripleOrErr.takeError();

// We don't have more bundles.
if (!*CurTripleOrErr)
break;

StringRef CurTriple = **CurTripleOrErr;
if (OffloadTargetInfo(CurTriple, BundlerConfig).Triple.str() ==
OffloadTargetInfo(triple, BundlerConfig).Triple.str()) {
if (*CurTripleOrErr == triple) {
found = true;
break;
}
Expand Down
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions clang/test/Driver/clang-offload-bundler-asserts-on.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

// Tests to check compatibility between Bundle Entry ID formats i.e. between presence/absence of extra hyphen in case of missing environment field
// RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa--gfx906,openmp-amdgcn-amd-amdhsa-gfx908 -input=%t.input-archive.a -output=%t-archive-gfx906-simple.a -output=%t-archive-gfx908-simple.a -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=BUNDLECOMPATIBILITY
// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: openmp-amdgcn-amd-amdhsa--gfx906] : [Target: openmp-amdgcn-amd-amdhsa--gfx906]
// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: openmp-amdgcn-amd-amdhsa--gfx908] : [Target: openmp-amdgcn-amd-amdhsa--gfx908]
// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: openmp-amdgcn-amd-amdhsa-gfx906] : [Target: openmp-amdgcn-amd-amdhsa--gfx906]
// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: openmp-amdgcn-amd-amdhsa--gfx908] : [Target: openmp-amdgcn-amd-amdhsa-gfx908]

// RUN: clang-offload-bundler -unbundle -type=a -targets=hip-amdgcn-amd-amdhsa--gfx906,hipv4-amdgcn-amd-amdhsa-gfx908 -input=%t.input-archive.a -output=%t-hip-archive-gfx906-simple.a -output=%t-hipv4-archive-gfx908-simple.a -hip-openmp-compatible -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=HIPOpenMPCOMPATIBILITY
// HIPOpenMPCOMPATIBILITY: Compatible: Code Objects are compatible [CodeObject: openmp-amdgcn-amd-amdhsa--gfx906] : [Target: hip-amdgcn-amd-amdhsa--gfx906]
// HIPOpenMPCOMPATIBILITY: Compatible: Code Objects are compatible [CodeObject: openmp-amdgcn-amd-amdhsa--gfx908] : [Target: hipv4-amdgcn-amd-amdhsa--gfx908]
// HIPOpenMPCOMPATIBILITY: Compatible: Code Objects are compatible [CodeObject: openmp-amdgcn-amd-amdhsa-gfx906] : [Target: hip-amdgcn-amd-amdhsa--gfx906]
// HIPOpenMPCOMPATIBILITY: Compatible: Code Objects are compatible [CodeObject: openmp-amdgcn-amd-amdhsa--gfx908] : [Target: hipv4-amdgcn-amd-amdhsa-gfx908]

// Some code so that we can create a binary out of this file.
int A = 0;
Expand Down

This file was deleted.

37 changes: 0 additions & 37 deletions clang/test/Driver/clang-offload-bundler-standardize.c

This file was deleted.

4 changes: 2 additions & 2 deletions clang/test/Driver/clang-offload-bundler-tgtsym-asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// RUN: llvm-readobj --string-dump=.tgtsym %t.fat.o | FileCheck %s

// CHECK: String dump of section '.tgtsym':
// CHECK-DAG: openmp-x86_64-pc-linux-gnu-.foo
// CHECK-DAG: sycl-spir64----.foo
// CHECK-DAG: openmp-x86_64-pc-linux-gnu.foo
// CHECK-DAG: sycl-spir64.foo

__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
void foo(void) {}
14 changes: 7 additions & 7 deletions clang/test/Driver/clang-offload-bundler-tgtsym.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
// RUN: llvm-readobj --string-dump=.tgtsym %t.fat.o | FileCheck %s

// CHECK: String dump of section '.tgtsym':
// CHECK-DAG: openmp-x86_64-pc-linux-gnu-.foo
// CHECK-DAG: openmp-x86_64-pc-linux-gnu-.bar
// CHECK-DAG: sycl-spir64----.foo
// CHECK-DAG: sycl-spir64----.bar
// CHECK-DAG: openmp-x86_64-pc-linux-gnu.foo
// CHECK-DAG: openmp-x86_64-pc-linux-gnu.bar
// CHECK-DAG: sycl-spir64.foo
// CHECK-DAG: sycl-spir64.bar
// CHECK-NOT: undefined_func
// CHECK-NOT: static_func
// CHECK-NOT: static_used
// CHECK-NOT: sycl-spir64----.llvm.used
// CHECK-NOT: sycl-spir64----.llvm.compiler.used
// CHECK-NOT: sycl-spir64----.const_as
// CHECK-NOT: sycl-spir64.llvm.used
// CHECK-NOT: sycl-spir64.llvm.compiler.used
// CHECK-NOT: sycl-spir64.const_as

// RUN: clang-offload-bundler --add-target-symbols-to-bundled-object=false -type=o -targets=host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu,sycl-spir64 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.fat.no.tgtsym.o
// RUN: llvm-readobj --string-dump=.tgtsym %t.fat.no.tgtsym.o | FileCheck %s --check-prefix CHECK-NO-TGTSYM
Expand Down
Loading