rocm-runtime-ext: init at 3.5.1

This package provides the closed-source extension for rocm-runtime
that is necessary for OpenCL image processing.
This commit is contained in:
Daniël de Kok
2020-07-16 14:56:33 +02:00
parent d2754e07bb
commit 68fecda43a
5 changed files with 89 additions and 8 deletions
@@ -1,4 +1,9 @@
{ stdenv, fetchFromGitHub, cmake, elfutils, rocm-thunk }:
{ stdenv
, fetchFromGitHub
, addOpenGLRunpath
, cmake
, elfutils
, rocm-thunk }:
stdenv.mkDerivation rec {
pname = "rocm-runtime";
@@ -17,14 +22,15 @@ stdenv.mkDerivation rec {
cmakeFlags = [ "-DCMAKE_PREFIX_PATH=${rocm-thunk}" ];
# Use the ROCR_EXT_DIR environment variable to try to find
# binary-only extension libraries. This environment variable is set
# by the `rocr-ext` derivation. If that derivation is not in scope,
# then the extension libraries are not loaded. Without this edit, we
# would have to rely on LD_LIBRARY_PATH to let the HSA runtime
# discover the shared libraries.
# Use the ROCR_EXT_DIR environment variable and/or OpenGL driver
# link path to try to find binary-only ROCm runtime extension
# libraries. Without this change, we would have to rely on
# LD_LIBRARY_PATH to let the HSA runtime discover the shared
# libraries.
patchPhase = ''
sed 's/\(k\(Image\|Finalizer\)Lib\[os_index(os::current_os)\]\)/os::GetEnvVar("ROCR_EXT_DIR") + "\/" + \1/g' -i core/runtime/runtime.cpp
substitute '${./rocr-ext-dir.diff}' ./rocr-ext-dir.diff \
--subst-var-by rocrExtDir "${addOpenGLRunpath.driverLink}/lib/rocm-runtime-ext"
patch -p2 < ./rocr-ext-dir.diff
'';
fixupPhase = ''
@@ -0,0 +1,24 @@
diff --git a/src/core/util/lnx/os_linux.cpp b/src/core/util/lnx/os_linux.cpp
index fdbe19a..42d4ef8 100644
--- a/src/core/util/lnx/os_linux.cpp
+++ b/src/core/util/lnx/os_linux.cpp
@@ -161,8 +161,17 @@ static_assert(sizeof(Mutex) == sizeof(pthread_mutex_t*), "OS abstraction size mi
static_assert(sizeof(Thread) == sizeof(os_thread*), "OS abstraction size mismatch");
LibHandle LoadLib(std::string filename) {
- void* ret = dlopen(filename.c_str(), RTLD_LAZY);
- if (ret == nullptr) debug_print("LoadLib(%s) failed: %s\n", filename.c_str(), dlerror());
+ std::string extDirFilename = GetEnvVar("ROCR_EXT_DIR") + "/" + filename;
+ void* ret = dlopen(extDirFilename.c_str(), RTLD_LAZY);
+
+ // Attempt to load from the directory hardcoded by rocrExtDir.
+ if (ret == nullptr) {
+ std::string runpathFilename = std::string("@rocrExtDir@") + "/" + filename;
+ ret = dlopen(runpathFilename.c_str(), RTLD_LAZY);
+
+ if (ret == nullptr) debug_print("LoadLib(%s) failed: %s\n", filename.c_str(), dlerror());
+ }
+
return *(LibHandle*)&ret;
}