Skip to content

Commit

Permalink
rocm-clr: bring back after ROCm 6 revert
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Zhao <git@gzgz.dev>
  • Loading branch information
GZGavinZhao committed Apr 7, 2024
1 parent 507a817 commit 0aeb066
Show file tree
Hide file tree
Showing 16 changed files with 2,232 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/r/rocm-clr/abi_libs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
libamdhip64.so.6
libamdocl64.so.6
libcltrace.so.6
libhiprtc-builtins.so.6
libhiprtc.so.6
603 changes: 603 additions & 0 deletions packages/r/rocm-clr/abi_symbols

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/r/rocm-clr/abi_used_libs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ld-linux-x86-64.so.2
libOpenCL.so.1
libamd_comgr.so.2
libc.so.6
libgcc_s.so.1
libhsa-runtime64.so.1
libm.so.6
libnuma.so.1
libstdc++.so.6
405 changes: 405 additions & 0 deletions packages/r/rocm-clr/abi_used_symbols

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
From c40c4ea099b4910c0d8206282b24c8db48043797 Mon Sep 17 00:00:00 2001
From: Gavin Zhao <git@gzgz.dev>
Date: Sat, 20 Jan 2024 11:00:02 -0500
Subject: [PATCH] Add HIP_CLANG_LAUNCHER for launching Clang through a wrapper
executable

Signed-off-by: Gavin Zhao <git@gzgz.dev>
---
amd/hipcc/bin/hipcc.pl | 10 ++++++++++
amd/hipcc/src/hipBin_amd.h | 5 +++++
amd/hipcc/src/hipBin_base.h | 5 +++++
3 files changed, 20 insertions(+)

diff --git a/amd/hipcc/bin/hipcc.pl b/amd/hipcc/bin/hipcc.pl
index 53b622286d5e6f..1215409caef01c 100755
--- a/amd/hipcc/bin/hipcc.pl
+++ b/amd/hipcc/bin/hipcc.pl
@@ -44,6 +44,9 @@
# HIP_ROCCLR_HOME : Path to HIP/ROCclr directory. Used on AMD platforms only.
# HIP_CLANG_PATH : Path to HIP-Clang (default to ../../llvm/bin relative to this
# script's abs_path). Used on AMD platforms only.
+# HIP_CLANG_LAUNCHER: Path to an executable to launch HIP-Clang with.
+# Analogous to CMAKE_C_COMPILER_LAUNCHER, this is commonly
+# used for launching HIP-Clang through a compiler cache.

