saiislam created this revision.
saiislam added reviewers: jdoerfert, yaxunl, grokos.
saiislam requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.
Earlier BundleEntryID used to be <OffloadKind>-<Triple>-<GPUArch>.
This used to work because the clang-offload-bundler didn't need
GPUArch explicitly for any bundling/unbundling action. With
unbundleArchive it needs GPUArch to ensure compatibility between
device specific code objects. D93525 <https://reviews.llvm.org/D93525> enforced
triples to have
separators for all 4 components irrespective of number of
components, like "amdgcn-amd-amdhsa--". It was required to
to correctly parse a possible 4th environment component or a GPU.
But, this condition is breaking backward compatibility with
archive libraries compiled with compilers older than D93525
<https://reviews.llvm.org/D93525>.
This patch allows triples to have any number of components with
and without extra separator for empty environment field. Thus,
both the following bundle entry IDs are same:
openmp-amdgcn-amd-amdhsa--gfx906
openmp-amdgcn-amd-amdhsa-gfx906
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D106809
Files:
clang/docs/ClangOffloadBundler.rst
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang-offload-bundler.c
clang/test/Driver/hip-rdc-device-only.hip
clang/test/Driver/hip-toolchain-rdc-separate.hip
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===================================================================
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -134,21 +134,32 @@
/// * Offload Kind - Host, OpenMP, or HIP
/// * Triple - Standard LLVM Triple
/// * GPUArch (Optional) - Processor name, like gfx906 or sm_30
-/// In presence of Proc, the Triple should contain separator "-" for all
-/// standard four components, even if they are empty.
+
struct OffloadTargetInfo {
StringRef OffloadKind;
llvm::Triple Triple;
StringRef GPUArch;
OffloadTargetInfo(const StringRef Target) {
- SmallVector<StringRef, 6> Components;
- Target.split(Components, '-', 5);
- Components.resize(6);
- this->OffloadKind = Components[0];
- this->Triple = llvm::Triple(Components[1], Components[2], Components[3],
- Components[4]);
- this->GPUArch = Components[5];
+ auto TargetFeatures = Target.split(':');
+ auto TripleOrGPU = TargetFeatures.first.rsplit('-');
+
+ // Check if the last option before any colon is a triple field or a GPU name
+ if (TripleOrGPU.second.startswith("gfx") ||
+ TripleOrGPU.second.startswith("sm_")) {
+ auto KindTriple = TripleOrGPU.first.split('-');
+ this->OffloadKind = KindTriple.first;
+ this->Triple = llvm::Triple(KindTriple.second);
+ auto TID = Target.substr(Target.find("gfx"));
+ if (TID.empty())
+ TID = Target.substr(Target.find("sm_"));
+ this->GPUArch = TID;
+ } else {
+ auto KindTriple = TargetFeatures.first.split('-');
+ this->OffloadKind = KindTriple.first;
+ this->Triple = llvm::Triple(KindTriple.second);
+ this->GPUArch = "";
+ }
}
bool hasHostKind() const { return this->OffloadKind == "host"; }
@@ -1279,6 +1290,16 @@
"' in heterogenous archive library: " + IFName)
.str();
return createStringError(inconvertibleErrorCode(), ErrMsg);
+ } else { // Create an empty archive file if no compatible code object is
+ // found and "allow-missing-bundles" is enabled. It ensures that
+ // the linker using output of this step doesn't complain about
+ // the missing input file.
+ std::vector<llvm::NewArchiveMember> EmptyArchive;
+ EmptyArchive.clear();
+ if (Error WriteErr = writeArchive(FileName, EmptyArchive, true,
+ getDefaultArchiveKindForHost(), true,
+ false, nullptr))
+ return WriteErr;
}
}
Index: clang/test/Driver/hip-toolchain-rdc-separate.hip
===================================================================
--- clang/test/Driver/hip-toolchain-rdc-separate.hip
+++ clang/test/Driver/hip-toolchain-rdc-separate.hip
@@ -44,7 +44,7 @@
// CHECK-SAME: {{.*}} [[A_SRC]]
// CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
-// CHECK-SAME: "-targets=hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900,host-x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-targets=hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900,host-x86_64-unknown-linux-gnu"
// CHECK-SAME: "-outputs=[[A_O:.*a.o]]" "-inputs=[[A_BC1]],[[A_BC2]],[[A_OBJ_HOST]]"
// CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
@@ -79,7 +79,7 @@
// CHECK-SAME: {{.*}} [[B_SRC]]
// CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
-// CHECK-SAME: "-targets=hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900,host-x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-targets=hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900,host-x86_64-unknown-linux-gnu"
// CHECK-SAME: "-outputs=[[B_O:.*b.o]]" "-inputs=[[B_BC1]],[[B_BC2]],[[B_OBJ_HOST]]"
// RUN: touch %T/a.o
@@ -91,22 +91,22 @@
// RUN: 2>&1 | FileCheck -check-prefix=LINK %s
// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
-// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900"
+// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
// LINK-SAME: "-inputs=[[A_O:.*a.o]]" "-outputs=[[A_OBJ_HOST:.*o]],{{.*o}},{{.*o}}"
// LINK: "-unbundle" "-allow-missing-bundles"
// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
-// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900"
+// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
// LINK-SAME: "-inputs=[[B_O:.*b.o]]" "-outputs=[[B_OBJ_HOST:.*o]],{{.*o}},{{.*o}}"
// LINK: "-unbundle" "-allow-missing-bundles"
// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
-// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900"
+// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
// LINK-SAME: "-inputs=[[A_O]]" "-outputs={{.*o}},[[A_BC1:.*o]],[[A_BC2:.*o]]"
// LINK: "-unbundle" "-allow-missing-bundles"
// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
-// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900"
+// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
// LINK-SAME: "-inputs=[[B_O]]" "-outputs={{.*o}},[[B_BC1:.*o]],[[B_BC2:.*o]]"
// LINK: "-unbundle" "-allow-missing-bundles"
Index: clang/test/Driver/hip-rdc-device-only.hip
===================================================================
--- clang/test/Driver/hip-rdc-device-only.hip
+++ clang/test/Driver/hip-rdc-device-only.hip
@@ -82,7 +82,7 @@
// COMMON-SAME: {{.*}} {{".*a.cu"}}
// COMMON: "{{.*}}clang-offload-bundler" "-type={{(bc|ll)}}"
-// COMMON-SAME: "-targets=hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900"
+// COMMON-SAME: "-targets=hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
// COMMON-SAME: "-outputs=a-hip-amdgcn-amd-amdhsa.{{(bc|ll)}}"
// COMMON: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
@@ -112,7 +112,7 @@
// COMMON-SAME: {{.*}} {{".*b.hip"}}
// COMMON: "{{.*}}clang-offload-bundler" "-type={{(bc|ll)}}"
-// COMMON-SAME: "-targets=hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900"
+// COMMON-SAME: "-targets=hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
// COMMON-SAME: "-outputs=b-hip-amdgcn-amd-amdhsa.{{(bc|ll)}}"
// SAVETEMP: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu"
@@ -142,7 +142,7 @@
// SAVETEMP-SAME: {{.*}} "-o" {{"a.*.ll"}} "-x" "ir" [[A_GFX900_TMP_BC]]
// SAVETEMP: "{{.*}}clang-offload-bundler" "-type=ll"
-// SAVETEMP-SAME: "-targets=hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900"
+// SAVETEMP-SAME: "-targets=hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
// SAVETEMP-SAME: "-outputs=a-hip-amdgcn-amd-amdhsa.ll"
// SAVETEMP: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu"
@@ -172,7 +172,7 @@
// SAVETEMP-SAME: {{.*}} "-o" {{"b.*.ll"}} "-x" "ir" [[B_GFX900_TMP_BC]]
// SAVETEMP: "{{.*}}clang-offload-bundler" "-type=ll"
-// SAVETEMP-SAME: "-targets=hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900"
+// SAVETEMP-SAME: "-targets=hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
// SAVETEMP-SAME: "-outputs=b-hip-amdgcn-amd-amdhsa.ll"
// FAIL: error: cannot specify -o when generating multiple output files
Index: clang/test/Driver/clang-offload-bundler.c
===================================================================
--- clang/test/Driver/clang-offload-bundler.c
+++ clang/test/Driver/clang-offload-bundler.c
@@ -386,7 +386,7 @@
// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-amdgcn-amd-amdhsa--gfx903 -inputs=%t.o,%t.tgt1 -outputs=%t.simple1.bundle
// RUN: llvm-ar cr %t.input-archive.a %t.simple.bundle %t.simple1.bundle
-// RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa--gfx906,openmp-amdgcn-amd-amdhsa--gfx908 -inputs=%t.input-archive.a -outputs=%t-archive-gfx906-simple.a,%t-archive-gfx908-simple.a
+// RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa-gfx906,openmp-amdgcn-amd-amdhsa-gfx908 -inputs=%t.input-archive.a -outputs=%t-archive-gfx906-simple.a,%t-archive-gfx908-simple.a
// RUN: llvm-ar t %t-archive-gfx906-simple.a | FileCheck %s -check-prefix=GFX906
// GFX906: simple-openmp-amdgcn-amd-amdhsa--gfx906
// RUN: llvm-ar t %t-archive-gfx908-simple.a | FileCheck %s -check-prefix=GFX908
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7667,16 +7667,12 @@
});
}
Triples += Action::GetOffloadKindName(CurKind);
- Triples += "-";
- std::string NormalizedTriple = CurTC->getTriple().normalize();
- Triples += NormalizedTriple;
-
- if (CurDep->getOffloadingArch() != nullptr) {
- // If OffloadArch is present it can only appear as the 6th hypen
- // sepearated field of Bundle Entry ID. So, pad required number of
- // hyphens in Triple.
- for (int i = 4 - StringRef(NormalizedTriple).count("-"); i > 0; i--)
- Triples += "-";
+ Triples += '-';
+ Triples += CurTC->getTriple().normalize();
+ if ((CurKind == Action::OFK_HIP || CurKind == Action::OFK_OpenMP ||
+ CurKind == Action::OFK_Cuda) &&
+ CurDep->getOffloadingArch()) {
+ Triples += '-';
Triples += CurDep->getOffloadingArch();
}
}
@@ -7746,17 +7742,13 @@
auto &Dep = DepInfo[I];
Triples += Action::GetOffloadKindName(Dep.DependentOffloadKind);
- Triples += "-";
- std::string NormalizedTriple =
- Dep.DependentToolChain->getTriple().normalize();
- Triples += NormalizedTriple;
-
- if (!Dep.DependentBoundArch.empty()) {
- // If OffloadArch is present it can only appear as the 6th hypen
- // sepearated field of Bundle Entry ID. So, pad required number of
- // hyphens in Triple.
- for (int i = 4 - StringRef(NormalizedTriple).count("-"); i > 0; i--)
- Triples += "-";
+ Triples += '-';
+ Triples += Dep.DependentToolChain->getTriple().normalize();
+ if ((Dep.DependentOffloadKind == Action::OFK_HIP ||
+ Dep.DependentOffloadKind == Action::OFK_OpenMP ||
+ Dep.DependentOffloadKind == Action::OFK_Cuda) &&
+ !Dep.DependentBoundArch.empty()) {
+ Triples += '-';
Triples += Dep.DependentBoundArch;
}
}
Index: clang/docs/ClangOffloadBundler.rst
===================================================================
--- clang/docs/ClangOffloadBundler.rst
+++ clang/docs/ClangOffloadBundler.rst
@@ -121,15 +121,7 @@
============= ==============================================================
**target-triple**
- The target triple of the code object:
-
-.. code::
-
- <Architecture>-<Vendor>-<OS>-<Environment>
-
-It is required to have all four components present, if target-id is present.
-Components are hyphen separated. If a component is not specified then the
-empty string must be used in its place.
+ The target triple of the code object.
**target-id**
The canonical target ID of the code object. Present only if the target
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits