Skip to content

Commit

Permalink
fixup! fixup! rocm-compilersupport: Update to v6.2.4
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Zhao <[email protected]>
  • Loading branch information
GZGavinZhao committed Dec 21, 2024
1 parent 3bd334b commit 9077bb5
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 83 deletions.
3 changes: 2 additions & 1 deletion packages/r/rocm-compilersupport/abi_used_symbols
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,11 @@ libstdc++.so.6:_ZTVSt13basic_filebufIcSt11char_traitsIcEE
libstdc++.so.6:_ZTVSt15basic_streambufIcSt11char_traitsIcEE
libstdc++.so.6:_ZTVSt9basic_iosIcSt11char_traitsIcEE
libstdc++.so.6:_ZdaPv
libstdc++.so.6:_ZdaPvm
libstdc++.so.6:_ZdlPv
libstdc++.so.6:_ZdlPvRKSt9nothrow_t
libstdc++.so.6:_ZdlPvSt11align_val_t
libstdc++.so.6:_ZdlPvm
libstdc++.so.6:_ZdlPvmSt11align_val_t
libstdc++.so.6:_Znam
libstdc++.so.6:_Znwm
libstdc++.so.6:_ZnwmRKSt9nothrow_t
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
From 2d8c459a4d4c0567a7a275b4b54560d88e5c6919 Mon Sep 17 00:00:00 2001
From: Gavin Zhao <[email protected]>
Date: Sat, 21 Dec 2024 09:43:46 -0500
Subject: [PATCH] [Comgr] Extend ISA compatibility for CCOB

Signed-off-by: Gavin Zhao <[email protected]>
---
amd/comgr/src/comgr-compiler.cpp | 57 +++++++++++++++++++++++++++++++-
amd/comgr/src/comgr-metadata.h | 2 ++
2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/amd/comgr/src/comgr-compiler.cpp b/amd/comgr/src/comgr-compiler.cpp
index 9f39b939dd12..cdd14650d83a 100644
--- a/amd/comgr/src/comgr-compiler.cpp
+++ b/amd/comgr/src/comgr-compiler.cpp
@@ -39,6 +39,7 @@
#include "comgr-compiler.h"
#include "comgr-device-libs.h"
#include "comgr-env.h"
+#include "comgr-metadata.h"
#include "lld/Common/CommonLinkerContext.h"
#include "lld/Common/Driver.h"
#include "clang/Basic/Version.h"
@@ -1298,9 +1299,63 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
size_t index = output_prefix.find_last_of(".");
output_prefix = output_prefix.substr(0, index);

