Skip to content

Commit 6b5a4f4

Browse files
committed
[ClangOffloadBundler] make hipv4 and hip compatible (llvm#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. Fixes: SWDEV-460869 Change-Id: I605647f12ef852a14afc13960cc765c5f0b4f12b
1 parent b64927f commit 6b5a4f4

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
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
@@ -473,6 +473,17 @@
473473
// RUN: -output=%t.res.tgt1 -input=%t.hip.bundle.bc -unbundle 2>&1 | FileCheck %s -check-prefix=NOGFX906
474474
// NOGFX906: error: Can't find bundles for hip-amdgcn-amd-amdhsa--gfx906
475475

476+
//
477+
// Check hip and hipv4 are compatible as offload kind.
478+
//
479+
// RUN: clang-offload-bundler -type=o -targets=hip-amdgcn-amd-amdhsa--gfx90a -input=%t.tgt1 -output=%t.bundle3.o
480+
// RUN: clang-offload-bundler -type=o -targets=hipv4-amdgcn-amd-amdhsa--gfx90a:sramecc-:xnack+ -output=%t.res.tgt1 -input=%t.bundle3.o -unbundle
481+
// RUN: diff %t.tgt1 %t.res.tgt1
482+
483+
// RUN: clang-offload-bundler -type=o -targets=hipv4-amdgcn-amd-amdhsa--gfx90a -input=%t.tgt1 -output=%t.bundle3.o
484+
// RUN: clang-offload-bundler -type=o -targets=hip-amdgcn-amd-amdhsa--gfx90a:sramecc-:xnack+ -output=%t.res.tgt1 -input=%t.bundle3.o -unbundle
485+
// RUN: diff %t.tgt1 %t.res.tgt1
486+
476487
//
477488
// Check archive unbundling
478489
//

0 commit comments

Comments
 (0)