From 68fecda43ad8701677ab3e9c63bafc0c8d43494b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Wed, 15 Jul 2020 19:40:26 +0200 Subject: [PATCH] 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. --- .../libraries/rocm-runtime-ext/default.nix | 42 +++++++++++++++++++ .../libraries/rocm-runtime-ext/setup-hook.sh | 7 ++++ .../libraries/rocm-runtime/default.nix | 22 ++++++---- .../libraries/rocm-runtime/rocr-ext-dir.diff | 24 +++++++++++ pkgs/top-level/all-packages.nix | 2 + 5 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 pkgs/development/libraries/rocm-runtime-ext/default.nix create mode 100644 pkgs/development/libraries/rocm-runtime-ext/setup-hook.sh create mode 100644 pkgs/development/libraries/rocm-runtime/rocr-ext-dir.diff diff --git a/pkgs/development/libraries/rocm-runtime-ext/default.nix b/pkgs/development/libraries/rocm-runtime-ext/default.nix new file mode 100644 index 000000000000..3962804306a4 --- /dev/null +++ b/pkgs/development/libraries/rocm-runtime-ext/default.nix @@ -0,0 +1,42 @@ +{ stdenv, fetchurl, autoPatchelfHook, rpmextract, rocm-runtime }: + +stdenv.mkDerivation rec { + pname = "rocm-runtime-ext"; + version = "3.5.1"; + + src = fetchurl { + url = "https://repo.radeon.com/rocm/yum/3.5.1/hsa-ext-rocr-dev-1.1.30501.0-rocm-rel-3.5-34-def83d8a-Linux.rpm"; + sha256 = "0r7lrmnplr10hs6wrji55i3dnczfzlmp8jahm1g3mhq2x12zmly0"; + }; + + nativeBuildInputs = [ autoPatchelfHook rpmextract ]; + + buildInputs = [ rocm-runtime stdenv.cc.cc ]; + + unpackPhase = "rpmextract ${src}"; + + installPhase = '' + mkdir -p $out/lib + cp -R opt/rocm-${version}/hsa/lib $out/lib/rocm-runtime-ext + ''; + + setupHook = ./setup-hook.sh; + + meta = with stdenv.lib; { + description = "Platform runtime for ROCm (closed-source extensions)"; + longDescription = '' + This package provides closed-source extensions to the ROCm + runtime. Currently this adds support for OpenCL image + processing. + + In order for the ROCm runtime to pick up the extension, you + should either set the ROCR_EXT_DIR environment variable should + be set to ''${rocm-runtime-ext}/lib/rocm-runtime-ext or this + package should be added to the hardware.opengl.extraPackages + NixOS configuration option. + ''; + homepage = "https://github.com/RadeonOpenCompute/ROCR-Runtime"; + license = with licenses; [ unfreeRedistributable ]; + maintainers = with maintainers; [ danieldk ]; + }; +} diff --git a/pkgs/development/libraries/rocm-runtime-ext/setup-hook.sh b/pkgs/development/libraries/rocm-runtime-ext/setup-hook.sh new file mode 100644 index 000000000000..150d65570e61 --- /dev/null +++ b/pkgs/development/libraries/rocm-runtime-ext/setup-hook.sh @@ -0,0 +1,7 @@ +addRocmRuntimeExtDir () { + if [[ -z "${ROCR_EXT_DIR-}" ]]; then + export ROCR_EXT_DIR="@out@/lib/rocm-runtime-ext" + fi +} + +addEnvHooks "$hostOffset" addRocmRuntimeExtDir diff --git a/pkgs/development/libraries/rocm-runtime/default.nix b/pkgs/development/libraries/rocm-runtime/default.nix index e50557c4b30e..7470784d4896 100644 --- a/pkgs/development/libraries/rocm-runtime/default.nix +++ b/pkgs/development/libraries/rocm-runtime/default.nix @@ -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 = '' diff --git a/pkgs/development/libraries/rocm-runtime/rocr-ext-dir.diff b/pkgs/development/libraries/rocm-runtime/rocr-ext-dir.diff new file mode 100644 index 000000000000..928c76816548 --- /dev/null +++ b/pkgs/development/libraries/rocm-runtime/rocr-ext-dir.diff @@ -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; + } + diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 584ab994a8be..77d01570fcc0 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -9282,6 +9282,8 @@ in rocm-runtime = callPackage ../development/libraries/rocm-runtime { }; + rocm-runtime-ext = callPackage ../development/libraries/rocm-runtime-ext { }; + rocm-thunk = callPackage ../development/libraries/rocm-thunk { }; rtags = callPackage ../development/tools/rtags {