+ std::set<std::string> co_entry_ids;
+ if (auto Error = OffloadBundler::GetBundleIDsInFile(input_file_path, BundlerConfig, co_entry_ids)) {
+ if (env::shouldEmitVerboseLogs()) {
+ LogS << "Failed to get bundle IDs in "
+ << input_file_path
+ << ", not trying to coerce compatible archs\n";
+ LogS.flush();
+ }
+ }
+ std::set<std::pair<std::string, std::string>> entry_ids_with_idents;
+ for (const auto& co_entry_id : co_entry_ids) {
+ std::string target_ident;
+ size_t pos = std::string::npos;
+ for (const auto& prefix : {"hipv4-", "hip-"}) {
+ if ((pos = co_entry_id.find(prefix)) == 0) {
+ target_ident = co_entry_id.substr(std::char_traits<char>::length(prefix));
+ break;
+ }
+ }
+
+ if (target_ident.empty()) {
+ continue;
+ }
+
+ entry_ids_with_idents.emplace(co_entry_id, target_ident);
+ }
+
// Bundler target and output names
for (auto entry: ActionInfo->BundleEntryIDs) {
- BundlerConfig.TargetNames.push_back(entry);
+ std::string compat_entry = entry;
+
+ std::string entry_ident;
+ size_t pos = std::string::npos;
+ for (const auto& prefix : {"hipv4-", "hip-"}) {
+ if ((pos = entry.find(prefix)) == 0) {
+ entry_ident = entry.substr(std::char_traits<char>::length(prefix));
+ break;
+ }
+ }
+
+ if (!entry_ident.empty()) {
+ std::string best_entry;
+ for (const auto& [co_entry, co_ident] : entry_ids_with_idents) {
+ if (entry_ident == co_ident) {
+ best_entry = co_entry;
+ break;
+ } else if (metadata::isCompatibleIsaName(entry_ident, co_ident)) {
+ best_entry = co_entry;
+ }
+ }
+
+ if (!best_entry.empty()) {
+ compat_entry = best_entry;
+ }
+ }
+
+ BundlerConfig.TargetNames.push_back(compat_entry);

// Add an output file for each target
std::string output_file_name = output_prefix + '-' + entry + "." +
diff --git a/amd/comgr/src/comgr-metadata.h b/amd/comgr/src/comgr-metadata.h
index 8c2ba7ee4f9f..08aebdb76e89 100644
--- a/amd/comgr/src/comgr-metadata.h
+++ b/amd/comgr/src/comgr-metadata.h
@@ -55,6 +55,8 @@ amd_comgr_status_t getIsaMetadata(llvm::StringRef IsaName,

bool isValidIsaName(llvm::StringRef IsaName);

+bool isCompatibleIsaName(llvm::StringRef IsaName, llvm::StringRef CodeObjectIsaName);
+
amd_comgr_status_t getElfIsaName(DataObject *DataP, std::string &IsaName);

amd_comgr_status_t lookUpCodeObject(DataObject *DataP,
--
2.47.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
From a439e4f37ce71de48d4a979594276e3be0e6278f Mon Sep 17 00:00:00 2001
From: Gavin Zhao <[email protected]>
Date: Fri, 20 Dec 2024 16:04:41 -0500
Subject: [PATCH] [Comgr] Extend ISA compatibility

Signed-off-by: Gavin Zhao <[email protected]>
---
amd/comgr/src/comgr-metadata.cpp | 52 +++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/amd/comgr/src/comgr-metadata.cpp b/amd/comgr/src/comgr-metadata.cpp
index 5571808be0e7..dcd4e66927a8 100644
--- a/amd/comgr/src/comgr-metadata.cpp
+++ b/amd/comgr/src/comgr-metadata.cpp
@@ -923,6 +923,55 @@ static constexpr const char *CLANG_OFFLOAD_BUNDLER_MAGIC =
static constexpr size_t OffloadBundleMagicLen =
strLiteralLength(CLANG_OFFLOAD_BUNDLER_MAGIC);

+struct GfxPattern {
+ StringRef root;
+ StringRef suffixes;
+};
+
+static bool matches(const GfxPattern& p, const StringRef s) {
+ if (p.root.size() + 1 != s.size()) {
+ return false;
+ }
+ if (0 != std::memcmp(p.root.data(), s.data(), p.root.size())) {
+ return false;
+ }
+ return p.suffixes.find(s[p.root.size()]) != std::string::npos;
+}
+
+static bool isGfx900EquivalentProcessor(const StringRef processor) {
+ return matches(GfxPattern{"gfx90", "029c"}, processor);
+}
+
+static bool isGfx900SupersetProcessor(const StringRef processor) {
+ return matches(GfxPattern{"gfx90", "0269c"}, processor);
+}
+
+static bool isGfx1030EquivalentProcessor(const StringRef processor) {
+ return matches(GfxPattern{"gfx103", "0123456"}, processor);
+}
+
+static bool isGfx1010EquivalentProcessor(const StringRef processor) {
+ return matches(GfxPattern{"gfx101", "0"}, processor);
+}
+
+static bool isGfx1010SupersetProcessor(const StringRef processor) {
+ return matches(GfxPattern{"gfx101", "0123"}, processor);
+}
+
+static bool isIsaCompatible(const StringRef isaIdent, const StringRef codeObjectIdent) {
+ if (isaIdent == codeObjectIdent) {
+ return true;
+ } else if (isGfx900SupersetProcessor(isaIdent) && isGfx900EquivalentProcessor(codeObjectIdent)) {
+ return true;
+ } else if (isGfx1010SupersetProcessor(isaIdent) && isGfx1010EquivalentProcessor(codeObjectIdent)) {
+ return true;
+ } else if (isGfx1030EquivalentProcessor(isaIdent) && isGfx1030EquivalentProcessor(codeObjectIdent)) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
bool isCompatibleIsaName(StringRef IsaName, StringRef CodeObjectIsaName) {
if (IsaName == CodeObjectIsaName) {
return true;
@@ -938,7 +987,8 @@ bool isCompatibleIsaName(StringRef IsaName, StringRef CodeObjectIsaName) {
return false;
}

- if (CodeObjectIdent.Processor != IsaIdent.Processor) {
+ if (CodeObjectIdent.Processor != IsaIdent.Processor
+ && !isIsaCompatible(IsaIdent.Processor, CodeObjectIdent.Processor)) {
return false;
}

--
2.47.0

This file was deleted.

6 changes: 3 additions & 3 deletions packages/r/rocm-compilersupport/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ environment: |
export ROCM_PATH=/usr
export CMAKE_PREFIX_PATH=/usr/lib64/llvm-rocm
export HIP_DEVICE_LIB_PATH=/usr/lib64/amdgcn/bitcode
cd amd/comgr
setup : |
%patch -p3 -i $pkgfiles/0001-Extend-ROCm-CompilerSupport-HIP-ISA-compatibility.patch
%cmake_ninja -L -DBUILD_TESTING=ON
%patch -p1 -i $pkgfiles/0001-Comgr-Extend-ISA-compatibility.patch
%patch -p1 -i $pkgfiles/0001-Comgr-Extend-ISA-compatibility-for-CCOB.patch
%cmake_ninja -S amd/comgr -L -DBUILD_TESTING=ON
build : |
%ninja_build
install : |
Expand Down
2 changes: 1 addition & 1 deletion packages/r/rocm-compilersupport/pspec_x86_64.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</Package>
<History>
<Update release="7">
<Date>2024-11-27</Date>
<Date>2024-12-21</Date>
<Version>6.2.4</Version>
<Comment>Packaging update</Comment>
<Name>Gavin Zhao</Name>
Expand Down

0 comments on commit 9077bb5

Please sign in to comment.