2021-09-18 10:52:07 +00:00
|
|
|
{ stdenv
|
|
|
|
, binutils-unwrapped
|
|
|
|
, clang
|
|
|
|
, cmake
|
|
|
|
, fetchFromGitHub
|
|
|
|
, fetchpatch
|
|
|
|
, file
|
|
|
|
, lib
|
2021-12-24 04:21:11 +00:00
|
|
|
, libglvnd
|
|
|
|
, libX11
|
|
|
|
, libxml2
|
2021-09-18 10:52:07 +00:00
|
|
|
, llvm
|
|
|
|
, makeWrapper
|
2021-12-24 04:21:11 +00:00
|
|
|
, numactl
|
2021-09-18 10:52:07 +00:00
|
|
|
, perl
|
2022-02-10 20:34:41 +00:00
|
|
|
, python3
|
2022-11-04 12:27:35 +00:00
|
|
|
, python3Packages
|
2021-09-18 10:52:07 +00:00
|
|
|
, rocclr
|
|
|
|
, rocm-comgr
|
|
|
|
, rocm-device-libs
|
|
|
|
, rocm-opencl-runtime
|
|
|
|
, rocm-runtime
|
|
|
|
, rocm-thunk
|
|
|
|
, rocminfo
|
2022-09-14 18:05:37 +00:00
|
|
|
, substituteAll
|
2021-09-18 10:52:07 +00:00
|
|
|
, writeScript
|
|
|
|
, writeText
|
|
|
|
}:
|
|
|
|
|
2021-12-24 04:21:11 +00:00
|
|
|
let
|
2022-11-27 09:42:12 +00:00
|
|
|
hip = stdenv.mkDerivation (finalAttrs: {
|
2021-12-24 04:21:11 +00:00
|
|
|
pname = "hip";
|
2022-12-17 10:02:37 +00:00
|
|
|
version = "5.4.0";
|
2021-12-24 04:21:11 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ROCm-Developer-Tools";
|
|
|
|
repo = "HIP";
|
2022-11-27 09:42:12 +00:00
|
|
|
rev = "rocm-${finalAttrs.version}";
|
2022-12-17 10:02:37 +00:00
|
|
|
hash = "sha256-34SJM2n3jZWIS2uwpboWOXVFhaVWGK5ELPKD/cJc1zw=";
|
2021-12-24 04:21:11 +00:00
|
|
|
};
|
|
|
|
|
2022-09-14 18:05:37 +00:00
|
|
|
patches = [
|
|
|
|
(substituteAll {
|
|
|
|
src = ./hip-config-paths.patch;
|
|
|
|
inherit llvm;
|
|
|
|
rocm_runtime = rocm-runtime;
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2021-12-24 04:21:11 +00:00
|
|
|
# - fix bash paths
|
|
|
|
# - fix path to rocm_agent_enumerator
|
|
|
|
# - fix hcc path
|
|
|
|
# - fix hcc version parsing
|
|
|
|
# - add linker flags for libhsa-runtime64 and hc_am since libhip_hcc
|
|
|
|
# refers to them.
|
|
|
|
prePatch = ''
|
|
|
|
for f in $(find bin -type f); do
|
|
|
|
sed -e 's,#!/usr/bin/perl,#!${perl}/bin/perl,' \
|
|
|
|
-e 's,#!/bin/bash,#!${stdenv.shell},' \
|
|
|
|
-i "$f"
|
|
|
|
done
|
|
|
|
|
2022-02-10 20:34:41 +00:00
|
|
|
sed 's,#!/usr/bin/python,#!${python3.interpreter},' -i hip_prof_gen.py
|
2021-12-24 04:21:11 +00:00
|
|
|
|
|
|
|
sed -e 's,$ROCM_AGENT_ENUM = "''${ROCM_PATH}/bin/rocm_agent_enumerator";,$ROCM_AGENT_ENUM = "${rocminfo}/bin/rocm_agent_enumerator";,' \
|
|
|
|
-e 's,^\($DEVICE_LIB_PATH=\).*$,\1"${rocm-device-libs}/amdgcn/bitcode";,' \
|
|
|
|
-e 's,^\($HIP_COMPILER=\).*$,\1"clang";,' \
|
|
|
|
-e 's,^\($HIP_RUNTIME=\).*$,\1"ROCclr";,' \
|
|
|
|
-e 's,^\([[:space:]]*$HSA_PATH=\).*$,\1"${rocm-runtime}";,'g \
|
2022-08-21 13:32:41 +00:00
|
|
|
-e 's,^\([[:space:]]*\)$HIP_CLANG_INCLUDE_PATH = abs_path("$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/include");,\1$HIP_CLANG_INCLUDE_PATH = "${llvm}/lib/clang/$HIP_CLANG_VERSION/include";,' \
|
2021-12-24 04:21:11 +00:00
|
|
|
-e 's,^\([[:space:]]*$HIPCXXFLAGS .= " -isystem \\"$HIP_CLANG_INCLUDE_PATH/..\\"\)";,\1 -isystem ${rocm-runtime}/include";,' \
|
2022-08-21 13:32:41 +00:00
|
|
|
-e 's,$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION,$HIP_CLANG_PATH/../resource-root,g' \
|
2021-12-24 04:21:11 +00:00
|
|
|
-e 's,`file,`${file}/bin/file,g' \
|
|
|
|
-e 's,`readelf,`${binutils-unwrapped}/bin/readelf,' \
|
|
|
|
-e 's, ar , ${binutils-unwrapped}/bin/ar ,g' \
|
2022-03-30 09:31:56 +00:00
|
|
|
-i bin/hipcc.pl
|
2021-12-24 04:21:11 +00:00
|
|
|
|
|
|
|
sed -e 's,^\($HSA_PATH=\).*$,\1"${rocm-runtime}";,' \
|
|
|
|
-e 's,^\($HIP_CLANG_PATH=\).*$,\1"${clang}/bin";,' \
|
|
|
|
-e 's,^\($HIP_PLATFORM=\).*$,\1"amd";,' \
|
|
|
|
-e 's,$HIP_CLANG_PATH/llc,${llvm}/bin/llc,' \
|
|
|
|
-e 's, abs_path, Cwd::abs_path,' \
|
2022-03-30 09:31:56 +00:00
|
|
|
-i bin/hipconfig.pl
|
2021-12-24 04:21:11 +00:00
|
|
|
|
|
|
|
sed -e 's, abs_path, Cwd::abs_path,' -i bin/hipvars.pm
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = "";
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p $out
|
|
|
|
cp -r * $out/
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "C++ Heterogeneous-Compute Interface for Portability";
|
|
|
|
homepage = "https://github.com/ROCm-Developer-Tools/HIP";
|
|
|
|
license = licenses.mit;
|
2022-11-27 09:42:12 +00:00
|
|
|
maintainers = with maintainers; [ lovesegfault ] ++ teams.rocm.members;
|
2021-12-24 04:21:11 +00:00
|
|
|
platforms = platforms.linux;
|
|
|
|
};
|
2022-11-27 09:42:12 +00:00
|
|
|
});
|
2021-12-24 04:21:11 +00:00
|
|
|
in
|
2022-11-27 09:42:12 +00:00
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2021-12-24 04:21:11 +00:00
|
|
|
pname = "hip";
|
2022-12-17 10:02:37 +00:00
|
|
|
version = "5.4.0";
|
2021-12-24 04:21:11 +00:00
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ROCm-Developer-Tools";
|
2021-12-24 04:21:11 +00:00
|
|
|
repo = "hipamd";
|
2022-11-27 09:42:12 +00:00
|
|
|
rev = "rocm-${finalAttrs.version}";
|
2022-12-17 10:02:37 +00:00
|
|
|
hash = "sha256-VL0vZVv099pZPX0J2pXPFvrhkVO/b6X+ZZDaD9B1hYI=";
|
2021-09-18 10:52:07 +00:00
|
|
|
};
|
|
|
|
|
2022-02-10 20:34:41 +00:00
|
|
|
nativeBuildInputs = [ cmake python3 makeWrapper perl ];
|
2022-11-04 12:27:35 +00:00
|
|
|
buildInputs = [ libxml2 numactl libglvnd libX11 python3Packages.cppheaderparser ];
|
2021-09-18 10:52:07 +00:00
|
|
|
propagatedBuildInputs = [
|
|
|
|
clang
|
|
|
|
llvm
|
|
|
|
rocm-comgr
|
|
|
|
rocm-device-libs
|
|
|
|
rocm-runtime
|
|
|
|
rocm-thunk
|
|
|
|
rocminfo
|
|
|
|
];
|
|
|
|
|
2022-09-14 18:05:37 +00:00
|
|
|
patches = [
|
|
|
|
(substituteAll {
|
|
|
|
src = ./hipamd-config-paths.patch;
|
2022-10-21 18:38:19 +00:00
|
|
|
inherit clang llvm hip;
|
2022-09-14 18:05:37 +00:00
|
|
|
rocm_runtime = rocm-runtime;
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
prePatch = ''
|
|
|
|
sed -e 's,#!/bin/bash,#!${stdenv.shell},' \
|
|
|
|
-i src/hip_embed_pch.sh
|
|
|
|
'';
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
preConfigure = ''
|
|
|
|
export HIP_CLANG_PATH=${clang}/bin
|
|
|
|
export DEVICE_LIB_PATH=${rocm-device-libs}/lib
|
|
|
|
'';
|
|
|
|
|
|
|
|
cmakeFlags = [
|
|
|
|
"-DHIP_PLATFORM=amd"
|
2021-12-24 04:21:11 +00:00
|
|
|
"-DAMD_OPENCL_PATH=${rocm-opencl-runtime.src}"
|
|
|
|
"-DHIP_COMMON_DIR=${hip}"
|
|
|
|
"-DROCCLR_PATH=${rocclr}"
|
2022-03-30 09:31:56 +00:00
|
|
|
"-DHIP_VERSION_BUILD_ID=0"
|
2022-11-04 12:27:35 +00:00
|
|
|
# Temporarily set variables to work around upstream CMakeLists issue
|
|
|
|
# Can be removed once https://github.com/ROCm-Developer-Tools/hipamd/issues/55 is fixed
|
|
|
|
"-DCMAKE_INSTALL_BINDIR=bin"
|
|
|
|
"-DCMAKE_INSTALL_INCLUDEDIR=include"
|
|
|
|
"-DCMAKE_INSTALL_LIBDIR=lib"
|
2021-09-18 10:52:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
postInstall = ''
|
2022-08-21 13:32:41 +00:00
|
|
|
patchShebangs $out/bin
|
|
|
|
wrapProgram $out/bin/hipcc --set HIP_PATH $out --set HSA_PATH ${rocm-runtime} --set HIP_CLANG_PATH ${clang}/bin --prefix PATH : ${llvm}/bin --set ROCM_PATH $out
|
2021-09-18 10:52:07 +00:00
|
|
|
wrapProgram $out/bin/hipconfig --set HIP_PATH $out --set HSA_PATH ${rocm-runtime} --set HIP_CLANG_PATH ${clang}/bin
|
|
|
|
'';
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
# TODO: Separate HIP and hipamd into separate derivations
|
2021-09-18 10:52:07 +00:00
|
|
|
passthru.updateScript = writeScript "update.sh" ''
|
|
|
|
#!/usr/bin/env nix-shell
|
2022-08-21 13:32:41 +00:00
|
|
|
#!nix-shell -i bash -p curl jq common-updater-scripts nix-prefetch-github
|
2022-12-17 10:02:37 +00:00
|
|
|
version="$(curl ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
|
|
|
|
-sL "https://api.github.com/repos/ROCm-Developer-Tools/HIP/releases?per_page=1" | jq '.[0].tag_name | split("-") | .[1]' --raw-output)"
|
|
|
|
|
|
|
|
IFS='.' read -a version_arr <<< "$version"
|
|
|
|
|
|
|
|
if [ "''${#version_arr[*]}" == 2 ]; then
|
|
|
|
version="''${version}.0"
|
|
|
|
fi
|
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
current_version="$(grep "version =" pkgs/development/compilers/hip/default.nix | head -n1 | cut -d'"' -f2)"
|
|
|
|
if [[ "$version" != "$current_version" ]]; then
|
|
|
|
tarball_meta="$(nix-prefetch-github ROCm-Developer-Tools HIP --rev "rocm-$version")"
|
|
|
|
tarball_hash="$(nix to-base64 sha256-$(jq -r '.sha256' <<< "$tarball_meta"))"
|
|
|
|
sed -i -z "pkgs/development/compilers/hip/default.nix" \
|
|
|
|
-e 's,version = "[^'"'"'"]*",version = "'"$version"'",1' \
|
|
|
|
-e 's,hash = "[^'"'"'"]*",hash = "sha256-'"$tarball_hash"'",1'
|
|
|
|
else
|
|
|
|
echo hip already up-to-date
|
|
|
|
fi
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
version="$(curl ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
|
|
|
|
-sL "https://api.github.com/repos/ROCm-Developer-Tools/hipamd/releases?per_page=1" | jq '.[0].tag_name | split("-") | .[1]' --raw-output)"
|
|
|
|
|
|
|
|
IFS='.' read -a version_arr <<< "$version"
|
|
|
|
|
|
|
|
if [ "''${#version_arr[*]}" == 2 ]; then
|
|
|
|
version="''${version}.0"
|
|
|
|
fi
|
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
current_version="$(grep "version =" pkgs/development/compilers/hip/default.nix | tail -n1 | cut -d'"' -f2)"
|
|
|
|
if [[ "$version" != "$current_version" ]]; then
|
|
|
|
tarball_meta="$(nix-prefetch-github ROCm-Developer-Tools hipamd --rev "rocm-$version")"
|
|
|
|
tarball_hash="$(nix to-base64 sha256-$(jq -r '.sha256' <<< "$tarball_meta"))"
|
|
|
|
sed -i -z "pkgs/development/compilers/hip/default.nix" \
|
|
|
|
-e 's,version = "[^'"'"'"]*",version = "'"$version"'",2' \
|
|
|
|
-e 's,hash = "[^'"'"'"]*",hash = "sha256-'"$tarball_hash"'",2'
|
|
|
|
else
|
|
|
|
echo hipamd already up-to-date
|
|
|
|
fi
|
2021-09-18 10:52:07 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "C++ Heterogeneous-Compute Interface for Portability";
|
2021-12-24 04:21:11 +00:00
|
|
|
homepage = "https://github.com/ROCm-Developer-Tools/hipamd";
|
2021-09-18 10:52:07 +00:00
|
|
|
license = licenses.mit;
|
2022-11-27 09:42:12 +00:00
|
|
|
maintainers = with maintainers; [ lovesegfault ] ++ teams.rocm.members;
|
2021-09-18 10:52:07 +00:00
|
|
|
platforms = platforms.linux;
|
|
|
|
};
|
2022-11-27 09:42:12 +00:00
|
|
|
})
|