-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[HIP] fix bundle ID for amdgcnspirv #139112
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the bundle ID issue for HIP apps targeting amdgcnspirv by updating both test cases and runtime handling of AMDHSA triples.
- Updated clang-offload-bundler tests to include a new target for HIP spirv bundles.
- Modified the string normalization in OffloadBundler.cpp to correctly handle AMDHSA triples for HIP spirv targets.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
clang/test/Driver/clang-offload-bundler-standardize.c | Added new target and device file to exercise HIP spirv bundling behavior. |
clang/lib/Driver/OffloadBundler.cpp | Updated runtime triple normalization and comments to reflect AMDHSA usage. |
Comments suppressed due to low confidence (1)
clang/lib/Driver/OffloadBundler.cpp:152
- [nitpick] Clarify in a comment that using Triple.getOS() to check for AMDHSA targets ensures proper normalization for HIP spirv, and verify that this logic consistently produces the intended bundle ID pattern.
if (Triple.getOS() == Triple::OSType::AMDHSA) {
@llvm/pr-subscribers-clang Author: Yaxun (Sam) Liu (yxsamliu) ChangesCurrently ROCm 6.4.0 only recognize spirv64-amd-amdhsa- in bundle ID. spirv64-amd-amdhsa-unknown causes all HIP apps compiled for amdgcnspirv to fail. Previously we fixed a similar issue for Full diff: https://github.com/llvm/llvm-project/pull/139112.diff 2 Files Affected:
diff --git a/clang/lib/Driver/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp
index 859e44fb9bdb2..e7a737796925e 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -145,11 +145,11 @@ bool OffloadTargetInfo::operator==(const OffloadTargetInfo &Target) const {
std::string OffloadTargetInfo::str() const {
std::string NormalizedTriple;
- // Unfortunately we need some special sauce for AMDGPU because all the runtime
- // assumes the triple to be "amdgcn-amd-amdhsa-" (empty environment) instead
- // of "amdgcn-amd-amdhsa-unknown". It's gonna be very tricky to patch
- // different layers of runtime.
- if (Triple.isAMDGPU()) {
+ // Unfortunately we need some special sauce for AMDHSA because all the runtime
+ // assumes the triple to be "amdgcn/spirv64-amd-amdhsa-" (empty environment)
+ // instead of "amdgcn/spirv64-amd-amdhsa-unknown". It's gonna be very tricky
+ // to patch different layers of runtime.
+ if (Triple.getOS() == Triple::OSType::AMDHSA) {
NormalizedTriple = Triple.normalize(Triple::CanonicalForm::THREE_IDENT);
NormalizedTriple.push_back('-');
} else {
diff --git a/clang/test/Driver/clang-offload-bundler-standardize.c b/clang/test/Driver/clang-offload-bundler-standardize.c
index fd87fca4ff59d..5b831eec794d2 100644
--- a/clang/test/Driver/clang-offload-bundler-standardize.c
+++ b/clang/test/Driver/clang-offload-bundler-standardize.c
@@ -11,16 +11,17 @@
//
// RUN: echo 'Content of device file 1' > %t.tgt1
// RUN: echo 'Content of device file 2' > %t.tgt2
-
+// RUN: echo 'Content of device file 3' > %t.tgt3
//
// Check code object compatibility for archive unbundling
//
// Create an object bundle
-// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx908 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle
+// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx908,hip-spirv64-amd-amdhsa--amdgcnspirv -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -input=%t.tgt3 -output=%t.bundle
-// RUN: clang-offload-bundler -unbundle -type=o -targets=hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx908 -input=%t.bundle -output=%t-hip-amdgcn-amd-amdhsa--gfx906.bc -output=%t-hip-amdgcn-amd-amdhsa--gfx908.bc -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=BUNDLE
+// RUN: clang-offload-bundler -unbundle -type=o -targets=hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx908,hip-spirv64-amd-amdhsa--amdgcnspirv -input=%t.bundle -output=%t-hip-amdgcn-amd-amdhsa--gfx906.bc -output=%t-hip-amdgcn-amd-amdhsa--gfx908.bc -output=%t-hip-spirv64-amd-amdhsa--amdgcnspirv.bc -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=BUNDLE
// BUNDLE: Compatible: Exact match: [CodeObject: hip-amdgcn-amd-amdhsa--gfx906] : [Target: hip-amdgcn-amd-amdhsa--gfx906]
// BUNDLE: Compatible: Exact match: [CodeObject: hip-amdgcn-amd-amdhsa--gfx908] : [Target: hip-amdgcn-amd-amdhsa--gfx908]
+// BUNDLE: Compatible: Exact match: [CodeObject: hip-spirv64-amd-amdhsa--amdgcnspirv] : [Target: hip-spirv64-amd-amdhsa--amdgcnspirv]
// Some code so that we can create a binary out of this file.
int A = 0;
|
@llvm/pr-subscribers-clang-driver Author: Yaxun (Sam) Liu (yxsamliu) ChangesCurrently ROCm 6.4.0 only recognize spirv64-amd-amdhsa- in bundle ID. spirv64-amd-amdhsa-unknown causes all HIP apps compiled for amdgcnspirv to fail. Previously we fixed a similar issue for Full diff: https://github.com/llvm/llvm-project/pull/139112.diff 2 Files Affected:
diff --git a/clang/lib/Driver/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp
index 859e44fb9bdb2..e7a737796925e 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -145,11 +145,11 @@ bool OffloadTargetInfo::operator==(const OffloadTargetInfo &Target) const {
std::string OffloadTargetInfo::str() const {
std::string NormalizedTriple;
- // Unfortunately we need some special sauce for AMDGPU because all the runtime
- // assumes the triple to be "amdgcn-amd-amdhsa-" (empty environment) instead
- // of "amdgcn-amd-amdhsa-unknown". It's gonna be very tricky to patch
- // different layers of runtime.
- if (Triple.isAMDGPU()) {
+ // Unfortunately we need some special sauce for AMDHSA because all the runtime
+ // assumes the triple to be "amdgcn/spirv64-amd-amdhsa-" (empty environment)
+ // instead of "amdgcn/spirv64-amd-amdhsa-unknown". It's gonna be very tricky
+ // to patch different layers of runtime.
+ if (Triple.getOS() == Triple::OSType::AMDHSA) {
NormalizedTriple = Triple.normalize(Triple::CanonicalForm::THREE_IDENT);
NormalizedTriple.push_back('-');
} else {
diff --git a/clang/test/Driver/clang-offload-bundler-standardize.c b/clang/test/Driver/clang-offload-bundler-standardize.c
index fd87fca4ff59d..5b831eec794d2 100644
--- a/clang/test/Driver/clang-offload-bundler-standardize.c
+++ b/clang/test/Driver/clang-offload-bundler-standardize.c
@@ -11,16 +11,17 @@
//
// RUN: echo 'Content of device file 1' > %t.tgt1
// RUN: echo 'Content of device file 2' > %t.tgt2
-
+// RUN: echo 'Content of device file 3' > %t.tgt3
//
// Check code object compatibility for archive unbundling
//
// Create an object bundle
-// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx908 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle
+// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx908,hip-spirv64-amd-amdhsa--amdgcnspirv -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -input=%t.tgt3 -output=%t.bundle
-// RUN: clang-offload-bundler -unbundle -type=o -targets=hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx908 -input=%t.bundle -output=%t-hip-amdgcn-amd-amdhsa--gfx906.bc -output=%t-hip-amdgcn-amd-amdhsa--gfx908.bc -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=BUNDLE
+// RUN: clang-offload-bundler -unbundle -type=o -targets=hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx908,hip-spirv64-amd-amdhsa--amdgcnspirv -input=%t.bundle -output=%t-hip-amdgcn-amd-amdhsa--gfx906.bc -output=%t-hip-amdgcn-amd-amdhsa--gfx908.bc -output=%t-hip-spirv64-amd-amdhsa--amdgcnspirv.bc -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=BUNDLE
// BUNDLE: Compatible: Exact match: [CodeObject: hip-amdgcn-amd-amdhsa--gfx906] : [Target: hip-amdgcn-amd-amdhsa--gfx906]
// BUNDLE: Compatible: Exact match: [CodeObject: hip-amdgcn-amd-amdhsa--gfx908] : [Target: hip-amdgcn-amd-amdhsa--gfx908]
+// BUNDLE: Compatible: Exact match: [CodeObject: hip-spirv64-amd-amdhsa--amdgcnspirv] : [Target: hip-spirv64-amd-amdhsa--amdgcnspirv]
// Some code so that we can create a binary out of this file.
int A = 0;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, lgtm
Currently ROCm 6.4.0 only recognize spirv64-amd-amdhsa- in bundle ID. spirv64-amd-amdhsa-unknown causes all HIP apps compiled for amdgcnspirv to fail. Previously we fixed a similar issue for amdgcn-amd-amdhsa-unknown. This patch extends that to spirv64-amd-amdhsa-unknown.
Currently ROCm 6.4.0 only recognize spirv64-amd-amdhsa- in bundle ID. spirv64-amd-amdhsa-unknown causes all HIP apps compiled for amdgcnspirv to fail.
Previously we fixed a similar issue for
amdgcn-amd-amdhsa-unknown. This patch extends that to spirv64-amd-amdhsa-unknown.