Skip to content

Commit ca39175

Browse files
authored
[ClangOffloadBundler] make hipv4 and hip compatible (#91637)
The distinction between the hip and hipv4 offload kinds is historically based. Originally, these designations might have indicated different versions of the code object ABI (Application Binary Interface). However, as the system has evolved, the ABI version is now embedded directly within the code object itself, making these historical distinctions irrelevant during the unbundling process. Consequently, hip and hipv4 are treated as compatible in current implementations, facilitating interchangeable handling of code objects without differentiation based on offload kind. This change streamlines code management within the ecosystem.
1 parent db94213 commit ca39175

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

clang/docs/ClangOffloadBundler.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Where:
245245
object as a data section with the name ``.hip_fatbin``.
246246

247247
hipv4 Offload code object for the HIP language. Used for AMD GPU
248-
code objects with at least ABI version V4 when the
248+
code objects with at least ABI version V4 and above when the
249249
``clang-offload-bundler`` is used to create a *fat binary*
250250
to be loaded by the HIP runtime. The fat binary can be
251251
loaded directly from a file, or be embedded in the host code
@@ -254,6 +254,14 @@ Where:
254254
openmp Offload code object for the OpenMP language extension.
255255
============= ==============================================================
256256

257+
Note: The distinction between the `hip` and `hipv4` offload kinds is historically based.
258+
Originally, these designations might have indicated different versions of the
259+
code object ABI. However, as the system has evolved, the ABI version is now embedded
260+
directly within the code object itself, making these historical distinctions irrelevant
261+
during the unbundling process. Consequently, `hip` and `hipv4` are treated as compatible
262+
in current implementations, facilitating interchangeable handling of code objects
263+
without differentiation based on offload kind.
264+
257265
**target-triple**
258266
The target triple of the code object. See `Target Triple
259267
<https://clang.llvm.org/docs/CrossCompilation.html#target-triple>`_.
@@ -295,7 +303,7 @@ Compatibility Rules for Bundle Entry ID
295303
A code object, specified using its Bundle Entry ID, can be loaded and
296304
executed on a target processor, if:
297305

298-
* Their offload kinds are the same.
306+
* Their offload kinds are the same or comptible.
299307
* Their target triples are compatible.
300308
* Their Target IDs are compatible as defined in :ref:`compatibility-target-id`.
301309

clang/lib/Driver/OffloadBundler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ bool OffloadTargetInfo::isOffloadKindValid() const {
113113

114114
bool OffloadTargetInfo::isOffloadKindCompatible(
115115
const StringRef TargetOffloadKind) const {
116-
if (OffloadKind == TargetOffloadKind)
116+
if ((OffloadKind == TargetOffloadKind) ||
117+
(OffloadKind == "hip" && TargetOffloadKind == "hipv4") ||
118+
(OffloadKind == "hipv4" && TargetOffloadKind == "hip"))
117119
return true;
120+
118121
if (BundlerConfig.HipOpenmpCompatible) {
119122
bool HIPCompatibleWithOpenMP = OffloadKind.starts_with_insensitive("hip") &&
120123
TargetOffloadKind == "openmp";

clang/test/Driver/clang-offload-bundler.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,17 @@
505505
// RUN: -output=%t.res.tgt1 -input=%t.hip.bundle.bc -unbundle 2>&1 | FileCheck %s -check-prefix=NOGFX906
506506
// NOGFX906: error: Can't find bundles for hip-amdgcn-amd-amdhsa--gfx906
507507

508+
//
509+
// Check hip and hipv4 are compatible as offload kind.
510+
//
511+
// RUN: clang-offload-bundler -type=o -targets=hip-amdgcn-amd-amdhsa--gfx90a -input=%t.tgt1 -output=%t.bundle3.o
512+
// RUN: clang-offload-bundler -type=o -targets=hipv4-amdgcn-amd-amdhsa--gfx90a:sramecc-:xnack+ -output=%t.res.tgt1 -input=%t.bundle3.o -unbundle
513+
// RUN: diff %t.tgt1 %t.res.tgt1
514+
515+
// RUN: clang-offload-bundler -type=o -targets=hipv4-amdgcn-amd-amdhsa--gfx90a -input=%t.tgt1 -output=%t.bundle3.o
516+
// RUN: clang-offload-bundler -type=o -targets=hip-amdgcn-amd-amdhsa--gfx90a:sramecc-:xnack+ -output=%t.res.tgt1 -input=%t.bundle3.o -unbundle
517+
// RUN: diff %t.tgt1 %t.res.tgt1
518+
508519
//
509520
// Check archive unbundling
510521
//

clang/test/Driver/linker-wrapper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ __attribute__((visibility("protected"), used)) int x;
120120

121121
// HIP: clang{{.*}} -o [[IMG_GFX908:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx908
122122
// HIP: clang{{.*}} -o [[IMG_GFX90A:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx90a
123-
// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx90a,hipv4-amdgcn-amd-amdhsa--gfx908 -input=/dev/null -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb
123+
// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input=/dev/null -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb
124124

125125
// RUN: clang-offload-packager -o %t.out \
126126
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \
@@ -210,7 +210,7 @@ __attribute__((visibility("protected"), used)) int x;
210210
// RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=RELOCATABLE-LINK-HIP
211211

212212
// RELOCATABLE-LINK-HIP: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa
213-
// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx90a -input=/dev/null -input={{.*}} -output={{.*}}
213+
// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a -input=/dev/null -input={{.*}} -output={{.*}}
214214
// RELOCATABLE-LINK-HIP: /usr/bin/ld.lld{{.*}}-r
215215
// RELOCATABLE-LINK-HIP: llvm-objcopy{{.*}}a.out --remove-section .llvm.offloading
216216

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ fatbinary(ArrayRef<std::pair<StringRef, StringRef>> InputFiles,
413413

414414
SmallVector<StringRef> Targets = {"-targets=host-x86_64-unknown-linux"};
415415
for (const auto &[File, Arch] : InputFiles)
416-
Targets.push_back(Saver.save("hipv4-amdgcn-amd-amdhsa--" + Arch));
416+
Targets.push_back(Saver.save("hip-amdgcn-amd-amdhsa--" + Arch));
417417
CmdArgs.push_back(Saver.save(llvm::join(Targets, ",")));
418418

419419
#ifdef _WIN32

0 commit comments

Comments
 (0)