if(scalar @ARGV == 0){
print "No Arguments passed, exiting ...\n";
@@ -83,6 +86,8 @@ sub get_path_options {
$HIP_CLANG_HCC_COMPAT_MODE=$ENV{'HIP_CLANG_HCC_COMPAT_MODE'}; # HCC compatibility mode
$HIP_COMPILE_CXX_AS_HIP=$ENV{'HIP_COMPILE_CXX_AS_HIP'} // "1";

+$HIP_CLANG_LAUNCHER=$ENV{'HIP_CLANG_LAUNCHER'};
+
#---
# Temporary directories
my @tmpDirs = ();
@@ -193,6 +198,7 @@ sub get_normalized_path {
print ("HIP_LIB_PATH=$HIP_LIB_PATH\n");
print ("DEVICE_LIB_PATH=$DEVICE_LIB_PATH\n");
print ("HIP_CLANG_RT_LIB=$HIP_CLANG_RT_LIB\n");
+ print ("HIP_CLANG_LAUNCHER=$HIP_CLANG_LAUNCHER\n");
}

if ($HIP_CLANG_HCC_COMPAT_MODE) {
@@ -594,6 +600,10 @@ sub get_normalized_path {
# TODO: convert CMD to an array rather than a string
my $CMD="$HIPCC";

+if ($HIP_CLANG_LAUNCHER) {
+ $CMD = "\"$HIP_CLANG_LAUNCHER\" \"$CMD\"";
+}
+
if ($needCFLAGS) {
$CMD .= " $HIPCFLAGS";
}
diff --git a/amd/hipcc/src/hipBin_amd.h b/amd/hipcc/src/hipBin_amd.h
index 01581b4d9b529c..92e7697188ae1e 100644
--- a/amd/hipcc/src/hipBin_amd.h
+++ b/amd/hipcc/src/hipBin_amd.h
@@ -878,6 +878,11 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
string compiler;
compiler = getHipCC();
string CMD = compiler;
+
+ if (!var.hipClangLauncher_.empty()) {
+ CMD = "\"" + var.hipClangLauncher_ + "\" \"" + compiler + "\"";
+ }
+
if (needCFLAGS) {
CMD += " " + HIPCFLAGS;
}
diff --git a/amd/hipcc/src/hipBin_base.h b/amd/hipcc/src/hipBin_base.h
index c459d16b086cb6..7efb0ed45957f3 100644
--- a/amd/hipcc/src/hipBin_base.h
+++ b/amd/hipcc/src/hipBin_base.h
@@ -50,6 +50,7 @@ THE SOFTWARE.
# define HIP_COMPILE_CXX_AS_HIP "HIP_COMPILE_CXX_AS_HIP"
# define HIPCC_VERBOSE "HIPCC_VERBOSE"
# define HCC_AMDGPU_TARGET "HCC_AMDGPU_TARGET"
+# define HIP_CLANG_LAUNCHER "HIP_CLANG_LAUNCHER"

# define HIP_BASE_VERSION_MAJOR "6"
# define HIP_BASE_VERSION_MINOR "0"
@@ -157,6 +158,7 @@ struct EnvVariables {
string hipClangHccCompactModeEnv_ = "";
string hipCompileCxxAsHipEnv_ = "";
string hccAmdGpuTargetEnv_ = "";
+ string hipClangLauncher_ = "";
friend std::ostream& operator <<(std::ostream& os, const EnvVariables& var) {
os << "Path: " << var.path_ << endl;
os << "Hip Path: " << var.hipPathEnv_ << endl;
@@ -181,6 +183,7 @@ struct EnvVariables {
os << "Hip Compile Cxx as Hip: " <<
var.hipCompileCxxAsHipEnv_ << endl;
os << "Hcc Amd Gpu Target: " << var.hccAmdGpuTargetEnv_ << endl;
+ os << "Hip Clang launcher: " << var.hipClangLauncher_ << endl;
return os;
}
};
@@ -316,6 +319,8 @@ void HipBinBase::readEnvVariables() {
envVariables_.hipClangHccCompactModeEnv_ = hipClangHccCompactMode;
if (const char* hipCompileCxxAsHip = std::getenv(HIP_COMPILE_CXX_AS_HIP))
envVariables_.hipCompileCxxAsHipEnv_ = hipCompileCxxAsHip;
+ if (const char* hipClangLuancher = std::getenv(HIP_CLANG_LAUNCHER))
+ envVariables_.hipClangLauncher_ = hipClangLuancher;
}

// constructs the HIP path
28 changes: 28 additions & 0 deletions packages/r/rocm-clr/files/0001-Remove-isystem-include-paths.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From ffac473657e2659d314bc6095ddd175d9023f8d1 Mon Sep 17 00:00:00 2001
From: Gavin Zhao <git@gzgz.dev>
Date: Sun, 24 Dec 2023 12:00:05 -0500
Subject: [PATCH] Remove isystem include paths

Signed-off-by: Gavin Zhao <git@gzgz.dev>
---
bin/hipcc.pl | 4 ----
1 file changed, 4 deletions(-)

diff --git a/bin/hipcc.pl b/bin/hipcc.pl
index 513a427..53b6222 100755
--- a/bin/hipcc.pl
+++ b/bin/hipcc.pl
@@ -218,10 +218,6 @@ if ($HIP_PLATFORM eq "amd") {
exit (-1);
}

-# Add paths to common HIP includes:
-$HIPCXXFLAGS .= " -isystem " . get_normalized_path("$HIP_INCLUDE_PATH");
-$HIPCFLAGS .= " -isystem " . get_normalized_path("$HIP_INCLUDE_PATH");
-
my $compileOnly = 0;
my $needCXXFLAGS = 0; # need to add CXX flags to compile step
my $needCFLAGS = 0; # need to add C flags to compile step
--
2.43.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
From 87136d5807502e43dbcf4c41d4ed58338803e8b9 Mon Sep 17 00:00:00 2001
From: taosang2 <tao.sang@amd.com>
Date: Fri, 15 Dec 2023 10:38:06 -0500
Subject: [PATCH 1/5] SWDEV-435296 - Fix sporatic segment fault

Fix sporatic segment fault in texture test
via retaining image in texture object which
references the image.
The image will be released when the texture
object is destroyed.

Change-Id: Ic3fefa2d5dda6afebd1acd4d41ad310b138af6dd
---
hipamd/src/hip_texture.cpp | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/hipamd/src/hip_texture.cpp b/hipamd/src/hip_texture.cpp
index 9eba4bd0f..55e1d0b73 100644
--- a/hipamd/src/hip_texture.cpp
+++ b/hipamd/src/hip_texture.cpp
@@ -240,8 +240,8 @@ hipError_t ihipCreateTextureObject(hipTextureObject_t* pTexObject,
if (image == nullptr) {
return hipErrorInvalidValue;
}
- } else if (image->parent()) {
- image->retain(); // Because it will be released as a view in ihipDestroyTextureObject()
+ } else {
+ image->retain(); // will be released in ihipDestroyTextureObject()
}
break;
}
@@ -281,6 +281,8 @@ hipError_t ihipCreateTextureObject(hipTextureObject_t* pTexObject,
if (image == nullptr) {
return hipErrorInvalidValue;
}
+ } else {
+ image->retain(); // will be released in ihipDestroyTextureObject()
}
break;
}
@@ -373,15 +375,7 @@ hipError_t ihipDestroyTextureObject(hipTextureObject_t texObject) {
return hipErrorNotSupported;
}

- const hipResourceType type = texObject->resDesc.resType;
- const bool isImageFromBuffer = (type == hipResourceTypeLinear) || (type == hipResourceTypePitch2D);
- const bool isImageView = ((type == hipResourceTypeArray) || (type == hipResourceTypeMipmappedArray)) &&
- texObject->image->parent() != nullptr;
- // If the texture object was created from an array, then the array owns the image SRD.
- // Otherwise, if the texture object is a view, or was created from a buffer, then it owns the image SRD.
- if (isImageFromBuffer || isImageView) {
- texObject->image->release();
- }
+ texObject->image->release();

// The texture object always owns the sampler SRD.
texObject->sampler->release();
--
2.43.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
From 2783c57b0f225ad8bc553e2d244837d57d8375bc Mon Sep 17 00:00:00 2001
From: Cordell Bloor <cgmb@slerp.xyz>
Date: Wed, 13 Jul 2022 18:45:41 -0600
Subject: [PATCH 2/5] improve rocclr isa compatibility check

There are a number of ISAs that are identical to each other, but are
not being treated as compatible by the upstream project. This more
sophisticated ISA compatibility check significantly reduces the number
of code objects that must be included in a binary in order to support
a wide variety of processors.

This change to rocclr is useless on its own because there are multiple
places in the ROCm stack where kernels are checked for compatibility.
However, when combined with matching changes within rocr and hipamd,
this patch should allow HIP to load compatible kernels even when the
GFX ISA number is not an exact match.

Signed-off-by: Gavin Zhao <git@gzgz.dev>
---
rocclr/device/device.cpp | 39 ++++++++++++++++++++++++++++++++++++---
1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/rocclr/device/device.cpp b/rocclr/device/device.cpp
index 0249f31d6..739bb027c 100644
--- a/rocclr/device/device.cpp
+++ b/rocclr/device/device.cpp
@@ -234,10 +234,43 @@ std::string Isa::isaName() const {
return std::string(hsaIsaNamePrefix) + targetId();
}

+template <class T, std::size_t N>
+static bool Contains(const std::array<T, N>& arr, const T& value) {
+ return std::find(std::begin(arr), std::end(arr), value) != std::end(arr);
+}
+
+static bool IsVersionCompatible(const Isa &codeObjectIsa,
+ const Isa &agentIsa) {
+ if (codeObjectIsa.versionMajor() == agentIsa.versionMajor() &&
+ codeObjectIsa.versionMinor() == agentIsa.versionMinor()) {
+
+ if (codeObjectIsa.versionStepping() == agentIsa.versionStepping()) {
+ return true; // exact match
+ }
+
+ // The code object and the agent may sometimes be compatible if
+ // they differ only by stepping version.
+ if (codeObjectIsa.versionMajor() == 9 &&
+ codeObjectIsa.versionMinor() == 0) {
+ const std::array<uint32_t, 4> equivalent_gfx90x = { 0, 2, 9, 12 };
+ if (Contains(equivalent_gfx90x, codeObjectIsa.versionStepping()) &&
+ Contains(equivalent_gfx90x, agentIsa.versionStepping())) {
+ return true; // gfx900 compatible object and agent
+ }
+ } else if (codeObjectIsa.versionMajor() == 10) {
+ if (codeObjectIsa.versionMinor() == 1) {
+ return true; // gfx1010 compatible object and agent
+ } else if (codeObjectIsa.versionMinor() == 3) {
+ return true; // gfx1030 compatible object and agent
+ }
+ }
+ }
+
+ return false;
+}
+
bool Isa::isCompatible(const Isa &codeObjectIsa, const Isa &agentIsa) {
- if (codeObjectIsa.versionMajor() != agentIsa.versionMajor() ||
- codeObjectIsa.versionMinor() != agentIsa.versionMinor() ||
- codeObjectIsa.versionStepping() != agentIsa.versionStepping())
+ if (!IsVersionCompatible(codeObjectIsa, agentIsa))
return false;

assert(codeObjectIsa.isSrameccSupported() == agentIsa.isSrameccSupported() &&
--
2.43.1

Loading

0 comments on commit 0aeb066

Please sign in to comment.